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

QFontMetrics::tightBoundingRect doesn’t return correct width somtimes

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 6.3.0 Alpha
    • 5.11.1
    • GUI: Text handling
    • None
    • 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

          For Gerrit Dashboard: QTBUG-70184
          # Subject Branch Project Status CR V

          Activity

            People

              allan.jensen Allan Sandfeld Jensen
              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