Skip to content

Commit

Permalink
Fixing outline heading section names that have been broken by PR #222
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas-C committed Sep 22, 2021
1 parent c822cea commit cfe9290
Show file tree
Hide file tree
Showing 12 changed files with 12 additions and 12 deletions.
4 changes: 3 additions & 1 deletion fpdf/syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ def camel_case(property_name):

class PDFString(str):
def serialize(self):
return f'({self.encode("UTF-16BE").decode("latin-1")})'
# Filtering out characters that are not encodable as Latin1 for now,
# as an outline /Title seemingly cannot "just" be encoded as UTF-16BE:
return f'({self.encode("latin-1", "ignore").decode("latin-1")})'


class PDFArray(list):
Expand Down
Binary file modified test/html/html_features.pdf
Binary file not shown.
Binary file modified test/html/html_heading_hebrew.pdf
Binary file not shown.
Binary file modified test/image/alt_text/alt_text_and_title.pdf
Binary file not shown.
Binary file modified test/image/alt_text/test_alt_text_on_two_pages.pdf
Binary file not shown.
Binary file modified test/link_alt_text.pdf
Binary file not shown.
Binary file modified test/outline/test_2_pages_outline.pdf
Binary file not shown.
Binary file modified test/outline/test_html_toc.pdf
Binary file not shown.
Binary file modified test/outline/test_html_toc_2_pages.pdf
Binary file not shown.
12 changes: 6 additions & 6 deletions test/outline/test_outline_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_serialize_outline():
)
assert (
serialize_outline(sections, first_object_id=6)
== f"""\
== """\
6 0 obj
<<
/Count 2
Expand All @@ -35,15 +35,15 @@ def test_serialize_outline():
/Last 8 0 R
/Next 9 0 R
/Parent 6 0 R
/Title ({'Title 1'.encode("UTF-16BE").decode("latin-1")})
/Title (Title 1)
>>
endobj
8 0 obj
<<
/Count 0
/Dest [5 0 R /XYZ 0 0 null]
/Parent 7 0 R
/Title ({'Subtitle 1.1'.encode("UTF-16BE").decode("latin-1")})
/Title (Subtitle 1.1)
>>
endobj
9 0 obj
Expand All @@ -54,7 +54,7 @@ def test_serialize_outline():
/Last 11 0 R
/Parent 6 0 R
/Prev 7 0 R
/Title ({'Title 2'.encode("UTF-16BE").decode("latin-1")})
/Title (Title 2)
>>
endobj
10 0 obj
Expand All @@ -63,7 +63,7 @@ def test_serialize_outline():
/Dest [9 0 R /XYZ 0 0 null]
/Next 11 0 R
/Parent 9 0 R
/Title ({'Subtitle 2.1'.encode("UTF-16BE").decode("latin-1")})
/Title (Subtitle 2.1)
>>
endobj
11 0 obj
Expand All @@ -72,7 +72,7 @@ def test_serialize_outline():
/Dest [11 0 R /XYZ 0 0 null]
/Parent 9 0 R
/Prev 10 0 R
/Title ({'Subtitle 2.2'.encode("UTF-16BE").decode("latin-1")})
/Title (Subtitle 2.2)
>>
endobj"""
)
Binary file modified test/outline/test_simple_outline.pdf
Binary file not shown.
8 changes: 3 additions & 5 deletions test/test_structure_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,9 @@ def test_single_image_structure_tree():
struct_builder.add_marked_content(
MarkedContent(1, 0, "/Figure", 0, "Image title", "Image description")
)
encoded_desc = "Image description".encode("UTF-16BE").decode("latin-1")
encoded_title = "Image title".encode("UTF-16BE").decode("latin-1")
assert (
struct_builder.serialize(first_object_id=3)
== f"""\
== """\
3 0 obj
<<
/K [4 0 R]
Expand All @@ -108,12 +106,12 @@ def test_single_image_structure_tree():
endobj
6 0 obj
<<
/Alt ({encoded_desc})
/Alt (Image description)
/K [0]
/P 4 0 R
/Pg 1 0 R
/S /Figure
/T ({encoded_title})
/T (Image title)
/Type /StructElem
>>
endobj"""
Expand Down

0 comments on commit cfe9290

Please sign in to comment.