This commit is contained in:
Kovid Goyal 2012-03-13 10:05:50 +05:30
parent 341f0d73c7
commit 3970da407c
2 changed files with 7 additions and 3 deletions

View File

@ -154,8 +154,8 @@ def update_flow_links(mobi8_reader, resource_map, log):
'valid font in %s' % (num, tag))
else:
replacement = '"%s"'%('../'+ href)
if href.endswith('.dat'):
replacement = 'unable-to-extract.ttf'
if href.endswith('.failed'):
replacement = '"%s"'%('failed-'+href)
tag = font_index_pattern.sub(replacement, tag, 1)
# process links to other css pieces

View File

@ -353,14 +353,18 @@ class Mobi8Reader(object):
fields = None
#self.log.debug('Font record fields: %s'%(fields,))
cdata = data[26:-4]
ext = 'dat'
try:
uncompressed_data = zlib.decompress(cdata, -15)
except:
self.log.warn('Failed to uncompress embedded font %d: '
'Fields: %s' % (fname_idx, fields,))
uncompressed_data = data[4:]
ext = 'failed'
hdr = uncompressed_data[0:4]
ext = 'dat'
if len(uncompressed_data) < 200:
self.log.warn('Corrupted font record: %d'%fname_idx)
ext = 'failed'
if hdr == b'\0\1\0\0' or hdr == b'true' or hdr == b'ttcf':
ext = 'ttf'
href = "fonts/%05d.%s" % (fname_idx, ext)