Skip to content

Commit

Permalink
Don't improve glyph sets
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenzV committed Jul 25, 2024
1 parent 6c715cd commit 9252556
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 31 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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 }
Expand Down
28 changes: 1 addition & 27 deletions src/render/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ");
Expand Down Expand Up @@ -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.
Expand All @@ -173,33 +171,9 @@ pub fn write_font(

/// Create a /ToUnicode CMap.
fn create_cmap(
ttf: &Face,
glyph_set: &mut BTreeMap<u16, String>,
glyph_remapper: &GlyphRemapper,
) -> Option<UnicodeCmap> {
// 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() {
Expand Down

0 comments on commit 9252556

Please sign in to comment.