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

Right-aligned text in a QTextDocument is not taken into account in the frame's bounding rect correctly

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.10.1
    • GUI: Text handling
    • None

    Description

      When text in a QTextDocument is right-aligned, a glyph at the end of a line with a right side-bearing extending beyond the advance width of the glyph will not be taken into account by the QTextFrame's bounding rect.

      You can see this most easily (in most fonts) with the lowercase letter 'f'. This overhangs the advance width to the right, and if it comes at the end of the line in right-aligned text, will also overhang the bounding rect. This is demonstrated with the attached test app; ensure the 'Right aligned' checkbox is checked and the block margin is set to zero, and you'll see the problem.

      It's correct that the text is lined up with advance positions, but the bounding rect should surely take the side-bearings into account correctly

      It looks like this happens when QTextDocumentLayoutPrivate::layoutBlock is updating the contentsWidth for each line in turn. It computes the right-hand side of each line by using the unaligned line X position and QTextLine::naturalTextWidth. If instead it used the right-hand side of QTextLine::naturalTextRect, then the alignment would be taken into account, as this shifts the X position and uses the textWidth rather than the advanceWidth. However, the side-bearing (i.e. the difference between textWidth and advanceWidth) should really be allowed to 'eat' into the block margin, so the fix isn't quite so straightforward as a simple swap between these two methods.

      Attachments

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

        Activity

          People

            esabraha Eskil Abrahamsen Blomfeldt
            jlarcombe James Larcombe
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes