Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 8 additions & 4 deletions scripts/sysinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
git:
Get branch master.
Otherwise <mupdf_location> is assumed to be a local mupdf checkout.

-p <pytest_flags>
Additional flags to pass to pytest.

Notes:

Expand Down Expand Up @@ -100,6 +103,7 @@ def main():
return 1

mupdf_location = 'git:'
pytest_flags = ''

args = iter(sys.argv[1:])
while 1:
Expand All @@ -112,6 +116,8 @@ def main():
return
elif arg == '-m':
mupdf_location = next(args)
elif arg == '-p':
pytest_flags = next(args)
else:
assert 0, f'Unrecognised {arg=}.'

Expand Down Expand Up @@ -185,8 +191,7 @@ def main():
if 1:
log()
log('## Building and installing MuPDF.')
run(f'cd {mupdf_dir} && make -j {multiprocessing.cpu_count()}')
run(f'cd {mupdf_dir} && make'
run(f'cd {os.path.abspath(mupdf_dir)} && make'
f' -j {multiprocessing.cpu_count()}'
f' barcode=yes'
f' build_prefix=system-libs-'
Expand All @@ -196,7 +201,6 @@ def main():
f' HAVE_LEPTONICA=yes'
f' HAVE_TESSERACT=yes'
f' INSTALL_MODE=755'
f' USE_SYSTEM_GUMBO=no' # Github Ubuntu's gumbo too old for mupdf.
f' USE_SYSTEM_LIBS=yes'
f' USE_SYSTEM_ZXINGCPP=no' # Github Ubuntu's zxingcpp too old for mupdf.
f' VENV_FLAG='
Expand Down Expand Up @@ -225,7 +229,7 @@ def main():
f'PYMUPDF_TEST_USE_4LLM=0 '
f'PYMUPDF_TEST_USE_LAYOUT=0 '
f'PYMUPDF_SYSINSTALL_ROOT={install_root} '
f'pytest {g_pymupdf_root}/tests'
f'pytest {pytest_flags} {g_pymupdf_root}/tests'
)


Expand Down
13 changes: 11 additions & 2 deletions tests/gentle_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ def rms(a, b, verbose=None, out_prefix=''):
return rms


def get_pixmap(path):
try:
pixmap = pymupdf.Pixmap(path)
except Exception:
with pymupdf.open(path) as document:
pixmap = document[0].get_pixmap()
return pixmap


def pixmaps_rms(a, b, out_prefix='', verbose=True):
'''
Returns RMS diff of raw bytes of two pixmaps.
Expand All @@ -53,11 +62,11 @@ def pixmaps_rms(a, b, out_prefix='', verbose=True):
if isinstance(a, str):
if verbose:
print(f'{out_prefix}pixmaps_rms(): reading pixmap from {a=}.')
a = pymupdf.Pixmap(a)
a = get_pixmap(a)
if isinstance(b, str):
if verbose:
print(f'{out_prefix}pixmaps_rms(): reading pixmap from {b=}.')
b = pymupdf.Pixmap(b)
b = get_pixmap(b)
assert a.irect == b.irect, f'Differing rects: {a.irect=} {b.irect=}.'
a_mv = a.samples_mv
b_mv = b.samples_mv
Expand Down
26 changes: 19 additions & 7 deletions tests/test_annots.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,8 @@ def draw_rectangle(rect, c, w):

def test_4944():
path = os.path.normpath(f'{__file__}/../../tests/resources/test_4944.pdf')
path_out = os.path.normpath(f'{__file__}/../../tests/test_4944_out.pdf')
path_out1 = os.path.normpath(f'{__file__}/../../tests/test_4944_out1.pdf')
path_out2 = os.path.normpath(f'{__file__}/../../tests/test_4944_out2.pdf')
print()
with pymupdf.open(path) as document:
page = document[0]
Expand All @@ -732,17 +733,28 @@ def test_4944():
print(f'{page.rotation=}')
print(f'{page.rotation_matrix=}')
print(f'{page.transformation_matrix=}')
text_json = page.get_text('rawjson')
#print(text_json)

text1 = page.get_text()
text1_json = page.get_text('rawjson')
print(f'{text1=}')
#print(text1_json)

page.add_redact_annot(page.rect)
document.save(path_out1)

page.apply_redactions(text=pymupdf.PDF_REDACT_TEXT_REMOVE)
page.draw_rect(page.rect, color=(1, 0, 0))
document.save(path_out)
print(repr(page.get_text()))
document.save(path_out2)

text_json = page.get_text('rawjson')
#print(text_json)
text2 = page.get_text()
text2_json = page.get_text('rawjson')
print(f'{text2=}')
#print(text2_json)

if 0:
assert text2 == ''
else:
assert text2 == 'p\np\n'


def test_5033():
Expand Down
8 changes: 6 additions & 2 deletions tests/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -2356,10 +2356,14 @@ def test_4846():
with open(path_expected) as f_expected:
expected = f_expected.read()
print(f'test_4846(): {pymupdf.mupdf_version=} {(svg_content==expected)=}')

rms = gentle_compare.pixmaps_rms(path_expected, path_out)
print(f'{rms=}')

if pymupdf.mupdf_version_tuple >= (1, 29):
assert svg_content == expected
assert rms < 0.5
else:
assert svg_content != expected
assert rms > 50


def test_4896():
Expand Down
Loading