summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2024-06-16 12:05:13 +0200
committerGitHub <noreply@github.com>2024-06-16 10:05:13 +0000
commit0d93ccd4bfc814534c106d3f78eef16b06b3cc70 (patch)
tree9a910fab3cd9fe62b8c6c8f9b95fa9c28fe3f5e0
parentfeedfe80cb86f880245f7b2361b83459c72ee36d (diff)
Compress CMaps (#4406)
-rw-r--r--crates/typst-pdf/src/font.rs11
1 files changed, 6 insertions, 5 deletions
diff --git a/crates/typst-pdf/src/font.rs b/crates/typst-pdf/src/font.rs
index 6c6e7682..fd719799 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<Font, Ref>) {
// 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<Font, BTreeMap<u16, EcoString
}
}
-/// Create a /ToUnicode CMap.
+/// Create a compressed `/ToUnicode` CMap.
+#[comemo::memoize]
+#[typst_macros::time(name = "create cmap")]
fn create_cmap(
glyph_set: &BTreeMap<u16, EcoString>,
glyph_remapper: &GlyphRemapper,
-) -> UnicodeCmap {
+) -> Arc<Vec<u8>> {
// 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()))
}