Skip to content

A unitless SVG width is taken as points when exporting to PDF #9765

Backlog

Description

@stratosjl

An SVG whose width and height have no unit should be read as CSS pixels (1 px = 0.75 pt). VectorCraft sizes the PDF page in points, so the page comes out a third too large.

Repro (vectorcraft-cli 0.24.1):

printf '<svg xmlns="http://www.w3.org/2000/svg" width="400" height="300" viewBox="0 0 400 300"><rect x="10" y="10" width="100" height="50" fill="#c00"/></svg>\n' > u.svg
vectorcraft-cli convert u.svg vc.pdf && pdfinfo vc.pdf | grep 'Page size'     # 400 x 300 pts
rsvg-convert -f pdf -o rsvg.pdf u.svg && pdfinfo rsvg.pdf | grep 'Page size'  # 300 x 225 pts
inkscape u.svg -o ink.pdf && pdfinfo ink.pdf | grep 'Page size'               # 300 x 225 pts

With width="4in" all three agree (288 x 216 pt). In the other direction, convert of a 300 pt PDF page to SVG writes width="300", which viewers show at 0.75 of the size. Related: #11, #3359.


Found while comparing the Craft apps with other open-source tools on Linux (CachyOS, native package), using synthetic test files only. Drafted with Claude Code; the repro above was re-run on the stated version before posting.

Activity

  1. stratosjl commented on Nov 27, 2026

    @stratosjl
    Author

    Correction after reading the code: this is by design, not a bug. RootUnits in crates/svg/src/import/layers.rs documents that a pixel and a unitless user unit are a point ("as we export"), with absolute root sizes kept physical and the mixed case handled in #1010. That matches a 72 ppi convention, where rsvg, Inkscape and browsers use CSS pixels at 96 per inch, hence the 4/3 difference I measured. Unless an option for 96 ppi CSS pixels is wanted, please feel free to close this; sorry for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions