From c4d213d49064041be1c8db4bc9a3cacb83faefcf Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 26 Nov 2013 17:15:22 +0530 Subject: [PATCH] Detect fonts with obsolete mimetypes as well --- src/calibre/ebooks/oeb/polish/container.py | 2 +- src/calibre/ebooks/oeb/polish/subset.py | 4 ++-- src/calibre/gui2/tweak_book/file_list.py | 6 ++---- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/calibre/ebooks/oeb/polish/container.py b/src/calibre/ebooks/oeb/polish/container.py index 9ec66bd7f2..ab20fb909a 100644 --- a/src/calibre/ebooks/oeb/polish/container.py +++ b/src/calibre/ebooks/oeb/polish/container.py @@ -43,7 +43,7 @@ exists, join, relpath = os.path.exists, os.path.join, os.path.relpath def guess_type(x): return _guess_type(x)[0] or 'application/octet-stream' -OEB_FONTS = {guess_type('a.ttf'), guess_type('b.otf')} +OEB_FONTS = {guess_type('a.ttf'), guess_type('b.otf'), guess_type('a.woff'), 'application/x-font-ttf', 'application/x-font-otf'} OPF_NAMESPACES = {'opf':OPF2_NS, 'dc':DC11_NS} class CSSPreProcessor(cssp): diff --git a/src/calibre/ebooks/oeb/polish/subset.py b/src/calibre/ebooks/oeb/polish/subset.py index adee8b2fb6..7cd918ae36 100644 --- a/src/calibre/ebooks/oeb/polish/subset.py +++ b/src/calibre/ebooks/oeb/polish/subset.py @@ -11,7 +11,7 @@ import os, sys from calibre import prints, as_unicode from calibre.ebooks.oeb.base import OEB_STYLES, OEB_DOCS, XPath -from calibre.ebooks.oeb.polish.container import OEB_FONTS +from calibre.ebooks.oeb.polish.container import OEB_FONTS, guess_type from calibre.utils.fonts.sfnt.subset import subset from calibre.utils.fonts.sfnt.errors import UnsupportedFont from calibre.utils.fonts.utils import get_font_names @@ -35,7 +35,7 @@ def subset_all_fonts(container, font_stats, report): remove = set() total_old = total_new = 0 for name, mt in container.mime_map.iteritems(): - if mt in OEB_FONTS or name.rpartition('.')[-1].lower() in {'otf', 'ttf'}: + 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()) path = container.name_path_map[name] total_old += os.path.getsize(path) diff --git a/src/calibre/gui2/tweak_book/file_list.py b/src/calibre/gui2/tweak_book/file_list.py index 876e8b7be4..0f972d0a71 100644 --- a/src/calibre/gui2/tweak_book/file_list.py +++ b/src/calibre/gui2/tweak_book/file_list.py @@ -17,7 +17,7 @@ from PyQt4.Qt import ( from calibre import human_readable, sanitize_file_name_unicode from calibre.ebooks.oeb.base import OEB_STYLES, OEB_DOCS -from calibre.ebooks.oeb.polish.container import guess_type +from calibre.ebooks.oeb.polish.container import guess_type, OEB_FONTS from calibre.ebooks.oeb.polish.cover import get_cover_page_name, get_raster_cover_name from calibre.gui2 import error_dialog, choose_files from calibre.gui2.tweak_book import current_container, elided_text @@ -178,13 +178,11 @@ class FileList(QTreeWidget): for names in container.manifest_type_map.itervalues(): manifested_names |= set(names) - font_types = {guess_type('a.'+x) for x in ('ttf', 'otf', 'woff')} - def get_category(name, mt): category = 'misc' if mt.startswith('image/'): category = 'images' - elif mt in font_types: + elif mt in OEB_FONTS: category = 'fonts' elif mt in OEB_STYLES: category = 'styles'