Direct2D QPA: Fix HighRes painting
It turns out that supporting HighRes painting with Direct2D is quite simple. Two things are necessary. First, we set the unit mode to D2D1_UNIT_MODE_PIXELS on all our device contexts, which tells Direct2D that we specify everything in pixels. Direct2D will internally do the required conversions. Second, we scale font sizes according to DPI. Previously rendering errors resulted when a highres mode was used, this fixes those errors. Task-number: QTBUG-39105 Change-Id: Ibb4dbea4746687228249e2c36d48c4bd6c5c7bf9 Reviewed-by: Risto Avila <risto.avila@digia.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
This commit is contained in:
parent
0057507184
commit
c6b8779172
@ -64,6 +64,7 @@ public:
|
||||
}
|
||||
|
||||
Q_ASSERT(deviceContext);
|
||||
deviceContext->SetUnitMode(D2D1_UNIT_MODE_PIXELS);
|
||||
}
|
||||
|
||||
void begin()
|
||||
|
@ -1465,29 +1465,27 @@ void QWindowsDirect2DPaintEngine::drawTextItem(const QPointF &p, const QTextItem
|
||||
rtl);
|
||||
}
|
||||
|
||||
// Points (1/72 inches) to Microsoft's Device Independent Pixels (1/96 inches)
|
||||
inline static Q_DECL_CONSTEXPR FLOAT pointSizeToDIP(qreal pointSize)
|
||||
inline static FLOAT pointSizeToDIP(qreal pointSize, FLOAT dpiY)
|
||||
{
|
||||
return pointSize + (pointSize / qreal(3.0));
|
||||
return (pointSize + (pointSize / qreal(3.0))) * (dpiY / 96.0f);
|
||||
}
|
||||
|
||||
inline static FLOAT pixelSizeToDIP(int pixelSize)
|
||||
inline static FLOAT pixelSizeToDIP(int pixelSize, FLOAT dpiY)
|
||||
{
|
||||
FLOAT dpiX, dpiY;
|
||||
factory()->GetDesktopDpi(&dpiX, &dpiY);
|
||||
|
||||
return FLOAT(pixelSize) / (dpiY / 96.0f);
|
||||
return FLOAT(pixelSize) * 96.0f / dpiY;
|
||||
}
|
||||
|
||||
inline static FLOAT fontSizeInDIP(const QFont &font)
|
||||
{
|
||||
// Direct2d wants the font size in DIPs (Device Independent Pixels), each of which is 1/96 inches.
|
||||
FLOAT dpiX, dpiY;
|
||||
QWindowsDirect2DContext::instance()->d2dFactory()->GetDesktopDpi(&dpiX, &dpiY);
|
||||
|
||||
if (font.pixelSize() == -1) {
|
||||
// font size was set as points
|
||||
return pointSizeToDIP(font.pointSizeF());
|
||||
return pointSizeToDIP(font.pointSizeF(), dpiY);
|
||||
} else {
|
||||
// font size was set as pixels
|
||||
return pixelSizeToDIP(font.pixelSize());
|
||||
return pixelSizeToDIP(font.pixelSize(), dpiY);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user