summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Biedert <github@ericbiedert.de>2024-12-16 21:23:13 +0100
committerGitHub <noreply@github.com>2024-12-16 20:23:13 +0000
commit51020fcf3cd6fbe62d148d2188b9aaac4445bf63 (patch)
treec7f12a4f1f170aae2a734ab5696a3b078d31410f
parent75273937f762ebeb05f71e91434b298b52b44670 (diff)
Get numbering of page counter from style chain (#5589)
-rw-r--r--crates/typst-library/src/introspection/counter.rs30
-rw-r--r--tests/ref/counter-page-display.pngbin0 -> 150 bytes
-rw-r--r--tests/suite/introspection/counter.typ8
3 files changed, 24 insertions, 14 deletions
diff --git a/crates/typst-library/src/introspection/counter.rs b/crates/typst-library/src/introspection/counter.rs
index b884844c..f67c6daa 100644
--- a/crates/typst-library/src/introspection/counter.rs
+++ b/crates/typst-library/src/introspection/counter.rs
@@ -366,20 +366,22 @@ impl Counter {
.custom()
.or_else(|| {
let styles = styles?;
- let CounterKey::Selector(Selector::Elem(func, _)) = self.0 else {
- return None;
- };
-
- if func == HeadingElem::elem() {
- HeadingElem::numbering_in(styles).clone()
- } else if func == FigureElem::elem() {
- FigureElem::numbering_in(styles).clone()
- } else if func == EquationElem::elem() {
- EquationElem::numbering_in(styles).clone()
- } else if func == FootnoteElem::elem() {
- Some(FootnoteElem::numbering_in(styles).clone())
- } else {
- None
+ match self.0 {
+ CounterKey::Page => PageElem::numbering_in(styles).clone(),
+ CounterKey::Selector(Selector::Elem(func, _)) => {
+ if func == HeadingElem::elem() {
+ HeadingElem::numbering_in(styles).clone()
+ } else if func == FigureElem::elem() {
+ FigureElem::numbering_in(styles).clone()
+ } else if func == EquationElem::elem() {
+ EquationElem::numbering_in(styles).clone()
+ } else if func == FootnoteElem::elem() {
+ Some(FootnoteElem::numbering_in(styles).clone())
+ } else {
+ None
+ }
+ }
+ _ => None,
}
})
.unwrap_or_else(|| NumberingPattern::from_str("1.1").unwrap().into());
diff --git a/tests/ref/counter-page-display.png b/tests/ref/counter-page-display.png
new file mode 100644
index 00000000..040b634d
--- /dev/null
+++ b/tests/ref/counter-page-display.png
Binary files differ
diff --git a/tests/suite/introspection/counter.typ b/tests/suite/introspection/counter.typ
index e97f05dd..2f095f2f 100644
--- a/tests/suite/introspection/counter.typ
+++ b/tests/suite/introspection/counter.typ
@@ -102,6 +102,14 @@ B
#set page(numbering: "1 / 1", margin: (bottom: 20pt))
#counter(page).update(5)
+--- counter-page-display ---
+// Counter display should use numbering from style chain.
+#set page(
+ numbering: "A",
+ margin: (bottom: 20pt),
+ footer: context align(center, counter(page).display())
+)
+
--- counter-figure ---
// Count figures.
#figure(numbering: "A", caption: [Four 'A's], kind: image, supplement: "Figure")[_AAAA!_]