From 323cd5198ce9d0f4f94b0cc9f3447a3318339ff7 Mon Sep 17 00:00:00 2001 From: James Turner Date: Sat, 17 Jan 2015 22:01:20 +0530 Subject: Fix bugs generating PDF on Cocoa MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Provide real implementations of: properties(), faceId() and getUnscaledGlyph Task-number: QTBUG-10094 Change-Id: Ib84a7a5c9e29e4d634b47bc2856787b2482048da (cherry picked from qtbase/517fb9026896f7ac20376f253babae5a7c57721d) Reviewed-by: Morten Johan Sørvig --- src/gui/text/qfontengine_coretext.mm | 68 +++++++++++++++++++++++++++++++++-- src/gui/text/qfontengine_coretext_p.h | 2 ++ 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/src/gui/text/qfontengine_coretext.mm b/src/gui/text/qfontengine_coretext.mm index 0a3d263569..9cd2699bbb 100644 --- a/src/gui/text/qfontengine_coretext.mm +++ b/src/gui/text/qfontengine_coretext.mm @@ -831,7 +831,13 @@ void QCoreTextFontEngine::recalcAdvances(QGlyphLayout *glyphs, QTextEngine::Shap 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) @@ -856,9 +862,26 @@ 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; + + 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 @@ -875,6 +898,45 @@ QFontEngine *QCoreTextFontEngine::cloneWithSize(qreal pixelSize) const return new QCoreTextFontEngine(cgFont, newFontDef); } +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 #endif// !defined(Q_WS_MAC) || (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) diff --git a/src/gui/text/qfontengine_coretext_p.h b/src/gui/text/qfontengine_coretext_p.h index 73d97540e6..ab7df57d9b 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; -- cgit v1.2.1