In order to create a nice outline effect to bitmaps, I would take an NSAttributedString, use CoreText to render it to a bitmap, with something like:
So basically drawing over the old. It's just that in iOS14 (I haven't checked iOS13, but iOS12 is ok) and BigSur (didn't check Catalina, Mojave was fine) I started getting very broken rendering.
After trying a gazillion things, I noted that if I first created the NSAttributedString with one NSFont, then replaced that NSFont with the same NSFont but with a larger size, rendering would get messed up. BUT if I replaced it with an NSFont of the exact same size it was fine!
Also, this only happened if I was switching colour inside of the NSAttributedString. With a single colour + outline it was fine.
Printing out the attributes in the broken NSAttributedString (with replaced font) and the original (with the smaller font), the attributes were identical aside from the font sizes and the pointer addresses. Everything else printed out was identical.
BUT the problem doesn't end there. Setting a gradient for a foreground colour completely stopped working as well. Looking at iOS12 again it works perfectly fine, iOS14 (and BigSur) it's just a single colour as if the feature had never been there. Here's the Mac OS code snippet:
Since both AppKit and UIKit stopped working here I can only assume there's some change in CoreText. But how do I work around these problems? Perfecting text rendering is something I already spent a lot of time doing and this used to be rock solid code.
Code Block CGContextSaveGState(context); CGContextSetTextDrawingMode(context, kCGTextStroke); CGContextSetLineWidth(context, (CGFloat)width * 2); CGContextSetLineJoin(context, kCGLineJoinRound); drawAttributedString(AttributedString(attributedString), context, drawArea); CGContextRestoreGState(context); drawAttributedString(AttributedString(attributedString), context, drawArea);
So basically drawing over the old. It's just that in iOS14 (I haven't checked iOS13, but iOS12 is ok) and BigSur (didn't check Catalina, Mojave was fine) I started getting very broken rendering.
After trying a gazillion things, I noted that if I first created the NSAttributedString with one NSFont, then replaced that NSFont with the same NSFont but with a larger size, rendering would get messed up. BUT if I replaced it with an NSFont of the exact same size it was fine!
Also, this only happened if I was switching colour inside of the NSAttributedString. With a single colour + outline it was fine.
Printing out the attributes in the broken NSAttributedString (with replaced font) and the original (with the smaller font), the attributes were identical aside from the font sizes and the pointer addresses. Everything else printed out was identical.
BUT the problem doesn't end there. Setting a gradient for a foreground colour completely stopped working as well. Looking at iOS12 again it works perfectly fine, iOS14 (and BigSur) it's just a single colour as if the feature had never been there. Here's the Mac OS code snippet:
Code Block NSImage *image = [[NSImage alloc] initWithCGImage:ret size:NSMakeSize(1, CGFloat(round(height)))]; NSColor *createdColorGradient = [NSColor colorWithPatternImage:image]; [copy addAttribute:(NSString *)kCTForegroundColorAttributeName value:createdColorGradient range:NSMakeRange(0, [copy length])];
Since both AppKit and UIKit stopped working here I can only assume there's some change in CoreText. But how do I work around these problems? Perfecting text rendering is something I already spent a lot of time doing and this used to be rock solid code.