summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorY.D.X <73375426+YDX-2147483647@users.noreply.github.com>2024-02-17 20:42:00 +0800
committerGitHub <noreply@github.com>2024-02-17 12:42:00 +0000
commit394864fd4a5069dba0b996e0e0630855b034b86e (patch)
tree7a1c10cbf6d78e06ebe89be639b67a06fd99cc6b
parent09b364e9a35bf5746b932a4bcadf69fbc45521d2 (diff)
fix: `ToUnicode` in PDF should describe CID instead of GID (#3435)
-rw-r--r--crates/typst-pdf/src/font.rs13
1 files changed, 6 insertions, 7 deletions
diff --git a/crates/typst-pdf/src/font.rs b/crates/typst-pdf/src/font.rs
index cc116613..0f8b5ba0 100644
--- a/crates/typst-pdf/src/font.rs
+++ b/crates/typst-pdf/src/font.rs
@@ -146,7 +146,7 @@ pub(crate) fn write_fonts(ctx: &mut PdfContext) {
// Write the /ToUnicode character map, which maps glyph ids back to
// unicode codepoints to enable copying out of the PDF.
- let cmap = create_cmap(ttf, glyph_set);
+ let cmap = create_cmap(font, glyph_set);
ctx.pdf.cmap(cmap_ref, &cmap.finish());
// Subset and write the font's bytes.
@@ -198,10 +198,9 @@ fn subset_tag(glyphs: &BTreeMap<u16, EcoString>) -> EcoString {
}
/// Create a /ToUnicode CMap.
-fn create_cmap(
- ttf: &ttf_parser::Face,
- glyph_set: &mut BTreeMap<u16, EcoString>,
-) -> UnicodeCmap {
+fn create_cmap(font: &Font, glyph_set: &mut BTreeMap<u16, EcoString>) -> UnicodeCmap {
+ let ttf = font.ttf();
+
// For glyphs that have codepoints mapping to them in the font's cmap table,
// we prefer them over pre-existing text mappings from the document. Only
// things that don't have a corresponding codepoint (or only a private-use
@@ -225,11 +224,11 @@ fn create_cmap(
});
}
- // Produce a reverse mapping from glyphs to unicode strings.
+ // 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() {
if !text.is_empty() {
- cmap.pair_with_multiple(g, text.chars());
+ cmap.pair_with_multiple(glyph_cid(font, g), text.chars());
}
}