Skip to content

Commit 32633ca

Browse files
authored
Don't "improve" glyph sets (#79)
1 parent 6c715cd commit 32633ca

File tree

4 files changed

+4
-33
lines changed

4 files changed

+4
-33
lines changed

Cargo.lock

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ pdfium-render = "0.8.6"
2727
termcolor = "1.2"
2828
usvg = { version = "0.42.0", default-features = false }
2929
tiny-skia = "0.11.4"
30-
unicode-properties = "0.1.1"
3130
resvg = { version = "0.42.0", default-features = false }
3231
subsetter = {git = "https://github.com/typst/subsetter", rev = "4e0058b"}
3332
ttf-parser = { version = "0.21.1" }
@@ -50,13 +49,12 @@ bench = false
5049
[features]
5150
default = ["image", "filters", "text"]
5251
text = ["usvg/text", "resvg/text", "dep:siphasher",
53-
"dep:subsetter", "dep:ttf-parser", "dep:unicode-properties",
52+
"dep:subsetter", "dep:ttf-parser",
5453
"dep:fontdb"]
5554
image = ["dep:image"]
5655
filters = ["image", "dep:tiny-skia", "resvg/raster-images"]
5756

5857
[dependencies]
59-
unicode-properties = { workspace = true, optional = true }
6058
miniz_oxide = { workspace = true }
6159
once_cell = { workspace = true }
6260
pdf-writer = { workspace = true }

src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ Among the unsupported features are currently:
4949
- The `spreadMethod` attribute of gradients
5050
- Raster images are not color managed but use PDF's DeviceRGB color space
5151
- A number of features that were added in SVG2, See
52-
[here](https://github.com/RazrFalcon/resvg/blob/master/docs/svg2-changelog.md) for a more
53-
comprehensive list.
52+
[here](https://github.com/RazrFalcon/resvg/blob/master/docs/svg2-changelog.md) for a more
53+
comprehensive list.
5454
*/
5555

5656
mod render;

src/render/text.rs

+1-27
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use std::hash::Hash;
1515
use std::sync::Arc;
1616
use subsetter::GlyphRemapper;
1717
use ttf_parser::{name_id, Face, GlyphId, PlatformId, Tag};
18-
use unicode_properties::{GeneralCategory, UnicodeGeneralCategory};
1918
use usvg::{Fill, Group, ImageKind, Node, PaintOrder, Stroke, Transform};
2019

2120
const CFF: Tag = Tag::from_bytes(b"CFF ");
@@ -154,8 +153,7 @@ pub fn write_font(
154153

155154
font_descriptor.finish();
156155

157-
let cmap =
158-
create_cmap(&ttf, glyph_set, glyph_remapper).ok_or(SubsetError(font.id))?;
156+
let cmap = create_cmap(glyph_set, glyph_remapper).ok_or(SubsetError(font.id))?;
159157
chunk.cmap(cmap_ref, &cmap.finish());
160158

161159
// Subset and write the font's bytes.
@@ -173,33 +171,9 @@ pub fn write_font(
173171

174172
/// Create a /ToUnicode CMap.
175173
fn create_cmap(
176-
ttf: &Face,
177174
glyph_set: &mut BTreeMap<u16, String>,
178175
glyph_remapper: &GlyphRemapper,
179176
) -> Option<UnicodeCmap> {
180-
// For glyphs that have codepoints mapping to them in the font's cmap table,
181-
// we prefer them over pre-existing text mappings from the document. Only
182-
// things that don't have a corresponding codepoint (or only a private-use
183-
// one) like the "Th" in Linux Libertine get the text of their first
184-
// occurrences in the document instead.
185-
for subtable in ttf.tables().cmap.into_iter().flat_map(|table| table.subtables) {
186-
if !subtable.is_unicode() {
187-
continue;
188-
}
189-
190-
subtable.codepoints(|n| {
191-
let Some(c) = std::char::from_u32(n) else { return };
192-
if c.general_category() == GeneralCategory::PrivateUse {
193-
return;
194-
}
195-
196-
let Some(GlyphId(g)) = ttf.glyph_index(c) else { return };
197-
if glyph_set.contains_key(&g) {
198-
glyph_set.insert(g, c.into());
199-
}
200-
});
201-
}
202-
203177
// Produce a reverse mapping from glyphs' CIDs to unicode strings.
204178
let mut cmap = UnicodeCmap::new(CMAP_NAME, SYSTEM_INFO);
205179
for (&g, text) in glyph_set.iter() {

0 commit comments

Comments
 (0)