FreeType: Support RGB rendering when not using FontConfig
Windows+FreeType, Linux with -no-fontconfig and the forthcoming OSX FreeType engine can now use sub pixel rendering. The function to get the subpixel type is in QPlatformScreen because we're moving to per screen font settings in the future. This patch is safe, as no functionality is changed for existing users, if one wants sub pixel rendering they'll still have to pass -DFT_CONFIG_OPTION_SUBPIXEL_RENDERING to configure. Task-number: QTBUG-44269 Change-Id: Ib6c22d48a1b7c7b85ee316d5d9e3b6eae0c1ecc0 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>bb10
parent
c5e2d5f73b
commit
fbc3d75354
|
|
@ -393,4 +393,31 @@ QRect QPlatformScreen::mapBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation
|
|||
return rect;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns a hint about this screen's subpixel layout structure.
|
||||
|
||||
The default implementation queries the \b{QT_SUBPIXEL_AA_TYPE} env variable.
|
||||
This is just a hint because most platforms don't have a way to retrieve the correct value from hardware
|
||||
and instead rely on font configurations.
|
||||
*/
|
||||
QPlatformScreen::SubpixelAntialiasingType QPlatformScreen::subpixelAntialiasingTypeHint() const
|
||||
{
|
||||
static int type = -1;
|
||||
if (type == -1) {
|
||||
QByteArray env = qgetenv("QT_SUBPIXEL_AA_TYPE");
|
||||
if (env == "RGB")
|
||||
type = QPlatformScreen::Subpixel_RGB;
|
||||
else if (env == "BGR")
|
||||
type = QPlatformScreen::Subpixel_BGR;
|
||||
else if (env == "VRGB")
|
||||
type = QPlatformScreen::Subpixel_VRGB;
|
||||
else if (env == "VBGR")
|
||||
type = QPlatformScreen::Subpixel_VBGR;
|
||||
else
|
||||
type = QPlatformScreen::Subpixel_None;
|
||||
}
|
||||
|
||||
return static_cast<QPlatformScreen::SubpixelAntialiasingType>(type);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -74,6 +74,14 @@ class Q_GUI_EXPORT QPlatformScreen
|
|||
Q_DECLARE_PRIVATE(QPlatformScreen)
|
||||
|
||||
public:
|
||||
enum SubpixelAntialiasingType { // copied from qfontengine_p.h since we can't include private headers
|
||||
Subpixel_None,
|
||||
Subpixel_RGB,
|
||||
Subpixel_BGR,
|
||||
Subpixel_VRGB,
|
||||
Subpixel_VBGR
|
||||
};
|
||||
|
||||
QPlatformScreen();
|
||||
virtual ~QPlatformScreen();
|
||||
|
||||
|
|
@ -107,6 +115,7 @@ public:
|
|||
virtual QString name() const { return QString(); }
|
||||
|
||||
virtual QPlatformCursor *cursor() const;
|
||||
virtual SubpixelAntialiasingType subpixelAntialiasingTypeHint() const;
|
||||
|
||||
static int angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b);
|
||||
static QTransform transformBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &target);
|
||||
|
|
|
|||
|
|
@ -305,6 +305,7 @@ protected:
|
|||
private:
|
||||
friend class QFontEngineFTRawFont;
|
||||
friend class QFontconfigDatabase;
|
||||
friend class QBasicFontDatabase;
|
||||
friend class QFontEngineMultiFontConfig;
|
||||
|
||||
int loadFlags(QGlyphSet *set, GlyphFormat format, int flags, bool &hsubpixel, int &vfactor) const;
|
||||
|
|
|
|||
|
|
@ -34,6 +34,9 @@
|
|||
#include "qplatformfontdatabase.h"
|
||||
#include <QtGui/private/qfontengine_p.h>
|
||||
#include <QtGui/private/qfontengine_qpf2_p.h>
|
||||
#include <QtGui/QGuiApplication>
|
||||
#include <QtGui/QScreen>
|
||||
#include <qpa/qplatformscreen.h>
|
||||
#include <QtCore/QLibraryInfo>
|
||||
#include <QtCore/QDir>
|
||||
|
||||
|
|
@ -457,6 +460,15 @@ bool QPlatformFontDatabase::fontsAlwaysScalable() const
|
|||
return ret;
|
||||
}
|
||||
|
||||
QFontEngine::SubpixelAntialiasingType QPlatformFontDatabase::subpixelAntialiasingTypeHint() const
|
||||
{
|
||||
static int type = -1;
|
||||
if (type == -1) {
|
||||
if (QScreen *screen = QGuiApplication::primaryScreen())
|
||||
type = screen->handle()->subpixelAntialiasingTypeHint();
|
||||
}
|
||||
return static_cast<QFontEngine::SubpixelAntialiasingType>(type);
|
||||
}
|
||||
|
||||
// ### copied to tools/makeqpf/qpf2.cpp
|
||||
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@
|
|||
#include <QtCore/QList>
|
||||
#include <QtCore/QHash>
|
||||
#include <QtGui/QFontDatabase>
|
||||
#include <QtGui/private/qfontengine_p.h>
|
||||
#include <QtGui/private/qfont_p.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
|
@ -107,6 +108,7 @@ public:
|
|||
virtual QString resolveFontFamilyAlias(const QString &family) const;
|
||||
virtual bool fontsAlwaysScalable() const;
|
||||
virtual QList<int> standardSizes() const;
|
||||
QFontEngine::SubpixelAntialiasingType subpixelAntialiasingTypeHint() const;
|
||||
|
||||
// helper
|
||||
static QSupportedWritingSystems writingSystemsFromTrueTypeBits(quint32 unicodeRange[4], quint32 codePageRange[2]);
|
||||
|
|
|
|||
|
|
@ -101,9 +101,19 @@ QFontEngine *QBasicFontDatabase::fontEngine(const QFontDef &fontDef, void *usrPt
|
|||
fid.index = fontfile->indexValue;
|
||||
|
||||
bool antialias = !(fontDef.styleStrategy & QFont::NoAntialias);
|
||||
QFontEngineFT::GlyphFormat format = antialias? QFontEngineFT::Format_A8 : QFontEngineFT::Format_Mono;
|
||||
|
||||
QFontEngineFT *engine = new QFontEngineFT(fontDef);
|
||||
QFontEngineFT::GlyphFormat format = QFontEngineFT::Format_Mono;
|
||||
if (antialias) {
|
||||
QFontEngine::SubpixelAntialiasingType subpixelType = subpixelAntialiasingTypeHint();
|
||||
if (subpixelType == QFontEngine::Subpixel_None || (fontDef.styleStrategy & QFont::NoSubpixelAntialias)) {
|
||||
format = QFontEngineFT::Format_A8;
|
||||
engine->subpixelType = QFontEngine::Subpixel_None;
|
||||
} else {
|
||||
format = QFontEngineFT::Format_A32;
|
||||
engine->subpixelType = subpixelType;
|
||||
}
|
||||
}
|
||||
|
||||
if (!engine->init(fid, antialias, format) || engine->invalid()) {
|
||||
delete engine;
|
||||
engine = 0;
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@
|
|||
|
||||
#include "qtwindows_additional.h"
|
||||
|
||||
#include <QtCore/QSettings>
|
||||
#include <QtGui/QPixmap>
|
||||
#include <QtGui/QGuiApplication>
|
||||
#include <qpa/qwindowsysteminterface.h>
|
||||
|
|
@ -358,6 +359,37 @@ void QWindowsScreen::handleChanges(const QWindowsScreenData &newData)
|
|||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Queries ClearType settings to check the pixel layout
|
||||
*/
|
||||
QPlatformScreen::SubpixelAntialiasingType QWindowsScreen::subpixelAntialiasingTypeHint() const
|
||||
{
|
||||
#if defined(Q_OS_WINCE) || !defined(FT_LCD_FILTER_H) || !defined(FT_CONFIG_OPTION_SUBPIXEL_RENDERING)
|
||||
return QPlatformScreen::Subpixel_None;
|
||||
#else
|
||||
QPlatformScreen::SubpixelAntialiasingType type = QPlatformScreen::subpixelAntialiasingTypeHint();
|
||||
if (type == QPlatformScreen::Subpixel_None) {
|
||||
QSettings settings(QLatin1String("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Avalon.Graphics\\DISPLAY1"), QSettings::NativeFormat);
|
||||
int registryValue = settings.value(QLatin1String("PixelStructure"), -1).toInt();
|
||||
switch (registryValue) {
|
||||
case 0:
|
||||
type = QPlatformScreen::Subpixel_None;
|
||||
break;
|
||||
case 1:
|
||||
type = QPlatformScreen::Subpixel_RGB;
|
||||
break;
|
||||
case 2:
|
||||
type = QPlatformScreen::Subpixel_BGR;
|
||||
break;
|
||||
default:
|
||||
type = QPlatformScreen::Subpixel_None;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return type;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
\class QWindowsScreenManager
|
||||
\brief Manages a list of QWindowsScreen.
|
||||
|
|
|
|||
|
|
@ -100,6 +100,7 @@ public:
|
|||
static QWindow *windowAt(const QPoint &point, unsigned flags);
|
||||
|
||||
QPixmap grabWindow(WId window, int qX, int qY, int qWidth, int qHeight) const Q_DECL_OVERRIDE;
|
||||
QPlatformScreen::SubpixelAntialiasingType subpixelAntialiasingTypeHint() const Q_DECL_OVERRIDE;
|
||||
|
||||
inline void handleChanges(const QWindowsScreenData &newData);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue