From 5a060a5ad322629f1a1ee0c850db94932543fee5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 30 Apr 2014 15:26:57 +0200 Subject: CoreText: Prevent creation of CGContext for glyphs with empty bounding box If the alphaMapBoundingBox of a glyph is empty we don't want to create a CGBitmapContext on it, as that will fail, and any further operations on the invalid context will result in possibly fatal errors from CG. This issue can be observed when drawing some glyphs of the Apple Color Emoji font. Change-Id: Ia45ba858b5fb6afa91e6d686a9c55e350d4095f3 Reviewed-by: Gunnar Sletta --- src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm b/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm index 0460f11139..6e2c8a2a9a 100644 --- a/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm +++ b/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm @@ -559,6 +559,9 @@ QImage QCoreTextFontEngine::imageForGlyph(glyph_t glyph, QFixed subPixelPosition QImage im(br.width.ceil().toInt(), br.height.ceil().toInt(), imageFormat); im.fill(0); + if (!im.width() || !im.height()) + return im; + #ifndef Q_OS_IOS CGColorSpaceRef colorspace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); #else @@ -568,9 +571,11 @@ QImage QCoreTextFontEngine::imageForGlyph(glyph_t glyph, QFixed subPixelPosition #ifdef kCGBitmapByteOrder32Host //only needed because CGImage.h added symbols in the minor version cgflags |= kCGBitmapByteOrder32Host; #endif + CGContextRef ctx = CGBitmapContextCreate(im.bits(), im.width(), im.height(), 8, im.bytesPerLine(), colorspace, cgflags); + Q_ASSERT(ctx); CGContextSetFontSize(ctx, fontDef.pixelSize); CGContextSetShouldAntialias(ctx, (aa || fontDef.pointSize > antialiasingThreshold) && !(fontDef.styleStrategy & QFont::NoAntialias)); -- cgit v1.2.3