Details
-
Bug
-
Resolution: Won't Do
-
P3: Somewhat important
-
None
-
5.8.0
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
- relates to
-
QTBUG-90958 When an image with a fixed DPI as the paint device for a QTextDocument's layout then it will still have differences when the Windows scale factor is changed
-
- Closed
-
- resulted in
-
QTBUG-80454 Add API to set the DPI of a QTextDocument
-
- Open
-