Inkscape Units Identifier Tests and Conclusions
Last updated 24 Nov. 2016
This page collects together a series of unit identifier dependent tests and makes some conclusions based on the tests.
For background and definitions see: Units in Inkscape wiki page.
Basic Units Identifier Tests
External unit identifiers are determined by the unit identifier in the SVG root 'width' and 'height' attributes.
Scale is determined by the viewBox dimensions in relationship to the SVG root 'width' and 'height' attributes. For example if the 'width' is '1in' and the viewBox is '0 0 90 90' the scale would be 90 'user units' per inch.
Patch 1 changes guides and 3d boxes to use 'user units'.
Patch 2 is my proposal for handling the transition from 90 to 96 dpi in 0.92.x.
Guides and Grids
Each test represents a 20mm x 20mm square including:
- A gray <rect> covering the entire drawing defined in %.
- A pink <rect> covering the upper-left quadrant defined in user units.
- A blue <path> (triangle) defined in user units.
- A red circle <circle> defined in user units.
- A green 'T' with font size in px.
- A purple 'T' with font size in mm.
- Three guides defined in external units.
- One to three grids (defined using user-units, mm, and/or px).
Tests
-
No external units, no 'viewBox', width of 20mm calculated based on 90px per inch. Inkscape version 0.91.
(Browsers will show this smaller than 20mm x 20mm as this SVG assumes 90 pixels per inch and browers use 96 pixels per inch.)- 0.91: OK.
- 0.91 Patch 1: OK.
- 0.92: Displays 'mm' base grid "wrong".
- 0.92: With Patch 2: With and without viewBox scaling: OK.
-
External units in px, no 'viewBox', width of 20mm calculated based on 90px per inch. Inkscape version 0.91.
(Browsers will show this smaller than 20mm x 20mm as this SVG assumes 90 pixels per inch and browers use 96 pixels per inch.)- 0.91: OK.
- 0.91 Patch 1: OK.
- 0.92: Displays 'mm' base grid "wrong".
- 0.92: With Patch 2: With and without viewBox scaling: OK.
-
External units in mm, no 'viewBox', shapes/guides/grid based on 90px per inch. Inkscape version 0.91.
Displays incorrectly in browsers (as expected).- 0.91: OK.
- 0.91 Patch 1: OK.
- 0.92: Square, triangle, circle too small (as expected).
- 0.92: Patch 2: Without viewBox scaling: Square, triangle, circle too small (as expected). With viewBox scaling: OK.
-
External units in mm, internal units in px assuming 90 pixels per inch. Inkscape version 0.91.
- 0.91: OK.
- 0.91 Patch 1: OK.
- 0.92: Displays 'px' based grid wrong.
- 0.92: Patch 2 OK. No need for dialog.
-
External units in mm, internal units in px assuming 96 pixels per inch. No Inkscape version.
- 0.91: Displays 'px' based grid wrong. Displays guides wrong.
- 0.91 Patch 1: Guides OK.
- 0.92: OK.
- 0.92: Patch 2 OK. No need for dialog.
-
External units in mm, internal units in mm, grid spacing assumes 90 pixels per inch. Inkscape version 0.91.
- 0.91: OK (displays grid defined in "external" pixels OK).
- 0.91 Patch 1: Guides OK.
- 0.92: Displays 'px' based grid wrong.
- 0.92: Patch 2 OK. No need for dialog.
-
External units in mm, internal units in mm, grid spacing assumes 96 pixels per inch. No Inkscape version.
- 0.91: Displays 'px' based grid wrong. Displays guides wrong.
- 0.91 Patch 1: Guides OK.
- 0.92: OK (displays grid defined in "external" pixels OK).
- 0.92: Patch 2 OK. No need for dialog.
-
External units in mm, internal units in tenths of mm. No Inkscape version.
- 0.91: Displays 'px' based grid wrong. Displays guides wrong.
- 0.91 Patch 1: Guides OK.
- 0.92: OK (displays grid defined in "external" pixels OK).
- 0.92: Patch 2 OK. No need for dialog.
3D Box Tool
Note: There is a bug in Inkscape that sometimes displays a box shifted in 'y' from its proper place. Nudging the box will move it to its proper place.
-
External units in px, no 'viewBox'. Box created with 0.48.
- 0.48: OK.
- 0.91 with Patch 1: OK.
- 0.92: OK.
-
External units in px, no 'viewBox'. Box created in 0.91 with Patch 1.
- 0.48: OK.
- 0.91: OK.
- 0.92: OK.
-
External units in mm, scale 1mm/'user unit'. Box created in 0.91 with Patch 1.
- 0.48: Too small (expected).
- 0.91: OK.
- 0.92: OK.
-
External units in px, no 'viewBox'. Box created with trunk.
- 0.48: OK.
- 0.91 with Patch 1: OK.
- 0.92: OK.
-
External units in mm, scale 1mm/'user unit'. Box created with trunk.
- 0.48: Too small (expected).
- 0.91 with Patch 1: OK.
- 0.92: OK.
Conclusions
From the various tests above:
- Use of unit identifiers in SVG root 'width'/'height' mandate use of 'viewBox' or display will be different between 0.91 and 0.92. Fixing SVG's with unit identifiers in 'width'/'height' and no 'viewBox' could be done by adding an appropriate 'viewBox'. (Lengths in terms of '%' are not corrected properly but Inkscape never creates such files.) -> Add 'viewBox' to all templates. PARTIALLY DONE.
- Use of unit identifiers in SVG root 'width'/'height' with 'viewBox' results in correct rendering in both 0.91 and 0.92. -> Add 'viewBox' to all templates. PARTIALLY DONE.
- Grid, guides, and 3D box tool need fixing between 0.91 and 0.92. If there is a 'viewBox', at least guides can be handled by using a 'scale' determined from 'width'/'height' and 'viewBox'. Should also be possible with grids. -> Add code to adjust guides and grids based on 'scale'. Code in trunk for guides and 3D Box tool. NEEDS BACKPORTING FOR 0.91.
- Use of "inkscape:document-units" should be limited to the GUI. There are about 50 places where "inkscape-document-units" is used in the codebase. DONE.
- The 'units' attribute in 'namedview' should be renamed to better indicate its purpose. DONE (Changed to 'page-size-unit;).
- The use of 'pt' as default unit identifier should be change to 'px'. Non-pixel units should not be used except possibly in the root 'width'/'height' SVG element. Change default unit identifier to 'px'. DONE.
- It is possible to use 'pt' for 'font-size' via a preference (Text->Text Size). -> Disable ability to use 'pt' or other unit other than 'px'. DONE.
- The 'Rect' tool displays values in the 'rectangle's coordinate frame which includes transforms while the 'Select' tool displays values in the document's coordinate frame. See #1384915. -> Out of scope.
- Changing document units at this point (0.91) needs disabling. There are too many places where things can go wrong (see bugs listed in Document Unit Change wiki page). -> Disable unit changing in Document Preferences. DONE.
Other Actions
- Backport r13632 from trunk to fix an accuracy bug. (See: #1384915.) DONE.
- Investigate adding an "inkscape:dpi" attribute to track 90 vs 96 dpi. Use this value to in PostScript/PDF export.
- Investigate not overwriting inkscape version until saving/export.
Specialized Tests
- W3C units test.
- To test 'pt' vs 'px' in 'font-size'. (Tests 90 vs 96 dpi.)
For testing changing document unit:
- Various uses of <use>.
- Text on path. (One path defined inside, the other outside <defs>.)
- Clipping.