summaryrefslogtreecommitdiffstats
path: root/src/plugins/styles
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@qt.io>2018-02-07 09:52:00 -0800
committerGabriel de Dietrich <gabriel.dedietrich@qt.io>2018-02-09 19:49:44 +0000
commitbd80f00f84f60590fb38d98f211ddf4486c88cdb (patch)
tree33555cee2b6b0fbfa0ad4064b72ba6ba2f0d7e48 /src/plugins/styles
parentad8a3e3530df9e6631f335fbeea78485f56d7450 (diff)
QMacStyle: Fix crash when using Freetype font engine
This amends cf7a4016a17615df2952389bae11149a49b151bc. Change-Id: I8bb3e934d10b2f522539b73ceaa80a9a4608ef12 Task-number: QTBUG-66248 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'src/plugins/styles')
-rw-r--r--src/plugins/styles/mac/qmacstyle_mac.mm50
1 files changed, 26 insertions, 24 deletions
diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm
index 1041187407..c927a20169 100644
--- a/src/plugins/styles/mac/qmacstyle_mac.mm
+++ b/src/plugins/styles/mac/qmacstyle_mac.mm
@@ -4340,39 +4340,41 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
// and then the combo inherits it and passes it onward. At that point the resolve mask
// is very, very weak. This makes it stonger.
myFont.setPointSizeF(QFontInfo(mi->font).pointSizeF());
-#if 0
- // QTBUG-65653: This doesn't look good enough, especially on non-retina displays.
- // Worked around below while waiting for a proper fix in QCoreTextFontEngine.
- p->setFont(myFont);
- p->drawText(xpos, yPos, mi->rect.width() - xm - tabwidth + 1,
- mi->rect.height(), text_flags, s);
-#else
- QMacCGContext cgCtx(p);
- d->setupNSGraphicsContext(cgCtx, YES);
-
- // Respect the menu item palette as set in the style option.
- const auto pc = p->pen().color();
- NSColor *c = [NSColor colorWithSRGBRed:pc.redF()
- green:pc.greenF()
- blue:pc.blueF()
- alpha:pc.alphaF()];
- // Respect the menu item action font as set in the style option.
+ // QTBUG-65653: Our own text rendering doesn't look good enough, especially on non-retina
+ // displays. Worked around here while waiting for a proper fix in QCoreTextFontEngine.
+ // Only if we're not using QCoreTextFontEngine we do fallback to our own text rendering.
const auto *fontEngine = QFontPrivate::get(myFont)->engineForScript(QChar::Script_Common);
Q_ASSERT(fontEngine);
if (fontEngine->type() == QFontEngine::Multi) {
fontEngine = static_cast<const QFontEngineMulti *>(fontEngine)->engine(0);
Q_ASSERT(fontEngine);
}
- Q_ASSERT(fontEngine->type() == QFontEngine::Mac);
- NSFont *f = (NSFont *)(CTFontRef)fontEngine->handle();
+ if (fontEngine->type() == QFontEngine::Mac) {
+ NSFont *f = (NSFont *)(CTFontRef)fontEngine->handle();
- s = qt_mac_removeMnemonics(s);
- [s.toNSString() drawInRect:CGRectMake(xpos, yPos, mi->rect.width() - xm - tabwidth + 1, mi->rect.height())
- withAttributes:@{ NSFontAttributeName:f, NSForegroundColorAttributeName:c }];
+ // Respect the menu item palette as set in the style option.
+ const auto pc = p->pen().color();
+ NSColor *c = [NSColor colorWithSRGBRed:pc.redF()
+ green:pc.greenF()
+ blue:pc.blueF()
+ alpha:pc.alphaF()];
- d->restoreNSGraphicsContext(cgCtx);
-#endif
+ s = qt_mac_removeMnemonics(s);
+ const auto textRect = CGRectMake(xpos, yPos, mi->rect.width() - xm - tabwidth + 1, mi->rect.height());
+
+ QMacCGContext cgCtx(p);
+ d->setupNSGraphicsContext(cgCtx, YES);
+
+ [s.toNSString() drawInRect:textRect
+ withAttributes:@{ NSFontAttributeName:f, NSForegroundColorAttributeName:c }];
+
+ d->restoreNSGraphicsContext(cgCtx);
+ } else {
+ p->setFont(myFont);
+ p->drawText(xpos, yPos, mi->rect.width() - xm - tabwidth + 1,
+ mi->rect.height(), text_flags, s);
+ }
}
p->restore();
}