From 18a3257f5dd0431f6ed25cf6c0b02b87abfa3a21 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 9 Nov 2012 12:34:05 +0530 Subject: [PATCH] OTF subsetting basically works, but leaves behind invalid entries in the GPOS table, which should be ignored by most user agents --- src/calibre/ebooks/conversion/plumber.py | 4 +--- src/calibre/gui2/convert/look_and_feel.ui | 4 ++-- src/calibre/utils/fonts/sfnt/cff/writer.py | 8 ++++---- src/calibre/utils/fonts/sfnt/subset.py | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/calibre/ebooks/conversion/plumber.py b/src/calibre/ebooks/conversion/plumber.py index 8d6a6e22f8..e64b901688 100644 --- a/src/calibre/ebooks/conversion/plumber.py +++ b/src/calibre/ebooks/conversion/plumber.py @@ -210,9 +210,7 @@ OptionRecommendation(name='subset_embedded_fonts', 'Subset all embedded fonts. Every embedded font is reduced ' 'to contain only the glyphs used in this document. This decreases ' 'the size of the font files. Useful if you are embedding a ' - 'particularly large font with lots of unused glyphs. Note that ' - 'subsetting is only supported for fonts that contain TrueType ' - 'outlines, not Postscript outlines.') + 'particularly large font with lots of unused glyphs.') ), OptionRecommendation(name='linearize_tables', diff --git a/src/calibre/gui2/convert/look_and_feel.ui b/src/calibre/gui2/convert/look_and_feel.ui index 16f781cb2c..505079a14c 100644 --- a/src/calibre/gui2/convert/look_and_feel.ui +++ b/src/calibre/gui2/convert/look_and_feel.ui @@ -6,7 +6,7 @@ 0 0 - 655 + 699 619 @@ -411,7 +411,7 @@ - &Subset all embedded fonts + &Subset all embedded fonts (Experimental) diff --git a/src/calibre/utils/fonts/sfnt/cff/writer.py b/src/calibre/utils/fonts/sfnt/cff/writer.py index c9c3dbf937..753d56b18e 100644 --- a/src/calibre/utils/fonts/sfnt/cff/writer.py +++ b/src/calibre/utils/fonts/sfnt/cff/writer.py @@ -107,7 +107,7 @@ class Subset(object): def __init__(self, cff, keep_charnames): self.cff = cff - self.keep_charnames = keep_charnames + keep_charnames.add(b'.notdef') header = pack(b'>4B', 1, 0, 4, cff.offset_size) @@ -127,9 +127,9 @@ class Subset(object): cname = self.cff.charset.safe_lookup(i) if cname in keep_charnames: char_strings.append(self.cff.char_strings[i]) - self.charname_map[cname] = i - if i > 0: # .notdef is not included - charsets.append(cname) + self.charname_map[cname] = len(self.charname_map) + if i > 0: # .notdef is not included + charsets.append(cname) # Add the strings char_strings.compile() diff --git a/src/calibre/utils/fonts/sfnt/subset.py b/src/calibre/utils/fonts/sfnt/subset.py index 36221c7a28..c0dac76e30 100644 --- a/src/calibre/utils/fonts/sfnt/subset.py +++ b/src/calibre/utils/fonts/sfnt/subset.py @@ -167,7 +167,7 @@ def main(args): with open(iff, 'rb') as f: orig = f.read() - chars = [x.strip() for x in chars.split(',')] + chars = [x for x in chars.split(',')] individual, ranges = set(), set() def not_single(c):