summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAna Gelez <ana@gelez.xyz>2024-04-19 16:33:49 +0200
committerGitHub <noreply@github.com>2024-04-19 14:33:49 +0000
commit0bb45b335fb8b34af9ce33e1684e58c046ee5e45 (patch)
tree74a90c2b6044e9610137e964285b632af13ffe18 /crates
parentb9457421decd87623590f8b80a7c798a58638ede (diff)
Fix subset tag for color fonts (#3960)
Diffstat (limited to 'crates')
-rw-r--r--crates/typst-pdf/src/font.rs9
1 files changed, 7 insertions, 2 deletions
diff --git a/crates/typst-pdf/src/font.rs b/crates/typst-pdf/src/font.rs
index e4b83f1d..15d1a50e 100644
--- a/crates/typst-pdf/src/font.rs
+++ b/crates/typst-pdf/src/font.rs
@@ -1,4 +1,5 @@
use std::collections::BTreeMap;
+use std::hash::Hash;
use std::sync::Arc;
use ecow::{eco_format, EcoString};
@@ -153,6 +154,7 @@ fn write_color_fonts(ctx: &mut PdfContext) {
let glyph_count = end - start;
let subset = &color_font.glyphs[start..end];
let mut widths = Vec::new();
+ let mut gids = Vec::new();
let scale_factor = font.ttf().units_per_em() as f32;
@@ -182,6 +184,7 @@ fn write_color_fonts(ctx: &mut PdfContext) {
// Use this stream as instructions to draw the glyph.
glyphs_to_instructions.push(instructions_stream_ref);
+ gids.push(color_glyph.gid);
}
// Write the Type3 font object.
@@ -229,10 +232,12 @@ fn write_color_fonts(ctx: &mut PdfContext) {
ctx.pdf.cmap(cmap_ref, &cmap.finish());
// Write the font descriptor.
+ gids.sort();
+ let subset_tag = subset_tag(&gids);
let postscript_name = font
.find_name(name_id::POST_SCRIPT_NAME)
.unwrap_or_else(|| "unknown".to_string());
- let base_font = eco_format!("COLOR{font_index:x}+{postscript_name}");
+ let base_font = eco_format!("{subset_tag}+{postscript_name}");
write_font_descriptor(&mut ctx.pdf, descriptor_ref, &font, &base_font);
// Write the widths array
@@ -312,7 +317,7 @@ fn subset_font(font: &Font, glyphs: &[u16]) -> Arc<Vec<u8>> {
}
/// Produce a unique 6 letter tag for a glyph set.
-fn subset_tag(glyphs: &BTreeMap<u16, EcoString>) -> EcoString {
+fn subset_tag<T: Hash>(glyphs: &T) -> EcoString {
const LEN: usize = 6;
const BASE: u128 = 26;
let mut hash = typst::util::hash128(&glyphs);