Details
-
Task
-
Resolution: Duplicate
-
P2: Important
-
6.0
-
None
Description
QFontMetrics(F)::boundingRect() (and the bounding rect returned from QPainter::drawText()) will use ascent+descent to determine the height of the bounding rect. Yet the documentation says that it will return a rectangle that covers "at least" the pixels drawn. But the ascent + descent will just return the typographic bounds of the text (i.e. the bounds used to position text lines relative to each other). It might not be expanded to cover for example the diacritics of a character.
On Windows, this works by accident, because for compatibility with the GDI rasterizer, fonts will have special winAscent and winDescent values that are intended to be usable for clipping. These are the values returned from ascent/descent in the GDI font engine at the moment.
But on macOS and Freetype, if you clip to the bounding rects returned by Qt, then you may end up clipping away parts of the glyphs, if the font is designed that way. Helvetica is one notable font which is designed to keep diacritics in the leading area of the text layout.
We want to make this consistent across platforms in Qt 6. It will cause some subtle changes in the returned values, so we will keep Qt 5 as it is.
So both QFontMetrics(F) and drawText() should return a rectangle which actually contains the text. We will not measure the actual size of the glyphs, since that would be too slow (we have tightBoundingRect() for this use case), but it is better if the rectangle is larger than the text than if it is smaller.
The approach will be to use winAscent/winDescent on the other platforms as well (although on macOS we can use CTFontGetOpticalBoundsForGlyphs() which seems to be using these metrics, or some other adjustments, internally).
Attachments
Issue Links
- duplicates
-
QTBUG-80554 Windows: Make QFontMetrics(F)::ascent() and descent() consistent with other platforms
- Closed
- is required for
-
QTBUG-63964 QFontMetrics::boundingRect gives too shallow rect on Mac
- Closed
For Gerrit Dashboard: QTBUG-80553 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
283913,6 | Make QFontMetrics(F) respect OS/2 table | dev | qt/qtbase | Status: ABANDONED | +1 | 0 |