summaryrefslogtreecommitdiff
path: root/library/src
diff options
context:
space:
mode:
authorSébastien d'Herbais de Thun <sebastien.d.herbais@gmail.com>2023-04-05 15:04:31 +0200
committerGitHub <noreply@github.com>2023-04-05 15:04:31 +0200
commit70a909b8badec1f14b67338a0e010e9a374866b8 (patch)
treead2d3f7b4e8060f5495cfe97db5ba47bfe7675c0 /library/src
parentd569f6b33b8cebd6f48ff9935e7c88024bdad72a (diff)
Fixed page numbering (#594)
Diffstat (limited to 'library/src')
-rw-r--r--library/src/layout/page.rs6
-rw-r--r--library/src/meta/context.rs9
-rw-r--r--library/src/meta/outline.rs22
3 files changed, 32 insertions, 5 deletions
diff --git a/library/src/layout/page.rs b/library/src/layout/page.rs
index 8ad85c79..0c70282d 100644
--- a/library/src/layout/page.rs
+++ b/library/src/layout/page.rs
@@ -324,8 +324,14 @@ impl PageElem {
});
let footer_descent = self.footer_descent(styles);
+ let numbering_meta = FrameItem::Meta(
+ Meta::PageNumbering(self.numbering(styles).into()),
+ Size::zero(),
+ );
+
// Realize overlays.
for frame in &mut fragment {
+ frame.prepend(Point::zero(), numbering_meta.clone());
let size = frame.size();
let pad = padding.resolve(styles).relative_to(size);
let pw = size.x - pad.left - pad.right;
diff --git a/library/src/meta/context.rs b/library/src/meta/context.rs
index e36e6b28..7426d27d 100644
--- a/library/src/meta/context.rs
+++ b/library/src/meta/context.rs
@@ -35,6 +35,15 @@ use crate::prelude::*;
///
/// - returns: dictionary
///
+/// ### page-numbering()
+/// Returns the page numbering pattern of the page at this location. This can be
+/// used when displaying the page counter in order to obtain the local numbering.
+/// This is useful if you are building custom indices or outlines.
+///
+/// If the page numbering is set to `none` at that location, this function returns `none`.
+///
+/// - returns: string or function or none
+///
/// Display: Locate
/// Category: meta
/// Returns: content
diff --git a/library/src/meta/outline.rs b/library/src/meta/outline.rs
index b591dcee..d25a1d1c 100644
--- a/library/src/meta/outline.rs
+++ b/library/src/meta/outline.rs
@@ -1,4 +1,8 @@
-use super::{Counter, CounterKey, HeadingElem, LocalName, Refable};
+use std::str::FromStr;
+
+use super::{
+ Counter, CounterKey, HeadingElem, LocalName, Numbering, NumberingPattern, Refable,
+};
use crate::layout::{BoxElem, HElem, HideElem, ParbreakElem, RepeatElem};
use crate::prelude::*;
use crate::text::{LinebreakElem, SpaceElem, TextElem};
@@ -205,6 +209,15 @@ impl Show for OutlineElem {
// Add the outline of the element.
seq.push(outline.linked(Destination::Location(location)));
+ let page_numbering = vt
+ .introspector
+ .page_numbering(location)
+ .cast::<Option<Numbering>>()
+ .unwrap()
+ .unwrap_or_else(|| {
+ Numbering::Pattern(NumberingPattern::from_str("1").unwrap())
+ });
+
// Add filler symbols between the section name and page number.
if let Some(filler) = self.fill(styles) {
seq.push(SpaceElem::new().pack());
@@ -221,11 +234,10 @@ impl Show for OutlineElem {
// Add the page number and linebreak.
let page = Counter::new(CounterKey::Page)
- // query the page counter state at location of heading
.at(vt, location)?
- .first();
- let end = TextElem::packed(eco_format!("{page}"));
- seq.push(end.linked(Destination::Location(location)));
+ .display(vt, &page_numbering)?;
+
+ seq.push(page.linked(Destination::Location(location)));
seq.push(LinebreakElem::new().pack());
ancestors.push(elem);