pub struct Line {
pub words: Option<Range<u32>>,
pub x: f32,
pub y: f32,
pub width: f32,
pub ascent: f32,
pub descent: f32,
}Expand description
One line of a section.
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);
let line = &laid_out.sections[0].lines[0];
// Half-open, over the section's own word indices.
assert_eq!(line.word_range(2), 0..2);Fields§
§words: Option<Range<u32>>The words this line covers, half-open, or None for the single
line of an empty section.
x: f32Position, y-down.
y: f32Position, y-down.
width: f32The line’s set width.
ascent: f32The tallest ascent on the line, floored at zero.
descent: f32The deepest descent on the line, capped at zero.
Implementations§
Source§impl Line
impl Line
Sourcepub fn word_range(&self, available: usize) -> Range<usize> ⓘ
pub fn word_range(&self, available: usize) -> Range<usize> ⓘ
The words this line covers, as a usize range clamped to available.
Empty for the single line of an empty section, and for a begin past
the section’s words — a layout that shrank under an edit.
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);
let line = &laid_out.sections[0].lines[0];
assert_eq!(line.word_range(2), 0..2);
// Clamped: a layout that shrank under an edit answers empty rather
// than a range past the end.
assert_eq!(line.word_range(0), 0..0);Sourcepub fn last_word(&self) -> Option<u32>
pub fn last_word(&self) -> Option<u32>
The last word index the line covers, if it covers any.
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);
let line = &laid_out.sections[0].lines[0];
assert_eq!(line.last_word(), Some(1));Trait Implementations§
impl StructuralPartialEq for Line
Auto Trait Implementations§
impl Freeze for Line
impl RefUnwindSafe for Line
impl Send for Line
impl Sync for Line
impl Unpin for Line
impl UnsafeUnpin for Line
impl UnwindSafe for Line
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