diff options
Diffstat (limited to 'src/platformsupport/fontdatabases/mac')
4 files changed, 49 insertions, 60 deletions
diff --git a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm index 9f2ff10a21..ac73cd04ad 100644 --- a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm +++ b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm @@ -286,25 +286,9 @@ static void getFontDescription(CTFontDescriptorRef font, FontDescription *fd) if (styles) { if (CFNumberRef weightValue = (CFNumberRef) CFDictionaryGetValue(styles, kCTFontWeightTrait)) { - double normalizedWeight; - if (CFNumberGetValue(weightValue, kCFNumberDoubleType, &normalizedWeight)) { - if (normalizedWeight >= 0.62) - fd->weight = QFont::Black; - else if (normalizedWeight >= 0.4) - fd->weight = QFont::Bold; - else if (normalizedWeight >= 0.3) - fd->weight = QFont::DemiBold; - else if (normalizedWeight >= 0.2) - fd->weight = qt_mediumFontWeight; - else if (normalizedWeight == 0.0) - fd->weight = QFont::Normal; - else if (normalizedWeight <= -0.4) - fd->weight = QFont::Light; - else if (normalizedWeight <= -0.6) - fd->weight = qt_extralightFontWeight; - else if (normalizedWeight <= -0.8) - fd->weight = qt_thinFontWeight; - } + float normalizedWeight; + if (CFNumberGetValue(weightValue, kCFNumberFloatType, &normalizedWeight)) + fd->weight = QCoreTextFontEngine::qtWeightFromCFWeight(normalizedWeight); } if (CFNumberRef italic = (CFNumberRef) CFDictionaryGetValue(styles, kCTFontSlantTrait)) { double d; @@ -842,6 +826,11 @@ QFont QCoreTextFontDatabase::defaultFont() const return QFont(defaultFontName); } +bool QCoreTextFontDatabase::fontsAlwaysScalable() const +{ + return true; +} + QList<int> QCoreTextFontDatabase::standardSizes() const { QList<int> ret; diff --git a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase_p.h b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase_p.h index 044db2b03d..b95a145c1a 100644 --- a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase_p.h +++ b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase_p.h @@ -87,6 +87,7 @@ public: void releaseHandle(void *handle); bool isPrivateFontFamily(const QString &family) const; QFont defaultFont() const; + bool fontsAlwaysScalable() const Q_DECL_OVERRIDE; QList<int> standardSizes() const; // For iOS and OS X platform themes diff --git a/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm b/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm index 23fe48b493..425c7471d4 100644 --- a/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm +++ b/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm @@ -41,6 +41,7 @@ #include "qfontengine_coretext_p.h" +#include <qpa/qplatformfontdatabase.h> #include <QtCore/qendian.h> #include <QtCore/qsettings.h> @@ -66,6 +67,29 @@ bool QCoreTextFontEngine::ct_getSfntTable(void *user_data, uint tag, uchar *buff return true; } +QFont::Weight QCoreTextFontEngine::qtWeightFromCFWeight(float value) +{ + if (value >= 0.62) + return QFont::Black; + if (value >= 0.5) + return QFont::ExtraBold; + if (value >= 0.4) + return QFont::Bold; + if (value >= 0.3) + return QFont::DemiBold; + if (value >= 0.2) + return QFont::Medium; + if (value == 0.0) + return QFont::Normal; + if (value <= -0.4) + return QFont::Light; + if (value <= -0.6) + return QFont::ExtraLight; + if (value <= -0.8) + return QFont::Thin; + return QFont::Normal; +} + static void loadAdvancesForGlyphs(CTFontRef ctfont, QVarLengthArray<CGGlyph> &cgGlyphs, QGlyphLayout *glyphs, int len, @@ -88,6 +112,16 @@ static void loadAdvancesForGlyphs(CTFontRef ctfont, } } +static float getTraitValue(CFDictionaryRef allTraits, CFStringRef trait) +{ + if (CFDictionaryContainsKey(allTraits, trait)) { + CFNumberRef traitNum = (CFNumberRef) CFDictionaryGetValue(allTraits, trait); + float v = 0; + CFNumberGetValue(traitNum, kCFNumberFloatType, &v); + return v; + } + return 0; +} int QCoreTextFontEngine::antialiasingThreshold = 0; QFontEngine::GlyphFormat QCoreTextFontEngine::defaultGlyphFormat = QFontEngine::Format_A32; @@ -129,34 +163,6 @@ QCoreTextFontEngine::~QCoreTextFontEngine() CFRelease(ctfont); } -static QFont::Weight weightFromInteger(int weight) -{ - if (weight < 400) - return QFont::Light; - else if (weight < 600) - return QFont::Normal; - else if (weight < 700) - return QFont::DemiBold; - else if (weight < 800) - return QFont::Bold; - else - return QFont::Black; -} - -int getTraitValue(CFDictionaryRef allTraits, CFStringRef trait) -{ - if (CFDictionaryContainsKey(allTraits, trait)) { - CFNumberRef traitNum = (CFNumberRef) CFDictionaryGetValue(allTraits, trait); - float v = 0; - CFNumberGetValue(traitNum, kCFNumberFloatType, &v); - // the value we get from CFNumberRef is from -1.0 to 1.0 - int value = v * 500 + 500; - return value; - } - - return 0; -} - void QCoreTextFontEngine::init() { Q_ASSERT(ctfont != NULL); @@ -182,8 +188,8 @@ void QCoreTextFontEngine::init() fontDef.style = QFont::StyleItalic; CFDictionaryRef allTraits = CTFontCopyTraits(ctfont); - fontDef.weight = weightFromInteger(getTraitValue(allTraits, kCTFontWeightTrait)); - int slant = getTraitValue(allTraits, kCTFontSlantTrait); + fontDef.weight = QCoreTextFontEngine::qtWeightFromCFWeight(getTraitValue(allTraits, kCTFontWeightTrait)); + int slant = static_cast<int>(getTraitValue(allTraits, kCTFontSlantTrait) * 500 + 500); if (slant > 500 && !(traits & kCTFontItalicTrait)) fontDef.style = QFont::StyleOblique; CFRelease(allTraits); @@ -646,15 +652,11 @@ QImage QCoreTextFontEngine::alphaMapForGlyph(glyph_t glyph, QFixed subPixelPosit QImage im = imageForGlyph(glyph, subPixelPosition, false, x); - QImage indexed(im.width(), im.height(), QImage::Format_Indexed8); - QVector<QRgb> colors(256); - for (int i=0; i<256; ++i) - colors[i] = qRgba(0, 0, 0, i); - indexed.setColorTable(colors); + QImage alphaMap(im.width(), im.height(), QImage::Format_Alpha8); for (int y=0; y<im.height(); ++y) { uint *src = (uint*) im.scanLine(y); - uchar *dst = indexed.scanLine(y); + uchar *dst = alphaMap.scanLine(y); for (int x=0; x<im.width(); ++x) { *dst = qGray(*src); ++dst; @@ -662,7 +664,7 @@ QImage QCoreTextFontEngine::alphaMapForGlyph(glyph_t glyph, QFixed subPixelPosit } } - return indexed; + return alphaMap; } QImage QCoreTextFontEngine::alphaRGBMapForGlyph(glyph_t glyph, QFixed subPixelPosition, const QTransform &x) diff --git a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h index 998a6abb18..d0f7c79929 100644 --- a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h +++ b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h @@ -57,7 +57,6 @@ QT_BEGIN_NAMESPACE -class QRawFontPrivate; class QCoreTextFontEngine : public QFontEngine { public: @@ -122,13 +121,11 @@ public: } 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; - private: - friend class QRawFontPrivate; - void init(); QImage imageForGlyph(glyph_t glyph, QFixed subPixelPosition, bool colorful, const QTransform &m); CTFontRef ctfont; |