- 
    
Bug
 - 
    Resolution: Done
 - 
    
P3: Somewhat important
 - 
    5.11.1
 - 
    None
 
When a text that contains Unicode character controls (ZWJ, ZWNJ, possible RLM LRM RLE LRE etc.), the width returned by QFontMetrics::tightBoundingRect is larger than what it’s actually is, even if the script doesn’t support such scripts at all.
Example code (this is PyQt5, but I am pretty sure that the binding have nothing to do with the width):
from PyQt5.QtGui import QGuiApplication, QFont, QFontMetricsF app = QGuiApplication(["myApp"]) notoFont = QFont("Noto Sans", 62) notoMetrics = QFontMetricsF(notoFont) print(notoMetrics.tightBoundingRect("ab")) print(notoMetrics.tightBoundingRect("a\u200Cb"))
Returns:
PyQt5.QtCore.QRectF(3.0, -64.0, 91.0, 65.0)
PyQt5.QtCore.QRectF(3.0, -64.0, 113.0, 65.0)
I’ve tested this with several fonts and the width was different in all of them (for the two cases).
This was originally about Arabic script, trying to prepend/append ZNJ character to an Arabic letter. The same issue happens with that as well, although it’s a bit more complicated.
- is duplicated by
 - 
                    
QTBUG-15974 QFontMetrics::boundingRect() returns too-small result
-         
 - Closed
 
 -         
 
- relates to
 - 
                    
QTBUG-85936 TextMetrics.width does not always give a correct width for the given text and is sometimes too short depending on the font used
-         
 - Closed
 
 -         
 
| For Gerrit Dashboard: QTBUG-70184 | ||||||
|---|---|---|---|---|---|---|
| # | Subject | Branch | Project | Status | CR | V | 
| 376365,13 | Fix inconsistencies between advanceWidth and bounding rects | dev | qt/qtbase | Status: MERGED | +2 | 0 |