Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions tests/test_textextract.py
Original file line number Diff line number Diff line change
Expand Up @@ -1033,3 +1033,45 @@ def test_4994():
assert len(search_results) == 2
#assert text == 'planet-warming gas driving climate change.'
sys.stdout.flush()


def test_5218():
print()
num_errors = 0
for use_actualtext in True, False:
with pymupdf.open() as doc:
page = doc.new_page()
font = doc.get_new_xref()
doc.update_object(font, '<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica /Encoding /WinAnsiEncoding >>')
if not use_actualtext:
cmap = doc.get_new_xref()
doc.update_object(cmap, '<< >>')
doc.update_stream(
cmap,
b'/CIDInit /ProcSet findresource begin 12 dict begin begincmap /CMapName /X def '
b'1 begincodespacerange <00> <FF> endcodespacerange 1 beginbfchar <41> <FDE2> endbfchar '
b'endcmap CMapName currentdict /CMap defineresource pop end end'
)
doc.xref_set_key(font, 'ToUnicode', f'{cmap} 0 R')
doc.xref_set_key(page.xref, 'Resources', f'<< /Font << /F1 {font} 0 R >> >>')
if use_actualtext:
body = '/Span << /ActualText <FEFFFDE2> >> BDC BT /F1 12 Tf 72 720 Td ( ) Tj ET EMC'
else:
body = 'BT /F1 12 Tf 72 720 Td (A) Tj ET'
c = doc.get_new_xref()
doc.update_object(c, '<< >>')
doc.update_stream(c, body.encode())
doc.xref_set_key(page.xref, 'Contents', f'{c} 0 R')

for b in page.get_textpage(flags=0).this:
if b.m_internal.type == 0:
for l in b:
for ch in l:
print(f'{use_actualtext=}: {ch.m_internal.c:#x}')
if ch.m_internal.c != 0xfde2:
num_errors += 1
print(f'{num_errors=}')
if pymupdf.mupdf_version_tuple >= (1, 29):
assert not num_errors
else:
assert num_errors
Loading