From 9dd2048c1a11b29f0e16a7906e216133201d24db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Sat, 24 Nov 2018 23:15:07 +0100 Subject: CoreText: Simplify and share code for loading glyph advances The function doesn't need the flags argument, nor does it need the ctfont or fontdef arguments if it's a normal const member function. It can also be used from QCoreTextFontEngine::stringToCMap(), instead of duplicating the code. This was originally the case before b4aa5d97 which improved surrogate pair handling, but for some reason the change introduced the duplicate code instead of just changing the arguments in the function call slightly. The use of 0xff000000 to skip certain glyphs looks dubious, and is probably related to QFontEngineMulti's use of the high byte to indicate which engine the glyph came from, but the multi engine strips this away before calling out to the concrete engine so it could potentially be removed in a later patch. Change-Id: I6c693595616da1b69fdbe3d7a31e392a8443369d Reviewed-by: Simon Hausmann --- src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h') diff --git a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h index b77aaa27c1..f4213a2ffa 100644 --- a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h +++ b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h @@ -128,6 +128,8 @@ public: protected: void init(); QImage imageForGlyph(glyph_t glyph, QFixed subPixelPosition, bool colorful, const QTransform &m); + void loadAdvancesForGlyphs(QVarLengthArray &cgGlyphs, QGlyphLayout *glyphs) const; + CTFontRef ctfont; CGFontRef cgFont; int synthesisFlags; -- cgit v1.2.3 From 61a94d2d046c1448ba4c66dfc8e0246286bab14c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Sat, 24 Nov 2018 23:42:32 +0100 Subject: CoreText: Share code by using delegate constructor Change-Id: If3d5d533f98552335517ef61cb748d0117fe3053 Reviewed-by: Simon Hausmann --- src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h') diff --git a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h index f4213a2ffa..33c3c0cd40 100644 --- a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h +++ b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h @@ -126,6 +126,7 @@ public: static QCoreTextFontEngine *create(const QByteArray &fontData, qreal pixelSize, QFont::HintingPreference hintingPreference); protected: + QCoreTextFontEngine(const QFontDef &def); void init(); QImage imageForGlyph(glyph_t glyph, QFixed subPixelPosition, bool colorful, const QTransform &m); void loadAdvancesForGlyphs(QVarLengthArray &cgGlyphs, QGlyphLayout *glyphs) const; -- cgit v1.2.3 From d3ec5a2b09f3c9f5a67e757aa6b7b0dd09bbe97a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Sun, 25 Nov 2018 00:41:00 +0100 Subject: CoreText: Use QCFType to track CoreFoundation member variables The operator T() function of QAppleRefCounted should be const so that the underlying type can be accessed from const member functions just like the naked underlying type could. Change-Id: I0819c5795d28442a6ff4db2732e211b183574f9f Reviewed-by: Simon Hausmann --- src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h') diff --git a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h index 33c3c0cd40..7ed2faff8e 100644 --- a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h +++ b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h @@ -131,8 +131,8 @@ protected: QImage imageForGlyph(glyph_t glyph, QFixed subPixelPosition, bool colorful, const QTransform &m); void loadAdvancesForGlyphs(QVarLengthArray &cgGlyphs, QGlyphLayout *glyphs) const; - CTFontRef ctfont; - CGFontRef cgFont; + QCFType ctfont; + QCFType cgFont; int synthesisFlags; CGAffineTransform transform; QFixed avgCharWidth; -- cgit v1.2.3 From d4e3442fdbb98b5c635448031ff9958819a46bc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Sun, 25 Nov 2018 15:59:04 +0100 Subject: CoreText: Modernize font smoothing and antialiasing threshold detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The way macOS does font smoothing has changed in Mojave, and we need to take both this new algorithm into account, as well as support users who set legacy preferences to revert back to subpixel font smoothing. As a followup to this patch we will tweak some of the existing logic to take the new font smoothing algorithm into account, so this is just a first step. Change-Id: If37014c18515f406b8bb8194c9df7a75c2eb10fc Reviewed-by: Simon Hausmann Reviewed-by: Tor Arne Vestbø Reviewed-by: Allan Sandfeld Jensen --- .../fontdatabases/mac/qfontengine_coretext_p.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h') diff --git a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h index 7ed2faff8e..2ce46a4706 100644 --- a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h +++ b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h @@ -53,6 +53,7 @@ #include #include +#include #ifdef Q_OS_OSX #include @@ -63,8 +64,12 @@ QT_BEGIN_NAMESPACE +Q_DECLARE_LOGGING_CATEGORY(lcQpaFonts) + class QCoreTextFontEngine : public QFontEngine { + Q_GADGET + public: QCoreTextFontEngine(CTFontRef font, const QFontDef &def); QCoreTextFontEngine(CGFontRef font, const QFontDef &def); @@ -118,13 +123,17 @@ public: QFontEngine::Properties properties() const override; + enum FontSmoothing { Disabled, Subpixel, Grayscale }; + Q_ENUM(FontSmoothing); + + static FontSmoothing fontSmoothing(); + static int antialiasingThreshold(); + static bool ct_getSfntTable(void *user_data, uint tag, uchar *buffer, uint *length); static QFont::Weight qtWeightFromCFWeight(float value); - static int antialiasingThreshold; - static QFontEngine::GlyphFormat defaultGlyphFormat; - static QCoreTextFontEngine *create(const QByteArray &fontData, qreal pixelSize, QFont::HintingPreference hintingPreference); + protected: QCoreTextFontEngine(const QFontDef &def); void init(); -- cgit v1.2.3 From 6b93b01ad6dfb5b0b2f067462690bdf14668f96c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Sun, 25 Nov 2018 16:22:30 +0100 Subject: CoreText: Add helper function to determine if a font has color glyphs Makes for clearer code than looking at the glyph format. Change-Id: Id6dd2a7851aac2a42cc27d9e2fb408ce9a5345d3 Reviewed-by: Simon Hausmann Reviewed-by: Allan Sandfeld Jensen --- src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h') diff --git a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h index 2ce46a4706..13505be0aa 100644 --- a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h +++ b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h @@ -139,6 +139,7 @@ protected: void init(); QImage imageForGlyph(glyph_t glyph, QFixed subPixelPosition, bool colorful, const QTransform &m); void loadAdvancesForGlyphs(QVarLengthArray &cgGlyphs, QGlyphLayout *glyphs) const; + bool hasColorGlyphs() const; QCFType ctfont; QCFType cgFont; -- cgit v1.2.3 From 3944f45c4d74b0389dc2246d1292790a9591ab82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 27 Nov 2018 17:13:38 +0100 Subject: CoreText: Remove handling of the AppleAntiAliasingThreshold user default The setting is not relevant for modern macOS applications, and none of the applications shipped with macOS today are affected by it. The only code path in macOS that picks it up is +[NSFont initialize] in the UIFoundation framework, storing it for later so that -[NSFont screenFont] and -[NSFont screenFontWithRenderingMode:] can use it, but these APIs are deprecated and we don't use them in Qt. Other NSFont code paths will not hit these APIs unless screen font substitution is enabled, something it hasn't been since OSX 10.7. https://preview.tinyurl.com/yctpfnqp Removing handling of this setting allows us to simplify the reasoning for whether or not antialiasing and font smoothing is enabled for a given engine. Change-Id: Ie2809052a1a0815d9bddedd4a6236eb6c898f993 Reviewed-by: Lars Knoll Reviewed-by: Allan Sandfeld Jensen --- src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h') diff --git a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h index 13505be0aa..0ff428084f 100644 --- a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h +++ b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h @@ -127,7 +127,6 @@ public: Q_ENUM(FontSmoothing); static FontSmoothing fontSmoothing(); - static int antialiasingThreshold(); static bool ct_getSfntTable(void *user_data, uint tag, uchar *buffer, uint *length); static QFont::Weight qtWeightFromCFWeight(float value); @@ -137,7 +136,7 @@ public: protected: QCoreTextFontEngine(const QFontDef &def); void init(); - QImage imageForGlyph(glyph_t glyph, QFixed subPixelPosition, bool colorful, const QTransform &m); + QImage imageForGlyph(glyph_t glyph, QFixed subPixelPosition, const QTransform &m); void loadAdvancesForGlyphs(QVarLengthArray &cgGlyphs, QGlyphLayout *glyphs) const; bool hasColorGlyphs() const; -- cgit v1.2.3 From ec254d2555083ff258db9675fa43ad23888f0685 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 27 Nov 2018 18:52:29 +0100 Subject: CoreText: Add font antialiasing and smoothing helper functions The font smoothing helper in particular now takes into account whether or not we're dealing with color glyphs, in which case we shouldn't (or don't need to) smooth, and also makes sure the QFont::NoSubpixelAntialias style strategy doesn't affect font smoothing when we're dealing with non-subpixel-antialiased font smoothing, as on macOS 10.14. Change-Id: Ibd477158629402c55cafec31576b6d9901d184cf Reviewed-by: Lars Knoll Reviewed-by: Allan Sandfeld Jensen --- src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h') diff --git a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h index 0ff428084f..28810f13bc 100644 --- a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h +++ b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h @@ -139,6 +139,8 @@ protected: QImage imageForGlyph(glyph_t glyph, QFixed subPixelPosition, const QTransform &m); void loadAdvancesForGlyphs(QVarLengthArray &cgGlyphs, QGlyphLayout *glyphs) const; bool hasColorGlyphs() const; + bool shouldAntialias() const; + bool shouldSmoothFont() const; QCFType ctfont; QCFType cgFont; -- cgit v1.2.3 From 58e66a2573e40cc3e12a5479575a8ecbef1be6d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 27 Nov 2018 19:13:54 +0100 Subject: CoreText: Define font smoothing gamma along with rest of relevant code Change-Id: I57909603732de6c1a91c744a358968941e64acdf Reviewed-by: Lars Knoll --- src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h') diff --git a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h index 28810f13bc..4064507058 100644 --- a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h +++ b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h @@ -127,6 +127,7 @@ public: Q_ENUM(FontSmoothing); static FontSmoothing fontSmoothing(); + static qreal fontSmoothingGamma(); static bool ct_getSfntTable(void *user_data, uint tag, uchar *buffer, uint *length); static QFont::Weight qtWeightFromCFWeight(float value); -- cgit v1.2.3