@@ -280,6 +280,10 @@ - (void)renderTo:(CGContextRef)context rect:(CGRect)rect
280
280
bytesPerRow,
281
281
colorSpace,
282
282
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big );
283
+ #if TARGET_OS_OSX // [macOS]
284
+ // on macOS currentCTM is not scaled properly with screen scale so we need to scale it manually
285
+ CGContextConcatCTM (bcontext, screenScaleCTM);
286
+ #endif // [macOS]
283
287
CGContextConcatCTM (bcontext, currentCTM);
284
288
285
289
// Clip to mask bounds and render the mask
@@ -348,33 +352,35 @@ - (void)renderTo:(CGContextRef)context rect:(CGRect)rect
348
352
CGImageRelease (maskImage);
349
353
#else // [macOS
350
354
// Render content of current SVG Renderable to image
351
- UIGraphicsBeginImageContextWithOptions (maskBounds .size , NO , 0 .0 );
355
+ UIGraphicsBeginImageContextWithOptions (scaledRect .size , NO , 1 .0 );
352
356
CGContextRef newContext = UIGraphicsGetCurrentContext ();
353
- CGContextTranslateCTM (newContext, 0.0 , height);
354
- CGContextScaleCTM (newContext, 1.0 , -1.0 );
355
- [self renderLayerTo: newContext rect: rect];
357
+ CGContextConcatCTM (newContext, CGAffineTransformInvert (CGContextGetCTM (newContext)));
358
+ CGContextConcatCTM (newContext, screenScaleCTM);
359
+ CGContextConcatCTM (newContext, currentCTM);
360
+ [self renderLayerTo: newContext rect: scaledRect];
356
361
CGImageRef contentImage = CGBitmapContextCreateImage (newContext);
357
362
UIGraphicsEndImageContext ();
358
363
359
364
// Blend current element and mask
360
- UIGraphicsBeginImageContextWithOptions (maskBounds .size , NO , 0 .0 );
365
+ UIGraphicsBeginImageContextWithOptions (scaledRect .size , NO , 1 .0 );
361
366
newContext = UIGraphicsGetCurrentContext ();
362
- CGContextTranslateCTM (newContext, 0.0 , height);
363
- CGContextScaleCTM (newContext, 1.0 , -1.0 );
367
+ CGContextConcatCTM (newContext, CGAffineTransformInvert (CGContextGetCTM (newContext)));
364
368
365
369
CGContextSetBlendMode (newContext, kCGBlendModeCopy );
366
- CGContextDrawImage (newContext, maskBounds , maskImage);
370
+ CGContextDrawImage (newContext, scaledRect , maskImage);
367
371
CGImageRelease (maskImage);
368
372
369
373
CGContextSetBlendMode (newContext, kCGBlendModeSourceIn );
370
- CGContextDrawImage (newContext, maskBounds , contentImage);
374
+ CGContextDrawImage (newContext, scaledRect , contentImage);
371
375
CGImageRelease (contentImage);
372
376
373
377
CGImageRef blendedImage = CGBitmapContextCreateImage (newContext);
374
378
UIGraphicsEndImageContext ();
375
379
376
380
// Render blended result into current render context
377
- CGContextDrawImage (context, maskBounds, blendedImage);
381
+ CGContextConcatCTM (context, CGAffineTransformInvert (currentCTM));
382
+ CGContextDrawImage (context, rect, blendedImage);
383
+ CGContextConcatCTM (context, currentCTM);
378
384
CGImageRelease (blendedImage);
379
385
#endif // macOS]
380
386
} else {
0 commit comments