mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
GwR fix regression with NCX encoding #6797
This commit is contained in:
parent
0474230567
commit
cee9c6e6db
@ -1574,15 +1574,14 @@ class MobiWriter(object):
|
|||||||
id = unicode(oeb.metadata.cover[0])
|
id = unicode(oeb.metadata.cover[0])
|
||||||
item = oeb.manifest.ids[id]
|
item = oeb.manifest.ids[id]
|
||||||
href = item.href
|
href = item.href
|
||||||
if href in self._images:
|
index = self._images[href] - 1
|
||||||
index = self._images[href] - 1
|
exth.write(pack('>III', 0xc9, 0x0c, index))
|
||||||
exth.write(pack('>III', 0xc9, 0x0c, index))
|
exth.write(pack('>III', 0xcb, 0x0c, 0))
|
||||||
exth.write(pack('>III', 0xcb, 0x0c, 0))
|
nrecs += 2
|
||||||
nrecs += 2
|
index = self._add_thumbnail(item)
|
||||||
index = self._add_thumbnail(item)
|
if index is not None:
|
||||||
if index is not None:
|
exth.write(pack('>III', 0xca, 0x0c, index - 1))
|
||||||
exth.write(pack('>III', 0xca, 0x0c, index - 1))
|
nrecs += 1
|
||||||
nrecs += 1
|
|
||||||
|
|
||||||
exth = exth.getvalue()
|
exth = exth.getvalue()
|
||||||
trail = len(exth) % 4
|
trail = len(exth) % 4
|
||||||
@ -1696,11 +1695,12 @@ class MobiWriter(object):
|
|||||||
header.write(pack('>I', 1))
|
header.write(pack('>I', 1))
|
||||||
|
|
||||||
# 0x1c - 0x1f : Text encoding ?
|
# 0x1c - 0x1f : Text encoding ?
|
||||||
# GR: Language encoding for NCX entries (latin_1)
|
# header.write(pack('>I', 650001))
|
||||||
header.write(pack('>I', 0x4e4))
|
# GR: This needs to be either 0xFDE9 or 0x4E4
|
||||||
|
header.write(pack('>I', 0xFDE9))
|
||||||
|
|
||||||
# 0x20 - 0x23 : Mimicking kindleGen
|
# 0x20 - 0x23 : Language code?
|
||||||
header.write(pack('>I', 0xFFFFFFFF))
|
header.write(iana2mobi(str(self._oeb.metadata.language[0])))
|
||||||
|
|
||||||
# 0x24 - 0x27 : Number of TOC entries in INDX1
|
# 0x24 - 0x27 : Number of TOC entries in INDX1
|
||||||
header.write(pack('>I', indxt_count + 1))
|
header.write(pack('>I', indxt_count + 1))
|
||||||
@ -1800,7 +1800,7 @@ class MobiWriter(object):
|
|||||||
text = text.strip()
|
text = text.strip()
|
||||||
if not isinstance(text, unicode):
|
if not isinstance(text, unicode):
|
||||||
text = text.decode('utf-8', 'replace')
|
text = text.decode('utf-8', 'replace')
|
||||||
text = text.encode('cp1252','replace')
|
text = text.encode('ascii','replace')
|
||||||
return text
|
return text
|
||||||
|
|
||||||
def _add_to_ctoc(self, ctoc_str, record_offset):
|
def _add_to_ctoc(self, ctoc_str, record_offset):
|
||||||
@ -2150,26 +2150,6 @@ class MobiWriter(object):
|
|||||||
indxt.write(decint(self._ctoc_map[index]['titleOffset'], DECINT_FORWARD)) # vwi title offset in CNCX
|
indxt.write(decint(self._ctoc_map[index]['titleOffset'], DECINT_FORWARD)) # vwi title offset in CNCX
|
||||||
indxt.write(decint(0, DECINT_FORWARD)) # unknown byte
|
indxt.write(decint(0, DECINT_FORWARD)) # unknown byte
|
||||||
|
|
||||||
def _write_subchapter_node(self, indxt, indices, index, offset, length, count):
|
|
||||||
# This style works without a parent chapter, mimicking what KindleGen does,
|
|
||||||
# using a value of 0x0B for parentIndex
|
|
||||||
# Writes an INDX1 NCXEntry of entryType 0x1F - subchapter
|
|
||||||
if self.opts.verbose > 2:
|
|
||||||
# *** GR: Turn this off while I'm developing my code
|
|
||||||
#self._oeb.log.debug('Writing TOC node to IDXT:', node.title, 'href:', node.href)
|
|
||||||
pass
|
|
||||||
|
|
||||||
pos = 0xc0 + indxt.tell()
|
|
||||||
indices.write(pack('>H', pos)) # Save the offset for IDXTIndices
|
|
||||||
name = "%04X"%count
|
|
||||||
indxt.write(chr(len(name)) + name) # Write the name
|
|
||||||
indxt.write(INDXT['subchapter']) # entryType [0x0F | 0xDF | 0xFF | 0x3F]
|
|
||||||
indxt.write(decint(offset, DECINT_FORWARD)) # offset
|
|
||||||
indxt.write(decint(length, DECINT_FORWARD)) # length
|
|
||||||
indxt.write(decint(self._ctoc_map[index]['titleOffset'], DECINT_FORWARD)) # vwi title offset in CNCX
|
|
||||||
indxt.write(decint(0, DECINT_FORWARD)) # unknown byte
|
|
||||||
indxt.write(decint(0xb, DECINT_FORWARD)) # parentIndex - null
|
|
||||||
|
|
||||||
def _compute_offset_length(self, i, node, entries) :
|
def _compute_offset_length(self, i, node, entries) :
|
||||||
h = node.href
|
h = node.href
|
||||||
if h not in self._id_offsets:
|
if h not in self._id_offsets:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user