Cocoa: fix up-side down issue with Transparent Bitmaps (issue #36714)

This commit is contained in:
rich2014 2024-06-05 16:51:51 +08:00
parent c030c1af73
commit b7183648e0

View File

@ -1510,8 +1510,11 @@ begin
FSize.cx := width; FSize.cx := width;
FSize.cy := height; FSize.cy := height;
if NOT ctx.isFlipped then begin
CGContextTranslateCTM(cg, 0, height); CGContextTranslateCTM(cg, 0, height);
CGContextScaleCTM(cg, 1, -1); CGContextScaleCTM(cg, 1, -1);
end;
FPenPos.x := 0; FPenPos.x := 0;
FPenPos.y := 0; FPenPos.y := 0;
end; end;
@ -2195,11 +2198,17 @@ var
Bmp: TCocoaBitmap; Bmp: TCocoaBitmap;
MskImage: CGImageRef; MskImage: CGImageRef;
ImgRect: CGRect; ImgRect: CGRect;
dcWidth: Integer;
dcHeight: Integer;
begin begin
Bmp := SrcDC.Bitmap; Bmp := SrcDC.Bitmap;
if not Assigned(Bmp) then if not Assigned(Bmp) then
Exit(False); Exit(False);
dcWidth:= Max(Width,FSize.Width);
dcHeight:= Max(Height,FSize.Height);
// Make sure that bitmap is the most up-to-date // Make sure that bitmap is the most up-to-date
Bmp.ReCreateHandle_IfModified(); // Fix for bug 28102 Bmp.ReCreateHandle_IfModified(); // Fix for bug 28102
@ -2212,15 +2221,17 @@ begin
if (Msk <> nil) and (Msk.Image <> nil) then if (Msk <> nil) and (Msk.Image <> nil) then
begin begin
MskImage := Msk.CreateMaskImage(Bounds(XMsk, YMsk, SrcWidth, SrcHeight)); MskImage := Msk.CreateMaskImage(Bounds(XMsk, YMsk, SrcWidth, SrcHeight));
ImgRect := CGRectMake(x, -y, SrcWidth, SrcHeight); ImgRect := CGRectMake(x, y, dcWidth, dcHeight);
CGContextSaveGState(CGContext); CGContextSaveGState(CGContext);
CGContextScaleCTM(CGContext, 1, -1);
CGContextTranslateCTM(CGContext, 0, -SrcHeight);
CGContextClipToMask(CGContext, ImgRect, MskImage ); CGContextClipToMask(CGContext, ImgRect, MskImage );
NSGraphicsContext.setCurrentContext(ctx); if NOT ctx.isFlipped then begin
CGContextScaleCTM(CGContext, 1, -1);
CGContextTranslateCTM(CGContext, 0, -dcHeight);
Y:= dcHeight - (Height + Y);
end;
Result := bmp.ImageRep.drawInRect_fromRect_operation_fraction_respectFlipped_hints( Result := bmp.ImageRep.drawInRect_fromRect_operation_fraction_respectFlipped_hints(
GetNSRect(X, -Y, Width, Height), GetNSRect(XSrc, YSrc, SrcWidth, SrcHeight), NSCompositeSourceOver, 1.0, True, nil ); GetNSRect(X, Y, Width, Height), GetNSRect(XSrc, YSrc, SrcWidth, SrcHeight), NSCompositeSourceOver, 1.0, True, nil );
CGImageRelease(MskImage); CGImageRelease(MskImage);
CGContextRestoreGState(CGContext); CGContextRestoreGState(CGContext);