KF8 Output: Fix calibre produced KF8 files not showing the 'Use publisher font' option on the Kindle Touch when they have embedded fonts

This commit is contained in:
Kovid Goyal 2012-07-14 11:08:15 +05:30
parent 56fb300163
commit f45341702f
4 changed files with 12 additions and 2 deletions

View File

@ -297,10 +297,13 @@ class MobiWriter(object):
# 0x70 - 0x73 : EXTH flags # 0x70 - 0x73 : EXTH flags
# Bit 6 (0b1000000) being set indicates the presence of an EXTH header # Bit 6 (0b1000000) being set indicates the presence of an EXTH header
# Bit 12 being set indicates the presence of embedded fonts
# The purpose of the other bits is unknown # The purpose of the other bits is unknown
exth_flags = 0b1010000 exth_flags = 0b1010000
if self.is_periodical: if self.is_periodical:
exth_flags |= 0b1000 exth_flags |= 0b1000
if self.resources.has_fonts:
exth_flags |= 0b1000000000000
record0.write(pack(b'>I', exth_flags)) record0.write(pack(b'>I', exth_flags))
# 0x74 - 0x93 : Unknown # 0x74 - 0x93 : Unknown
@ -406,7 +409,10 @@ class MobiWriter(object):
# Now change the header fields that need to be different in the MOBI 6 # Now change the header fields that need to be different in the MOBI 6
# header # header
header_fields['first_resource_record'] = first_image_record header_fields['first_resource_record'] = first_image_record
header_fields['exth_flags'] = 0b100001010000 # Kinglegen uses this ef = 0b100001010000 # Kinglegen uses this
if self.resources.has_fonts:
ef |= 0b1000000000000
header_fields['exth_flags'] = ef
header_fields['fdst_record'] = pack(b'>HH', 1, last_content_record) header_fields['fdst_record'] = pack(b'>HH', 1, last_content_record)
header_fields['fdst_count'] = 1 # Why not 0? Kindlegen uses 1 header_fields['fdst_count'] = 1 # Why not 0? Kindlegen uses 1
header_fields['flis_record'] = flis_number header_fields['flis_record'] = flis_number

View File

@ -32,6 +32,7 @@ class Resources(object):
self.used_image_indices = set() self.used_image_indices = set()
self.image_indices = set() self.image_indices = set()
self.cover_offset = self.thumbnail_offset = None self.cover_offset = self.thumbnail_offset = None
self.has_fonts = False
self.add_resources(add_fonts) self.add_resources(add_fonts)
@ -109,6 +110,7 @@ class Resources(object):
'ttf', 'otf'} and isinstance(item.data, bytes): 'ttf', 'otf'} and isinstance(item.data, bytes):
self.records.append(write_font_record(item.data)) self.records.append(write_font_record(item.data))
self.item_map[item.href] = len(self.records) self.item_map[item.href] = len(self.records)
self.has_fonts = True
def add_extra_images(self): def add_extra_images(self):
''' '''

View File

@ -140,7 +140,7 @@ def build_exth(metadata, prefer_author_sort=False, is_periodical=False,
nrecs += 1 nrecs += 1
if be_kindlegen2: if be_kindlegen2:
vals = {204:201, 205:2, 206:2, 207:35621} vals = {204:201, 205:2, 206:5, 207:0}
elif is_periodical: elif is_periodical:
# Pretend to be amazon's super secret periodical generator # Pretend to be amazon's super secret periodical generator
vals = {204:201, 205:2, 206:0, 207:101} vals = {204:201, 205:2, 206:0, 207:101}

View File

@ -277,6 +277,8 @@ class KF8Book(object):
self.exth_flags = 0b1010000 self.exth_flags = 0b1010000
if writer.opts.mobi_periodical: if writer.opts.mobi_periodical:
self.exth_flags |= 0b1000 self.exth_flags |= 0b1000
if resources.has_fonts:
self.exth_flags |= 0b1000000000000
self.opts = writer.opts self.opts = writer.opts
self.start_offset = writer.start_offset self.start_offset = writer.start_offset