Skip to content

TextWriter - wrong font being used #561

@jotaf98

Description

@jotaf98

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.
screen
test.pdf

Your configuration (mandatory)

  • Windows 10, 64 bits
  • Python 3.7.3, 64 bits
  • PyMuPDF 1.17.3, installed with pip (wheel)

Metadata

Metadata

Assignees

Labels

bugresolvedfixed / implemented / answered

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions