Edit book: Fix undo not working for subsetting fonts

This commit is contained in:
Kovid Goyal 2014-01-29 11:07:02 +05:30
parent 662b696fd0
commit 0260880952

View File

@ -38,13 +38,14 @@ def subset_all_fonts(container, font_stats, report):
for name, mt in container.mime_map.iteritems(): for name, mt in container.mime_map.iteritems():
if (mt in OEB_FONTS or name.rpartition('.')[-1].lower() in {'otf', 'ttf'}) and mt != guess_type('a.woff'): if (mt in OEB_FONTS or name.rpartition('.')[-1].lower() in {'otf', 'ttf'}) and mt != guess_type('a.woff'):
chars = font_stats.get(name, set()) chars = font_stats.get(name, set())
path = container.name_path_map[name] with container.open(name, 'rb') as f:
total_old += os.path.getsize(path) f.seek(0, os.SEEK_END)
total_old += f.tell()
if not chars: if not chars:
remove.add(name) remove.add(name)
report('Removed unused font: %s'%name) report('Removed unused font: %s'%name)
continue continue
with open(path, 'r+b') as f: with container.open(name, 'r+b') as f:
raw = f.read() raw = f.read()
font_name = get_font_names(raw)[-1] font_name = get_font_names(raw)[-1]
warnings = [] warnings = []