Skip to main content

layout

Function layout 

Source
pub fn layout(text: &str, config: &Config, metrics: &Metrics<'_>) -> Layout
Expand description

Lays out a piece of variable text.

A pure function: nothing here reads a document or a font dictionary, only the numbers Metrics supplies, which is what makes the whole engine testable against a stub.

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);

assert_eq!(laid_out.sections.len(), 1);
assert_eq!(laid_out.sections[0].words.len(), 2);