Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

Commit

Permalink
Fix bugs generating PDF on Cocoa
Browse files Browse the repository at this point in the history
Provide real implementations of:
    properties(), faceId() and getUnscaledGlyph

Task-number: QTBUG-10094
Change-Id: I5899f247742406de53c68c5cd04fee6fb9b6b7d2
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
(cherry picked from qtbase/517fb9026896f7ac20376f253babae5a7c57721d)
  • Loading branch information
zakalawe authored and ashkulz committed Jan 17, 2015
1 parent 2173492 commit c74350c
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
68 changes: 65 additions & 3 deletions src/gui/text/qfontengine_coretext.mm
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,13 @@ static void convertCGPathToQPainterPath(void *info, const CGPathElement *element

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)
Expand All @@ -856,9 +862,26 @@ static void convertCGPathToQPainterPath(void *info, const CGPathElement *element
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<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);
metric->xoff = QFixed::fromReal(metric->xoff.toReal() * scale);
metric->yoff = QFixed::fromReal(metric->yoff.toReal() * scale);
}

QFixed QCoreTextFontEngine::emSquareSize() const
Expand All @@ -875,6 +898,45 @@ static void convertCGPathToQPainterPath(void *info, const CGPathElement *element
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)
Expand Down
1 change: 1 addition & 0 deletions src/gui/text/qfontengine_coretext_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class QCoreTextFontEngine : public QFontEngine
virtual QFixed emSquareSize() const;

virtual QFontEngine *cloneWithSize(qreal pixelSize) const;
virtual QFontEngine::Properties properties() const;

private:
friend class QRawFontPrivate;
Expand Down

0 comments on commit c74350c

Please sign in to comment.