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 (cherry picked from commit 36185dbe)
parent
c79b239e
Please register or sign in to comment