Skip to content

Commit

Permalink
Merge pull request #10 from SDWebImage/bugfix/macOS_-flip_upside_down
Browse files Browse the repository at this point in the history
Fix the wrong flipping rendering on macOS because of CoreGraphics/AppKit differences
dreampiggy authored Jan 11, 2024
2 parents 43fa043 + 29680b9 commit 09a6199
Showing 4 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -22,12 +22,12 @@ - (void)viewDidLoad {

CGSize screenSize = self.view.bounds.size;

NSImageView *imageView1 = [[NSImageView alloc] init];
imageView1.frame = CGRectMake(0, 0, screenSize.width, screenSize.height / 2);
UIImageView *imageView1 = [[UIImageView alloc] init];
imageView1.frame = CGRectMake(0, 0, screenSize.width / 2, screenSize.height);
imageView1.imageScaling = NSImageScaleProportionallyUpOrDown;

NSImageView *imageView2 = [[NSImageView alloc] init];
imageView2.frame = CGRectMake(0, screenSize.height / 2, screenSize.width, screenSize.height / 2);
UIImageView *imageView2 = [[UIImageView alloc] init];
imageView2.frame = CGRectMake(screenSize.width / 2, 0, screenSize.width / 2, screenSize.height);
imageView2.imageScaling = NSImageScaleProportionallyUpOrDown;

[self.view addSubview:imageView1];
Binary file added Example/Screenshot/SVGDemo-macOS.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -121,6 +121,7 @@ To run the example project, clone the repo, and run `pod install` from the Examp
## Screenshot

<img src="https://raw.githubusercontent.com/SDWebImage/SDWebImageSVGNativeCoder/main/Example/Screenshot/SVGDemo.png" width="300" />
<img src="https://raw.githubusercontent.com/SDWebImage/SDWebImageSVGNativeCoder/main/Example/Screenshot/SVGDemo-macOS.png" width="600" />

## Author

7 changes: 7 additions & 0 deletions SDWebImageSVGNativeCoder/Classes/SDImageSVGNativeCoder.mm
Original file line number Diff line number Diff line change
@@ -80,6 +80,13 @@ - (nullable UIImage *)decodedImageWithData:(nullable NSData *)data options:(null

renderer->SetGraphicsContext(ctx);

#if SD_MAC
// Core Graphics Coordinate System convert. SDWebImage use's non-flipped one
// See: [NSGraphicsContext graphicsContextWithCGContext:context flipped:NO];
CGContextScaleCTM(ctx, 1, -1);
CGContextTranslateCTM(ctx, 0, -svgSize.height);
#endif

doc->Render(svgSize.width, svgSize.height);

renderer->ReleaseGraphicsContext();

0 comments on commit 09a6199

Please sign in to comment.