Skip to content
Browse files

Switch from margin area to border area for the link "hit box"

  • Loading branch information...
1 parent b1965a1 commit b98820df5b1c1d41c67f34f2a038e8dc4fe5bb49 @SimonSapin SimonSapin committed Jun 14, 2012
Showing with 11 additions and 7 deletions.
  1. +4 −2 weasyprint/browser.py
  2. +7 −5 weasyprint/pdf.py
View
6 weasyprint/browser.py
@@ -33,8 +33,10 @@ def find_links(box, links):
href = '/' + href
else:
href = None
- links.append((href, anchor, box.position_x, box.position_y,
- box.margin_width(), box.margin_height()))
+ # "Border area. That's the area that hit-testing is done on."
+ # http://lists.w3.org/Archives/Public/www-style/2012Jun/0318.html
+ links.append((href, anchor, box.border_box_x(), box.border_box_y(),
+ box.border_width(), box.border_height()))
if isinstance(box, boxes.ParentBox):
for child in box.children:
View
12 weasyprint/pdf.py
@@ -351,23 +351,25 @@ def process_bookmarks(raw_bookmarks):
def gather_metadata(document):
"""Traverse the layout tree (boxes) to find all metadata."""
def walk(box):
+ # "Border area. That's the area that hit-testing is done on."
+ # http://lists.w3.org/Archives/Public/www-style/2012Jun/0318.html
if box.bookmark_label and box.bookmark_level:
- pos_x, pos_y = point_to_pdf(box.position_x, box.position_y)
+ pos_x, pos_y = point_to_pdf(box.border_box_x(), box.border_box_y())
bookmarks.append((
box.bookmark_level,
box.bookmark_label,
(page_index, pos_x, pos_y)))
if box.style.link:
- pos_x, pos_y = point_to_pdf(box.position_x, box.position_y)
+ pos_x, pos_y = point_to_pdf(box.border_box_x(), box.border_box_y())
width, height = distance_to_pdf(
- box.margin_width(), box.margin_height())
+ box.border_width(), box.border_height())
page_links.append(
(box, (pos_x, pos_y, pos_x + width, pos_y + height)))
if box.style.anchor and box.style.anchor not in anchors:
- anchors[box.style.anchor] = (
- (page_index,) + point_to_pdf(box.position_x, box.position_y))
+ pos_x, pos_y = point_to_pdf(box.border_box_x(), box.border_box_y())
+ anchors[box.style.anchor] = (page_index, pos_x, pos_y)
if isinstance(box, boxes.ParentBox):
for child in box.children:

0 comments on commit b98820d

Please sign in to comment.
Something went wrong with that request. Please try again.