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 | |
| parent | d569f6b33b8cebd6f48ff9935e7c88024bdad72a (diff) | |
Fixed page numbering (#594)
Diffstat (limited to 'src')
| -rw-r--r-- | src/doc.rs | 2 | ||||
| -rw-r--r-- | src/eval/methods.rs | 3 | ||||
| -rw-r--r-- | src/export/pdf/page.rs | 1 | ||||
| -rw-r--r-- | src/export/render.rs | 1 | ||||
| -rw-r--r-- | src/model/introspect.rs | 19 |
5 files changed, 23 insertions, 3 deletions
@@ -609,6 +609,8 @@ pub enum Meta { /// An identifiable element that produces something within the area this /// metadata is attached to. Elem(Content), + /// The numbering of the current page. + PageNumbering(Value), /// Indicates that content should be hidden. This variant doesn't appear /// in the final frames as it is removed alongside the content that should /// be hidden. diff --git a/src/eval/methods.rs b/src/eval/methods.rs index bfe9b0e4..b88bca50 100644 --- a/src/eval/methods.rs +++ b/src/eval/methods.rs @@ -154,6 +154,7 @@ pub fn call( match method { "page" => vm.vt.introspector.page(location).into(), "position" => vm.vt.introspector.position(location).into(), + "page-numbering" => vm.vt.introspector.page_numbering(location), _ => return missing(), } } else { @@ -308,7 +309,7 @@ pub fn methods_on(type_name: &str) -> &[(&'static str, bool)] { ], "function" => &[("where", true), ("with", true)], "arguments" => &[("named", false), ("pos", false)], - "location" => &[("page", false), ("position", false)], + "location" => &[("page", false), ("position", false), ("page-numbering", false)], "counter" => &[ ("display", true), ("at", true), diff --git a/src/export/pdf/page.rs b/src/export/pdf/page.rs index 8f767e87..636d42c7 100644 --- a/src/export/pdf/page.rs +++ b/src/export/pdf/page.rs @@ -298,6 +298,7 @@ fn write_frame(ctx: &mut PageContext, frame: &Frame) { Meta::Link(dest) => write_link(ctx, pos, dest, *size), Meta::Elem(_) => {} Meta::Hide => {} + Meta::PageNumbering(_) => {} }, } } diff --git a/src/export/render.rs b/src/export/render.rs index 89e45b15..18d8a74b 100644 --- a/src/export/render.rs +++ b/src/export/render.rs @@ -61,6 +61,7 @@ fn render_frame( FrameItem::Meta(meta, _) => match meta { Meta::Link(_) => {} Meta::Elem(_) => {} + Meta::PageNumbering(_) => {} Meta::Hide => {} }, } 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 |
