Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/memononen/nanosvg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorOlivier Galibert <galibert@pobox.com>2015-11-05 19:07:14 +0300
committerOlivier Galibert <galibert@pobox.com>2015-11-05 19:07:14 +0300
commitd023064305fd37405974b4b9735e3c8d4d28abfb (patch)
treece8db8bccea6cfe4bb591b074a5d56d2ee81f69d /src
parentd057a2c42557a1590f8e0a3383b5400dc0705006 (diff)
Fix the visibility attribute parsing, keep the information in the
shape and take it into account in the rendering.
Diffstat (limited to 'src')
-rw-r--r--src/nanosvg.h15
-rw-r--r--src/nanosvgrast.h3
2 files changed, 15 insertions, 3 deletions
diff --git a/src/nanosvg.h b/src/nanosvg.h
index 2cd1258..a952207 100644
--- a/src/nanosvg.h
+++ b/src/nanosvg.h
@@ -99,6 +99,10 @@ enum NSVGfillRule {
NSVG_FILLRULE_EVENODD = 1,
};
+enum NSVGflags {
+ NSVG_FLAGS_VISIBLE = 0x01
+};
+
typedef struct NSVGgradientStop {
unsigned int color;
float offset;
@@ -138,7 +142,8 @@ typedef struct NSVGshape
float strokeWidth; // Stroke width (scaled).
char strokeLineJoin; // Stroke join type.
char strokeLineCap; // Stroke cap type.
- char fillRule; // Fille rule, see NSVGfillRule.
+ char fillRule; // Fill rule, see NSVGfillRule.
+ unsigned char flags; // Logical or of NSVG_FLAGS_* flags
float bounds[4]; // Tight bounding box of the shape [minx,miny,maxx,maxy].
NSVGpath* paths; // Linked list of paths in the image.
struct NSVGshape* next; // Pointer to next shape, or NULL if last element.
@@ -155,6 +160,7 @@ typedef struct NSVGimage
NSVGimage* nsvgParseFromFile(const char* filename, const char* units, float dpi);
// Parses SVG file from a null terminated string, returns SVG image as paths.
+// Important note: changes the string.
NSVGimage* nsvgParse(char* input, const char* units, float dpi);
// Deletes list of paths.
@@ -858,6 +864,9 @@ static void nsvg__addShape(NSVGparser* p)
shape->stroke.type = NSVG_PAINT_NONE;
}
+ // Set flags
+ shape->flags = (attr->visible ? NSVG_FLAGS_VISIBLE : 0x00);
+
// Add to tail
prev = NULL;
cur = p->image->shapes;
@@ -1493,8 +1502,8 @@ static int nsvg__parseAttr(NSVGparser* p, const char* name, const char* value)
} else if (strcmp(name, "display") == 0) {
if (strcmp(value, "none") == 0)
attr->visible = 0;
- else
- attr->visible = 1;
+ // Don't reset ->visible on display:inline, one display:none hides the whole subtree
+
} else if (strcmp(name, "fill") == 0) {
if (strcmp(value, "none") == 0) {
attr->hasFill = 0;
diff --git a/src/nanosvgrast.h b/src/nanosvgrast.h
index a822d6a..fd05d43 100644
--- a/src/nanosvgrast.h
+++ b/src/nanosvgrast.h
@@ -1266,6 +1266,9 @@ void nsvgRasterize(NSVGrasterizer* r,
memset(&dst[i*stride], 0, w*4);
for (shape = image->shapes; shape != NULL; shape = shape->next) {
+ if (!(shape->flags & NSVG_FLAGS_VISIBLE))
+ continue;
+
if (shape->fill.type != NSVG_PAINT_NONE) {
nsvg__resetPool(r);
r->freelist = NULL;