How can I interpret an input file as mm (instead of pixels)?

Asked by Nikolas

Hello

I am trying to read a .svg file in which the corrdinates are given in mm:

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="90.0" height="260.0"
 viewBox="0 0 90.0 260.0"
 xmlns="http://www.w3.org/2000/svg" version="1.1"
 xmlns:xlink="http://www.w3.org/1999/xlink">
<desc>Output from Flights of Ideas SVG Sketchup Plugin</desc>

  <g id="face0" fill="none" stroke="rgb(0,0,255)" stroke-width="1" stroke-miterlimit="4" stroke-dasharray="none" stroke-linejoin="round" stroke-linecap="round">
    <line x1="80.0" y1="60.0" x2="80.0" y2="55.0"/>
    <line x1="80.0" y1="55.0" x2="77.3660537803193" y2="52.3119486730611"/>
    <line x1="77.3660537803193" y1="52.3119486730611" x2="75.1358599648681" y2="49.2805252170008"/>
    <line x1="75.1358599648681" y1="49.2805252170008" x2="73.3536531117097" y2="45.9658560997307"/>

(...)

(This file was created using the svg-Plugin for google sketchup). If I load this file in inkscape, the distances are interpreted as pixels. I need it in mm as I use this file later to cut the pieces on a laser cutter.

So: how can I tell inkscape that the values given in the file are mm?

Cheers,
  Nikolas

Question information

Language:
English Edit question
Status:
Solved
For:
Inkscape Edit question
Assignee:
No assignee Edit question
Solved by:
su_v
Solved:
Last query:
Last reply:
Revision history for this message
Best su_v (suv-lp) said :
#1

The pasted SVG file snippet contains no information about using 'mm' as
base document unit, not even the slightest hint. You might consider to
ask the authors of the creator software of that file about why the
information saved does not match your expectations - Inkscape interprets
the units as stored in the file correctly, in compliance with the SVG
1.1 specification.

To adjust it e.g. for Inkscape, you could use a regular (and
recommended) SVG method to set a scale for the document based on the
combination of the 'viewBox' attribute and the 'width' and height'
attributes (these three attributes nedd to be set for the top-level
<svg> element) - assuming that this corresponds to the intention of the
creater software:

Edit the SVG file in a plain-text editor, and change the (unitless - aka
in 'SVG user units' aka in 'px' units) values for 'width' and 'height'
to 'mm', while leaving the 'viewBox' attribute as is (no units here!):

<svg width="90.0mm" height="260.0mm"
 viewBox="0 0 90.0 260.0"
(...)

This will scale the initial viewport (defined in SVG user units, aka
'px') to match a rectangluar area in (real units) 'mm'. Thus all
coordinate and length information used by elements inside the <svg>
container will be equally affected by the same scale. This method works
well as long as all elements inside the SVG file do not randomly mix
'px' (or unitless aka 'SVG user units') with real units (e.g. 'mm').
AFAICT it should work reasonably well with elements as shown in your
pasted snippet of the original SVG file.

For more information, see e.g.
<http://www.w3.org/TR/SVG11/coords.html#ViewBoxAttribute>
and
<http://www.w3.org/TR/SVG11/struct.html#SVGElementWidthAttribute>
<http://www.w3.org/TR/SVG11/struct.html#SVGElementHeightAttribute>

Revision history for this message
Nikolas (nikolas-engelhard-v) said :
#2

Thanks ~suv, that solved my question.

Revision history for this message
Nikolas (nikolas-engelhard-v) said :
#3

I guess that was the best answer I got in a mailing list or forum ever : )
If you happen to be in Munich in the next time, a beer is waiting for you!

I'll contact the author of the plugin (or see if I can write a patch myself) so that others won't have the same problem.

NIkolas

Revision history for this message
su_v (suv-lp) said :
#4

Note that Inkscape's support for 'viewBox' in combination with real
units defined via width/height might still have some deficiencies (with
some (but not all) of unit selectors used in the GUI [*]) - it is
hwoever on the roadmap, and currently the scope for a proposed GSoC
project this summer:

<http://google-melange.appspot.com/gsoc/proposal/review/google/gsoc2013/mpetroff/1>

-----
[1] e.g. <http://article.gmane.org/gmane.comp.graphics.inkscape.devel/39368>

Revision history for this message
Richard Timsit (richard-timsit) said :
#5

But how to export files from Inkscape to AI, in SVG format (eg for a laser cutting...) ?

With export SVG in Inkscape, it is impossible to change the resolution (90dpi) as with cairo in eps ...

Adobe Illustrator uses a resolution of 72dpi by default :-(( so the dimsensions are wrong !