comparison tests/test_spikes.py @ 1:1d09e1dec1d9 upstream

ADD: PyMuPDF v1.26.4: the original sdist. It does not yet contain MuPDF. This normally will be downloaded when building PyMuPDF.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:37:51 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 1:1d09e1dec1d9
1 import pymupdf
2 import pathlib
3 import os
4
5
6 def test_spikes():
7 """Check suppression of text spikes caused by long miters."""
8 root = os.path.abspath(f"{__file__}/../..")
9 spikes_yes = pathlib.Path(f"{root}/docs/images/spikes-yes.png")
10 spikes_no = pathlib.Path(f"{root}/docs/images/spikes-no.png")
11 doc = pymupdf.open()
12 text = "NATO MEMBERS" # some text provoking spikes ("N", "M")
13 point = (10, 35) # insert point
14
15 # make text provoking spikes
16 page = doc.new_page(width=200, height=50) # small page
17 page.insert_text(
18 point,
19 text,
20 fontsize=20,
21 render_mode=1, # stroke text only
22 border_width=0.3, # causes thick border lines
23 miter_limit=None, # do not care about miter spikes
24 )
25 # write same text in white over the previous for better demo purpose
26 page.insert_text(point, text, fontsize=20, color=(1, 1, 1))
27 pix1 = page.get_pixmap()
28 assert pix1.tobytes() == spikes_yes.read_bytes()
29
30 # make text suppressing spikes
31 page = doc.new_page(width=200, height=50)
32 page.insert_text(
33 point,
34 text,
35 fontsize=20,
36 render_mode=1,
37 border_width=0.3,
38 miter_limit=1, # suppress each and every miter spike
39 )
40 page.insert_text(point, text, fontsize=20, color=(1, 1, 1))
41 pix2 = page.get_pixmap()
42 assert pix2.tobytes() == spikes_no.read_bytes()