From 0d93ccd4bfc814534c106d3f78eef16b06b3cc70 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 16 Jun 2024 12:05:13 +0200 Subject: [PATCH] Compress CMaps (#4406) --- crates/typst-pdf/src/font.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/crates/typst-pdf/src/font.rs b/crates/typst-pdf/src/font.rs index 6c6e76823..fd719799d 100644 --- a/crates/typst-pdf/src/font.rs +++ b/crates/typst-pdf/src/font.rs @@ -117,7 +117,7 @@ pub fn write_fonts(context: &WithGlobalRefs) -> (PdfChunk, HashMap) { // Write the /ToUnicode character map, which maps glyph ids back to // unicode codepoints to enable copying out of the PDF. let cmap = create_cmap(glyph_set, glyph_remapper); - chunk.cmap(cmap_ref, &cmap.finish()); + chunk.cmap(cmap_ref, &cmap).filter(Filter::FlateDecode); let subset = subset_font(font, glyph_remapper); let mut stream = chunk.stream(data_ref, &subset); @@ -258,11 +258,13 @@ pub fn improve_glyph_sets(glyph_sets: &mut HashMap, glyph_remapper: &GlyphRemapper, -) -> UnicodeCmap { +) -> Arc> { // Produce a reverse mapping from glyphs' CIDs to unicode strings. let mut cmap = UnicodeCmap::new(CMAP_NAME, SYSTEM_INFO); for (&g, text) in glyph_set.iter() { @@ -272,6 +274,5 @@ fn create_cmap( cmap.pair_with_multiple(cid, text.chars()); } } - - cmap + Arc::new(deflate(&cmap.finish())) }