summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2018-11-25 16:22:30 +0100
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2018-11-29 12:03:44 +0000
commit6b93b01ad6dfb5b0b2f067462690bdf14668f96c (patch)
tree2b589a14cf5a1310359d9599e26eeeb931563a1f
parentd4e3442fdbb98b5c635448031ff9958819a46bc5 (diff)
CoreText: Add helper function to determine if a font has color glyphs
Makes for clearer code than looking at the glyph format. Change-Id: Id6dd2a7851aac2a42cc27d9e2fb408ce9a5345d3 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io> Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r--src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm16
-rw-r--r--src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h1
2 files changed, 11 insertions, 6 deletions
diff --git a/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm b/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm
index d939ee1b24..91d3d811b5 100644
--- a/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm
+++ b/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm
@@ -433,6 +433,11 @@ qreal QCoreTextFontEngine::maxCharWidth() const
return bb.xoff.toReal();
}
+bool QCoreTextFontEngine::hasColorGlyphs() const
+{
+ return glyphFormat == QFontEngine::Format_ARGB;
+}
+
void QCoreTextFontEngine::draw(CGContextRef ctx, qreal x, qreal y, const QTextItemInt &ti, int paintDeviceHeight)
{
QVarLengthArray<QFixedPoint> positions;
@@ -529,7 +534,7 @@ static void convertCGPathToQPainterPath(void *info, const CGPathElement *element
void QCoreTextFontEngine::addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int nGlyphs,
QPainterPath *path, QTextItem::RenderFlags)
{
- if (glyphFormat == QFontEngine::Format_ARGB)
+ if (hasColorGlyphs())
return; // We can't convert color-glyphs to path
CGAffineTransform cgMatrix = CGAffineTransformIdentity;
@@ -731,8 +736,7 @@ QImage QCoreTextFontEngine::imageForGlyph(glyph_t glyph, QFixed subPixelPosition
{
glyph_metrics_t br = alphaMapBoundingBox(glyph, subPixelPosition, matrix, glyphFormat);
- bool isColorGlyph = glyphFormat == QFontEngine::Format_ARGB;
- QImage::Format imageFormat = isColorGlyph ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32;
+ QImage::Format imageFormat = hasColorGlyphs() ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32;
QImage im(br.width.ceil().toInt(), br.height.ceil().toInt(), imageFormat);
if (!im.width() || !im.height())
return im;
@@ -751,7 +755,7 @@ QImage QCoreTextFontEngine::imageForGlyph(glyph_t glyph, QFixed subPixelPosition
if (!qt_mac_applicationIsInDarkMode())
glyphColor = CGColorGetConstantColor(kCGColorBlack);
}
- const bool blackOnWhiteGlyphs = !isColorGlyph
+ const bool blackOnWhiteGlyphs = !hasColorGlyphs()
&& CGColorEqualToColor(glyphColor, CGColorGetConstantColor(kCGColorBlack));
if (blackOnWhiteGlyphs)
im.fill(Qt::white);
@@ -775,7 +779,7 @@ QImage QCoreTextFontEngine::imageForGlyph(glyph_t glyph, QFixed subPixelPosition
if (synthesisFlags & QFontEngine::SynthesizedItalic)
cgMatrix = CGAffineTransformConcat(cgMatrix, CGAffineTransformMake(1, 0, SYNTHETIC_ITALIC_SKEW, 1, 0, 0));
- if (!isColorGlyph) // CTFontDrawGlyphs incorporates the font's matrix already
+ if (!hasColorGlyphs()) // CTFontDrawGlyphs incorporates the font's matrix already
cgMatrix = CGAffineTransformConcat(cgMatrix, transform);
if (matrix.isScaling())
@@ -785,7 +789,7 @@ QImage QCoreTextFontEngine::imageForGlyph(glyph_t glyph, QFixed subPixelPosition
qreal pos_x = -br.x.truncate() + subPixelPosition.toReal();
qreal pos_y = im.height() + br.y.toReal();
- if (!isColorGlyph) {
+ if (!hasColorGlyphs()) {
CGContextSetTextMatrix(ctx, cgMatrix);
#if defined(Q_OS_MACOS)
CGContextSetFillColorWithColor(ctx, glyphColor);
diff --git a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h
index 2ce46a4706..13505be0aa 100644
--- a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h
+++ b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h
@@ -139,6 +139,7 @@ protected:
void init();
QImage imageForGlyph(glyph_t glyph, QFixed subPixelPosition, bool colorful, const QTransform &m);
void loadAdvancesForGlyphs(QVarLengthArray<CGGlyph> &cgGlyphs, QGlyphLayout *glyphs) const;
+ bool hasColorGlyphs() const;
QCFType<CTFontRef> ctfont;
QCFType<CGFontRef> cgFont;