svg2gcode 3.3.4__tar.gz → 3.3.6__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.4 → svg2gcode-3.3.6}/PKG-INFO +24 -10
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/README.md +23 -9
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/svg2gcode/__init__.py +1 -1
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/svg2gcode/svg_to_gcode/compiler/_compiler.py +19 -17
- svg2gcode-3.3.6/svg2gcode/svg_to_gcode/compiler/newcompiler.py +1148 -0
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/svg2gcode/svg_to_gcode/svg_parser/__init__.py +1 -1
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/svg2gcode/svg_to_gcode/svg_parser/_parser_methods.py +5 -5
- svg2gcode-3.3.6/svg2gcode/svg_to_gcode/svg_parser/new__init.py +11 -0
- svg2gcode-3.3.6/svg2gcode/svg_to_gcode/svg_parser/newparsermethods.py +248 -0
- svg2gcode-3.3.6/svg2gcode/svg_to_gcode/svg_parser/t +5 -0
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/LICENSE +0 -0
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/pyproject.toml +0 -0
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/svg2gcode/__main__.py +0 -0
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/svg2gcode/svg_to_gcode/LICENSE +0 -0
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/svg2gcode/svg_to_gcode/__init__.py +0 -0
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/svg2gcode/svg_to_gcode/compiler/__init__.py +0 -0
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/svg2gcode/svg_to_gcode/compiler/interfaces/__init__.py +0 -0
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/svg2gcode/svg_to_gcode/compiler/interfaces/_abstract_interface.py +0 -0
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/svg2gcode/svg_to_gcode/compiler/interfaces/_fan_controlled_gcode.py +0 -0
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/svg2gcode/svg_to_gcode/compiler/interfaces/_gcode.py +0 -0
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/svg2gcode/svg_to_gcode/css_color.py +0 -0
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/svg2gcode/svg_to_gcode/formulas.py +0 -0
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/svg2gcode/svg_to_gcode/geometry/__init__.py +0 -0
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/svg2gcode/svg_to_gcode/geometry/_abstract_chain.py +0 -0
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/svg2gcode/svg_to_gcode/geometry/_abstract_curve.py +0 -0
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/svg2gcode/svg_to_gcode/geometry/_circular_arc.py +0 -0
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/svg2gcode/svg_to_gcode/geometry/_cubic_bazier.py +0 -0
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/svg2gcode/svg_to_gcode/geometry/_elliptical_arc.py +0 -0
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/svg2gcode/svg_to_gcode/geometry/_line.py +0 -0
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/svg2gcode/svg_to_gcode/geometry/_line_segment_chain.py +0 -0
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/svg2gcode/svg_to_gcode/geometry/_matrix.py +0 -0
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/svg2gcode/svg_to_gcode/geometry/_quadratic_bazier.py +0 -0
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/svg2gcode/svg_to_gcode/geometry/_raster_image.py +0 -0
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/svg2gcode/svg_to_gcode/geometry/_smooth_arc_chain.py +0 -0
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/svg2gcode/svg_to_gcode/geometry/_vector.py +0 -0
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/svg2gcode/svg_to_gcode/svg_parser/_path.py +0 -0
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/svg2gcode/svg_to_gcode/svg_parser/_transformation.py +0 -0
- {svg2gcode-3.3.4 → svg2gcode-3.3.6}/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.6
|
|
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>
|
|
@@ -50,9 +50,7 @@ Currently only value *evenodd* of *fill-rule* is supported.
|
|
|
50
50
|
|
|
51
51
|
### *WYSIWYG*
|
|
52
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 ```
|
|
54
|
-
|
|
55
|
-
Note that the latest version of *svg2gcode* (3.3.3) has support for ```<g``` tags (attribute inheritance) and is able to correctly convert text without ```Ungroup```.
|
|
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.)
|
|
56
54
|
|
|
57
55
|
You can use *gcode2image* to check the conversion result:
|
|
58
56
|
```
|
|
@@ -61,12 +59,30 @@ You can use *gcode2image* to check the conversion result:
|
|
|
61
59
|
```
|
|
62
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.
|
|
63
61
|
|
|
64
|
-
####
|
|
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
|
+
|
|
65
78
|
- drawing objects - within the composer - must be converted to a```path```to be translated to a gcode sequence
|
|
66
79
|
- image objects should **not** be converted to a ```path```
|
|
67
80
|
- images must be linked or embedded using base64 (Inkscape default).
|
|
68
81
|
- images can be in several formats (my tests included *.png* and *.jpg* image files)
|
|
69
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
|
+
|
|
70
86
|
### Important Commandline options
|
|
71
87
|
|
|
72
88
|
Option ```--color_coded``` can be used to specify what part(s) of the drawing to cut, engrave or even ignore.
|
|
@@ -314,11 +330,8 @@ Note: to get options and defaults:
|
|
|
314
330
|
> svg2gcode --help
|
|
315
331
|
```
|
|
316
332
|
#### How do we cut these lines?
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
style="fill:none;stroke:none;stroke-width:.1"
|
|
320
|
-
```
|
|
321
|
-
or add 'gcode-pathcut' to the style string:
|
|
333
|
+
|
|
334
|
+
Add 'gcode-pathcut' to the style string:
|
|
322
335
|
```
|
|
323
336
|
style="fill:none;stroke:red;stroke-width:.1;gcode-pathcut:true"
|
|
324
337
|
```
|
|
@@ -368,3 +381,4 @@ One containing the drawings of the .svg, the other containing the images:
|
|
|
368
381
|
|
|
369
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.
|
|
370
383
|
|
|
384
|
+
|
|
@@ -36,9 +36,7 @@ Currently only value *evenodd* of *fill-rule* is supported.
|
|
|
36
36
|
|
|
37
37
|
### *WYSIWYG*
|
|
38
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 ```
|
|
40
|
-
|
|
41
|
-
Note that the latest version of *svg2gcode* (3.3.3) has support for ```<g``` tags (attribute inheritance) and is able to correctly convert text without ```Ungroup```.
|
|
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.)
|
|
42
40
|
|
|
43
41
|
You can use *gcode2image* to check the conversion result:
|
|
44
42
|
```
|
|
@@ -47,12 +45,30 @@ You can use *gcode2image* to check the conversion result:
|
|
|
47
45
|
```
|
|
48
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.
|
|
49
47
|
|
|
50
|
-
####
|
|
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
|
+
|
|
51
64
|
- drawing objects - within the composer - must be converted to a```path```to be translated to a gcode sequence
|
|
52
65
|
- image objects should **not** be converted to a ```path```
|
|
53
66
|
- images must be linked or embedded using base64 (Inkscape default).
|
|
54
67
|
- images can be in several formats (my tests included *.png* and *.jpg* image files)
|
|
55
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
|
+
|
|
56
72
|
### Important Commandline options
|
|
57
73
|
|
|
58
74
|
Option ```--color_coded``` can be used to specify what part(s) of the drawing to cut, engrave or even ignore.
|
|
@@ -300,11 +316,8 @@ Note: to get options and defaults:
|
|
|
300
316
|
> svg2gcode --help
|
|
301
317
|
```
|
|
302
318
|
#### How do we cut these lines?
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
style="fill:none;stroke:none;stroke-width:.1"
|
|
306
|
-
```
|
|
307
|
-
or add 'gcode-pathcut' to the style string:
|
|
319
|
+
|
|
320
|
+
Add 'gcode-pathcut' to the style string:
|
|
308
321
|
```
|
|
309
322
|
style="fill:none;stroke:red;stroke-width:.1;gcode-pathcut:true"
|
|
310
323
|
```
|
|
@@ -353,3 +366,4 @@ One containing the drawings of the .svg, the other containing the images:
|
|
|
353
366
|
### Burn mode M3/M4:
|
|
354
367
|
|
|
355
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.
|
|
369
|
+
|
|
@@ -19,7 +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,
|
|
22
|
+
from svg2gcode.svg_to_gcode.svg_parser import NAMESPACES, ElementTreeParent
|
|
23
23
|
|
|
24
24
|
from svg2gcode import __version__
|
|
25
25
|
|
|
@@ -483,13 +483,13 @@ class Compiler:
|
|
|
483
483
|
style['pathcut'] = curve.path_attrib['gcode_pathcut']
|
|
484
484
|
|
|
485
485
|
# check missing attributes, if any
|
|
486
|
-
if
|
|
487
|
-
parent = curve.path_attrib[
|
|
486
|
+
if ElementTreeParent in curve.path_attrib:
|
|
487
|
+
parent = curve.path_attrib[ElementTreeParent]
|
|
488
488
|
|
|
489
|
-
# find first parent g (group) tag, if any
|
|
489
|
+
# find first parent <g (group) tag, if any
|
|
490
490
|
while parent and parent.tag != "{%s}g" % NAMESPACES["svg"]:
|
|
491
|
-
if
|
|
492
|
-
parent = parent.attrib[
|
|
491
|
+
if ElementTreeParent in parent.attrib:
|
|
492
|
+
parent = parent.attrib[ElementTreeParent]
|
|
493
493
|
else:
|
|
494
494
|
parent = None
|
|
495
495
|
if parent:
|
|
@@ -671,7 +671,7 @@ class Compiler:
|
|
|
671
671
|
def get_style_info_of_line_chain(line_chain: LineSegmentChain) -> ():
|
|
672
672
|
"""
|
|
673
673
|
Get style info of line_chain.
|
|
674
|
-
Returns tuple (stroke_width, stroke_color, stroke_alpha, fill_color, fill_alpha, fill_rule)
|
|
674
|
+
Returns tuple (stroke_width, stroke_color, stroke_alpha, fill_color, fill_alpha, fill_rule, pathcut)
|
|
675
675
|
"""
|
|
676
676
|
# defaults
|
|
677
677
|
stroke_width = 0
|
|
@@ -685,8 +685,7 @@ class Compiler:
|
|
|
685
685
|
first_line_of_chain = line_chain.get(0)
|
|
686
686
|
style = self.parse_style_attribute(first_line_of_chain)
|
|
687
687
|
if style:
|
|
688
|
-
if
|
|
689
|
-
and style['stroke'] is not None and style['stroke'] != "none":
|
|
688
|
+
if style['stroke'] is not None and style['stroke'] != "none":
|
|
690
689
|
stroke_color = style['stroke']
|
|
691
690
|
if style['stroke-opacity'] is not None:
|
|
692
691
|
# fill opacity attribute overrides rgba property
|
|
@@ -721,7 +720,7 @@ class Compiler:
|
|
|
721
720
|
fill_alpha = rgba[3]
|
|
722
721
|
fill_color = round(fill_color * fill_alpha)
|
|
723
722
|
|
|
724
|
-
return (stroke_width, stroke_color, stroke_alpha, fill_color, fill_alpha, fill_rule)
|
|
723
|
+
return (stroke_width, stroke_color, stroke_alpha, fill_color, fill_alpha, fill_rule, style['pathcut'])
|
|
725
724
|
|
|
726
725
|
|
|
727
726
|
path_curves = {}
|
|
@@ -776,9 +775,13 @@ class Compiler:
|
|
|
776
775
|
# Render svg 'stroke' attribute
|
|
777
776
|
for line_chain in path_curves[name_id]:
|
|
778
777
|
# get style info
|
|
779
|
-
stroke_width, stroke_color, stroke_alpha, fill_color, fill_alpha, fill_rule = get_style_info_of_line_chain(line_chain)
|
|
778
|
+
stroke_width, stroke_color, stroke_alpha, fill_color, fill_alpha, fill_rule, style_pathcut = get_style_info_of_line_chain(line_chain)
|
|
780
779
|
|
|
781
|
-
if
|
|
780
|
+
if (style_pathcut is not None and style_pathcut == 'true') or self.settings["pathcut"]:
|
|
781
|
+
# cut path
|
|
782
|
+
self.body.extend([f"\n; cut path (pathcut set) '{name_id}'"])
|
|
783
|
+
render_pathwidth(line_chain, [0], None, None, boundingbox)
|
|
784
|
+
elif len(stroke_color):
|
|
782
785
|
|
|
783
786
|
# Get stroke alpha channel (opacity)
|
|
784
787
|
# fill opacity attribute overrides rgba property
|
|
@@ -840,13 +843,12 @@ class Compiler:
|
|
|
840
843
|
if not (delta == stroke_width and stroke_width % 2 != 0):
|
|
841
844
|
steps.append(round(-delta * pixel_size, self.precision))
|
|
842
845
|
|
|
843
|
-
# color_coded isn't set:
|
|
844
|
-
self.body.extend([f"\n; engrave path '{name_id}', color '{stroke_color}'"])
|
|
846
|
+
# color_coded isn't set: engrave path with stroke color
|
|
847
|
+
self.body.extend([f"\n; default action: engrave path '{name_id}', color '{stroke_color}'"])
|
|
845
848
|
render_pathwidth(line_chain, steps, inverse_bw, speed, boundingbox)
|
|
846
849
|
else:
|
|
847
|
-
#
|
|
848
|
-
self.body.extend([f"\n; no stroke color set:
|
|
849
|
-
#render_pathwidth(line_chain, [0], None, None, boundingbox)
|
|
850
|
+
# cannot engrave path (ignore)
|
|
851
|
+
self.body.extend([f"\n; cannot engrave path (ignore) no stroke color set: path '{name_id}'"])
|
|
850
852
|
|
|
851
853
|
# Render svg 'fill' attribute
|
|
852
854
|
#if not self.settings["nofill"] and fill_color is not None and boundingbox.get() is not None:
|