sameer / svg2gcode

Convert vector graphics to g-code for pen plotters, laser engravers, and other CNC machines
https://sameer.github.io/svg2gcode
MIT License
241 stars 48 forks source link

Converting from 'Percent' to millimeters is not supported, treating as millimeters #20

Closed matopeto closed 2 years ago

matopeto commented 2 years ago

Hi

I exported svg from Affinity Photo and svg looks like:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="100%" height="100%" viewBox="0 0 354 1181" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5;">
    <g transform="matrix(0.30102,0,0,1,4.19388,0)">
        <path d="M6,1175L1182,1179L1178,3L6,1L6,1175Z" style="fill:none;stroke:rgb(255,0,57);stroke-width:1.13px;"/>
    </g>
</svg>

It defines viewBox (in some units, seems like pixels mm x dpi) and width and height in percent

I run your program and get this warning

Converting from 'Percent' to millimeters is not supported, treating as millimeters

And result is 100x100 mm instead correct dimensions

It can be sized by --dimensions but i cannot specify only one dimension because of wrong aspect ratio 100x100 instead of 354x1181

cargo run --release -- examples/affinityexport.svg --off 'M4' --on 'M5' -o out.gcode
[2021-10-02T16:12:21Z WARN  svg2gcode::converter] Converting from 'Percent' to millimeters is not supported, treating as millimeters
[2021-10-02T16:12:21Z WARN  svg2gcode::converter] Converting from 'Percent' to millimeters is not supported, treating as millimeters

Generated output:

G21
G90;svg > g > path
M4
G0 X1.6949152542372883 Y0.5080440304826368
M5
G1 X101.69477966101695 Y0.1693480101608884 F300
G1 X101.35464406779661 Y99.74597798475868 F300
G1 X1.6949152542372883 Y99.91532599491956 F300
G1 X1.6949152542372883 Y0.5080440304826368 F300
M4
M2
sameer commented 2 years ago

Hi matopeto,

I've added some more nuanced handling for the use case you described:

Checked output with dimensions arguments 354mm,, ,1181mm and 354mm,1181mm and all look identical

matopeto commented 2 years ago

It works, great :)