Specifying units for SVG Paths

Discuss SVG code, accessible via the XML Editor.
felipemdc
Posts: 1
Joined: Fri Aug 27, 2010 6:20 pm

Specifying units for SVG Paths

Postby felipemdc » Fri Aug 27, 2010 6:25 pm

Hello, I am writing a software which generates SVG files to be opened with Inkscape. So far, for a simple line I have:

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with fpVectorial (http://wiki.lazarus.freepascal.org/fpvectorial) -->

<svg
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:cc="http://creativecommons.org/ns#"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:svg="http://www.w3.org/2000/svg"
  xmlns="http://www.w3.org/2000/svg"
  xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
  width="100mm"
  height="100mm"
  id="svg2"
  version="1.1"
  sodipodi:docname="New document 1">
  <g id="layer1">
  <path
    style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
    d="m 0mm,20mm 30mm,30mm "
  id="path0" />
  </g>
</svg>


But Inkscape doesn't render this file. It will render if I change the path to this: d="m 0,20 30,30 "

But then there are no real world units, only pixels! And I've openned the file with Inkscape and it doesn't match the same amounts I wanted in milimiters. Is it impossible to specify paths with real world units?

If it is impossible, then what do people do? Hardcode to DPI 72?

If it is indeed like that this is a very serious shortcoming for the SVG format...

thanks,

~suv
Posts: 2272
Joined: Sun May 10, 2009 2:07 am

Re: Specifying units for SVG Paths

Postby ~suv » Sat Aug 28, 2010 6:29 pm

felipemdc wrote:

Code: Select all

  <path
    style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
    d="m 0mm,20mm 30mm,30mm "
  id="path0" />
But Inkscape doesn't render this file. It will render if I change the path to this: d="m 0,20 30,30 "

Units are not allowed in path data 'd' according to the SVG 1.1 specification, only coordinates. AFAIU the viewBox attribute can be used for "scaling" to other units than 'user units' (px). Note however that Inkscape does not fully support 'viewBox' i.e. it renders it but has no interface to create it itself.


Return to “SVG / XML Code”