pub struct Metrics<'a> {
pub width: &'a dyn Fn(u32) -> i32,
pub ascent: i32,
pub descent: i32,
}Expand description
What the engine needs to know about the font it is setting.
A plain record rather than a trait: there is exactly one real implementation, and the test stub is a different set of numbers rather than a different behavior.
use pdfrum_doc::geom;
use pdfrum_doc::vt::{Config, Metrics, layout};
// Every character ten thousandths wide: the stub the layout assertions
// in this crate are written against.
let width = |_code: u32| 10;
let metrics = Metrics { width: &width, ascent: 1000, descent: -200 };
let config = Config {
plate: geom::rect(0.0, 0.0, 100.0, 40.0),
font_size: 10.0,
multi_line: true,
..Config::default()
};
let laid_out = layout("Hi", &config, &metrics);
// Nothing here reads a font dictionary; the numbers are the whole
// contract between a caller and the engine.
assert_eq!(laid_out.font_size, 10.0);Fields§
§width: &'a dyn Fn(u32) -> i32Width per character, in thousandths of an em.
ascent: i32The font’s ascent, in thousandths.
descent: i32The font’s descent, in thousandths — normally negative.
Trait Implementations§
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for Metrics<'a>
impl<'a> !Send for Metrics<'a>
impl<'a> !Sync for Metrics<'a>
impl<'a> !UnwindSafe for Metrics<'a>
impl<'a> Freeze for Metrics<'a>
impl<'a> Unpin for Metrics<'a>
impl<'a> UnsafeUnpin for Metrics<'a>
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