svg2gcode 3.3.2__tar.gz → 3.3.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/PKG-INFO +44 -16
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/README.md +43 -15
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/svg2gcode/__init__.py +1 -1
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/svg2gcode/svg_to_gcode/compiler/_compiler.py +20 -0
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/svg2gcode/svg_to_gcode/svg_parser/__init__.py +1 -1
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/svg2gcode/svg_to_gcode/svg_parser/_parser_methods.py +20 -2
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/LICENSE +0 -0
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/pyproject.toml +0 -0
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/svg2gcode/__main__.py +0 -0
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/svg2gcode/svg_to_gcode/LICENSE +0 -0
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/svg2gcode/svg_to_gcode/__init__.py +0 -0
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/svg2gcode/svg_to_gcode/compiler/__init__.py +0 -0
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/svg2gcode/svg_to_gcode/compiler/interfaces/__init__.py +0 -0
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/svg2gcode/svg_to_gcode/compiler/interfaces/_abstract_interface.py +0 -0
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/svg2gcode/svg_to_gcode/compiler/interfaces/_fan_controlled_gcode.py +0 -0
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/svg2gcode/svg_to_gcode/compiler/interfaces/_gcode.py +0 -0
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/svg2gcode/svg_to_gcode/css_color.py +0 -0
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/svg2gcode/svg_to_gcode/formulas.py +0 -0
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/svg2gcode/svg_to_gcode/geometry/__init__.py +0 -0
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/svg2gcode/svg_to_gcode/geometry/_abstract_chain.py +0 -0
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/svg2gcode/svg_to_gcode/geometry/_abstract_curve.py +0 -0
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/svg2gcode/svg_to_gcode/geometry/_circular_arc.py +0 -0
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/svg2gcode/svg_to_gcode/geometry/_cubic_bazier.py +0 -0
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/svg2gcode/svg_to_gcode/geometry/_elliptical_arc.py +0 -0
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/svg2gcode/svg_to_gcode/geometry/_line.py +0 -0
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/svg2gcode/svg_to_gcode/geometry/_line_segment_chain.py +0 -0
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/svg2gcode/svg_to_gcode/geometry/_matrix.py +0 -0
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/svg2gcode/svg_to_gcode/geometry/_quadratic_bazier.py +0 -0
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/svg2gcode/svg_to_gcode/geometry/_raster_image.py +0 -0
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/svg2gcode/svg_to_gcode/geometry/_smooth_arc_chain.py +0 -0
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/svg2gcode/svg_to_gcode/geometry/_vector.py +0 -0
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/svg2gcode/svg_to_gcode/svg_parser/_path.py +0 -0
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/svg2gcode/svg_to_gcode/svg_parser/_transformation.py +0 -0
- {svg2gcode-3.3.2 → svg2gcode-3.3.5}/svg2gcode/svg_to_gcode/svg_parser/debug_methods.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: svg2gcode
|
|
3
|
-
Version: 3.3.
|
|
3
|
+
Version: 3.3.5
|
|
4
4
|
Summary: svg2gcode: convert an SVG (Scalable Vector Graphic) image to gcode.
|
|
5
5
|
Keywords: scalable vector graphics,svg,image,laser cutter,laser engraving
|
|
6
6
|
Author-email: Johannes Noordanus <mailjohannes.mailnoordanus@gmail.com>
|
|
@@ -14,7 +14,7 @@ Project-URL: Home, https://github.com/johannesnoordanus/svg2gcode
|
|
|
14
14
|
|
|
15
15
|
# svg2gcode
|
|
16
16
|
|
|
17
|
-
*svg2gcode* is a *WYSIWYG* converter of Scalable Vector Graphic *(SVG)* drawings. It is based on library *SvgToGcode* (*
|
|
17
|
+
*svg2gcode* is a *WYSIWYG* converter of Scalable Vector Graphic *(SVG)* drawings. It is based on library *SvgToGcode* (*https://github.com/johannesnoordanus/SvgToGcode*)<sup>(*)</sup>.
|
|
18
18
|
|
|
19
19
|
Drawings and images can be composed using Inkscape (or other *SVG* image software), saved to a *.svg* file and - *WYSIWYG* - converted to gcode.
|
|
20
20
|
Color coding can be used to mark what part(s) of the drawing to cut, engrave or even ignore.
|
|
@@ -31,13 +31,16 @@ More info can be obtained by looking at the documentation and examples below and
|
|
|
31
31
|
|
|
32
32
|
*svg2gcode* has three related programs: *image2gcode* mentioned above has similar capabilities but handles raster image files (like *png* and *jpg*) directly, *gcode2image* performs the inverse function and is capable of showing multiple writes (burns) to the same location and last *grblhud* which gives full control over gcode execution.
|
|
33
33
|
|
|
34
|
+
<sup>(*)</sup> Note that an upgraded and corrected version of this library is included.
|
|
35
|
+
|
|
34
36
|
-----
|
|
35
37
|
|
|
36
38
|
Please consider supporting me, so I can make this application better and add new functionality to it: <http://paypal.me/johannesnoordanus/5,00>
|
|
37
39
|
|
|
38
40
|
My next update will add *fill-rule* 'nonzero' (see information on *fill-rule* below).
|
|
39
41
|
|
|
40
|
-
|
|
42
|
+
-----
|
|
43
|
+
|
|
41
44
|
### Supported SVG elements and attributes
|
|
42
45
|
|
|
43
46
|
*SVG* *path* and *image* elements (specific: ```<svg:path ..>```tags and images```<svg:image ..>```tags) are supported. Other drawing objects must be converted to a *path* first to be able to translate them to a gcode sequence.
|
|
@@ -45,6 +48,41 @@ My next update will add *fill-rule* 'nonzero' (see information on *fill-rule* be
|
|
|
45
48
|
Attributes *stroke* (color), *stroke-width*, *stroke_alpha*, *fill* (color), *fill-rule*, *fill_alpha* are supported.
|
|
46
49
|
Currently only value *evenodd* of *fill-rule* is supported.
|
|
47
50
|
|
|
51
|
+
### *WYSIWYG*
|
|
52
|
+
|
|
53
|
+
As seen above, not all *svg* elements are directly supported, but they are after a *path* conversion within the composer (Inkscape: ```menu Path->Object/Stroke to Path```). Without a *path* conversion *svg2gcode* simply ignores all elements except *path* and *image*. Text (fonts) require another step after *selecting* all text and clicking menu ```Object to Path```. Clicking menu```Object->Ungroup``` <sup>(**)</sup> generates a separate *path* for each letter which contains all relevant attributes. (Otherwise Inkscape uses a group tag ```<g``` to set some attributes for all letters within the text that are not repeated for each individual letter.)
|
|
54
|
+
|
|
55
|
+
You can use *gcode2image* to check the conversion result:
|
|
56
|
+
```
|
|
57
|
+
> svg2gcode some.svg some.gc
|
|
58
|
+
> gcode2image --showimage --flip --grid --showorigin some.gc some.png
|
|
59
|
+
```
|
|
60
|
+
The image shown should be the same as the one shown by the composer (Inkscape). This is also a good way to measure the conversion result. Note that ```--grid``` and ```--showorigin``` can give some inteference. To be sure run *gcode2image* without them.
|
|
61
|
+
|
|
62
|
+
#### Contour & fill
|
|
63
|
+
|
|
64
|
+
Inkscape translates a contour of a raster image to an outline and fill. So, if you create a contour via (select bitmap first) ```Path->Trace Bitmap...``` slide the ```Treshold``` of the Trace Bitmap menu to almost 1 (0,995) to make the entire bitmap image black (this is a bit *trial and error*, use ```Update preview``` to get the highest slider value before the whole images is black).
|
|
65
|
+
|
|
66
|
+
You can look at the result xml tree via Inkscapes ```XML editor``` which now shows a path for the outline of the raster image and a style attribue like this:
|
|
67
|
+
```
|
|
68
|
+
style fill:#000000;stroke-width:0.172652
|
|
69
|
+
```
|
|
70
|
+
To cut this outline, you can set the *fill* attribute to *none* (via the ```XML editor``` or menu ```Fill and Stroke```) and set a specific *stroke* color, for example *red*. The following command generates gcode to cut the outline.
|
|
71
|
+
```
|
|
72
|
+
> svg2gcode --color_coded "red = cut" contour.svg contour.gc
|
|
73
|
+
```
|
|
74
|
+
You can also engrave the whole bitmap image by setting a specific fill color (via menu ```Fill and Stroke```) (in this case there is no need to use option ```color_coded```)
|
|
75
|
+
|
|
76
|
+
#### Notes
|
|
77
|
+
|
|
78
|
+
- drawing objects - within the composer - must be converted to a```path```to be translated to a gcode sequence
|
|
79
|
+
- image objects should **not** be converted to a ```path```
|
|
80
|
+
- images must be linked or embedded using base64 (Inkscape default).
|
|
81
|
+
- images can be in several formats (my tests included *.png* and *.jpg* image files)
|
|
82
|
+
- *SVG* source documents must be in unit 'mm' and set to ```1 'user unit' is 1 mm``` (Inkscape default)
|
|
83
|
+
|
|
84
|
+
<sup>(**)</sup> Note that the latest version of *svg2gcode* (3.3.4) has support for ```<g``` tags (attribute inheritance) and is able to correctly convert text without ```Ungroup```.
|
|
85
|
+
|
|
48
86
|
### Important Commandline options
|
|
49
87
|
|
|
50
88
|
Option ```--color_coded``` can be used to specify what part(s) of the drawing to cut, engrave or even ignore.
|
|
@@ -90,7 +128,7 @@ Note that engraving is the default action, so if option *color_coded* isn't set
|
|
|
90
128
|
|
|
91
129
|
This makes it possible to make a drawing where all path elements are drawn in their respective colors to make an engraving of the entire vector drawing.
|
|
92
130
|
When you set the engrave action for a set of colors, only those colors will be engraved (having their respective colors), all other paths having no action set are ignored.
|
|
93
|
-
Also, when a path has no stroke attribute (or it is set to none) the element cannot be engraved (because it has no color) so it is
|
|
131
|
+
Also, when a path has no stroke attribute (or it is set to none) the element cannot be engraved (because it has no color) so it is ignored.
|
|
94
132
|
|
|
95
133
|
Option ```--pathcut``` can be used to override all stroke attributes and force cutting of all *paths* of the *SVG*.
|
|
96
134
|
Note that this option cannot be set at the same time as *--color_coded* above.
|
|
@@ -121,7 +159,6 @@ General optimizations
|
|
|
121
159
|
- borders are drawn in parallel and in one go, following the *path* coordinates.
|
|
122
160
|
- fill has support for alpha channel and 'fill-opacity'
|
|
123
161
|
|
|
124
|
-
|
|
125
162
|
### Install:
|
|
126
163
|
```
|
|
127
164
|
>
|
|
@@ -293,11 +330,8 @@ Note: to get options and defaults:
|
|
|
293
330
|
> svg2gcode --help
|
|
294
331
|
```
|
|
295
332
|
#### How do we cut these lines?
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
style="fill:none;stroke:none;stroke-width:.1"
|
|
299
|
-
```
|
|
300
|
-
or add 'gcode-pathcut' to the style string:
|
|
333
|
+
|
|
334
|
+
Add 'gcode-pathcut' to the style string:
|
|
301
335
|
```
|
|
302
336
|
style="fill:none;stroke:red;stroke-width:.1;gcode-pathcut:true"
|
|
303
337
|
```
|
|
@@ -347,10 +381,4 @@ One containing the drawings of the .svg, the other containing the images:
|
|
|
347
381
|
|
|
348
382
|
Default *svg2gcode* uses constant burn mode *M3*. This can be changed by setting option *--no-constantburn* which selects burn mode *M4*. Mode *M4* is not suitable for engravings because it automatically compensates (laser)power for speed. This conflicts with the specific gcode settings given by *image2gcode* (called by *svg2gcode*) for each pixel. In fact some experiments show that *M4* causes loss of quality and image deterioration when speed is increased. On white oak images had too much black and grey which did not go away for substantially higher speed. When switched back to constant burn (*M3*) mode, the same high speed gave excellent images having a sepia (licht yellow brown) color tone.
|
|
349
383
|
|
|
350
|
-
### Notes:
|
|
351
|
-
- drawing objects - within the composer - must be converted to a```path```to be translated to a gcode sequence
|
|
352
|
-
- also, image objects should **not** be converted to a ```path```
|
|
353
|
-
- images must be linked or embedded using base64.
|
|
354
|
-
- images can be in several formats (my tests included *.png* and *.jpg* image files)
|
|
355
|
-
- SVG source documents must be in unit 'mm' (and set to 1 'user unit' is 1 mm) which is the default for Inkscape (check document settings and look at the 'scaling' parameter)
|
|
356
384
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# svg2gcode
|
|
2
2
|
|
|
3
|
-
*svg2gcode* is a *WYSIWYG* converter of Scalable Vector Graphic *(SVG)* drawings. It is based on library *SvgToGcode* (*
|
|
3
|
+
*svg2gcode* is a *WYSIWYG* converter of Scalable Vector Graphic *(SVG)* drawings. It is based on library *SvgToGcode* (*https://github.com/johannesnoordanus/SvgToGcode*)<sup>(*)</sup>.
|
|
4
4
|
|
|
5
5
|
Drawings and images can be composed using Inkscape (or other *SVG* image software), saved to a *.svg* file and - *WYSIWYG* - converted to gcode.
|
|
6
6
|
Color coding can be used to mark what part(s) of the drawing to cut, engrave or even ignore.
|
|
@@ -17,13 +17,16 @@ More info can be obtained by looking at the documentation and examples below and
|
|
|
17
17
|
|
|
18
18
|
*svg2gcode* has three related programs: *image2gcode* mentioned above has similar capabilities but handles raster image files (like *png* and *jpg*) directly, *gcode2image* performs the inverse function and is capable of showing multiple writes (burns) to the same location and last *grblhud* which gives full control over gcode execution.
|
|
19
19
|
|
|
20
|
+
<sup>(*)</sup> Note that an upgraded and corrected version of this library is included.
|
|
21
|
+
|
|
20
22
|
-----
|
|
21
23
|
|
|
22
24
|
Please consider supporting me, so I can make this application better and add new functionality to it: <http://paypal.me/johannesnoordanus/5,00>
|
|
23
25
|
|
|
24
26
|
My next update will add *fill-rule* 'nonzero' (see information on *fill-rule* below).
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
-----
|
|
29
|
+
|
|
27
30
|
### Supported SVG elements and attributes
|
|
28
31
|
|
|
29
32
|
*SVG* *path* and *image* elements (specific: ```<svg:path ..>```tags and images```<svg:image ..>```tags) are supported. Other drawing objects must be converted to a *path* first to be able to translate them to a gcode sequence.
|
|
@@ -31,6 +34,41 @@ My next update will add *fill-rule* 'nonzero' (see information on *fill-rule* be
|
|
|
31
34
|
Attributes *stroke* (color), *stroke-width*, *stroke_alpha*, *fill* (color), *fill-rule*, *fill_alpha* are supported.
|
|
32
35
|
Currently only value *evenodd* of *fill-rule* is supported.
|
|
33
36
|
|
|
37
|
+
### *WYSIWYG*
|
|
38
|
+
|
|
39
|
+
As seen above, not all *svg* elements are directly supported, but they are after a *path* conversion within the composer (Inkscape: ```menu Path->Object/Stroke to Path```). Without a *path* conversion *svg2gcode* simply ignores all elements except *path* and *image*. Text (fonts) require another step after *selecting* all text and clicking menu ```Object to Path```. Clicking menu```Object->Ungroup``` <sup>(**)</sup> generates a separate *path* for each letter which contains all relevant attributes. (Otherwise Inkscape uses a group tag ```<g``` to set some attributes for all letters within the text that are not repeated for each individual letter.)
|
|
40
|
+
|
|
41
|
+
You can use *gcode2image* to check the conversion result:
|
|
42
|
+
```
|
|
43
|
+
> svg2gcode some.svg some.gc
|
|
44
|
+
> gcode2image --showimage --flip --grid --showorigin some.gc some.png
|
|
45
|
+
```
|
|
46
|
+
The image shown should be the same as the one shown by the composer (Inkscape). This is also a good way to measure the conversion result. Note that ```--grid``` and ```--showorigin``` can give some inteference. To be sure run *gcode2image* without them.
|
|
47
|
+
|
|
48
|
+
#### Contour & fill
|
|
49
|
+
|
|
50
|
+
Inkscape translates a contour of a raster image to an outline and fill. So, if you create a contour via (select bitmap first) ```Path->Trace Bitmap...``` slide the ```Treshold``` of the Trace Bitmap menu to almost 1 (0,995) to make the entire bitmap image black (this is a bit *trial and error*, use ```Update preview``` to get the highest slider value before the whole images is black).
|
|
51
|
+
|
|
52
|
+
You can look at the result xml tree via Inkscapes ```XML editor``` which now shows a path for the outline of the raster image and a style attribue like this:
|
|
53
|
+
```
|
|
54
|
+
style fill:#000000;stroke-width:0.172652
|
|
55
|
+
```
|
|
56
|
+
To cut this outline, you can set the *fill* attribute to *none* (via the ```XML editor``` or menu ```Fill and Stroke```) and set a specific *stroke* color, for example *red*. The following command generates gcode to cut the outline.
|
|
57
|
+
```
|
|
58
|
+
> svg2gcode --color_coded "red = cut" contour.svg contour.gc
|
|
59
|
+
```
|
|
60
|
+
You can also engrave the whole bitmap image by setting a specific fill color (via menu ```Fill and Stroke```) (in this case there is no need to use option ```color_coded```)
|
|
61
|
+
|
|
62
|
+
#### Notes
|
|
63
|
+
|
|
64
|
+
- drawing objects - within the composer - must be converted to a```path```to be translated to a gcode sequence
|
|
65
|
+
- image objects should **not** be converted to a ```path```
|
|
66
|
+
- images must be linked or embedded using base64 (Inkscape default).
|
|
67
|
+
- images can be in several formats (my tests included *.png* and *.jpg* image files)
|
|
68
|
+
- *SVG* source documents must be in unit 'mm' and set to ```1 'user unit' is 1 mm``` (Inkscape default)
|
|
69
|
+
|
|
70
|
+
<sup>(**)</sup> Note that the latest version of *svg2gcode* (3.3.4) has support for ```<g``` tags (attribute inheritance) and is able to correctly convert text without ```Ungroup```.
|
|
71
|
+
|
|
34
72
|
### Important Commandline options
|
|
35
73
|
|
|
36
74
|
Option ```--color_coded``` can be used to specify what part(s) of the drawing to cut, engrave or even ignore.
|
|
@@ -76,7 +114,7 @@ Note that engraving is the default action, so if option *color_coded* isn't set
|
|
|
76
114
|
|
|
77
115
|
This makes it possible to make a drawing where all path elements are drawn in their respective colors to make an engraving of the entire vector drawing.
|
|
78
116
|
When you set the engrave action for a set of colors, only those colors will be engraved (having their respective colors), all other paths having no action set are ignored.
|
|
79
|
-
Also, when a path has no stroke attribute (or it is set to none) the element cannot be engraved (because it has no color) so it is
|
|
117
|
+
Also, when a path has no stroke attribute (or it is set to none) the element cannot be engraved (because it has no color) so it is ignored.
|
|
80
118
|
|
|
81
119
|
Option ```--pathcut``` can be used to override all stroke attributes and force cutting of all *paths* of the *SVG*.
|
|
82
120
|
Note that this option cannot be set at the same time as *--color_coded* above.
|
|
@@ -107,7 +145,6 @@ General optimizations
|
|
|
107
145
|
- borders are drawn in parallel and in one go, following the *path* coordinates.
|
|
108
146
|
- fill has support for alpha channel and 'fill-opacity'
|
|
109
147
|
|
|
110
|
-
|
|
111
148
|
### Install:
|
|
112
149
|
```
|
|
113
150
|
>
|
|
@@ -279,11 +316,8 @@ Note: to get options and defaults:
|
|
|
279
316
|
> svg2gcode --help
|
|
280
317
|
```
|
|
281
318
|
#### How do we cut these lines?
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
style="fill:none;stroke:none;stroke-width:.1"
|
|
285
|
-
```
|
|
286
|
-
or add 'gcode-pathcut' to the style string:
|
|
319
|
+
|
|
320
|
+
Add 'gcode-pathcut' to the style string:
|
|
287
321
|
```
|
|
288
322
|
style="fill:none;stroke:red;stroke-width:.1;gcode-pathcut:true"
|
|
289
323
|
```
|
|
@@ -333,9 +367,3 @@ One containing the drawings of the .svg, the other containing the images:
|
|
|
333
367
|
|
|
334
368
|
Default *svg2gcode* uses constant burn mode *M3*. This can be changed by setting option *--no-constantburn* which selects burn mode *M4*. Mode *M4* is not suitable for engravings because it automatically compensates (laser)power for speed. This conflicts with the specific gcode settings given by *image2gcode* (called by *svg2gcode*) for each pixel. In fact some experiments show that *M4* causes loss of quality and image deterioration when speed is increased. On white oak images had too much black and grey which did not go away for substantially higher speed. When switched back to constant burn (*M3*) mode, the same high speed gave excellent images having a sepia (licht yellow brown) color tone.
|
|
335
369
|
|
|
336
|
-
### Notes:
|
|
337
|
-
- drawing objects - within the composer - must be converted to a```path```to be translated to a gcode sequence
|
|
338
|
-
- also, image objects should **not** be converted to a ```path```
|
|
339
|
-
- images must be linked or embedded using base64.
|
|
340
|
-
- images can be in several formats (my tests included *.png* and *.jpg* image files)
|
|
341
|
-
- SVG source documents must be in unit 'mm' (and set to 1 'user unit' is 1 mm) which is the default for Inkscape (check document settings and look at the 'scaling' parameter)
|
|
@@ -19,6 +19,7 @@ from svg2gcode.svg_to_gcode import DEFAULT_SETTING
|
|
|
19
19
|
from svg2gcode.svg_to_gcode import TOLERANCES, SETTING, check_setting
|
|
20
20
|
|
|
21
21
|
from svg2gcode.svg_to_gcode import css_color
|
|
22
|
+
from svg2gcode.svg_to_gcode.svg_parser import NAMESPACES, ElementTree_MY_PARENT
|
|
22
23
|
|
|
23
24
|
from svg2gcode import __version__
|
|
24
25
|
|
|
@@ -481,6 +482,25 @@ class Compiler:
|
|
|
481
482
|
if 'gcode_pathcut' in curve.path_attrib:
|
|
482
483
|
style['pathcut'] = curve.path_attrib['gcode_pathcut']
|
|
483
484
|
|
|
485
|
+
# check missing attributes, if any
|
|
486
|
+
if ElementTree_MY_PARENT in curve.path_attrib:
|
|
487
|
+
parent = curve.path_attrib[ElementTree_MY_PARENT]
|
|
488
|
+
|
|
489
|
+
# find first parent g (group) tag, if any
|
|
490
|
+
while parent and parent.tag != "{%s}g" % NAMESPACES["svg"]:
|
|
491
|
+
if ElementTree_MY_PARENT in parent.attrib:
|
|
492
|
+
parent = parent.attrib[ElementTree_MY_PARENT]
|
|
493
|
+
else:
|
|
494
|
+
parent = None
|
|
495
|
+
if parent:
|
|
496
|
+
# fill in missing attribues, if any
|
|
497
|
+
for key, value in style.items():
|
|
498
|
+
if not value and key in ['fill', 'fill-rule', 'fill-opacity', 'stroke', 'stroke-width', 'stroke-opacity']:
|
|
499
|
+
# get missing attribute (if any)
|
|
500
|
+
if key in parent.attrib:
|
|
501
|
+
attrib = parent.attrib[key]
|
|
502
|
+
if attrib and attrib != 'none':
|
|
503
|
+
style[key] = attrib
|
|
484
504
|
return style
|
|
485
505
|
|
|
486
506
|
def color_coded_paths(self, set_color_coded = False) -> ():
|
|
@@ -8,4 +8,4 @@ specific maintenance notes:
|
|
|
8
8
|
|
|
9
9
|
from svg2gcode.svg_to_gcode.svg_parser._transformation import Transformation
|
|
10
10
|
from svg2gcode.svg_to_gcode.svg_parser._path import Path
|
|
11
|
-
from svg2gcode.svg_to_gcode.svg_parser._parser_methods import parse_file, parse_string, parse_root
|
|
11
|
+
from svg2gcode.svg_to_gcode.svg_parser._parser_methods import parse_file, parse_string, parse_root, NAMESPACES, ElementTree_MY_PARENT
|
|
@@ -11,6 +11,23 @@ from svg2gcode.svg_to_gcode.geometry import Curve, RasterImage
|
|
|
11
11
|
NAMESPACES = {'svg': 'http://www.w3.org/2000/svg',
|
|
12
12
|
'xlink':'http://www.w3.org/1999/xlink'}
|
|
13
13
|
|
|
14
|
+
ElementTree_MY_PARENT = '__my_parent__'
|
|
15
|
+
|
|
16
|
+
def addParentInfo(et):
|
|
17
|
+
for child in et:
|
|
18
|
+
child.attrib[ElementTree_MY_PARENT] = et
|
|
19
|
+
addParentInfo(child)
|
|
20
|
+
|
|
21
|
+
def stripParentInfo(et):
|
|
22
|
+
for child in et:
|
|
23
|
+
child.attrib.pop(ElementTree_MY_PARENT, 'None')
|
|
24
|
+
stripParentInfo(child)
|
|
25
|
+
|
|
26
|
+
def getParent(et):
|
|
27
|
+
if ElementTree_MY_PARENT in et.attrib:
|
|
28
|
+
return et.attrib[ElementTree_MY_PARENT]
|
|
29
|
+
else:
|
|
30
|
+
return None
|
|
14
31
|
|
|
15
32
|
def _has_style(element: ElementTree.Element, key: str, value: str) -> bool:
|
|
16
33
|
"""
|
|
@@ -178,8 +195,7 @@ def parse_root(root: ElementTree.Element, transform_origin=True, viewbox=None, d
|
|
|
178
195
|
add_viewbox_transformation(transformation, transform_origin, viewbox, origin, scale, rotate))
|
|
179
196
|
|
|
180
197
|
curves.extend(path.curves)
|
|
181
|
-
|
|
182
|
-
if element.tag == "{%s}image" % NAMESPACES["svg"]:
|
|
198
|
+
elif element.tag == "{%s}image" % NAMESPACES["svg"]:
|
|
183
199
|
# svg image
|
|
184
200
|
|
|
185
201
|
# instantiate curve (image)
|
|
@@ -209,6 +225,7 @@ def parse_string(svg_string: str, transform_origin=True, viewbox=None, draw_hidd
|
|
|
209
225
|
:return: A list of geometric curves describing the svg. Use the Compiler sub-module to compile them to gcode.
|
|
210
226
|
"""
|
|
211
227
|
root = ElementTree.fromstring(svg_string)
|
|
228
|
+
addParentInfo(root)
|
|
212
229
|
return parse_root(root, transform_origin, viewbox, draw_hidden, origin=delta_origin, scale=scale_factor, rotate=rotate_deg)
|
|
213
230
|
|
|
214
231
|
|
|
@@ -227,4 +244,5 @@ def parse_file(file_path: str, transform_origin=True, viewbox=None, draw_hidden=
|
|
|
227
244
|
:return: A list of geometric curves describing the svg. Use the Compiler sub-module to compile them to gcode.
|
|
228
245
|
"""
|
|
229
246
|
root = ElementTree.parse(file_path).getroot()
|
|
247
|
+
addParentInfo(root)
|
|
230
248
|
return parse_root(root, transform_origin, viewbox, draw_hidden, origin=delta_origin, scale=scale_factor, rotate=rotate_deg)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|