Skip to content

Commit 472fd88

Browse files
committed
fix text draw functions
Fix drawAttributedStringGL and drawAttributedStringMTL for 10.15 and 11 since initWithFocusedViewRect was deprecated starting with 10.15 and was not working anymore. Checked the new code is also working on 10.14.
1 parent 9602077 commit 472fd88

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

AnimatedGif/AnimatedGifView.m

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,12 +1623,13 @@ - (void) drawAttributedStringGL:(NSAttributedString *)attributedString atPoint:(
16231623
NSSize frameSize = NSMakeSize(0.0f, 0.0f);
16241624

16251625
frameSize = [attributedString size];
1626-
NSImage * image = [[NSImage alloc] initWithSize:frameSize];
1627-
[image lockFocus];
1628-
[[NSGraphicsContext currentContext] setShouldAntialias:YES];
1626+
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL pixelsWide:round(frameSize.width) pixelsHigh:round(frameSize.height)
1627+
bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO colorSpaceName:NSCalibratedRGBColorSpace bitmapFormat:NS32BitLittleEndianBitmapFormat bytesPerRow:round(frameSize.width)*4 bitsPerPixel:0];
1628+
NSGraphicsContext *context = [NSGraphicsContext graphicsContextWithBitmapImageRep:bitmap];
1629+
[NSGraphicsContext saveGraphicsState];
1630+
[NSGraphicsContext setCurrentContext:context];
16291631
[attributedString drawAtPoint:NSMakePoint (0.0f, 0.0f)];
1630-
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect(0.0f, 0.0f, frameSize.width, frameSize.height)];
1631-
[image unlockFocus];
1632+
[NSGraphicsContext restoreGraphicsState];
16321633
texturSize.width = [bitmap pixelsWide];
16331634
texturSize.height = [bitmap pixelsHigh];
16341635
NSRect bounds = NSMakeRect (point.x, point.y, texturSize.width, texturSize.height);
@@ -1874,12 +1875,13 @@ - (void) drawAttributedStringMTL:(NSAttributedString *)attributedString atPoint:
18741875
NSSize frameSize = NSMakeSize(0.0f, 0.0f);
18751876

18761877
frameSize = [attributedString size];
1877-
NSImage * image = [[NSImage alloc] initWithSize:frameSize];
1878-
[image lockFocus];
1879-
[[NSGraphicsContext currentContext] setShouldAntialias:YES];
1878+
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL pixelsWide:round(frameSize.width) pixelsHigh:round(frameSize.height)
1879+
bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO colorSpaceName:NSCalibratedRGBColorSpace bitmapFormat:NS32BitLittleEndianBitmapFormat bytesPerRow:round(frameSize.width)*4 bitsPerPixel:0];
1880+
NSGraphicsContext *context = [NSGraphicsContext graphicsContextWithBitmapImageRep:bitmap];
1881+
[NSGraphicsContext saveGraphicsState];
1882+
[NSGraphicsContext setCurrentContext:context];
18801883
[attributedString drawAtPoint:NSMakePoint (0.0f, 0.0f)];
1881-
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect(0.0f, 0.0f, frameSize.width, frameSize.height)];
1882-
[image unlockFocus];
1884+
[NSGraphicsContext restoreGraphicsState];
18831885
texturSize.width = [bitmap pixelsWide];
18841886
texturSize.height = [bitmap pixelsHigh];
18851887
NSRect bounds = NSMakeRect (point.x, point.y, texturSize.width, texturSize.height);

0 commit comments

Comments
 (0)