pub struct Length { /* private fields */ }Expand description
Length measurement stored as millipoints (1/1000 point)
Conversion factors:
- 1 point = 1/72 inch
- 1 inch = 72 points = 72000 millipoints
- 1 mm = 2.834645669 points
- 1 cm = 28.34645669 points
Font-relative units:
- 1em = current font-size
- 1ex = x-height of current font (typically ~0.5em)
Implementations§
Source§impl Length
impl Length
Sourcepub const fn from_millipoints(millipoints: i32) -> Length
pub const fn from_millipoints(millipoints: i32) -> Length
Create a length from millipoints directly
Sourcepub fn from_em(em: f64) -> LengthUnit
pub fn from_em(em: f64) -> LengthUnit
Create a font-relative length in em units
1em equals the current font-size. The returned LengthUnit must be resolved with a FontContext to get an absolute length.
§Examples
use fop_types::{Length, FontContext, LengthUnit};
let em_unit = LengthUnit::Em(1.5);
let context = FontContext::new(Length::from_pt(12.0));
let resolved = Length::resolve_unit(&em_unit, &context);
assert_eq!(resolved, Length::from_pt(18.0)); // 1.5 * 12ptSourcepub fn from_ex(ex: f64) -> LengthUnit
pub fn from_ex(ex: f64) -> LengthUnit
Create a font-relative length in ex units
1ex equals the x-height of the current font (typically ~0.5em). The returned LengthUnit must be resolved with a FontContext to get an absolute length.
§Examples
use fop_types::{Length, FontContext, LengthUnit};
let ex_unit = LengthUnit::Ex(2.0);
let context = FontContext::new(Length::from_pt(12.0));
let resolved = Length::resolve_unit(&ex_unit, &context);
// 2.0 * 6pt (x-height is 0.5 * font-size)
assert_eq!(resolved, Length::from_pt(12.0));Sourcepub fn resolve_unit(unit: &LengthUnit, context: &FontContext) -> Length
pub fn resolve_unit(unit: &LengthUnit, context: &FontContext) -> Length
Resolve a LengthUnit to an absolute Length using a FontContext
For absolute units, returns the length directly. For em units, multiplies by the font size. For ex units, multiplies by the x-height.
§Examples
use fop_types::{Length, FontContext, LengthUnit};
let context = FontContext::new(Length::from_pt(12.0));
// Absolute unit
let abs = LengthUnit::Absolute(12000);
assert_eq!(Length::resolve_unit(&abs, &context), Length::from_pt(12.0));
// Em unit
let em = LengthUnit::Em(1.5);
assert_eq!(Length::resolve_unit(&em, &context), Length::from_pt(18.0));
// Ex unit
let ex = LengthUnit::Ex(2.0);
assert_eq!(Length::resolve_unit(&ex, &context), Length::from_pt(12.0));Sourcepub const fn millipoints(self) -> i32
pub const fn millipoints(self) -> i32
Get the raw millipoint value
Trait Implementations§
Source§impl AddAssign for Length
impl AddAssign for Length
Source§fn add_assign(&mut self, other: Length)
fn add_assign(&mut self, other: Length)
Performs the
+= operation. Read moreSource§impl Ord for Length
impl Ord for Length
Source§impl PartialOrd for Length
impl PartialOrd for Length
Source§impl SubAssign for Length
impl SubAssign for Length
Source§fn sub_assign(&mut self, other: Length)
fn sub_assign(&mut self, other: Length)
Performs the
-= operation. Read moreimpl Copy for Length
impl Eq for Length
impl StructuralPartialEq for Length
Auto Trait Implementations§
impl Freeze for Length
impl RefUnwindSafe for Length
impl Send for Length
impl Sync for Length
impl Unpin for Length
impl UnsafeUnpin for Length
impl UnwindSafe for Length
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more