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

NanoSVG.diff « patches « nanosvg « extern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 68dbb18573b04aa4971dad765df3269c02a21bf4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
diff --git a/c:/tmp/nanosvg_original.h b/c:/tmp/nanosvg_modif.h
index 24a01a86d3d..eca0d07e79d 100644
--- a/c:/tmp/nanosvg_original.h
+++ b/c:/tmp/nanosvg_modif.h
@@ -24,7 +24,8 @@
  *
  * Bounding box calculation based on http://blog.hackers-cafe.net/2009/06/how-to-calculate-bezier-curves-bounding.html
  *
- */
+ * This is a modified version for Blender used by importers.
+ **/
 
 #ifndef NANOSVG_H
 #define NANOSVG_H
@@ -148,6 +149,8 @@ extern "C" {
 	typedef struct NSVGshape
 	{
 		char id[64];				// Optional 'id' attr of the shape or its group
+		/* Blender: Parent ID used for layer creation. */
+  		char id_parent[64];		
 		NSVGpaint fill;				// Fill paint
 		NSVGpaint stroke;			// Stroke paint
 		float opacity;				// Opacity of the shape.
@@ -370,6 +373,7 @@ int nsvg__parseXML(char* input,
 /* Simple SVG parser. */
 
 #define NSVG_MAX_ATTR 128
+#define NSVG_MAX_BREADCRUMB 5
 
 enum NSVGgradientUnits
 {
@@ -471,6 +475,10 @@ typedef struct NSVGparser
 	float dpi;
 	char pathFlag;
 	char defsFlag;
+	/** Blender breadcrumb for layers. */
+  	char breadcrumb[NSVG_MAX_BREADCRUMB][64];
+  	/** Blender number of elements in breadcrumb. */
+  	int breadcrumb_len;
 } NSVGparser;
 
 static void nsvg__xformIdentity(float* t)
@@ -980,6 +988,14 @@ static void nsvg__addShape(NSVGparser* p)
 	memset(shape, 0, sizeof(NSVGshape));
 
 	memcpy(shape->id, attr->id, sizeof shape->id);
+	/* Copy parent id from breadcrumb. */
+	if (p->breadcrumb_len > 0) {
+		memcpy(shape->id_parent, p->breadcrumb[0], sizeof shape->id_parent);
+	}
+	else {
+		memcpy(shape->id_parent, attr->id, sizeof shape->id_parent);
+	}
+
 	scale = nsvg__getAverageScale(attr->xform);
 	shape->strokeWidth = attr->strokeWidth * scale;
 	shape->strokeDashOffset = attr->strokeDashOffset * scale;
@@ -2814,6 +2830,14 @@ static void nsvg__startElement(void* ud, const char* el, const char** attr)
 	if (strcmp(el, "g") == 0) {
 		nsvg__pushAttr(p);
 		nsvg__parseAttribs(p, attr);
+
+		/* Save the breadcrumb of groups. */
+		if (p->breadcrumb_len < NSVG_MAX_BREADCRUMB) {
+		NSVGattrib *attr_id = nsvg__getAttr(p);
+		memcpy(
+			p->breadcrumb[p->breadcrumb_len], attr_id->id, sizeof(p->breadcrumb[p->breadcrumb_len]));
+		p->breadcrumb_len++;
+		}
 	}
 	else if (strcmp(el, "path") == 0) {
 		if (p->pathFlag)	// Do not allow nested paths.
@@ -2874,7 +2898,12 @@ static void nsvg__endElement(void* ud, const char* el)
 	NSVGparser* p = (NSVGparser*)ud;
 
 	if (strcmp(el, "g") == 0) {
-		nsvg__popAttr(p);
+  		/* Remove the breadcrumb level. */
+    	if (p->breadcrumb_len > 0) {
+      		p->breadcrumb[p->breadcrumb_len - 1][0] = '\0';
+      		p->breadcrumb_len--;
+		}
+	  nsvg__popAttr(p);
 	}
 	else if (strcmp(el, "path") == 0) {
 		p->pathFlag = 0;