nanosvg: update to 9da543e
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Daniel Eklöf · committed by Daniel Eklöf · parent 8c012f2 · Browse files · 2 files·+50 added−22 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+50 added−22 removed
- other:+50 added−22 removed
Provenance
- Commit
633471e- Tree
d4f2f41- Author
Daniel Eklöf <daniel@ekloef.se>- Committer
Daniel Eklöf <daniel@ekloef.se>- Parent
8c012f2
2 files changed+50 added−22 removed
modified:3rd-party/nanosvg/src/nanosvg.h+49 added-21 removed
70 unmodified lines71 nsvgDelete(image);72 */73 74 enum NSVGpaintType {75+ NSVG_PAINT_UNDEF = -1,76 NSVG_PAINT_NONE = 0,77 NSVG_PAINT_COLOR = 1,78 NSVG_PAINT_LINEAR_GRADIENT = 2,79 NSVG_PAINT_RADIAL_GRADIENT = 339 unmodified lines119 NSVGgradientStop stops[1];120 } NSVGgradient;121 122 typedef struct NSVGpaint {122- char type;123+ signed char type;124 union {125 unsigned int color;126 NSVGgradient* gradient;127 };15 unmodified lines143 NSVGpaint stroke; // Stroke paint144 float opacity; // Opacity of the shape.145 float strokeWidth; // Stroke width (scaled).146 float strokeDashOffset; // Stroke dash offset (scaled).146- float strokeDashArray[8]; // Stroke dash array (scaled).147- char strokeDashCount; // Number of dash values in dash array.147+ float strokeDashArray[8]; // Stroke dash array (scaled).148+ char strokeDashCount; // Number of dash values in dash array.149 char strokeLineJoin; // Stroke join type.150 char strokeLineCap; // Stroke cap type.151 float miterLimit; // Miter limit152 char fillRule; // Fill rule, see NSVGfillRule.153 unsigned char flags; // Logical or of NSVG_FLAGS_* flags154 float bounds[4]; // Tight bounding box of the shape [minx,miny,maxx,maxy].155+ char fillGradient[64]; // Optional 'id' of fill gradient156+ char strokeGradient[64]; // Optional 'id' of stroke gradient157+ float xform[6]; // Root transformation for fill/stroke gradient158 NSVGpath* paths; // Linked list of paths in the image.159 struct NSVGshape* next; // Pointer to next shape, or NULL if last element.160 } NSVGshape;161 235 unmodified lines397 typedef struct NSVGgradientData398 {399 char id[64];400 char ref[64];397- char type;401+ signed char type;402 union {403 NSVGlinearData linear;404 NSVGradialData radial;405 };411 unmodified lines817 }818 return NULL;819 }820 817-static NSVGgradient* nsvg__createGradient(NSVGparser* p, const char* id, const float* localBounds, char* paintType)821+static NSVGgradient* nsvg__createGradient(NSVGparser* p, const char* id, const float* localBounds, float *xform, signed char* paintType)822 {819- NSVGattrib* attr = nsvg__getAttr(p);823 NSVGgradientData* data = NULL;824 NSVGgradientData* ref = NULL;825 NSVGgradientStop* stops = NULL;826 NSVGgradient* grad;66 unmodified lines893 grad->fy = fy / r;894 }895 896 nsvg__xformMultiply(grad->xform, data->xform);894- nsvg__xformMultiply(grad->xform, attr->xform);897+ nsvg__xformMultiply(grad->xform, xform);898 899 grad->spread = data->spread;900 memcpy(grad->stops, stops, nstops*sizeof(NSVGgradientStop));901 grad->nstops = nstops;55 unmodified lines957 if (shape == NULL) goto error;958 memset(shape, 0, sizeof(NSVGshape));959 960 memcpy(shape->id, attr->id, sizeof shape->id);961+ memcpy(shape->fillGradient, attr->fillGradient, sizeof shape->fillGradient);962+ memcpy(shape->strokeGradient, attr->strokeGradient, sizeof shape->strokeGradient);963+ memcpy(shape->xform, attr->xform, sizeof shape->xform);964 scale = nsvg__getAverageScale(attr->xform);965 shape->strokeWidth = attr->strokeWidth * scale;966 shape->strokeDashOffset = attr->strokeDashOffset * scale;967 shape->strokeDashCount = (char)attr->strokeDashCount;27 unmodified lines995 shape->fill.type = NSVG_PAINT_COLOR;996 shape->fill.color = attr->fillColor;997 shape->fill.color |= (unsigned int)(attr->fillOpacity*255) << 24;998 } else if (attr->hasFill == 2) {993- float inv[6], localBounds[4];994- nsvg__xformInverse(inv, attr->xform);995- nsvg__getLocalBounds(localBounds, shape, inv);996- shape->fill.gradient = nsvg__createGradient(p, attr->fillGradient, localBounds, &shape->fill.type);997- if (shape->fill.gradient == NULL) {998- shape->fill.type = NSVG_PAINT_NONE;999+ shape->fill.type = NSVG_PAINT_UNDEF;999- }1000 }1001 1002 // Set stroke1003 if (attr->hasStroke == 0) {2 unmodified lines1006 shape->stroke.type = NSVG_PAINT_COLOR;1007 shape->stroke.color = attr->strokeColor;1008 shape->stroke.color |= (unsigned int)(attr->strokeOpacity*255) << 24;1009 } else if (attr->hasStroke == 2) {1010- float inv[6], localBounds[4];1011- nsvg__xformInverse(inv, attr->xform);1012- nsvg__getLocalBounds(localBounds, shape, inv);1013- shape->stroke.gradient = nsvg__createGradient(p, attr->strokeGradient, localBounds, &shape->stroke.type);1014- if (shape->stroke.gradient == NULL)1015- shape->stroke.type = NSVG_PAINT_NONE;1010+ shape->stroke.type = NSVG_PAINT_UNDEF;1011 }1012 1013 // Set flags1014 shape->flags = (attr->visible ? NSVG_FLAGS_VISIBLE : 0x00);1620 unmodified lines2635 }2636 }2637 }2638 2644-static void nsvg__parseGradient(NSVGparser* p, const char** attr, char type)2639+static void nsvg__parseGradient(NSVGparser* p, const char** attr, signed char type)2640 {2641 int i;2642 NSVGgradientData* grad = (NSVGgradientData*)malloc(sizeof(NSVGgradientData));2643 if (grad == NULL) return;316 unmodified lines2960 shape->strokeDashArray[i] *= avgs;2961 }2962 }2963 2964+static void nsvg__createGradients(NSVGparser* p)2965+{2966+ NSVGshape* shape;2967+2968+ for (shape = p->image->shapes; shape != NULL; shape = shape->next) {2969+ if (shape->fill.type == NSVG_PAINT_UNDEF) {2970+ if (shape->fillGradient[0] != '\0') {2971+ float inv[6], localBounds[4];2972+ nsvg__xformInverse(inv, shape->xform);2973+ nsvg__getLocalBounds(localBounds, shape, inv);2974+ shape->fill.gradient = nsvg__createGradient(p, shape->fillGradient, localBounds, shape->xform, &shape->fill.type);2975+ }2976+ if (shape->fill.type == NSVG_PAINT_UNDEF) {2977+ shape->fill.type = NSVG_PAINT_NONE;2978+ }2979+ }2980+ if (shape->stroke.type == NSVG_PAINT_UNDEF) {2981+ if (shape->strokeGradient[0] != '\0') {2982+ float inv[6], localBounds[4];2983+ nsvg__xformInverse(inv, shape->xform);2984+ nsvg__getLocalBounds(localBounds, shape, inv);2985+ shape->stroke.gradient = nsvg__createGradient(p, shape->strokeGradient, localBounds, shape->xform, &shape->stroke.type);2986+ }2987+ if (shape->stroke.type == NSVG_PAINT_UNDEF) {2988+ shape->stroke.type = NSVG_PAINT_NONE;2989+ }2990+ }2991+ }2992+}2993+2994 NSVGimage* nsvgParse(char* input, const char* units, float dpi)2995 {2996 NSVGparser* p;2997 NSVGimage* ret = 0;5 unmodified lines3003 p->dpi = dpi;3004 3005 nsvg__parseXML(input, nsvg__startElement, nsvg__endElement, nsvg__content, p);3006 3007+ // Create gradients after all definitions have been parsed3008+ nsvg__createGradients(p);3009+3010 // Scale to viewBox3011 nsvg__scaleToViewbox(p, units);3012 3013 ret = p->image;85 unmodified linesmodified:3rd-party/nanosvg/src/nanosvgrast.h+1 added-1 removed
112 unmodified lines113 struct NSVGmemPage* next;114 } NSVGmemPage;115 116 typedef struct NSVGcachedPaint {117- char type;117+ signed char type;118 char spread;119 float xform[6];120 unsigned int colors[256];121 } NSVGcachedPaint;1337 unmodified lines