From 3fc78e21ca5965d0f70ab6e381ec62686942adc8 Mon Sep 17 00:00:00 2001 From: paul Date: Thu, 6 Sep 2012 12:21:32 +0000 Subject: [PATCH] carbon: save/restore clipping region on SaveDC/RestoreDC, correctly return region type on SelectClipRGN call git-svn-id: trunk@38535 - --- lcl/interfaces/carbon/carboncanvas.pp | 49 ++++++++++++++--------- lcl/interfaces/carbon/carbongdiobjects.pp | 5 +++ 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/lcl/interfaces/carbon/carboncanvas.pp b/lcl/interfaces/carbon/carboncanvas.pp index 89ea3b5d70..b268166641 100644 --- a/lcl/interfaces/carbon/carboncanvas.pp +++ b/lcl/interfaces/carbon/carboncanvas.pp @@ -56,6 +56,9 @@ type ROP2: Integer; PenPos: TPoint; + + isClipped: Boolean; + ClipShape: HIShapeRef; end; TCarbonBitmapContext = class; @@ -100,6 +103,7 @@ type function SaveDCData: TCarbonDCData; virtual; procedure RestoreDCData(const AData: TCarbonDCData); virtual; procedure ExcludeClipRect(Left, Top, Right, Bottom: Integer); + procedure ApplyTransform(Trans: CGAffineTransform); procedure ClearClipping; public constructor Create; @@ -564,14 +568,10 @@ begin {$ENDIF} if FSavedDCList.Count = 0 then FreeAndNil(FSavedDCList); - - - if isClipped then - begin - // should clip be restored? - isClipped:=false; - FClipRegion.Shape := HIShapeCreateEmpty; - end; + + + if isClipped then + CGContextSaveGState(CGContext); end; {------------------------------------------------------------------------------ @@ -596,6 +596,9 @@ begin Result.ROP2 := FROP2; Result.PenPos := FPenPos; + + Result.isClipped := isClipped; + Result.ClipShape := FClipRegion.GetShapeCopy; end; {------------------------------------------------------------------------------ @@ -651,6 +654,9 @@ begin FROP2 := AData.ROP2; FPenPos := AData.PenPos; + + isClipped := AData.isClipped; + FClipRegion.Shape := AData.ClipShape; end; {------------------------------------------------------------------------------ @@ -887,6 +893,17 @@ begin end; end; +procedure TCarbonDeviceContext.ApplyTransform(Trans: CGAffineTransform); +var + T2: CGAffineTransform; +begin + T2 := CGContextGetCTM(CGContext); + // restore old CTM since CTM may changed after the clipping + if CGAffineTransformEqualToTransform(Trans, T2) = 0 then + CGContextTranslateCTM(CGContext, Trans.a * Trans.tx - T2.a * T2.tx, + Trans.d * Trans.ty - T2.d * T2.ty); +end; + {------------------------------------------------------------------------------ Method: TCarbonDeviceContext.ExtTextOut Params: X - X-coordinate of reference point @@ -1554,16 +1571,13 @@ end; procedure TCarbonDeviceContext.ClearClipping; var - T1, T2: CGAffineTransform; + Trans: CGAffineTransform; begin if isClipped then begin - T1 := CGContextGetCTM(CGContext); + Trans := CGContextGetCTM(CGContext); CGContextRestoreGState(CGContext); - T2 := CGContextGetCTM(CGContext); - // restore old CTM since CTM may changed after the clipping - if CGAffineTransformEqualToTransform(T1, T2) = 0 then - CGContextTranslateCTM(CGContext, T1.a * T1.tx - T2.a * T2.tx, T1.d * T1.ty - T2.d * T2.ty); + ApplyTransform(Trans); end; end; @@ -1573,18 +1587,15 @@ begin isClipped := False; if not Assigned(AClipRegion) then - begin - HIShapeSetEmpty(FClipRegion.Shape); - Result := LCLType.NullRegion; - end + HIShapeSetEmpty(FClipRegion.Shape) else begin CGContextSaveGState(CGContext); FClipRegion.CombineWith(AClipRegion, Mode); FClipRegion.Apply(Self); isClipped := true; - Result := LCLType.ComplexRegion; end; + Result := FClipRegion.GetType; end; function TCarbonDeviceContext.CopyClipRegion(ADstRegion: TCarbonRegion): Integer; diff --git a/lcl/interfaces/carbon/carbongdiobjects.pp b/lcl/interfaces/carbon/carbongdiobjects.pp index 0e0997ee3b..f20c37ce3c 100644 --- a/lcl/interfaces/carbon/carbongdiobjects.pp +++ b/lcl/interfaces/carbon/carbongdiobjects.pp @@ -74,6 +74,7 @@ type procedure SetShape(AShape: HIShapeRef); function CombineWith(ARegion: TCarbonRegion; CombineMode: Integer): Integer; procedure Offset(dx, dy: Integer); + function GetShapeCopy: HIShapeRef; public property Shape: HIShapeRef read FShape write SetShape; end; @@ -862,6 +863,10 @@ begin HIShapeOffset(FShape, dx, dy); end; +function TCarbonRegion.GetShapeCopy: HIShapeRef; +begin + Result := HIShapeCreateCopy(Shape); +end; { TCarbonTextLayout }