Detect fonts with obsolete mimetypes as well

This commit is contained in:
Kovid Goyal 2013-11-26 17:15:22 +05:30
parent 3bc7e7d943
commit c4d213d490
3 changed files with 5 additions and 7 deletions

View File

@ -43,7 +43,7 @@ exists, join, relpath = os.path.exists, os.path.join, os.path.relpath
def guess_type(x): def guess_type(x):
return _guess_type(x)[0] or 'application/octet-stream' 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} OPF_NAMESPACES = {'opf':OPF2_NS, 'dc':DC11_NS}
class CSSPreProcessor(cssp): class CSSPreProcessor(cssp):

View File

@ -11,7 +11,7 @@ import os, sys
from calibre import prints, as_unicode from calibre import prints, as_unicode
from calibre.ebooks.oeb.base import OEB_STYLES, OEB_DOCS, XPath 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.subset import subset
from calibre.utils.fonts.sfnt.errors import UnsupportedFont from calibre.utils.fonts.sfnt.errors import UnsupportedFont
from calibre.utils.fonts.utils import get_font_names from calibre.utils.fonts.utils import get_font_names
@ -35,7 +35,7 @@ def subset_all_fonts(container, font_stats, report):
remove = set() remove = set()
total_old = total_new = 0 total_old = total_new = 0
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'}: 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] path = container.name_path_map[name]
total_old += os.path.getsize(path) total_old += os.path.getsize(path)

View File

@ -17,7 +17,7 @@ from PyQt4.Qt import (
from calibre import human_readable, sanitize_file_name_unicode from calibre import human_readable, sanitize_file_name_unicode
from calibre.ebooks.oeb.base import OEB_STYLES, OEB_DOCS 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.ebooks.oeb.polish.cover import get_cover_page_name, get_raster_cover_name
from calibre.gui2 import error_dialog, choose_files from calibre.gui2 import error_dialog, choose_files
from calibre.gui2.tweak_book import current_container, elided_text 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(): for names in container.manifest_type_map.itervalues():
manifested_names |= set(names) manifested_names |= set(names)
font_types = {guess_type('a.'+x) for x in ('ttf', 'otf', 'woff')}
def get_category(name, mt): def get_category(name, mt):
category = 'misc' category = 'misc'
if mt.startswith('image/'): if mt.startswith('image/'):
category = 'images' category = 'images'
elif mt in font_types: elif mt in OEB_FONTS:
category = 'fonts' category = 'fonts'
elif mt in OEB_STYLES: elif mt in OEB_STYLES:
category = 'styles' category = 'styles'