pub struct Length(pub f32);Expand description
A length, held in points.
ODF writes a length as a number and a unit, and the unit varies by writer and by locale: the same document carries centimetres in its page layout and points in its font sizes. Everything is converted on the way in so that nothing downstream has to ask which unit it is looking at. A point is the unit a renderer wants, being what a font size is already in.
Tuple Fields§
§0: f32Implementations§
Source§impl Length
impl Length
Sourcepub fn parse(text: &str) -> Option<Self>
pub fn parse(text: &str) -> Option<Self>
Parse a length with its unit, as ODF writes one.
None for anything unreadable, including a bare number: ODF requires a
unit on every length, and a number with none is a writer’s mistake whose
intended unit cannot be guessed.
Sourcepub fn write(self, unit: &str) -> String
pub fn write(self, unit: &str) -> String
Write the length in a unit, as ODF spells one: 2.54cm.
The unit is whichever the attribute carried when it was read, so a document written in centimetres stays in centimetres; anything not an ODF unit is written in centimetres. Four decimals, trailing zeros dropped, which is finer than a hundredth of a point in any unit.