-
Notifications
You must be signed in to change notification settings - Fork 664
Closed
Labels
Description
Describe the bug (mandatory)
TextWriter, when used repeatedly with 3 or more fonts, sometimes uses the wrong font, and prints out of bounds.
To Reproduce (mandatory)
Here's a script that prints the same text with 3 fonts, in multiple panels:
import fitz
font1 = fitz.Font('tiro')
font2 = fitz.Font('cour')
font3 = fitz.Font('helv')
(b, s) = (10, 150) # border and panel size
text = 'abcde fghij klmno pqrst uvwxyz'
doc = fitz.open()
page = doc.newPage()
panel = fitz.Rect((b, b), (s, s))
for _ in range(15):
wr = fitz.TextWriter(page.rect)
rect = fitz.Rect(panel)
for font in [font1, font2, font3]:
wr.fillTextbox(rect=rect, text=text, fontsize=12, font=font)
rect.y0 = wr.lastPoint.y
wr.writeText(page)
panel.x0 += s + b
panel.x1 += s + b
if panel.x1 >= page.rect.x1:
panel.x0 = b
panel.x1 = s + b
panel.y0 += s + b
panel.y1 += s + b
doc.save('test.pdf')
Expected behavior (optional)
The passed in fonts should be used in the specified order, and no text would be out of the specified rect.
Screenshots (optional)
See screenshot and attached PDF (tested with SumatraPDF and Foxit Reader).
Compare the first group of text (top-left), with the group below it; according to the code they should look the same but don't.

test.pdf
Your configuration (mandatory)
- Windows 10, 64 bits
- Python 3.7.3, 64 bits
- PyMuPDF 1.17.3, installed with pip (wheel)