Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions apple/RNSVGRenderable.mm
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ - (void)renderTo:(CGContextRef)context rect:(CGRect)rect
bytesPerRow,
colorSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
#if TARGET_OS_OSX // [macOS]
// on macOS currentCTM is not scaled properly with screen scale so we need to scale it manually
CGContextConcatCTM(bcontext, screenScaleCTM);
#endif // [macOS]
CGContextConcatCTM(bcontext, currentCTM);

// Clip to mask bounds and render the mask
Expand Down Expand Up @@ -348,33 +352,35 @@ - (void)renderTo:(CGContextRef)context rect:(CGRect)rect
CGImageRelease(maskImage);
#else // [macOS
// Render content of current SVG Renderable to image
UIGraphicsBeginImageContextWithOptions(maskBounds.size, NO, 0.0);
UIGraphicsBeginImageContextWithOptions(scaledRect.size, NO, 1.0);
CGContextRef newContext = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(newContext, 0.0, height);
CGContextScaleCTM(newContext, 1.0, -1.0);
[self renderLayerTo:newContext rect:rect];
CGContextConcatCTM(newContext, CGAffineTransformInvert(CGContextGetCTM(newContext)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we get a comment of what we exactly do in those next lines?

CGContextConcatCTM(newContext, screenScaleCTM);
CGContextConcatCTM(newContext, currentCTM);
[self renderLayerTo:newContext rect:scaledRect];
CGImageRef contentImage = CGBitmapContextCreateImage(newContext);
UIGraphicsEndImageContext();

// Blend current element and mask
UIGraphicsBeginImageContextWithOptions(maskBounds.size, NO, 0.0);
UIGraphicsBeginImageContextWithOptions(scaledRect.size, NO, 1.0);
newContext = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(newContext, 0.0, height);
CGContextScaleCTM(newContext, 1.0, -1.0);
CGContextConcatCTM(newContext, CGAffineTransformInvert(CGContextGetCTM(newContext)));

CGContextSetBlendMode(newContext, kCGBlendModeCopy);
CGContextDrawImage(newContext, maskBounds, maskImage);
CGContextDrawImage(newContext, scaledRect, maskImage);
CGImageRelease(maskImage);

CGContextSetBlendMode(newContext, kCGBlendModeSourceIn);
CGContextDrawImage(newContext, maskBounds, contentImage);
CGContextDrawImage(newContext, scaledRect, contentImage);
CGImageRelease(contentImage);

CGImageRef blendedImage = CGBitmapContextCreateImage(newContext);
UIGraphicsEndImageContext();

// Render blended result into current render context
CGContextDrawImage(context, maskBounds, blendedImage);
CGContextConcatCTM(context, CGAffineTransformInvert(currentCTM));
CGContextDrawImage(context, rect, blendedImage);
CGContextConcatCTM(context, currentCTM);
CGImageRelease(blendedImage);
#endif // macOS]
} else {
Expand Down