Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-80553

Make font bounding rects consistent across platforms

    XMLWordPrintable

    Details

    • Platform/s:
      All
    • Technical Risk:
      Normal

      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

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Activity

              People

              Assignee:
              esabraha Eskil Abrahamsen Blomfeldt
              Reporter:
              esabraha Eskil Abrahamsen Blomfeldt
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes