summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorTor Arne Vestbø <torarnv@gmail.com>2019-05-09 20:43:30 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2019-05-10 17:15:27 +0000
commit123053bba8dc2241041c31a262420edd3583b1c7 (patch)
treecd7289e179c1bd911555298b9d2138da27c2b99f /src/plugins
parentb7edc811ec00b6e0687cb96fda64c7e608af56c6 (diff)
macOS: Don't clip menu item drawing to bounding rect when using CoreText
The bounding rect was computed based on the font metrics HarfBuzz gave us, but those may not be 1:1 with what CoreText ends up using. When that happens, drawInRect: will line-break the last word, which makes it fall completely outside of the single line bounding rect. This is not a good failure mode, so we prefer to draw the text at a point instead, allowing the resulting text to draw slightly outside of the bounding rect. This is preferable to adding a random padding to the width and hoping it will be enough to solve the problem. Change-Id: Ifa58a33bd9fad689ed4ee947327b7079f3c1b61d Fixes: QTBUG-74565 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/styles/mac/qmacstyle_mac.mm7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm
index 2a6f212569..81835b7c63 100644
--- a/src/plugins/styles/mac/qmacstyle_mac.mm
+++ b/src/plugins/styles/mac/qmacstyle_mac.mm
@@ -4290,12 +4290,15 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
alpha:pc.alphaF()];
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
+ // Draw at point instead of in rect, as the rect we've computed for the menu item
+ // is based on the font metrics we got from HarfBuzz, so we may risk having CoreText
+ // line-break the string if it doesn't fit the given rect. It's better to draw outside
+ // the rect and possibly overlap something than to have part of the text disappear.
+ [s.toNSString() drawAtPoint:CGPointMake(xpos, yPos)
withAttributes:@{ NSFontAttributeName:f, NSForegroundColorAttributeName:c,
NSObliquenessAttributeName: [NSNumber numberWithDouble: myFont.italic() ? 0.3 : 0.0]}];