Skip to content

Commit

Permalink
create: define a max box size for the top stamp
Browse files Browse the repository at this point in the history
Re-enable the too long test.
  • Loading branch information
cbm755 committed Nov 22, 2022
1 parent ed6a6ee commit df9b38d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
13 changes: 8 additions & 5 deletions plom/create/mergeAndCodePages.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,18 @@ def pdf_page_add_labels_QRs(page, shortname, stamp, qr_code, odd=True):
BR = fitz.Rect(pg_width - mx - w, pg_height - my - w, pg_width - mx, pg_height - my)

tw = fitz.TextWriter(page.rect)
# location does not matter: we will centre it ourselves
tw.append(fitz.Point(0, 40), stamp, fontsize=18, font=fitz.Font("helv"))
maxbox = fitz.Rect(mx + w + 10, my, pg_width - mx - w - 10, my + 30)
# page.draw_rect(maxbox, color=(1, 0, 0))
extra = tw.fill_textbox(
maxbox, stamp, align=fitz.TEXT_ALIGN_CENTER, fontsize=14, font=fitz.Font("helv")
)
assert not extra, "Text didn't fit: is paper number label too long?"
r = tw.text_rect
r = fitz.Rect(
pg_width // 2 - r.width / 2, my, pg_width // 2 + r.width / 2, my + r.height
)
# + minor tweak here to adjust drawn box
page.draw_rect(r + (-3, 0, -3, 1))
page.write_text(rect=r, writers=tw)
page.draw_rect(r)
tw.write_text(page)

# special code to skip staple mark and QR codes
if odd is None:
Expand Down
6 changes: 3 additions & 3 deletions plom/create/test_stamps.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ def test_staple_marker_diagname_very_long(tmpdir):


# TODO: faster to use a Class with setup and teardown to build the PDF
def test_stamp_very_long(tmpdir):
def test_stamp_too_long(tmpdir):
tmpdir = Path(tmpdir)
assert buildDemoSourceFiles(basedir=tmpdir)
d = fitz.open(tmpdir / "sourceVersions/version1.pdf")
pdf_page_add_labels_QRs(d[0], "foo", "1234 Q33 p. 38", [])
# even long ones are not errors, after Issue #1902
pdf_page_add_labels_QRs(d[0], "foo", "MMMM " * 6, [])
with raises(AssertionError):
pdf_page_add_labels_QRs(d[0], "foo", "12345 " * 20, [])
d.close()


Expand Down

0 comments on commit df9b38d

Please sign in to comment.