mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
PDF Output: Do not crash when unable to find page for link destination, instead use previous page. Fixes #1687914 [Private bug](https://bugs.launchpad.net/calibre/+bug/1687914)
This commit is contained in:
parent
8f8dd46e81
commit
e54d347726
@ -13,6 +13,7 @@ from datetime import datetime
|
|||||||
from binascii import hexlify
|
from binascii import hexlify
|
||||||
|
|
||||||
from calibre.constants import plugins, ispy3
|
from calibre.constants import plugins, ispy3
|
||||||
|
from calibre.utils.logging import default_log
|
||||||
|
|
||||||
pdf_float = plugins['speedup'][0].pdf_float
|
pdf_float = plugins['speedup'][0].pdf_float
|
||||||
|
|
||||||
@ -238,3 +239,11 @@ class Reference(object):
|
|||||||
return repr(self)
|
return repr(self)
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
|
def current_log(newlog=None):
|
||||||
|
if newlog:
|
||||||
|
current_log.ans = newlog
|
||||||
|
return current_log.ans or default_log
|
||||||
|
|
||||||
|
|
||||||
|
current_log.ans = None
|
||||||
|
@ -11,17 +11,23 @@ import os
|
|||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
from urllib2 import unquote
|
from urllib2 import unquote
|
||||||
|
|
||||||
from calibre.ebooks.pdf.render.common import Array, Name, Dictionary, String, UTF16String
|
from calibre.ebooks.pdf.render.common import Array, Name, Dictionary, String, UTF16String, current_log
|
||||||
|
|
||||||
|
|
||||||
class Destination(Array):
|
class Destination(Array):
|
||||||
|
|
||||||
def __init__(self, start_page, pos, get_pageref):
|
def __init__(self, start_page, pos, get_pageref):
|
||||||
pnum = start_page + max(0, pos['column'])
|
pnum = start_page + max(0, pos['column'])
|
||||||
|
q = pnum
|
||||||
|
while q > -1:
|
||||||
try:
|
try:
|
||||||
pref = get_pageref(pnum)
|
pref = get_pageref(q)
|
||||||
|
break
|
||||||
except IndexError:
|
except IndexError:
|
||||||
pref = get_pageref(pnum-1)
|
pos['left'] = pos['top'] = 0
|
||||||
|
q -= 1
|
||||||
|
if q != pnum:
|
||||||
|
current_log().warn('Could not find page {} for link destination, using page {} instead'.format(pnum, q))
|
||||||
super(Destination, self).__init__([
|
super(Destination, self).__init__([
|
||||||
pref, Name('XYZ'), pos['left'], pos['top'], None
|
pref, Name('XYZ'), pos['left'], pos['top'], None
|
||||||
])
|
])
|
||||||
@ -139,5 +145,3 @@ class Links(object):
|
|||||||
item = Dictionary({'Parent':parentref, 'Dest':dest,
|
item = Dictionary({'Parent':parentref, 'Dest':dest,
|
||||||
'Title':UTF16String(toc.text or _('Unknown'))})
|
'Title':UTF16String(toc.text or _('Unknown'))})
|
||||||
return self.pdf.objects.add(item)
|
return self.pdf.objects.add(item)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user