From 6129b92d325d63ff06b55d0d9a0637d970c43712 Mon Sep 17 00:00:00 2001 From: paul Date: Fri, 28 Sep 2012 08:37:22 +0000 Subject: [PATCH] cocoa: fix DrawImageRep (apply property before new context creation), fix memory management in TCocoaTextLayout git-svn-id: trunk@38883 - --- lcl/interfaces/cocoa/cocoagdiobjects.pas | 35 +++++++++++++----------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/lcl/interfaces/cocoa/cocoagdiobjects.pas b/lcl/interfaces/cocoa/cocoagdiobjects.pas index 8cd643fc40..ab15d97b42 100644 --- a/lcl/interfaces/cocoa/cocoagdiobjects.pas +++ b/lcl/interfaces/cocoa/cocoagdiobjects.pas @@ -940,17 +940,20 @@ end; constructor TCocoaTextLayout.Create; var S: NSString; + LocalPool: NSAutoReleasePool; begin + inherited Create; + LocalPool := NSAutoReleasePool.alloc.init; + FTextStorage := NSTextStorage.alloc.initWithString(NSSTR('')); FLayout := NSLayoutManager.alloc.init; + FTextStorage.addLayoutManager(FLayout); FTextContainer := NSTextContainer.alloc.init; FTextContainer.setLineFragmentPadding(0); FLayout.addTextContainer(FTextContainer); - FTextContainer.release; - S := NSSTR(''); - FTextStorage := NSTextStorage.alloc.initWithString(S); - S.release; - FTextStorage.addLayoutManager(FLayout); - FLayout.release; + + FTextStorage.retain; + LocalPool.release; + FFont := DefaultFont; FFont.AddRef; FText := ''; @@ -969,7 +972,9 @@ procedure TCocoaTextLayout.SetFont(AFont: TCocoaFont); begin if FFont <> AFont then begin + FFont.Release; FFont := AFont; + FFont.AddRef; FTextStorage.beginEditing; updateFont; FTextStorage.endEditing; @@ -1719,17 +1724,15 @@ var Context: NSGraphicsContext; begin ctx.saveGraphicsState; - - // we flip the context on it initialization (see InitDraw) so to draw - // a bitmap correctly we need to create a flipped context and to draw onto it - - if not ctx.isFlipped then - Context := NSGraphicsContext.graphicsContextWithGraphicsPort_flipped(ctx.graphicsPort, True) - else - Context := ctx; - ctx.setCurrentContext(Context); - CGContextSetBlendMode(CGContext, kCGBlendModeNormal); try + // we flip the context on it initialization (see InitDraw) so to draw + // a bitmap correctly we need to create a flipped context and to draw onto it + + if not ctx.isFlipped then + Context := NSGraphicsContext.graphicsContextWithGraphicsPort_flipped(ctx.graphicsPort, True) + else + Context := ctx; + ctx.setCurrentContext(Context); Result := ImageRep.drawInRect_fromRect_operation_fraction_respectFlipped_hints( dstRect, srcRect, NSCompositeSourceOver, 1.0, True, nil );