From cf7a4016a17615df2952389bae11149a49b151bc Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Mon, 8 Jan 2018 19:16:49 -0800 Subject: QMacStyle: Draw CE_MenuItem text using AppKit We seem to induce QCoreTextFontEngine to draw text the wrong way in non-native QMenu popups. Here, we just delegate menu items' text rendering to AppKit. This is only a workaround pending a proper fix or better understanding of the aforementioned issue. Change-Id: I71088ebe2a534bebca2ad396b1ea6754be093f55 Task-number: QTBUG-65653 Reviewed-by: Gabriel de Dietrich Reviewed-by: Jake Petroules --- src/plugins/styles/mac/qmacstyle_mac.mm | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/plugins/styles') diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm index e540ff4d3b..ee5fb6def8 100644 --- a/src/plugins/styles/mac/qmacstyle_mac.mm +++ b/src/plugins/styles/mac/qmacstyle_mac.mm @@ -4285,9 +4285,39 @@ 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. + const auto *fontEngine = QFontPrivate::get(myFont)->engineForScript(QChar::Script_Common); + Q_ASSERT(fontEngine); + if (fontEngine->type() == QFontEngine::Multi) { + fontEngine = static_cast(fontEngine)->engine(0); + Q_ASSERT(fontEngine); + } + Q_ASSERT(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 }]; + + d->restoreNSGraphicsContext(cgCtx); +#endif } p->restore(); } -- cgit v1.2.3