Skip to content
Commit 36185dbe authored by Nyan Pasu's avatar Nyan Pasu 🐈
Browse files

Fix hang in line-break algorithm

findBreak() previously mixed QFontMetrics::boundingRect().width() (the
width a string takes up, including left/right overhangs) and
QFontMetrics::horizontalAdvance() (which excludes overhangs). This
resulted in inconsistent behaviors within the function.

For borderline strings where fm->boundingRect(text).width() >= maxWidth
but fm->horizontalAdvance(text) < maxWidth, the code would not return
early, and would never exit the binary search loop because halfWidth <
maxWidth even when halfPos == text.length(). In fact, bottomPos gets set
to text.length() + 1 and the loop continues forever.

By consistently using QFontMetrics::boundingRect().width(), we make sure
the binary search loop always breaks out. It would be nice to add a
(halfWidth < maxWidth && halfPos < breakPos) check, but it's not
strictly necessary.

BUG: 428917
parent 1c8b8558
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment