From 241ee2ee4208eb6b338390f82b71f1b1d7c4c5b0 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 17 Apr 2013 12:44:36 +0200 Subject: [PATCH] Read correct font hinting config on Gnome/Unity Fixes regression against Qt 4. This tries to recreate the logic from 5c46d9a4c85abbcc0b5db2bbbafded3efd784cd9 in Qt 4, where we on Gnome would override the default hint style specified in FontConfig with Xft.hintstyle settings. This is the configuration used for changing the hint style in the Gnome Tweak Tool. Task-number: QTBUG-29582 Change-Id: I6b9fe2c8ff55ff080d034e5a53fc8cbb49f7651f Reviewed-by: Konstantin Ritt Reviewed-by: Paul Olav Tvete --- .../fontconfig/qfontconfigdatabase.cpp | 19 +++++++++ .../platforms/xcb/qxcbnativeinterface.cpp | 3 ++ .../platforms/xcb/qxcbnativeinterface.h | 3 +- src/plugins/platforms/xcb/qxcbscreen.cpp | 42 +++++++++++++++---- src/plugins/platforms/xcb/qxcbscreen.h | 9 ++++ 5 files changed, 68 insertions(+), 8 deletions(-) diff --git a/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp b/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp index 9c28c9fa63..91472f9efb 100644 --- a/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp +++ b/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp @@ -47,11 +47,17 @@ #include +#include #include +#include +#include #include #include #include +#include + +#include #include #include FT_TRUETYPE_TABLES_H @@ -640,6 +646,19 @@ QFontEngine *QFontconfigDatabase::fontEngine(const QFontDef &f, QChar::Script sc break; } } + + if (f.hintingPreference == QFont::PreferDefaultHinting) { + QByteArray desktopEnvironment = QGuiApplicationPrivate::platformIntegration()->services()->desktopEnvironment(); + if (desktopEnvironment == "GNOME" || desktopEnvironment == "UNITY") { + void *hintStyleResource = + QGuiApplication::platformNativeInterface()->nativeResourceForScreen("hintstyle", + QGuiApplication::primaryScreen()); + int hintStyle = int(reinterpret_cast(hintStyleResource)); + if (hintStyle > 0) + default_hint_style = QFontEngine::HintStyle(hintStyle - 1); + } + } + engine->setDefaultHintStyle(default_hint_style); if (antialias) { diff --git a/src/plugins/platforms/xcb/qxcbnativeinterface.cpp b/src/plugins/platforms/xcb/qxcbnativeinterface.cpp index 6241898462..6ac69a8335 100644 --- a/src/plugins/platforms/xcb/qxcbnativeinterface.cpp +++ b/src/plugins/platforms/xcb/qxcbnativeinterface.cpp @@ -77,6 +77,7 @@ public: insert("glxcontext",QXcbNativeInterface::GLXContext); insert("apptime",QXcbNativeInterface::AppTime); insert("appusertime",QXcbNativeInterface::AppUserTime); + insert("hintstyle", QXcbNativeInterface::ScreenHintStyle); } }; @@ -139,6 +140,8 @@ void *QXcbNativeInterface::nativeResourceForScreen(const QByteArray &resource, Q case AppUserTime: result = appUserTime(xcbScreen); break; + case ScreenHintStyle: + result = reinterpret_cast(xcbScreen->hintStyle() + 1); default: break; } diff --git a/src/plugins/platforms/xcb/qxcbnativeinterface.h b/src/plugins/platforms/xcb/qxcbnativeinterface.h index db0fa3e2ca..919a21d00d 100644 --- a/src/plugins/platforms/xcb/qxcbnativeinterface.h +++ b/src/plugins/platforms/xcb/qxcbnativeinterface.h @@ -64,7 +64,8 @@ public: EglContext, GLXContext, AppTime, - AppUserTime + AppUserTime, + ScreenHintStyle }; QXcbNativeInterface(); diff --git a/src/plugins/platforms/xcb/qxcbscreen.cpp b/src/plugins/platforms/xcb/qxcbscreen.cpp index 7ae4e19dc3..38b4c873ad 100644 --- a/src/plugins/platforms/xcb/qxcbscreen.cpp +++ b/src/plugins/platforms/xcb/qxcbscreen.cpp @@ -67,6 +67,7 @@ QXcbScreen::QXcbScreen(QXcbConnection *connection, xcb_screen_t *scr, , m_number(number) , m_refreshRate(60) , m_forcedDpi(-1) + , m_hintStyle(QFontEngine::HintStyle(-1)) { if (connection->hasXRandr()) xcb_randr_select_input(xcb_connection(), screen()->root, true); @@ -481,6 +482,35 @@ QPixmap QXcbScreen::grabWindow(WId window, int x, int y, int width, int height) return result; } +bool QXcbScreen::xResource(const QByteArray &identifier, + const QByteArray &expectedIdentifier, + int *value) +{ + Q_ASSERT(value != 0); + if (identifier.startsWith(expectedIdentifier)) { + QByteArray stringValue = identifier.mid(expectedIdentifier.size()); + + bool ok; + *value = stringValue.toInt(&ok); + if (!ok) { + if (stringValue == "hintfull") + *value = QFontEngine::HintFull; + else if (stringValue == "hintnone") + *value = QFontEngine::HintNone; + else if (stringValue == "hintmedium") + *value = QFontEngine::HintMedium; + else if (stringValue == "hintslight") + *value = QFontEngine::HintLight; + + return *value != 0; + } + + return true; + } + + return false; +} + void QXcbScreen::readXResources() { int offset = 0; @@ -508,13 +538,11 @@ void QXcbScreen::readXResources() QList split = resources.split('\n'); for (int i = 0; i < split.size(); ++i) { const QByteArray &r = split.at(i); - if (r.startsWith("Xft.dpi:\t")) { - bool ok; - int dpi = r.mid(sizeof("Xft.dpi:")).toInt(&ok); - if (ok) - m_forcedDpi = dpi; - break; - } + int value; + if (xResource(r, "Xft.dpi:\t", &value)) + m_forcedDpi = value; + else if (xResource(r, "Xft.hintstyle:\t", &value)) + m_hintStyle = QFontEngine::HintStyle(value); } } diff --git a/src/plugins/platforms/xcb/qxcbscreen.h b/src/plugins/platforms/xcb/qxcbscreen.h index 4c7d7f2c1c..c3b13fd1ea 100644 --- a/src/plugins/platforms/xcb/qxcbscreen.h +++ b/src/plugins/platforms/xcb/qxcbscreen.h @@ -50,6 +50,8 @@ #include "qxcbobject.h" +#include + QT_BEGIN_NAMESPACE class QXcbConnection; @@ -97,7 +99,13 @@ public: void updateRefreshRate(); void readXResources(); + + QFontEngine::HintStyle hintStyle() const { return m_hintStyle; } private: + static bool xResource(const QByteArray &identifier, + const QByteArray &expectedIdentifier, + int *value); + xcb_screen_t *m_screen; xcb_randr_crtc_t m_crtc; QString m_outputName; @@ -116,6 +124,7 @@ private: QXcbCursor *m_cursor; int m_refreshRate; int m_forcedDpi; + QFontEngine::HintStyle m_hintStyle; }; QT_END_NAMESPACE