From 43a8c8c851aabb61b9be6e045c2bf17d053b45c3 Mon Sep 17 00:00:00 2001 From: Antonin Stefanutti Date: Fri, 8 May 2015 18:31:15 +0200 Subject: [PATCH] PDF font embedding fails on Mac 64-bit due to unimplemented methods in QCoreTextFontEngine Fix bugs generating PDF on Cocoa Provide real implementations of: properties(), faceId() and getUnscaledGlyph Task-number: QTBUG-10094 https://github.com/ariya/phantomjs/issues/10373 --- .../fontdatabases/mac/qfontengine_coretext.mm | 67 ++++++++++++++++++- .../mac/qfontengine_coretext_p.h | 1 + 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/src/qt/qtbase/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm b/src/qt/qtbase/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm index 23fe48b493..f2824a7ec0 100644 --- a/src/qt/qtbase/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm +++ b/src/qt/qtbase/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm @@ -700,7 +700,12 @@ static void qcoretextfontengine_scaleMetrics(glyph_metrics_t &br, const QTransfo QFontEngine::FaceId QCoreTextFontEngine::faceId() const { - return QFontEngine::FaceId(); + FaceId result; + result.index = 0; + QCFString name = CTFontCopyName(ctfont, kCTFontUniqueNameKey); + result.filename = QCFString::toQString(name).toUtf8(); + + return result; } bool QCoreTextFontEngine::canRender(const QChar *string, int len) const @@ -714,9 +719,26 @@ static void qcoretextfontengine_scaleMetrics(glyph_metrics_t &br, const QTransfo return ct_getSfntTable((void *)&ctfont, tag, buffer, length); } -void QCoreTextFontEngine::getUnscaledGlyph(glyph_t, QPainterPath *, glyph_metrics_t *) +void QCoreTextFontEngine::getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_metrics_t *metric) { - // ### + CGAffineTransform cgMatrix = CGAffineTransformIdentity; + + qreal emSquare = CTFontGetUnitsPerEm(ctfont); + qreal scale = emSquare / CTFontGetSize(ctfont); + cgMatrix = CGAffineTransformScale(cgMatrix, scale, -scale); + + QCFType 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); + metric->xoff = QFixed::fromReal(metric->xoff.toReal() * scale); + metric->yoff = QFixed::fromReal(metric->yoff.toReal() * scale); } QFixed QCoreTextFontEngine::emSquareSize() const @@ -744,4 +766,43 @@ static void qcoretextfontengine_scaleMetrics(glyph_metrics_t &br, const QTransfo return false; } +QFontEngine::Properties QCoreTextFontEngine::properties() const +{ + Properties result; + + QCFString psName, copyright; + psName = CTFontCopyPostScriptName(ctfont); + copyright = CTFontCopyName(ctfont, kCTFontCopyrightNameKey); + result.postscriptName = QCFString::toQString(psName).toUtf8(); + result.copyright = QCFString::toQString(copyright).toUtf8(); + + qreal emSquare = CTFontGetUnitsPerEm(ctfont); + qreal scale = emSquare / CTFontGetSize(ctfont); + + CGRect cgRect = CTFontGetBoundingBox(ctfont); + result.boundingBox = QRectF(cgRect.origin.x * scale, + -CTFontGetAscent(ctfont) * scale, + cgRect.size.width * scale, + cgRect.size.height * scale); + + result.emSquare = emSquareSize(); + result.ascent = QFixed::fromReal(CTFontGetAscent(ctfont) * scale); + result.descent = QFixed::fromReal(CTFontGetDescent(ctfont) * scale); + result.leading = QFixed::fromReal(CTFontGetLeading(ctfont) * scale); + result.italicAngle = QFixed::fromReal(CTFontGetSlantAngle(ctfont)); + result.capHeight = QFixed::fromReal(CTFontGetCapHeight(ctfont) * scale); + result.lineWidth = QFixed::fromReal(CTFontGetUnderlineThickness(ctfont) * scale); + + if (fontDef.styleStrategy & QFont::ForceIntegerMetrics) { + result.ascent = result.ascent.round(); + result.descent = result.descent.round(); + result.leading = result.leading.round(); + result.italicAngle = result.italicAngle.round(); + result.capHeight = result.capHeight.round(); + result.lineWidth = result.lineWidth.round(); + } + + return result; +} + QT_END_NAMESPACE diff --git a/src/qt/qtbase/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h b/src/qt/qtbase/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h index 998a6abb18..7fe84acb70 100644 --- a/src/qt/qtbase/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h +++ b/src/qt/qtbase/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h @@ -104,6 +104,7 @@ class QCoreTextFontEngine : public QFontEngine bool supportsTransformation(const QTransform &transform) const; virtual QFontEngine *cloneWithSize(qreal pixelSize) const; + virtual QFontEngine::Properties properties() const; virtual int glyphMargin(QFontEngine::GlyphFormat format) { Q_UNUSED(format); return 0; } static bool supportsColorGlyphs()