domoszlai / juicy-gcode

A lightweight SVG to GCode converter for maximal curve fitting
https://hackage.haskell.org/package/juicy-gcode
MIT License
113 stars 7 forks source link

-d option is not considered when svg height and width are length in centimeters #29

Open monperrus opened 11 months ago

monperrus commented 11 months ago

Given a SVG file with height and width as real length in centimeters

    <svg height="26cm" version="1.2" viewBox="0 0 500.0 500.0" width="26cm">

Actual behavior

the -d DPI option is silently ignored

Expected behavior

Either

domoszlai commented 11 months ago

You do not need the DPI in this case as 26cm is ~10in so the SVG has ~50DPI. This reflected in juicy-gcode --help:

image

I feel like a warning would be appropriate, but also luxurious :D

domoszlai commented 11 months ago

Actually, there might be a bug in the current implementation:

<svg width="10cm" height="10cm" viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
  <rect x="1cm" y="1cm" width="10" height="20"/>
</svg>

Not sure in this case what should happen...

domoszlai commented 11 months ago

Looking at this example:

<svg width="10cm" height="10cm" viewBox="0 0 300 300" xmlns="http://www.w3.org/2000/svg">
  <rect x="1in" y="1in" width="10" height="20"/>
  <rect x="96" y="96" width="10" height="20"/>
</svg>

The two rectangles rendered to the same spot independently of what the viewBox is. Thus, some default DPI is used to do the inner conversion, event though, the document size is in cm. This is exactly how juicy-gcode works, so the DPI setting still required

monperrus commented 11 months ago

I confirm that with this example, -d has an effect on the first rectangle.

Now coming back to the use case.

I was changing -d without any effect on the output. After a tedious debug session, I realized that the input SVG had something new: the real length.

What would be the luxurious message to save me precious time?

Maybe "Drawing area {X}cm x {Y}cm onto gcode max_x=100,max_y=100"

Thanks!

domoszlai commented 11 months ago

But as my previous example suggests, even if the width and height of the SVG is in cm, you might need the DPI to render it. So I can't give a warning like "-d option ignored because SVG height and width are in centimeters", because it is not true (it might not being used but it is not ignored).

I also can't just dump debug messages to the standard output freely as I might break other people's application.

I could probably add like a debug or info flag...

monperrus commented 11 months ago

ack, thanks!