diff options
| author | Sébastien d'Herbais de Thun <sebastien.d.herbais@gmail.com> | 2023-04-05 15:04:31 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-05 15:04:31 +0200 |
| commit | 70a909b8badec1f14b67338a0e010e9a374866b8 (patch) | |
| tree | ad2d3f7b4e8060f5495cfe97db5ba47bfe7675c0 /src/model | |
| parent | d569f6b33b8cebd6f48ff9935e7c88024bdad72a (diff) | |
Fixed page numbering (#594)
Diffstat (limited to 'src/model')
| -rw-r--r-- | src/model/introspect.rs | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/model/introspect.rs b/src/model/introspect.rs index 31786d5b..31808872 100644 --- a/src/model/introspect.rs +++ b/src/model/introspect.rs @@ -5,7 +5,7 @@ use std::num::NonZeroUsize; use super::{Content, Selector}; use crate::diag::StrResult; use crate::doc::{Frame, FrameItem, Meta, Position}; -use crate::eval::cast_from_value; +use crate::eval::{cast_from_value, Value}; use crate::geom::{Point, Transform}; use crate::model::Label; use crate::util::NonZeroExt; @@ -84,12 +84,18 @@ impl StabilityProvider { pub struct Introspector { pages: usize, elems: Vec<(Content, Position)>, + // Indexed by page number. + page_numberings: Vec<Value>, } impl Introspector { /// Create a new introspector. pub fn new(frames: &[Frame]) -> Self { - let mut introspector = Self { pages: frames.len(), elems: vec![] }; + let mut introspector = Self { + pages: frames.len(), + elems: vec![], + page_numberings: vec![], + }; for (i, frame) in frames.iter().enumerate() { let page = NonZeroUsize::new(1 + i).unwrap(); introspector.extract(frame, page, Transform::identity()); @@ -121,6 +127,9 @@ impl Introspector { let pos = pos.transform(ts); self.elems.push((content.clone(), Position { page, point: pos })); } + FrameItem::Meta(Meta::PageNumbering(numbering), _) => { + self.page_numberings.push(numbering.clone()); + } _ => {} } } @@ -184,6 +193,12 @@ impl Introspector { self.position(location).page } + /// Gets the page numbering for the given location, if any. + pub fn page_numbering(&self, location: Location) -> Value { + let page = self.page(location); + self.page_numberings.get(page.get() - 1).cloned().unwrap_or_default() + } + /// Find the position for the given location. pub fn position(&self, location: Location) -> Position { self.elems |
