From 8610534f53b228d996279e1208fcf3ec0f125398 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 10 Sep 2014 10:29:48 +0200 Subject: [PATCH] OSX: Properly detect language support in fonts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The language support detection in Cocoa does not report the correct set of languages for all fonts. One consequence of this is that e.g. Mkhedruli (Georgian) was not supported on Mac because the 'ka' language code was not reported for e.g. the Arial Unicode MS font. This was never detected in Qt 4, because the writing system support we set for each font was never used for font matching, since we let CoreText do the matching in Qt 4. To remedy this, we also detect writing system support based on the OS/2 table in the font. We add this in addition to the current test in case the language list has information about fonts with incomplete OS/2 tables, to avoid regressing. [ChangeLog][OS X] Fixed detection of writing system support in fonts for some scripts such as Mkhedruli. Change-Id: I26c2a42ef45112e17d6794d8798a57c8d8aaaafa Task-number: QTBUG-41208 Reviewed-by: Simon Hausmann Reviewed-by: Tor Arne Vestbø --- .../mac/qcoretextfontdatabase.mm | 22 +++++++++++++++++++ .../fontdatabases/mac/qfontengine_coretext.mm | 2 +- .../mac/qfontengine_coretext_p.h | 2 ++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm index 8e4c1c07a8..a775f745fd 100644 --- a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm +++ b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm @@ -52,6 +52,7 @@ #include "qfontengine_coretext_p.h" #include #include +#include QT_BEGIN_NAMESPACE @@ -262,6 +263,27 @@ static void getFontDescription(CTFontDescriptorRef font, FontDescription *fd) fd->stretch = QFont::Unstretched; fd->fixedPitch = false; + if (QCFType tempFont = CTFontCreateWithFontDescriptor(font, 0.0, 0)) { + uint length = 0; + uint tag = MAKE_TAG('O', 'S', '/', '2'); + CTFontRef tempFontRef = tempFont; + void *userData = reinterpret_cast(&tempFontRef); + if (QCoreTextFontEngine::ct_getSfntTable(userData, tag, 0, &length)) { + QVarLengthArray os2Table(length); + if (length >= 86 && QCoreTextFontEngine::ct_getSfntTable(userData, tag, os2Table.data(), &length)) { + quint32 unicodeRange[4] = { + qFromBigEndian(os2Table.data() + 42), + qFromBigEndian(os2Table.data() + 46), + qFromBigEndian(os2Table.data() + 50), + qFromBigEndian(os2Table.data() + 54) + }; + quint32 codePageRange[2] = { qFromBigEndian(os2Table.data() + 78), + qFromBigEndian(os2Table.data() + 82) }; + fd->writingSystems = QPlatformFontDatabase::writingSystemsFromTrueTypeBits(unicodeRange, codePageRange); + } + } + } + if (styles) { if (CFNumberRef weightValue = (CFNumberRef) CFDictionaryGetValue(styles, kCTFontWeightTrait)) { double normalizedWeight; diff --git a/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm b/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm index 6e2c8a2a9a..f96163fc5b 100644 --- a/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm +++ b/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm @@ -50,7 +50,7 @@ QT_BEGIN_NAMESPACE static float SYNTHETIC_ITALIC_SKEW = tanf(14 * acosf(0) / 90); -static bool ct_getSfntTable(void *user_data, uint tag, uchar *buffer, uint *length) +bool QCoreTextFontEngine::ct_getSfntTable(void *user_data, uint tag, uchar *buffer, uint *length) { CTFontRef ctfont = *(CTFontRef *)user_data; diff --git a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h index b9593b983e..e39f514878 100644 --- a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h +++ b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h @@ -118,6 +118,8 @@ public: #endif } + static bool ct_getSfntTable(void *user_data, uint tag, uchar *buffer, uint *length); + static int antialiasingThreshold; static QFontEngine::GlyphFormat defaultGlyphFormat;