mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Correct error message for fonts with no format 4 cmap tables
This commit is contained in:
parent
5efd38eb4b
commit
3fd03f45d7
@ -114,7 +114,7 @@ FontSourcedInfoBuilder::~FontSourcedInfoBuilder() { }
|
||||
|
||||
CALLER_ATTACH FontInfo* FontSourcedInfoBuilder::GetFontInfo() {
|
||||
if (!cmap_) {
|
||||
PyErr_SetString(Error, "This font has no cmap table!");
|
||||
PyErr_SetString(UnsupportedFont, "This font has no format 4 cmap table (usually symbol or asian fonts), subsetting is not supported");
|
||||
return NULL;
|
||||
}
|
||||
CharacterMap* chars_to_glyph_ids = new CharacterMap;
|
||||
@ -515,6 +515,11 @@ do_subset(const char *data, Py_ssize_t sz, Ptr<CharacterPredicate> &predicate) {
|
||||
PyErr_SetString(Error, "Loaded font has 0 tables.");
|
||||
return NULL;
|
||||
}
|
||||
Ptr<CMapTable> cmap_table = down_cast<CMapTable*>(font->GetTable(Tag::cmap));
|
||||
if (!cmap_table) {
|
||||
PyErr_SetString(Error, "Loaded font has no cmap table.");
|
||||
return NULL;
|
||||
}
|
||||
Ptr<PredicateSubsetter> subsetter = new PredicateSubsetter(font, predicate);
|
||||
Ptr<Font> new_font;
|
||||
new_font.Attach(subsetter->Subset());
|
||||
|
@ -110,13 +110,18 @@ def test():
|
||||
def all():
|
||||
from calibre.utils.fonts.scanner import font_scanner
|
||||
failed = []
|
||||
unsupported = []
|
||||
for family in font_scanner.find_font_families():
|
||||
for font in font_scanner.fonts_for_family(family):
|
||||
raw = font_scanner.get_font_data(font)
|
||||
print ('Subsetting', font['full_name'])
|
||||
print ('Subsetting', font['full_name'], end='\t')
|
||||
try:
|
||||
sf, old_stats, new_stats = subset(raw, set(('a', 'b', 'c')), ())
|
||||
except (NoGlyphs, UnsupportedFont) as e:
|
||||
except NoGlyphs:
|
||||
continue
|
||||
except UnsupportedFont as e:
|
||||
unsupported.append((font['full_name'], font['path'], unicode(e)))
|
||||
print ('Unsupported!')
|
||||
continue
|
||||
except Exception as e:
|
||||
print ('Failed!')
|
||||
@ -125,6 +130,11 @@ def all():
|
||||
print ('Reduced to:', '%.1f'%(
|
||||
sum(new_stats.itervalues())/sum(old_stats.itervalues())
|
||||
* 100), '%')
|
||||
if unsupported:
|
||||
print ('\n\nUnsupported:')
|
||||
for name, path, err in unsupported:
|
||||
print (name, path, err)
|
||||
print()
|
||||
if failed:
|
||||
print ('\n\nFailures:')
|
||||
for name, path, err in failed:
|
||||
|
Loading…
x
Reference in New Issue
Block a user