pygobject / pycairo

Python bindings for cairo
https://pycairo.readthedocs.io
Other
611 stars 83 forks source link

SVG renders with poor precision #354

Open gskluzacek opened 6 months ago

gskluzacek commented 6 months ago

New, to pycairo, so maybe I'm missing something...

I'm trying to draw a simple polygon with move_to & line_to, however the values appearing in the SVG output are only accurate to the 100th place.

for example:

  I give an x coordinate in the move_to call of 6.426575
             but it shows up in the SVG file as 6.425781

for some reason its loosing precision after 6.42, the next digit should be a 6, but I'm getting a 5.

here's my code:

import cairo
with cairo.SVGSurface("test_2.svg", 100, 100) as surface:
    context = cairo.Context(surface)
    context.set_line_width(.1)
    context.set_source_rgb(1, 0, 0)
    context.move_to(6.426575, 89.055378)
    context.line_to(65.205100, 3.311026)
    context.line_to(123.983626, 89.055378)
    context.close_path()
    context.stroke()

here is the svg output

<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100" height="100"
     viewBox="0 0 100 100">
    <path fill="none" stroke-width="0.1" stroke-linecap="butt" stroke-linejoin="miter" stroke="rgb(100%, 0%, 0%)"
          stroke-opacity="1" stroke-miterlimit="10"
          d="M 6.425781 89.054688 L 65.207031 3.3125 L 123.984375 89.054688 Z M 6.425781 89.054688 "/>
</svg>