Units In Inkscape

From Inkscape Wiki
Revision as of 13:00, 18 November 2014 by Tavmjong (Talk | contribs) (Inkscape & Units)

Jump to: navigation, search

Introduction

This page documents the philosophy for Units handling inside Inkscape. Units are not as straight-forward as one should think they are.

Historical View

Part of the problem with units in SVG and CSS in general is why they are there in the first place. In the early days it was assumed that one would want to display drawings on a screen at full scale. In otherwords, a "one inch square" would be display on a screen as a physical one inch square. This required that displays be queryable as to what there true DPI was. Display manufactures rarely provided the means to query the DPI of the display, and when they did, they often returned incorrect results. Thus, the use of "real" units never became popular and in reality is usually not what one wanted. Eventually, after long arguments, the CSS working group dictated that one inch would be fixed to 96 pixels regardless of screen resolution (ironically, with so called Retina displays, there is once again interest in scaling drawings based on DPI).

The Philosophy

Absolute units should not be used inside an SVG file with one exception:

The root width and height may have units, which with a proper viewBox determines an appropriate scale for a drawing. (This sets the "real" world value of the SVG user unit.) This reflect the opinion of the majority of the SVG working group.

It should be noted that the relative units em, ex, and % can be useful in some cases.

Inkscape & Units

Inkscape should not write out absolute units other than in the root SVG element. Inkscape must, however, be able to interpret units from non-Inkscape produced files according to the CSS defined value of 96 pixels (initial user-units) per inch.[1]

The use of units in the Inkscape GUI is for ease of authoring only. The actual values should be stored as user-units.

Changing the Inkscape Document unit should not introduce any transforms on elements nor should changing the SVG root width/height or the viewBox.

The GUI should show sizes taking into account both the Inkscape Document unit as well as the choosen GUI unit, taking into account the width/height and viewBox.

For example:

<svg width="100mm" height="100mm" viewBox="0 0 100 100">

describes a drawing 100mm x 100mm where one user-unit is equivalent to one "mm".

The Inkscape property inkscape:document-units should be set to "mm".

Question: Why do we have this property? Can't it be determined from width and/or height?

Answer: It should be determined from the viewBox and width/height. We need to be able to handle files where the ratio is not one of the SVG units.


If the GUI unit is set to "mm" then the GUI would show a width of '25.4' for a rectangle 25.4 user-units wide. If the GUI unit is set to "in", the GUI would show '1.0'.

A 2013 GSoC project by Matthew Petroff unified the Units handling in Inkscape, mostly implementing this philosophy. Inconsistencies should be viewed as bugs.


Use Scenarios

How does/should Inkscape behave in various use scenarios?

Cases

  • Pixel art

    Should not be a problem. Everything is done in user units.

  • A4/Letter size page.

    Here the key is exporting to PDF. PDF follows postscript and uses 72 units per inch. Documents sized in terms of pixels need to be scaled properly (0.91 72/90, 0.92 72/96). This could be handled by an export option like is done for PNG export. Documents sized in terms of real units should not have a problem.

  • Scaled drawings.

    Scaling determined by document size and viewBox. The current implementation does not handle arbitrary scaling well.

Document Unit Changes

  • Resize page
    1. Grids/guides should not change.
    2. It might be useful to able to specify a guide at 50%.
  • Rescale page
    • Change width/height but leave viewBox alone
    • Change viewBox but leave width/height alone
  • Change document units
    1. Very messy and bug prone.
  • Edit a 90dpi unit in 0.92 (96dpi)
  • Edit a 96dpi unit in 0.91 (90dpi)


Notes:

  1. Guides are currently defined in pixels in with respect to the page.
  2. Grids are current defined in pixels or other units with respect to the page.

Notes

The outer SVG width/height, viewBox, and document-units should not be changed in the XML Editor. Use the Page tab of the Document Properties to change the document size or document unit to avoid the risk of them becoming inconsistent.