perf(engine): binary-search auto-size font fitting + deprecate unused adjustFontSizeToFit (F12)#146
Merged
Merged
Conversation
…adjustFontSizeToFit Auto-size paragraphs (.autoSize(...)) resolved the font size by scanning every step from max down to min, re-measuring the line at each candidate (up to ~50 measures). Line width is linear in font size so the fit is monotonic; binary-search the grid for the same boundary in ~log2(n) measures instead of n. Byte-identical: returns the same grid size the linear scan did (covered by the existing auto-size integration and snapshot tests). Also deprecate Font.adjustFontSizeToFit (+ the PdfFont/WordFont implementations): unused and incorrect — the PdfFont impl re-measured with the unchanged style, so it always returned the minimum size. Kept for binary compatibility; canonical auto-size is the layout compiler path above. Dropped a dead local while there. Finding 12.
…ry-search # Conflicts: # CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Auto-size font fitting binary-searches the size grid (the optimization)
A paragraph with
.autoSize(maxSize, minSize)resolved its font size by scanning every step from max down to min and re-measuring the longest line at each candidate (default step0.5→ up to ~50 measurements). Line width is linear in font size, so the fit predicate is monotonic — the search now binary-searches the grid for the same boundary in ~log2(n) measurements (≈6 instead of ~50), the same pattern as the F2fitCharactersfix.0.5step,maxSize - i*stepequals the scan's repeated subtraction exactly). Guarded by the 11 existing auto-size integration / snapshot tests, includingLayoutSnapshotExtractorTestwhich snapshots the resolved size. No public API or behaviour change.Deprecate the unused, buggy
adjustFontSizeToFitFont#adjustFontSizeToFit(and thePdfFont/WordFontimplementations) is dead code — zero callers — and thePdfFontimplementation is incorrect: it re-measures with the unchangedstyle, sotextWidthnever shrinks and the loop runs to the minimum size regardless of fit. Marked@Deprecatedrather than deleted becauseengine.font.Fontis in the japicmp binary-compat baseline (deletion is a next-major change); the javadoc points to the canonical layout-compiler auto-size path. Dropped a dead local inPdfFontwhile there.Verification
./mvnw verify -pl .— BUILD SUCCESS, 1151 tests, 0 failures (checkstyle + SpotBugs + javadoc); auto-size suite unchanged (proves byte-identity).@Deprecatedis binary-compatible, so the japicmp gate stays green.