summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlia <43654815+istudyatuni@users.noreply.github.com>2024-02-23 17:14:07 +0300
committerGitHub <noreply@github.com>2024-02-23 14:14:07 +0000
commitffd57bf56b6d23cd5f81c4d9473adfbc24c61274 (patch)
tree6d3e77c44d79c50c0b3929f284b3183f86341607
parent0fe03bae6e154c30934d9f25037fa57e7381780f (diff)
Sort languages when writing XMP metadata for reproducible builds (#3469)
-rw-r--r--crates/typst-pdf/src/lib.rs11
1 files changed, 4 insertions, 7 deletions
diff --git a/crates/typst-pdf/src/lib.rs b/crates/typst-pdf/src/lib.rs
index 467b4ffb..cc2edba2 100644
--- a/crates/typst-pdf/src/lib.rs
+++ b/crates/typst-pdf/src/lib.rs
@@ -85,7 +85,8 @@ struct PdfContext<'a> {
glyph_sets: HashMap<Font, BTreeMap<u16, EcoString>>,
/// The number of glyphs for all referenced languages in the document.
/// We keep track of this to determine the main document language.
- languages: HashMap<Lang, usize>,
+ /// BTreeMap is used to write sorted list of languages to metadata.
+ languages: BTreeMap<Lang, usize>,
/// Allocator for indirect reference IDs.
alloc: Ref,
@@ -134,7 +135,7 @@ impl<'a> PdfContext<'a> {
pdf: Pdf::new(),
pages: vec![],
glyph_sets: HashMap::new(),
- languages: HashMap::new(),
+ languages: BTreeMap::new(),
alloc,
page_tree_ref,
page_refs: vec![],
@@ -158,11 +159,7 @@ impl<'a> PdfContext<'a> {
/// Write the document catalog.
fn write_catalog(ctx: &mut PdfContext, ident: Option<&str>, timestamp: Option<Datetime>) {
- let lang = ctx
- .languages
- .iter()
- .max_by_key(|(&lang, &count)| (count, lang))
- .map(|(&k, _)| k);
+ let lang = ctx.languages.iter().max_by_key(|(_, &count)| count).map(|(&l, _)| l);
let dir = if lang.map(Lang::dir) == Some(Dir::RTL) {
Direction::R2L