2.1.3. Parsing Dimensions (layout.datatypes.parse_dimensions
)¶
In many applications dimensions will be specified as input from the
user. When coding, you can use the constants in
layout.datatypes.units
, such as 12*mm
. When processing
input, this module converts textual representations of dimensions into
the corresponding values in postscript points (the standard unit of
size used throughout the package).
2.1.3.1. Reference¶
This module is designed for parsing dimensions in text form and turning them into sizes in printer’s points (i.e. 72 per inch).
-
exception
layout.datatypes.parse_dimensions.
DimensionError
¶ Bases:
Exception
-
layout.datatypes.parse_dimensions.
parse_dimension
(text)¶ Parses the given text into one dimension and returns its equivalent size in points.
The numbers provided can be integer or decimal, but exponents are not supported.
The units may be inches (“, in, ins, inch, inchs, inches), millimeters (mm), points (pt, pts, point, points, or nothing), or centimeters (cm). Because this module is intended for use with paper-size dimensions, no larger or smaller units are currently supported.
-
layout.datatypes.parse_dimensions.
parse_dimensions
(text)¶ Parses a set of dimensions into tuple of values representing the sizes in points.
The dimensions that this method supports are exactly as for parse_dimension. It supports multiple dimensions, separated by whitespace, comma, semicolon, hyphen, or the letter x. The units may follow each dimension (in which case they can be different in each case) or only after the last one. Because no-units also means points, if you have some dimensions in the middle of the set with units and some without, then those without will be interpreted as points: i.e. the 2 in “1in, 2, 3mm” will be treated as 2 points, where as the 1 and 2 in “1, 2, 3mm” will be treated as millimeters.