mirror of
https://github.com/Kozea/WeasyPrint.git
synced 2024-10-04 07:57:52 +03:00
Sort anchors
Name trees, used to store PDF destinations (HTML anchors) have to be sorted according to section 7.9.6 of the PDF 1.7 specification. Fix #1352.
This commit is contained in:
parent
815c01f735
commit
d4561b13af
@ -334,6 +334,18 @@ def test_links():
|
||||
assert rects.pop(0) == [0, TOP, RIGHT, TOP - 30]
|
||||
|
||||
|
||||
@assert_no_logs
|
||||
def test_sorted_links():
|
||||
# Regression test for https://github.com/Kozea/WeasyPrint/issues/1352
|
||||
pdf = FakeHTML(string='''
|
||||
<p id="zzz">zzz</p>
|
||||
<p id="aaa">aaa</p>
|
||||
<a href="#zzz">z</a>
|
||||
<a href="#aaa">a</a>
|
||||
''', base_url=resource_filename('<inline HTML>')).write_pdf()
|
||||
assert b'(zzz) [' in pdf.split(b'(aaa) [')[-1]
|
||||
|
||||
|
||||
@assert_no_logs
|
||||
def test_relative_links_no_height():
|
||||
# 100% wide (block), 0pt high
|
||||
|
@ -469,7 +469,8 @@ def add_hyperlinks(links, anchors, matrix, pdf, page, names):
|
||||
page['Annots'] = pydyf.Array()
|
||||
page['Annots'].append(annot.reference)
|
||||
|
||||
for anchor in anchors:
|
||||
# Anchors are name trees that have to be sorted
|
||||
for anchor in sorted(anchors):
|
||||
anchor_name, x, y = anchor
|
||||
x, y = matrix.transform_point(x, y)
|
||||
names.append(pydyf.String(anchor_name))
|
||||
|
Loading…
Reference in New Issue
Block a user