Repository navigation
Conversation
Measure line positions with the candidate font while fitting text to a height. Cover growth and shrinkage with explicit breaks, blank lines, spacing, stroke, and automatic wrapping.
Muguett-DBY
left a comment
There was a problem hiding this comment.
The candidate font now reaches the line-spacing calculation as well as the glyph bounds, which addresses the grow/shrink mismatch.
I checked head 287d2185b1d3d5cf0ff8d7e4a09b03f3a07115d4 with FreeMono/BASIC: all six new test bodies pass, while five fail against the base module. A separate 93-case check enumerating sizes 1–80 and measuring the resulting lines with ImageDraw.multiline_textbbox also selects the largest fitting size. That covers explicit breaks, a blank line, automatic wrapping, descenders, spacing and stroke. The 48 no-scaling comparisons keep the same output or exception on both versions.
This executes the exact Python modules with the existing Pillow 12.3.0 FreeType extensions on Windows/Python 3.12. The 59 selftest examples pass against those extensions. I haven't built this branch or run the full suite or RAQM. Review and checks assisted by Codex.
|
Heads-up on the latest CI attempt for My earlier approval was based on BASIC only; I couldn't run RAQM locally. I haven't established whether this is a pre-existing RAQM behavior or a regression in this change, but wanted to flag the gap while the remaining CI jobs finish. Update: I traced the same input through the exact base ( |
|
Reproduced the failure on the base revision with RAQM. When a blank line exceeded the height limit, The fix stops that wrapping attempt and preserves the remaining text, allowing the shrink loop to retry with a smaller font. Added regression tests for blank and whitespace-only lines, covering Autonomous contribution by codex (GPT-6 Astra). |
Text.wrap()measures glyphs with each candidate font while scaling, but_Wrap.add_line()gets line positions from the original font. Growing multiline text can therefore exceed the requested height, while shrinking can select a smaller font than needed or fail despite a fitting size.For example, growing
"A\nB"with FreeMono from size 10 into a 400 × 50 box selects size 47 with a bounding-box bottom of 80. Shrinking the same text from size 60 raisesValueError. With this change, both select size 28 and fit exactly within the height of 50.Pass the candidate font through
_split()so line spacing and glyph measurements use the same font. The regression cases cover growth and shrinkage with explicit line breaks, a blank line with spacing and stroke, and automatic wrapping. They check the final bounds and verify that the next larger font exceeds the height limit.Stop
_Wrapwhen a blank line exceeds the height limit, preserving the remaining text so shrinking can retry. This also fixes a pre-existing RAQM layout failure exposed by the blank-line shrink case.Validation on Ubuntu 24.04 / Python 3.12.3 with RAQM 0.11.0, built from this branch:
strandbytes.tox -e lint,tox -e mypyandgit diff --checkpass.Autonomous contribution by ChatGPT (GPT-6 Pro).