Commit: bb24bb63a1954c8a12176be2b24a1d3efea72323
Author: Antonio Vazquez
Date:   Thu Feb 11 16:29:02 2021 +0100
Branches: temp-gpencil-io
https://developer.blender.org/rBbb24bb63a1954c8a12176be2b24a1d3efea72323

GPencil: Import SVG - Include layer name using breadcrumb of groups

Now the groups are saved to generate the parent group as layer name.

Also, clang format applied.

===================================================================

M       source/blender/io/gpencil/intern/gpencil_io_import_svg.cc
M       source/blender/io/gpencil/nanosvg/nanosvg.h

===================================================================

diff --git a/source/blender/io/gpencil/intern/gpencil_io_import_svg.cc 
b/source/blender/io/gpencil/intern/gpencil_io_import_svg.cc
index 308c0b1b8a2..a75bc0866af 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_import_svg.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_import_svg.cc
@@ -99,11 +99,11 @@ bool GpencilImporterSVG::read(void)
   char prv_id[70] = {"*"};
   int prefix = 0;
   for (NSVGshape *shape = svg_data->shapes; shape; shape = shape->next) {
-    char *layer_id = BLI_sprintfN("%03d_%s", prefix, shape->id);
+    char *layer_id = BLI_sprintfN("%03d_%s", prefix, shape->id_parent);
     if (!STREQ(prv_id, layer_id)) {
       prefix++;
       MEM_freeN(layer_id);
-      layer_id = BLI_sprintfN("%03d_%s", prefix, shape->id);
+      layer_id = BLI_sprintfN("%03d_%s", prefix, shape->id_parent);
       strcpy(prv_id, layer_id);
     }
 
diff --git a/source/blender/io/gpencil/nanosvg/nanosvg.h 
b/source/blender/io/gpencil/nanosvg/nanosvg.h
index a110a00a3d2..950c8df105e 100644
--- a/source/blender/io/gpencil/nanosvg/nanosvg.h
+++ b/source/blender/io/gpencil/nanosvg/nanosvg.h
@@ -22,7 +22,10 @@
  *
  * Arc calculation code based on canvg (https://code.google.com/p/canvg/)
  *
- * Bounding box calculation based on 
http://blog.hackers-cafe.net/2009/06/how-to-calculate-bezier-curves-bounding.html
+ * 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.
  *
  */
 
@@ -30,167 +33,153 @@
 #define NANOSVG_H
 
 #ifndef NANOSVG_CPLUSPLUS
-#ifdef __cplusplus
+#  ifdef __cplusplus
 extern "C" {
-#endif
+#  endif
 #endif
 
-// NanoSVG is a simple stupid single-header-file SVG parse. The output of the 
parser is a list of cubic bezier shapes.
+// NanoSVG is a simple stupid single-header-file SVG parse. The output of the 
parser is a list of
+// cubic bezier shapes.
 //
-// The library suits well for anything from rendering scalable icons in your 
editor application to prototyping a game.
+// The library suits well for anything from rendering scalable icons in your 
editor application to
+// prototyping a game.
 //
-// NanoSVG supports a wide range of SVG features, but something may be 
missing, feel free to create a pull request!
+// NanoSVG supports a wide range of SVG features, but something may be 
missing, feel free to create
+// a pull request!
 //
 // The shapes in the SVG images are transformed by the viewBox and converted 
to specified units.
 // That is, you should get the same looking data as your designed in your 
favorite app.
 //
-// NanoSVG can return the paths in few different units. For example if you 
want to render an image, you may choose
-// to get the paths in pixels, or if you are feeding the data into a 
CNC-cutter, you may want to use millimeters.
+// NanoSVG can return the paths in few different units. For example if you 
want to render an image,
+// you may choose to get the paths in pixels, or if you are feeding the data 
into a CNC-cutter, you
+// may want to use millimeters.
 //
 // The units passed to NanoSVG should be one of: 'px', 'pt', 'pc' 'mm', 'cm', 
or 'in'.
 // DPI (dots-per-inch) controls how the unit conversion is done.
 //
 // If you don't know or care about the units stuff, "px" and 96 should get you 
going.
 
-
 /* Example Usage:
-       // Load SVG
-       NSVGimage* image;
-       image = nsvgParseFromFile("test.svg", "px", 96);
-       printf("size: %f x %f\n", image->width, image->height);
-       // Use...
-       for (NSVGshape *shape = image->shapes; shape != NULL; shape = 
shape->next) {
-               for (NSVGpath *path = shape->paths; path != NULL; path = 
path->next) {
-                       for (int i = 0; i < path->npts-1; i += 3) {
-                               float* p = &path->pts[i*2];
-                               drawCubicBez(p[0],p[1], p[2],p[3], p[4],p[5], 
p[6],p[7]);
-                       }
-               }
-       }
-       // Delete
-       nsvgDelete(image);
+  // Load SVG
+  NSVGimage* image;
+  image = nsvgParseFromFile("test.svg", "px", 96);
+  printf("size: %f x %f\n", image->width, image->height);
+  // Use...
+  for (NSVGshape *shape = image->shapes; shape != NULL; shape = shape->next) {
+    for (NSVGpath *path = shape->paths; path != NULL; path = path->next) {
+      for (int i = 0; i < path->npts-1; i += 3) {
+        float* p = &path->pts[i*2];
+        drawCubicBez(p[0],p[1], p[2],p[3], p[4],p[5], p[6],p[7]);
+      }
+    }
+  }
+  // Delete
+  nsvgDelete(image);
 */
 
 enum NSVGpaintType {
-       NSVG_PAINT_NONE = 0,
-       NSVG_PAINT_COLOR = 1,
-       NSVG_PAINT_LINEAR_GRADIENT = 2,
-       NSVG_PAINT_RADIAL_GRADIENT = 3
+  NSVG_PAINT_NONE = 0,
+  NSVG_PAINT_COLOR = 1,
+  NSVG_PAINT_LINEAR_GRADIENT = 2,
+  NSVG_PAINT_RADIAL_GRADIENT = 3
 };
 
-enum NSVGspreadType {
-       NSVG_SPREAD_PAD = 0,
-       NSVG_SPREAD_REFLECT = 1,
-       NSVG_SPREAD_REPEAT = 2
-};
+enum NSVGspreadType { NSVG_SPREAD_PAD = 0, NSVG_SPREAD_REFLECT = 1, 
NSVG_SPREAD_REPEAT = 2 };
 
-enum NSVGlineJoin {
-       NSVG_JOIN_MITER = 0,
-       NSVG_JOIN_ROUND = 1,
-       NSVG_JOIN_BEVEL = 2
-};
+enum NSVGlineJoin { NSVG_JOIN_MITER = 0, NSVG_JOIN_ROUND = 1, NSVG_JOIN_BEVEL 
= 2 };
 
-enum NSVGlineCap {
-       NSVG_CAP_BUTT = 0,
-       NSVG_CAP_ROUND = 1,
-       NSVG_CAP_SQUARE = 2
-};
+enum NSVGlineCap { NSVG_CAP_BUTT = 0, NSVG_CAP_ROUND = 1, NSVG_CAP_SQUARE = 2 
};
 
-enum NSVGfillRule {
-       NSVG_FILLRULE_NONZERO = 0,
-       NSVG_FILLRULE_EVENODD = 1
-};
+enum NSVGfillRule { NSVG_FILLRULE_NONZERO = 0, NSVG_FILLRULE_EVENODD = 1 };
 
-enum NSVGflags {
-       NSVG_FLAGS_VISIBLE = 0x01
-};
+enum NSVGflags { NSVG_FLAGS_VISIBLE = 0x01 };
 
 typedef struct NSVGgradientStop {
-       unsigned int color;
-       float offset;
+  unsigned int color;
+  float offset;
 } NSVGgradientStop;
 
 typedef struct NSVGgradient {
-       float xform[6];
-       char spread;
-       float fx, fy;
-       int nstops;
-       NSVGgradientStop stops[1];
+  float xform[6];
+  char spread;
+  float fx, fy;
+  int nstops;
+  NSVGgradientStop stops[1];
 } NSVGgradient;
 
 typedef struct NSVGpaint {
-       char type;
-       union {
-               unsigned int color;
-               NSVGgradient* gradient;
-       };
+  char type;
+  union {
+    unsigned int color;
+    NSVGgradient *gradient;
+  };
 } NSVGpaint;
 
-typedef struct NSVGpath
-{
-       float* pts;                                     // Cubic bezier points: 
x0,y0, [cpx1,cpx1,cpx2,cpy2,x1,y1], ...
-       int npts;                                       // Total number of 
bezier points.
-       char closed;                            // Flag indicating if shapes 
should be treated as closed.
-       float bounds[4];                        // Tight bounding box of the 
shape [minx,miny,maxx,maxy].
-       struct NSVGpath* next;          // Pointer to next path, or NULL if 
last element.
+typedef struct NSVGpath {
+  float *pts;             // Cubic bezier points: x0,y0, 
[cpx1,cpx1,cpx2,cpy2,x1,y1], ...
+  int npts;               // Total number of bezier points.
+  char closed;            // Flag indicating if shapes should be treated as 
closed.
+  float bounds[4];        // Tight bounding box of the shape 
[minx,miny,maxx,maxy].
+  struct NSVGpath *next;  // Pointer to next path, or NULL if last element.
 } NSVGpath;
 
-typedef struct NSVGshape
-{
-       char id[64];                            // Optional 'id' attr of the 
shape or its group
-       NSVGpaint fill;                         // Fill paint
-       NSVGpaint stroke;                       // Stroke paint
-       float opacity;                          // Opacity of the shape.
-       float strokeWidth;                      // Stroke width (scaled).
-       float strokeDashOffset;         // Stroke dash offset (scaled).
-       float strokeDashArray[8];                       // Stroke dash array 
(scaled).
-       char strokeDashCount;                           // Number of dash 
values in dash array.
-       char strokeLineJoin;            // Stroke join type.
-       char strokeLineCap;                     // Stroke cap type.
-       float miterLimit;                       // Miter limit
-       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.
+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.
+  float strokeWidth;         // Stroke width (scaled).
+  float strokeDashOffset;    // Stroke dash offset (scaled).
+  float strokeDashArray[8];  // Stroke dash array (scaled).
+  char strokeDashCount;      // Number of dash values in dash array.
+  char strokeLineJoin;       // Stroke join type.
+  char strokeLineCap;        // Stroke cap type.
+  float miterLimit;          // Miter limit
+  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.
 } NSVGshape;
 
-typedef struct NSVGimage
-{
-       float width;                            // Width of the image.
-       float height;                           // Height of the image.
-       NSVGshape* shapes;                      // Linked list of shapes in the 
image.
+typedef struct NSVGimage {
+  float width;        // Width of the image.
+  float height;       // Height of the image.
+  NSVGshape *shapes;  // Linked list of shapes in the image.
 } NSVGimage;
 
 // Parses SVG file from a file, returns SVG image as paths.
-NSVGimage* nsvgParseFromFile(const char* filename, const char* units, float 
dpi);
+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);
+NSVGimage *nsvgParse(char *input, const char *units, float dpi);
 
 // Duplicates a path.
-NSVGpath* nsvgDuplicatePath(NSVGpath* p);
+NSVGpath *nsvgDuplicatePath(NSVGpath *p);
 
 // Deletes an image.
-void nsvgDelete(NSVGimage* image);
+void nsvgDelete(NSVGimage *image);
 
 #ifndef NANOSVG_CPLUSPLUS
-#ifdef __cplusplus
+#  ifdef __cplusplus
 }
-#endif
+#  endif
 #endif
 
-#endif // NANOSVG_H
+#endif  // NANOSVG_H
 
 #ifdef NANOSVG_IMPLEMENTATION
 
-#include <string.h>
-#include <stdlib.h>
 #include <math.h>
+#include <stdlib.h>
+#include <string.h>
 
 #define NSVG_PI (3.1415926

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to