From 925255610240b8f15e3730015abe3ca576551bfe Mon Sep 17 00:00:00 2001 From: Laurenz Stampfl Date: Thu, 25 Jul 2024 14:12:28 +0200 Subject: [PATCH] Don't improve glyph sets --- Cargo.lock | 1 - Cargo.toml | 4 +--- src/render/text.rs | 28 +--------------------------- 3 files changed, 2 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 320adb4d..43ee10fa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1558,7 +1558,6 @@ dependencies = [ "subsetter", "tiny-skia", "ttf-parser", - "unicode-properties", "usvg", ] diff --git a/Cargo.toml b/Cargo.toml index ff0b1470..2bb798db 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,6 @@ pdfium-render = "0.8.6" termcolor = "1.2" usvg = { version = "0.42.0", default-features = false } tiny-skia = "0.11.4" -unicode-properties = "0.1.1" resvg = { version = "0.42.0", default-features = false } subsetter = {git = "https://github.com/typst/subsetter", rev = "4e0058b"} ttf-parser = { version = "0.21.1" } @@ -50,13 +49,12 @@ bench = false [features] default = ["image", "filters", "text"] text = ["usvg/text", "resvg/text", "dep:siphasher", - "dep:subsetter", "dep:ttf-parser", "dep:unicode-properties", + "dep:subsetter", "dep:ttf-parser", "dep:fontdb"] image = ["dep:image"] filters = ["image", "dep:tiny-skia", "resvg/raster-images"] [dependencies] -unicode-properties = { workspace = true, optional = true } miniz_oxide = { workspace = true } once_cell = { workspace = true } pdf-writer = { workspace = true } diff --git a/src/render/text.rs b/src/render/text.rs index 6626287b..45c79263 100644 --- a/src/render/text.rs +++ b/src/render/text.rs @@ -15,7 +15,6 @@ use std::hash::Hash; use std::sync::Arc; use subsetter::GlyphRemapper; use ttf_parser::{name_id, Face, GlyphId, PlatformId, Tag}; -use unicode_properties::{GeneralCategory, UnicodeGeneralCategory}; use usvg::{Fill, Group, ImageKind, Node, PaintOrder, Stroke, Transform}; const CFF: Tag = Tag::from_bytes(b"CFF "); @@ -154,8 +153,7 @@ pub fn write_font( font_descriptor.finish(); - let cmap = - create_cmap(&ttf, glyph_set, glyph_remapper).ok_or(SubsetError(font.id))?; + let cmap = create_cmap(glyph_set, glyph_remapper).ok_or(SubsetError(font.id))?; chunk.cmap(cmap_ref, &cmap.finish()); // Subset and write the font's bytes. @@ -173,33 +171,9 @@ pub fn write_font( /// Create a /ToUnicode CMap. fn create_cmap( - ttf: &Face, glyph_set: &mut BTreeMap, glyph_remapper: &GlyphRemapper, ) -> Option { - // 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 - // one) like the "Th" in Linux Libertine get the text of their first - // occurrences in the document instead. - for subtable in ttf.tables().cmap.into_iter().flat_map(|table| table.subtables) { - if !subtable.is_unicode() { - continue; - } - - subtable.codepoints(|n| { - let Some(c) = std::char::from_u32(n) else { return }; - if c.general_category() == GeneralCategory::PrivateUse { - return; - } - - let Some(GlyphId(g)) = ttf.glyph_index(c) else { return }; - if glyph_set.contains_key(&g) { - glyph_set.insert(g, c.into()); - } - }); - } - // 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() {