summaryrefslogtreecommitdiff
path: root/crates/typst-pdf
diff options
context:
space:
mode:
authorEduardo Sánchez Muñoz <eduardosanchezmunoz@gmail.com>2025-03-24 19:16:33 +0100
committerGitHub <noreply@github.com>2025-03-24 18:16:33 +0000
commit38213ed534d8a7cd520c0265b99a345bc2966b39 (patch)
tree248bbfcead3218067e399145be10b2ef3187624e /crates/typst-pdf
parent636eea18bc1c3fe2acb09e59e67f38a4a0c1b323 (diff)
Use `u64` instead of `usize` to store counter and enumeration item numbers, so behavior does not vary from 64-bit to 32-bit platforms (#6026)
Diffstat (limited to 'crates/typst-pdf')
-rw-r--r--crates/typst-pdf/src/page.rs14
1 files changed, 7 insertions, 7 deletions
diff --git a/crates/typst-pdf/src/page.rs b/crates/typst-pdf/src/page.rs
index 4e95f3c7..68125d29 100644
--- a/crates/typst-pdf/src/page.rs
+++ b/crates/typst-pdf/src/page.rs
@@ -1,5 +1,5 @@
use std::collections::HashMap;
-use std::num::NonZeroUsize;
+use std::num::NonZeroU64;
use ecow::EcoString;
use pdf_writer::types::{ActionType, AnnotationFlags, AnnotationType, NumberingStyle};
@@ -48,7 +48,7 @@ pub fn traverse_pages(
// the real (not logical) page numbers. Here, the final PDF page number
// will differ, but we can at least use labels to indicate what was
// the corresponding real page number in the Typst document.
- (skipped_pages > 0).then(|| PdfPageLabel::arabic(i + 1))
+ (skipped_pages > 0).then(|| PdfPageLabel::arabic((i + 1) as u64))
});
pages.push(Some(encoded));
}
@@ -219,7 +219,7 @@ pub(crate) struct PdfPageLabel {
///
/// Describes where to start counting from when setting a style.
/// (Has to be greater or equal than 1)
- pub offset: Option<NonZeroUsize>,
+ pub offset: Option<NonZeroU64>,
}
/// A PDF page label number style.
@@ -242,7 +242,7 @@ pub enum PdfPageLabelStyle {
impl PdfPageLabel {
/// Create a new `PdfNumbering` from a `Numbering` applied to a page
/// number.
- fn generate(numbering: &Numbering, number: usize) -> Option<PdfPageLabel> {
+ fn generate(numbering: &Numbering, number: u64) -> Option<PdfPageLabel> {
let Numbering::Pattern(pat) = numbering else {
return None;
};
@@ -275,18 +275,18 @@ impl PdfPageLabel {
(!prefix.is_empty()).then(|| prefix.clone())
};
- let offset = style.and(NonZeroUsize::new(number));
+ let offset = style.and(NonZeroU64::new(number));
Some(PdfPageLabel { prefix, style, offset })
}
/// Creates an arabic page label with the specified page number.
/// For example, this will display page label `11` when given the page
/// number 11.
- fn arabic(number: usize) -> PdfPageLabel {
+ fn arabic(number: u64) -> PdfPageLabel {
PdfPageLabel {
prefix: None,
style: Some(PdfPageLabelStyle::Arabic),
- offset: NonZeroUsize::new(number),
+ offset: NonZeroU64::new(number),
}
}
}