mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
b454952438
commit
ef4d50ea61
@ -33,8 +33,10 @@ class CNCX(object): # {{{
|
||||
self.strings[item.title] = 0
|
||||
if is_periodical:
|
||||
self.strings[item.klass] = 0
|
||||
aut, desc = item.author, item.description
|
||||
self.strings[item.author] = self.strings[item.description] = 0
|
||||
if item.author:
|
||||
self.strings[item.author] = 0
|
||||
if item.description:
|
||||
self.strings[item.description] = 0
|
||||
|
||||
self.records = []
|
||||
offset = 0
|
||||
@ -65,8 +67,8 @@ class CNCX(object): # {{{
|
||||
class TAGX(object): # {{{
|
||||
|
||||
BITMASKS = {11:0b1}
|
||||
BITMASKS.update({x:i+1 for i, x in enumerate([1, 2, 3, 4, 5, 21, 22, 23])})
|
||||
BITMASKS.update({x:i+1 for i, x in enumerate([69, 70, 71, 72, 73])})
|
||||
BITMASKS.update({x:(1 << i) for i, x in enumerate([1, 2, 3, 4, 5, 21, 22, 23])})
|
||||
BITMASKS.update({x:(1 << i) for i, x in enumerate([69, 70, 71, 72, 73])})
|
||||
|
||||
NUM_VALUES = defaultdict(lambda x:1)
|
||||
NUM_VALUES[11] = 3
|
||||
@ -181,7 +183,7 @@ class IndexEntry(object):
|
||||
def entry_type(self):
|
||||
ans = 0
|
||||
for tag in self.tag_nums:
|
||||
ans |= (1 << (TAGX.BITMASKS[tag])) # 1 << x == 2**x
|
||||
ans |= TAGX.BITMASKS[tag]
|
||||
return ans
|
||||
|
||||
@property
|
||||
@ -201,7 +203,7 @@ class IndexEntry(object):
|
||||
for attr in ('image_index', 'desc_offset', 'author_offset'):
|
||||
val = getattr(self, attr)
|
||||
if val is not None:
|
||||
tag = self.RTAG_MAP[attr]
|
||||
tag = self.TAG_VALUES[attr]
|
||||
bm = TAGX.BITMASKS[tag]
|
||||
flags |= bm
|
||||
buf.write(bytes(bytearray([flags])))
|
||||
@ -226,7 +228,7 @@ class IndexEntry(object):
|
||||
class PeriodicalIndexEntry(IndexEntry):
|
||||
|
||||
def __init__(self, offset, label_offset, class_offset, depth):
|
||||
IndexEntry.__init__(offset, label_offset)
|
||||
IndexEntry.__init__(self, offset, label_offset)
|
||||
self.depth = depth
|
||||
self.class_offset = class_offset
|
||||
self.control_byte_count = 2
|
||||
@ -478,7 +480,7 @@ class Indexer(object): # {{{
|
||||
def create_index_record(self, secondary=False): # {{{
|
||||
header_length = 192
|
||||
buf = StringIO()
|
||||
indices = list(SecondaryIndexEntry.entries) if secondary else self.indices
|
||||
indices = list(SecondaryIndexEntry.entries()) if secondary else self.indices
|
||||
|
||||
# Write index entries
|
||||
offsets = []
|
||||
@ -552,7 +554,7 @@ class Indexer(object): # {{{
|
||||
buf.write(b'\xff'*4)
|
||||
|
||||
# Number of index entries 36-40
|
||||
indices = list(SecondaryIndexEntry.entries) if secondary else self.indices
|
||||
indices = list(SecondaryIndexEntry.entries()) if secondary else self.indices
|
||||
buf.write(pack(b'>I', len(indices)))
|
||||
|
||||
# ORDT offset 40-44
|
||||
|
@ -106,7 +106,7 @@ class MobiWriter(object):
|
||||
self.log.exception('Failed to generate MOBI index:')
|
||||
else:
|
||||
self.primary_index_record_idx = len(self.records)
|
||||
for i in xrange(len(self.records)):
|
||||
for i in xrange(self.last_text_record_idx + 1):
|
||||
if i == 0: continue
|
||||
tbs = self.indexer.get_trailing_byte_sequence(i)
|
||||
self.records[i] += encode_trailing_data(tbs)
|
||||
@ -146,6 +146,7 @@ class MobiWriter(object):
|
||||
oeb = self.oeb
|
||||
oeb.logger.info('Serializing images...')
|
||||
self.image_records = []
|
||||
self.image_map = {}
|
||||
|
||||
mh_href = self.masthead_offset = None
|
||||
if 'masthead' in oeb.guide:
|
||||
@ -171,10 +172,12 @@ class MobiWriter(object):
|
||||
oeb.logger.warn('Bad image file %r' % item.href)
|
||||
continue
|
||||
else:
|
||||
self.image_map[item.href] = len(self.image_records)
|
||||
self.image_records.append(data)
|
||||
|
||||
if item.href == mh_href:
|
||||
self.masthead_offset = len(self.image_records) - 1
|
||||
elif item.href == cover_href:
|
||||
self.image_records.append(data)
|
||||
self.cover_offset = len(self.image_records) - 1
|
||||
try:
|
||||
data = rescale_image(item.data, dimen=MAX_THUMB_DIMEN,
|
||||
@ -193,7 +196,7 @@ class MobiWriter(object):
|
||||
|
||||
def generate_text(self):
|
||||
self.oeb.logger.info('Serializing markup content...')
|
||||
self.serializer = Serializer(self.oeb, self.images,
|
||||
self.serializer = Serializer(self.oeb, self.image_map,
|
||||
write_page_breaks_after_item=self.write_page_breaks_after_item)
|
||||
text = self.serializer()
|
||||
self.text_length = len(text)
|
||||
@ -539,7 +542,7 @@ class MobiWriter(object):
|
||||
else:
|
||||
# Pretend to be kindlegen 1.2
|
||||
vals = {204:201, 205:1, 206:2, 207:33307}
|
||||
for code, val in vals:
|
||||
for code, val in vals.iteritems():
|
||||
exth.write(pack(b'>III', code, 12, val))
|
||||
nrecs += 1
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user