pub struct Place {
pub section: u32,
pub line: u32,
pub word: Option<u32>,
}Expand description
A caret position: after character word of line line of section
section.
word == None is the line header — the position before the line’s first
character. Every other value names the character the caret sits after.
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);
use pdfrum_doc::vt::hit;
use pdfrum_doc::vt::hit::Place;
// The header -- the position before a line's first character --
// orders ahead of every character on it.
assert!(Place::new(0, 0, None) < Place::new(0, 0, Some(0)));Fields§
§section: u32Which paragraph.
line: u32Which line of that paragraph.
word: Option<u32>The character the caret follows, or None for the line header.
None orders before every Some, so the header sorts ahead of the
line’s characters.
Implementations§
Source§impl Place
impl Place
Sourcepub const START: Place
pub const START: Place
The place every layout begins at: the header of its first line.
A constant rather than a query, because it does not depend on the
layout — the first caret position is the first line’s header whatever
the text is, including no text at all. begin_place is the same
value, spelled for symmetry with end_place, which does need the
layout.
The header is None, not a sentinel index.
use pdfrum_doc::vt::hit::Place;
// The beginning of the text, not `(0, 0, 0)`: a zero `word` is the
// position *after* the first character.
assert_eq!(Place::START, Place::new(0, 0, None));
assert_eq!(Place::default(), Place::START);Sourcepub fn new(section: u32, line: u32, word: Option<u32>) -> Place
pub fn new(section: u32, line: u32, word: Option<u32>) -> Place
A place, from the three indices.
use pdfrum_doc::vt::hit::Place;
let after_first = Place::new(0, 0, Some(0));
assert_eq!(after_first.word, Some(0));Sourcepub fn start() -> Place
pub fn start() -> Place
Place::START, as a function.
use pdfrum_doc::vt::hit::Place;
assert_eq!(Place::start(), Place::START);Trait Implementations§
impl Copy for Place
Source§impl Default for Place
The beginning of the text, not (0, 0, 0).
impl Default for Place
The beginning of the text, not (0, 0, 0).
#[derive(Default)] would zero all three fields, and a zero word is the
position after the first character — a different, valid-looking caret
that no layout ever means by “the default”. The beginning of the text is
section 0, line 0, and no word, which is what a caller reaching for a
default wants.