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

QTextDocument should refrain from utilizing the qt_defaultDpi() and instead calculate the scale based on the resolution of the paint device

    XMLWordPrintable

Details

    Description

      The following is taken partially verbatim from the original reporter:

      "Imagine a QTextDocument which contains a table with fixed size.
      We want it to be 2 inches large (for an example). 2 inches = 144 pt = 192 px. So we use QTextLength::FixedLength and rawValue of 192 px.

      Unfortunately, QTextDocument will not render correctly a fixed length on a offscreen device in the following cases :

      • the user changed the screen resolution (from normal, i.e. 96 dpi to something else)
      • QTextDocument is run from a QCoreApplication (ex: to generate reporting)
        Note that I am not speaking of widget rendering. I use a QImage backend for offscreen rendering with a specific resolution (let say 300 dpi).

      The reason behind this incorrect behavior is the following function:
      QTextDocumentLayoutPrivate::scaleToDevice(qreal value)
      Where returned value is "value * paintDevice->logicalDpiY() / qreal(qt_defaultDpi());"
      As long as qt_defaultDpi() returns 96 dpi, this is fine (i.e. 72 / 0.75 = 96 as expected from specification).
      But it will be wrong for QCoreApplication and any computer where user modified the resolution.

      You can see that easily : change the screen resolution to 150% and run again the mini program which generate an offscreen rendering.

      Text is still correctly render but table cell is now much smaller (1.33 inches), because of qt_defaultDpi() which returns 144 instead of 96.

      Now, modify a bit the mini program to run as a QCoreApplication and you'll get 25% error, because qt_defaultDpi returns 75.

      TMHO, QTextDocumentLayoutPrivate::scaleToDevice (2 functions, actually) should rather return what the specification expect to:
      return value * paintDevice->logicalDpiY() / 72.0 / 0.75;"

      Attachments

        Issue Links

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

          Activity

            People

              esabraha Eskil Abrahamsen Blomfeldt
              andysh Andy Shaw
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes