Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs generating PDF on Cocoa #2

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 65 additions & 3 deletions src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,13 @@ 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
Expand All @@ -714,9 +720,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<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 Down Expand Up @@ -744,4 +767,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
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ class QCoreTextFontEngine : public QFontEngine
virtual QFontEngine *cloneWithSize(qreal pixelSize) const;
virtual int glyphMargin(QFontEngine::GlyphFormat format) { Q_UNUSED(format); return 0; }

virtual QFontEngine::Properties properties() const;

static bool supportsColorGlyphs()
{
#if defined(Q_OS_IOS)
Expand Down