mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
PDF Output: Fix anchors sometimes located incorrectly
PDF Output: Workaround bug in WebKit's getBoundingClientRect() method that could cause links to occasionally point to incorrect locations. Fixes #1202390 [Private bug](https://bugs.launchpad.net/calibre/+bug/1202390)
This commit is contained in:
parent
ce4d12711a
commit
0c5959f298
Binary file not shown.
@ -294,8 +294,20 @@ class PagedDisplay
|
||||
return Math.floor(xpos/this.page_width)
|
||||
|
||||
column_location: (elem) ->
|
||||
# Return the location of elem relative to its containing column
|
||||
# Return the location of elem relative to its containing column.
|
||||
# WARNING: This method may cause the viewport to scroll (to workaround
|
||||
# a bug in WebKit).
|
||||
br = elem.getBoundingClientRect()
|
||||
# Because of a bug in WebKit's getBoundingClientRect() in column
|
||||
# mode, this position can be inaccurate, see
|
||||
# https://bugs.launchpad.net/calibre/+bug/1202390 for a test case.
|
||||
# The usual symptom of the inaccuracy is br.top is highly negative.
|
||||
if br.top < -100
|
||||
# We have to actually scroll the element into view to get its
|
||||
# position
|
||||
elem.scrollIntoView()
|
||||
[left, top] = calibre_utils.viewport_to_document(elem.scrollLeft, elem.scrollTop, elem.ownerDocument)
|
||||
else
|
||||
[left, top] = calibre_utils.viewport_to_document(br.left, br.top, elem.ownerDocument)
|
||||
c = this.column_at(left)
|
||||
width = Math.min(br.right, (c+1)*this.page_width) - br.left
|
||||
|
@ -353,6 +353,7 @@ class PDFWriter(QObject):
|
||||
paged_display.layout();
|
||||
paged_display.fit_images();
|
||||
py_bridge.value = book_indexing.all_links_and_anchors();
|
||||
window.scrollTo(0, 0); // This is needed as getting anchor positions could have caused the viewport to scroll
|
||||
'''%(self.margin_top, 0, self.margin_bottom))
|
||||
|
||||
amap = self.bridge_value
|
||||
|
Loading…
x
Reference in New Issue
Block a user