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:
Kovid Goyal 2013-07-18 10:03:30 +05:30
parent ce4d12711a
commit 0c5959f298
3 changed files with 15 additions and 2 deletions

Binary file not shown.

View File

@ -294,9 +294,21 @@ class PagedDisplay
return Math.floor(xpos/this.page_width) return Math.floor(xpos/this.page_width)
column_location: (elem) -> 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() br = elem.getBoundingClientRect()
[left, top] = calibre_utils.viewport_to_document(br.left, br.top, elem.ownerDocument) # 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) c = this.column_at(left)
width = Math.min(br.right, (c+1)*this.page_width) - br.left width = Math.min(br.right, (c+1)*this.page_width) - br.left
if br.bottom < br.top if br.bottom < br.top

View File

@ -353,6 +353,7 @@ class PDFWriter(QObject):
paged_display.layout(); paged_display.layout();
paged_display.fit_images(); paged_display.fit_images();
py_bridge.value = book_indexing.all_links_and_anchors(); 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)) '''%(self.margin_top, 0, self.margin_bottom))
amap = self.bridge_value amap = self.bridge_value