Notes On Units Handling in Extensions in 0.91
Since the release of Inkscape 0.48.4 there has been a fundamental change made in the scaling of length variables in Inkscape. The
viewBox attribute has been introduced as a standard feature of all files, and its size is determined by the units that are chosen for the variable
inkscape:document-units (see dialog Document Properties: Default Units). In the Python extensions this has led to the requirement that units of length variables must be explicitly taken into account, otherwise they will not scale correctly when changing the Default Units (see Bug 1240455). Previously this type of scaling was done with a call to
inkex.unittouu(), the new syntax for this call is
self.unittouu(). Attached is a list of situations in which you may need to do this type of scaling, to convert to document units:
- When reading the document height/width (see dxf_outlines.py, r12722)
- When reading any .inx file input variable that has units of length (see grid_cartesian.py, r13007)
- When specifying a stroke-width or font-size in a style attribute (see split.py, r12722; render_gears.py r12722, r13001, r13036)
- For multiple items in a group, it may be more efficient to scale the group with a transform, rather than scaling individual objects (see render_barcode.py, r13015).
- Remember that console commands like
inkscape --query-all, to query the bbox, return pixels regardless of the document units, so they will need to be converted (see dimension.py, r13028).
- Remember that guides, which are in the
sodipodi:namedviewsection, are not affected by document units, so they do not need to be scaled (see guides_creator.py, r12722, r13007).
- If you are creating new classes unique to your application, you may need to provide a mechanism to allow your new class to continue to access
unittouu()(see ink2canvas.py, r12722, r13027).
Original version of the notes by Alvin Penner: scaling.txt (see comments 31-34 in Bug 1240455)