Re: NSShadow with [bezierPath addClip]
Re: NSShadow with [bezierPath addClip]
- Subject: Re: NSShadow with [bezierPath addClip]
- From: Leonardo <email@hidden>
- Date: Sat, 25 Jan 2014 17:18:36 +0100
- Thread-topic: NSShadow with [bezierPath addClip]
Hi David,
After a few days using CGContextBeginTransparencyLayer
I have just noticed that the text I draw on a trasparent background with
[super drawRect:rect]; // we are in a drawRect: method of a NSTextView
looks without antialias. No matter whether I add before
CGContextSetAllowsAntialiasing(context, YES);
CGContextSetShouldAntialias(context, YES);
CGContextSetAllowsFontSmoothing (context, true);
CGContextSetShouldSmoothFonts (context, true);
CGContextSetAllowsFontSubpixelPositioning(context, YES);
CGContextSetShouldSubpixelPositionFonts(context, YES);
CGContextSetAllowsFontSubpixelQuantization(context, YES);
CGContextSetShouldSubpixelQuantizeFonts(context, YES);
If I eliminate CGContextBeginTransparencyLayer, the text gets properly
drawn. Do I still miss something?
Regards
-- Leonardo
> Da: David Duncan <email@hidden>
> Data: Wed, 01 Jan 2014 17:44:01 -0800
> A: Leonardo <email@hidden>
> Cc: Cocoa-dev <email@hidden>
> Oggetto: Re: NSShadow with [bezierPath addClip]
>
> In CoreGraphics the way you would do this is to setup your shadow parameters,
> then start a transparency layer, do your drawing there, then composite that
> back to the original context. Something like this:
>
> CGContextSetShadow(context, shadowOffset, shadowBlur);
> CGContextBeginTransparencyLayer(context, NULL);
> // do your drawing
> CGContextEndTransparencyLayer(context);
>
> You could get the graphicsPort from the NSGraphicsContext to call the
> transperancy layer methods and otherwise stick to NSGraphics stuff.
>
> On Dec 31, 2013, at 4:15 AM, Leonardo <email@hidden> wrote:
>
>> In my NSView subclass, I have to draw an image within a bezierPath and apply
>> an NSShadow to the result.
>> So within the drawRect: method I add
>>
>> [bezierPath addClip];
>> [mImage drawInRect:inRect fromRect:fromRect
>> operation:NSCompositeSourceOver fraction:mOpacity];
>>
>> It works. The image gets clipped by the path.
>> Now I would like to apply the NSShadow to the result, so before those lines
>> above I add
>>
>> [bezierPath addClip];
>> [mShadow set];
>> [mImage drawInRect:inRect fromRect:fromRect operation:NSCompositeSourceOver
>> fraction:mOpacity];
>>
>> I can't get the shadow drawn because the bezierPath is clipping the drawing
>> area where the shadow should fall.
>> How to solve this trouble?
>> I have tried to use a layer, but I get weird results when I resize, rotate
>> and modify other parameters of the view.
>>
>>
>> Regards
>> -- Leonardo
>>
>>
>> _______________________________________________
>>
>> Cocoa-dev mailing list (email@hidden)
>>
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>
>> Help/Unsubscribe/Update your Subscription:
>>
>> This email sent to email@hidden
>
> --
> David Duncan
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden