Skip to content

Commit 323cd51

Browse files
zakalaweKonstantinRitt
authored andcommitted
Fix bugs generating PDF on Cocoa
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 <[email protected]>
1 parent b2ee1cf commit 323cd51

File tree

2 files changed

+67
-3
lines changed

2 files changed

+67
-3
lines changed

src/gui/text/qfontengine_coretext.mm

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,13 @@ static void convertCGPathToQPainterPath(void *info, const CGPathElement *element
831831

832832
QFontEngine::FaceId QCoreTextFontEngine::faceId() const
833833
{
834-
return QFontEngine::FaceId();
834+
FaceId result;
835+
result.index = 0;
836+
837+
QCFString name = CTFontCopyName(ctfont, kCTFontUniqueNameKey);
838+
result.filename = QCFString::toQString(name).toUtf8();
839+
840+
return result;
835841
}
836842

837843
bool QCoreTextFontEngine::canRender(const QChar *string, int len)
@@ -856,9 +862,26 @@ static void convertCGPathToQPainterPath(void *info, const CGPathElement *element
856862
return true;
857863
}
858864

859-
void QCoreTextFontEngine::getUnscaledGlyph(glyph_t, QPainterPath *, glyph_metrics_t *)
865+
void QCoreTextFontEngine::getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_metrics_t *metric)
860866
{
861-
// ###
867+
CGAffineTransform cgMatrix = CGAffineTransformIdentity;
868+
869+
qreal emSquare = CTFontGetUnitsPerEm(ctfont);
870+
qreal scale = emSquare / CTFontGetSize(ctfont);
871+
cgMatrix = CGAffineTransformScale(cgMatrix, scale, -scale);
872+
873+
QCFType<CGPathRef> cgpath = CTFontCreatePathForGlyph(ctfont, (CGGlyph) glyph, &cgMatrix);
874+
ConvertPathInfo info(path, QPointF(0,0));
875+
CGPathApply(cgpath, &info, convertCGPathToQPainterPath);
876+
877+
*metric = boundingBox(glyph);
878+
// scale the metrics too
879+
metric->width = QFixed::fromReal(metric->width.toReal() * scale);
880+
metric->height = QFixed::fromReal(metric->height.toReal() * scale);
881+
metric->x = QFixed::fromReal(metric->x.toReal() * scale);
882+
metric->y = QFixed::fromReal(metric->y.toReal() * scale);
883+
metric->xoff = QFixed::fromReal(metric->xoff.toReal() * scale);
884+
metric->yoff = QFixed::fromReal(metric->yoff.toReal() * scale);
862885
}
863886

864887
QFixed QCoreTextFontEngine::emSquareSize() const
@@ -875,6 +898,45 @@ static void convertCGPathToQPainterPath(void *info, const CGPathElement *element
875898
return new QCoreTextFontEngine(cgFont, newFontDef);
876899
}
877900

901+
QFontEngine::Properties QCoreTextFontEngine::properties() const
902+
{
903+
Properties result;
904+
905+
QCFString psName, copyright;
906+
psName = CTFontCopyPostScriptName(ctfont);
907+
copyright = CTFontCopyName(ctfont, kCTFontCopyrightNameKey);
908+
result.postscriptName = QCFString::toQString(psName).toUtf8();
909+
result.copyright = QCFString::toQString(copyright).toUtf8();
910+
911+
qreal emSquare = CTFontGetUnitsPerEm(ctfont);
912+
qreal scale = emSquare / CTFontGetSize(ctfont);
913+
914+
CGRect cgRect = CTFontGetBoundingBox(ctfont);
915+
result.boundingBox = QRectF(cgRect.origin.x * scale,
916+
-CTFontGetAscent(ctfont) * scale,
917+
cgRect.size.width * scale,
918+
cgRect.size.height * scale);
919+
920+
result.emSquare = emSquareSize();
921+
result.ascent = QFixed::fromReal(CTFontGetAscent(ctfont) * scale);
922+
result.descent = QFixed::fromReal(CTFontGetDescent(ctfont) * scale);
923+
result.leading = QFixed::fromReal(CTFontGetLeading(ctfont) * scale);
924+
result.italicAngle = QFixed::fromReal(CTFontGetSlantAngle(ctfont));
925+
result.capHeight = QFixed::fromReal(CTFontGetCapHeight(ctfont) * scale);
926+
result.lineWidth = QFixed::fromReal(CTFontGetUnderlineThickness(ctfont) * scale);
927+
928+
if (fontDef.styleStrategy & QFont::ForceIntegerMetrics) {
929+
result.ascent = result.ascent.round();
930+
result.descent = result.descent.round();
931+
result.leading = result.leading.round();
932+
result.italicAngle = result.italicAngle.round();
933+
result.capHeight = result.capHeight.round();
934+
result.lineWidth = result.lineWidth.round();
935+
}
936+
937+
return result;
938+
}
939+
878940
QT_END_NAMESPACE
879941

880942
#endif// !defined(Q_WS_MAC) || (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)

src/gui/text/qfontengine_coretext_p.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ class QCoreTextFontEngine : public QFontEngine
103103

104104
virtual QFontEngine *cloneWithSize(qreal pixelSize) const;
105105

106+
virtual QFontEngine::Properties properties() const;
107+
106108
private:
107109
friend class QRawFontPrivate;
108110

0 commit comments

Comments
 (0)