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

QFontMetrics::tightBoundingRect doesn’t return correct width somtimes

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3: Somewhat important
    • Resolution: Done
    • Affects Version/s: 5.11.1
    • Fix Version/s: 6.3.0 Alpha
    • Component/s: GUI: Text handling
    • Labels:
      None
    • Platform/s:
      Linux/X11

      Description

      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.

        Attachments

          Issue Links

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

            Activity

              People

              Assignee:
              allan.jensen Allan Sandfeld Jensen
              Reporter:
              safa alfulaij Safa Alfulaij
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes