summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLouai Al-Khanji <louai.al-khanji@digia.com>2014-05-22 10:12:39 +0300
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-05-23 08:54:30 +0200
commitc6b877917241257d159bd3b9070c4be09231f40b (patch)
tree9706431dc75c7b9a75daecaa94abe33f744a5936 /src
parent0057507184bc87fc26be95298d8d734a47e73251 (diff)
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>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/platforms/direct2d/qwindowsdirect2ddevicecontext.cpp1
-rw-r--r--src/plugins/platforms/direct2d/qwindowsdirect2dpaintengine.cpp20
2 files changed, 10 insertions, 11 deletions
diff --git a/src/plugins/platforms/direct2d/qwindowsdirect2ddevicecontext.cpp b/src/plugins/platforms/direct2d/qwindowsdirect2ddevicecontext.cpp
index fb47851a06..f2400cf8fc 100644
--- a/src/plugins/platforms/direct2d/qwindowsdirect2ddevicecontext.cpp
+++ b/src/plugins/platforms/direct2d/qwindowsdirect2ddevicecontext.cpp
@@ -64,6 +64,7 @@ public:
}
Q_ASSERT(deviceContext);
+ deviceContext->SetUnitMode(D2D1_UNIT_MODE_PIXELS);
}
void begin()
diff --git a/src/plugins/platforms/direct2d/qwindowsdirect2dpaintengine.cpp b/src/plugins/platforms/direct2d/qwindowsdirect2dpaintengine.cpp
index e3adcde964..a1c405067c 100644
--- a/src/plugins/platforms/direct2d/qwindowsdirect2dpaintengine.cpp
+++ b/src/plugins/platforms/direct2d/qwindowsdirect2dpaintengine.cpp
@@ -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);
}
}