mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Fix #1996002 [[Bug] ebook edit subset embedded fonts fail](https://bugs.launchpad.net/calibre/+bug/1996002)
This commit is contained in:
parent
d535259677
commit
1211aef0bc
@ -95,7 +95,7 @@ def split_range(start_code, end_code, cmap): # {{{
|
|||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
def set_id_delta(id_delta): # {{{
|
def set_id_delta(index, start_code): # {{{
|
||||||
# The lowest gid in glyphIndexArray, after subtracting id_delta, must be 1.
|
# The lowest gid in glyphIndexArray, after subtracting id_delta, must be 1.
|
||||||
# id_delta is a short, and must be between -32K and 32K
|
# id_delta is a short, and must be between -32K and 32K
|
||||||
# startCode can be between 0 and 64K-1, and the first glyph index can be between 1 and 64K-1
|
# startCode can be between 0 and 64K-1, and the first glyph index can be between 1 and 64K-1
|
||||||
@ -109,10 +109,11 @@ def set_id_delta(id_delta): # {{{
|
|||||||
# Similarly , we can get from a startCode of 64K-1 to a final GID of 1 by adding 2, because of
|
# Similarly , we can get from a startCode of 64K-1 to a final GID of 1 by adding 2, because of
|
||||||
# the modulo arithmetic.
|
# the modulo arithmetic.
|
||||||
|
|
||||||
|
id_delta = index - start_code
|
||||||
if id_delta > 0x7FFF:
|
if id_delta > 0x7FFF:
|
||||||
id_delta = id_delta - 0x10000
|
id_delta -= 0x10000
|
||||||
elif id_delta < -0x7FFF:
|
elif id_delta < -0x7FFF:
|
||||||
id_delta = id_delta + 0x10000
|
id_delta += 0x10000
|
||||||
|
|
||||||
return id_delta
|
return id_delta
|
||||||
# }}}
|
# }}}
|
||||||
@ -256,9 +257,14 @@ class CmapTable(UnknownTable):
|
|||||||
indices = tuple(cmap[char_code] for char_code in range(start_code[i], end_code[i] + 1))
|
indices = tuple(cmap[char_code] for char_code in range(start_code[i], end_code[i] + 1))
|
||||||
if indices == tuple(range(indices[0], indices[0] + len(indices))):
|
if indices == tuple(range(indices[0], indices[0] + len(indices))):
|
||||||
# indices is a contiguous list
|
# indices is a contiguous list
|
||||||
id_delta_temp = set_id_delta(indices[0] - start_code[i])
|
id_delta_temp = set_id_delta(indices[0], start_code[i])
|
||||||
id_delta.append(id_delta_temp)
|
if id_delta_temp > 0x7FFF or id_delta_temp < -0x7FFF:
|
||||||
id_range_offset.append(0)
|
id_delta.append(0)
|
||||||
|
id_range_offset.append(2 * (len(end_code) + len(glyph_index_array) - i))
|
||||||
|
glyph_index_array.extend(indices)
|
||||||
|
else:
|
||||||
|
id_delta.append(id_delta_temp)
|
||||||
|
id_range_offset.append(0)
|
||||||
else:
|
else:
|
||||||
id_delta.append(0)
|
id_delta.append(0)
|
||||||
id_range_offset.append(2 * (len(end_code) + len(glyph_index_array) - i))
|
id_range_offset.append(2 * (len(end_code) + len(glyph_index_array) - i))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user