Created
May 7, 2014 03:49
-
-
Save inferiorhumanorgans/31bcb6e5a95bb2fcca6d to your computer and use it in GitHub Desktop.
Backport of QTBUG-10094
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/gui/text/qfontdatabase_mac.cpp b/src/gui/text/qfontdatabase_mac.cpp | |
index ea16846..35cb03d 100644 | |
--- a/src/gui/text/qfontdatabase_mac.cpp | |
+++ b/src/gui/text/qfontdatabase_mac.cpp | |
@@ -146,7 +146,9 @@ if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) { | |
CTFontDescriptorRef font = (CTFontDescriptorRef)CFArrayGetValueAtIndex(fonts, i); | |
QCFString family_name = (CFStringRef)CTFontDescriptorCopyLocalizedAttribute(font, kCTFontFamilyNameAttribute, NULL); | |
QCFString style_name = (CFStringRef)CTFontDescriptorCopyLocalizedAttribute(font, kCTFontStyleNameAttribute, NULL); | |
- QtFontFamily *family = db->family(family_name, true); | |
+ QCFString ps_name = (CFStringRef)CTFontDescriptorCopyLocalizedAttribute(font, kCTFontNameAttribute, NULL); | |
+ QtFontFamily *family = db->family(family_name, true), | |
+ *psFont = db->family(ps_name, true); | |
if (QCFType<CFArrayRef> languages = (CFArrayRef) CTFontDescriptorCopyAttribute(font, kCTFontLanguagesAttribute)) { | |
CFIndex length = CFArrayGetCount(languages); | |
@@ -154,12 +156,15 @@ if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) { | |
if (!languageForWritingSystem[i]) | |
continue; | |
QCFString lang = CFStringCreateWithCString(NULL, languageForWritingSystem[i], kCFStringEncodingASCII); | |
- if (CFArrayContainsValue(languages, CFRangeMake(0, length), lang)) | |
+ if (CFArrayContainsValue(languages, CFRangeMake(0, length), lang)) { | |
family->writingSystems[i] = QtFontFamily::Supported; | |
+ psFont->writingSystems[i] = QtFontFamily::Supported; | |
+ } | |
} | |
} | |
- QtFontFoundry *foundry = family->foundry(foundry_name, true); | |
+ QtFontFoundry *foundry = family->foundry(foundry_name, true), | |
+ *psFoundry = psFont->foundry(foundry_name, true); | |
QtFontStyle::Key styleKey; | |
QString styleName = style_name; | |
@@ -183,8 +188,11 @@ if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) { | |
} | |
} | |
- QtFontStyle *style = foundry->style(styleKey, styleName, true); | |
- style->smoothScalable = true; | |
+ QtFontStyle *style = foundry->style(styleKey, styleName, true), | |
+ *psStyle = psFoundry->style(styleKey, styleName, true); | |
+ | |
+ style->smoothScalable = psStyle->smoothScalable = true; | |
+ | |
if(QCFType<CFNumberRef> size = (CFNumberRef)CTFontDescriptorCopyAttribute(font, kCTFontSizeAttribute)) { | |
//qDebug() << "WHEE"; | |
int pixel_size=0; | |
@@ -196,8 +204,10 @@ if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) { | |
CFNumberGetValue(size, kCFNumberIntType, &pixel_size); | |
} | |
//qDebug() << "SIZE" << (QString)family_name << pixel_size; | |
- if(pixel_size) | |
+ if(pixel_size) { | |
style->pixelSize(pixel_size, true); | |
+ psStyle->pixelSize(pixel_size, true); | |
+ } | |
} else { | |
//qDebug() << "WTF?"; | |
} | |
@@ -322,6 +332,26 @@ static QFontEngine *loadFromDatabase(QFontDef &req, const QFontPrivate *d) | |
QFontDatabasePrivate *db = privateDb(); | |
if (!db->count) | |
initializeDb(); | |
+ | |
+#if defined(QT_MAC_USE_COCOA) | |
+ CFStringRef foundName, psName = CFStringCreateWithCString(NULL, req.family.toLocal8Bit().constData(), kCFStringEncodingUTF8); | |
+ QCFType<CTFontRef> ctNamedFont = CTFontCreateWithName(psName, 0, NULL); | |
+ | |
+ if (ctNamedFont) { | |
+ foundName = CTFontCopyPostScriptName(ctNamedFont); | |
+ if (CFStringCompare(psName, foundName, kCFCompareCaseInsensitive) == kCFCompareEqualTo) { | |
+ fontName = CTFontCopyFullName(ctNamedFont); | |
+ | |
+ CFRelease(psName); | |
+ CFRelease(foundName); | |
+ | |
+ goto found; | |
+ } | |
+ CFRelease(foundName); | |
+ } | |
+ CFRelease(psName); | |
+#endif | |
+ | |
for (int i = 0; i < family_list.size(); ++i) { | |
for (int k = 0; k < db->count; ++k) { | |
if (db->families[k]->name.compare(family_list.at(i), Qt::CaseInsensitive) == 0) { | |
@@ -337,7 +367,7 @@ static QFontEngine *loadFromDatabase(QFontDef &req, const QFontPrivate *d) | |
if (ctFont) { | |
fontName = CTFontCopyFullName(ctFont); | |
goto found; | |
- } | |
+ } | |
#else | |
familyRef = ATSFontFamilyFindFromName(QCFString(db->families[k]->name), kATSOptionFlagsDefault); | |
if (familyRef) { | |
@@ -559,7 +589,7 @@ QString QFontDatabase::resolveFontFamilyAlias(const QString &family) | |
QCFType<CTFontRef> font = CTFontCreateWithFontDescriptor(descriptor, 0.0, NULL); | |
QCFType<CTFontDescriptorRef> matched = CTFontDescriptorCreateMatchingFontDescriptor(descriptor, mandatoryAttributes); | |
if (!matched) | |
- return family; | |
+ return family; | |
QCFString familyName = (CFStringRef) CTFontDescriptorCopyLocalizedAttribute(matched, kCTFontFamilyNameAttribute, NULL); | |
return familyName; | |
diff --git a/src/gui/text/qfontengine_coretext.mm b/src/gui/text/qfontengine_coretext.mm | |
index 0a3d263..f779739 100644 | |
--- a/src/gui/text/qfontengine_coretext.mm | |
+++ b/src/gui/text/qfontengine_coretext.mm | |
@@ -831,7 +831,14 @@ void QCoreTextFontEngine::recalcAdvances(QGlyphLayout *glyphs, QTextEngine::Shap | |
QFontEngine::FaceId QCoreTextFontEngine::faceId() const | |
{ | |
- return QFontEngine::FaceId(); | |
+ FaceId result; | |
+ result.index = 0; | |
+ | |
+ CFStringRef name = CTFontCopyName(ctfont, kCTFontFullNameKey); | |
+ result.filename = QCFString::toQString(name).toUtf8(); | |
+ CFRelease(name); | |
+ | |
+ return result; | |
} | |
bool QCoreTextFontEngine::canRender(const QChar *string, int len) | |
@@ -840,6 +847,39 @@ bool QCoreTextFontEngine::canRender(const QChar *string, int len) | |
return CTFontGetGlyphsForCharacters(ctfont, (const UniChar *) string, cgGlyphs.data(), len); | |
} | |
+QFontEngine::Properties QCoreTextFontEngine::properties() const | |
+{ | |
+ Properties result; | |
+ | |
+ CFStringRef psName, copyright; | |
+ psName = CTFontCopyPostScriptName(ctfont); | |
+ copyright = CTFontCopyName(ctfont, kCTFontCopyrightNameKey); | |
+ result.postscriptName = QCFString::toQString(psName).toUtf8(); | |
+ result.copyright = QCFString::toQString(copyright).toUtf8(); | |
+ CFRelease(psName); | |
+ CFRelease(copyright); | |
+ | |
+ CGRect cgRect = CTFontGetBoundingBox(ctfont); | |
+ result.boundingBox = QRectF(cgRect.origin.x, cgRect.origin.y, cgRect.size.width, cgRect.size.height); | |
+ | |
+ result.emSquare = emSquareSize(); | |
+ result.ascent = ascent(); | |
+ result.descent = descent(); | |
+ result.leading = leading(); | |
+ result.italicAngle = QFixed::fromReal(CTFontGetSlantAngle(ctfont)); | |
+ result.capHeight = QFixed::fromReal(CTFontGetCapHeight(ctfont)); | |
+ result.lineWidth = QFixed::fromReal(CTFontGetUnderlineThickness(ctfont)); | |
+ | |
+ if (fontDef.styleStrategy & QFont::ForceIntegerMetrics) { | |
+ result.italicAngle = result.italicAngle.round(); | |
+ result.capHeight = result.capHeight.round(); | |
+ result.lineWidth = result.lineWidth.round(); | |
+ } | |
+ | |
+ return result; | |
+} | |
+ | |
+ | |
bool QCoreTextFontEngine::getSfntTableData(uint tag, uchar *buffer, uint *length) const | |
{ | |
QCFType<CFDataRef> table = CTFontCopyTable(ctfont, tag, 0); | |
@@ -856,9 +896,24 @@ bool QCoreTextFontEngine::getSfntTableData(uint tag, uchar *buffer, uint *length | |
return true; | |
} | |
-void QCoreTextFontEngine::getUnscaledGlyph(glyph_t, QPainterPath *, glyph_metrics_t *) | |
+void QCoreTextFontEngine::getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_metrics_t *metric) | |
{ | |
- // ### | |
+ CGAffineTransform cgMatrix = CGAffineTransformIdentity; | |
+ | |
+ int emSquare = emSquareSize().toInt(); | |
+ float scale = emSquare / (CTFontGetDescent(ctfont) + CTFontGetAscent(ctfont)); | |
+ cgMatrix = CGAffineTransformScale(cgMatrix, scale, -scale); | |
+ | |
+ QCFType<CGPathRef> cgpath = CTFontCreatePathForGlyph(ctfont, (CGGlyph) glyph, &cgMatrix); | |
+ ConvertPathInfo info(path, QPointF(0,0)); | |
+ CGPathApply(cgpath, &info, convertCGPathToQPainterPath); | |
+ | |
+ *metric = boundingBox(glyph); | |
+ // scale the metrics too | |
+ metric->width = QFixed::fromReal(metric->width.toReal() * scale); | |
+ metric->height = QFixed::fromReal(metric->height.toReal() * scale); | |
+ metric->x = QFixed::fromReal(metric->x.toReal() * scale); | |
+ metric->y = QFixed::fromReal(metric->y.toReal() * scale); | |
} | |
QFixed QCoreTextFontEngine::emSquareSize() const | |
diff --git a/src/gui/text/qfontengine_coretext_p.h b/src/gui/text/qfontengine_coretext_p.h | |
index 73d9754..ab7df57 100644 | |
--- a/src/gui/text/qfontengine_coretext_p.h | |
+++ b/src/gui/text/qfontengine_coretext_p.h | |
@@ -103,6 +103,8 @@ public: | |
virtual QFontEngine *cloneWithSize(qreal pixelSize) const; | |
+ virtual QFontEngine::Properties properties() const; | |
+ | |
private: | |
friend class QRawFontPrivate; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@inferiorhumanorgans: the fix has been finally merged with changes. You may want to submit the PS font names part directly, if it is not already present in Qt5.