Re: draw NSAttributedstring with transparency

2010-07-23 Thread Kyle Sluder
On Jul 23, 2010, at 4:41 AM, Andreas Mayer  wrote:

> 
> Am 23.07.2010 um 12:53 Uhr schrieb Bernard Knaepen:
> 
>> I am currently using the drawAtPoint method but I would like to specify a 
>> global opacity (transparency) to draw the string. Is there a way to do this 
>> or should I scan the whole string and make the changes to each character 
>> color individually by using the colorWithAlphaComponent method?
> 
> You could draw the string to an intermediate image and composite that image 
> with the desired opacity onto the target image.

This would prevent Quartz from being able to perform subpixel antialiasing, 
resulting is crummy text.

--Kyle Sluder___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: draw NSAttributedstring with transparency

2010-07-23 Thread Bernard Knaepen
Excellent, works perfectly!

Thanks a lot,

Bernard.

ps. for future reference, there is just a tiny typo: currentContent should read 
currentContext...


On 23 Jul 2010, at 15:50, Steve Christensen wrote:

> On Jul 23, 2010, at 3:53 AM, Bernard Knaepen wrote:
> 
>> I need to draw an NSAttributedString over an image. The characters of the 
>> string might have different sizes, fonts and colors. 
>> 
>> I am currently using the drawAtPoint method but I would like to specify a 
>> global opacity (transparency) to draw the string. Is there a way to do this 
>> or should I scan the whole string and make the changes to each character 
>> color individually by using the colorWithAlphaComponent method?
> 
> Something like this, perhaps:
> 
> NSGraphicsContext* nsContext = [NSGraphicsContext currentContent];
> CGContextRef cgContext = (CGContextRef)[nsContext graphicsPort];
> 
> [nsContext saveGraphicsState];
> [nsContext setCompositingOperation:NSCompositeSourceOver];
> CGContextSetAlpha(cgContext, 0.5);
> 
> [theString drawAtPoint:thePoint];
> 
> [nsContext restoreGraphicsState];
> 

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: draw NSAttributedstring with transparency

2010-07-23 Thread Steve Christensen
On Jul 23, 2010, at 3:53 AM, Bernard Knaepen wrote:

> I need to draw an NSAttributedString over an image. The characters of the 
> string might have different sizes, fonts and colors. 
> 
> I am currently using the drawAtPoint method but I would like to specify a 
> global opacity (transparency) to draw the string. Is there a way to do this 
> or should I scan the whole string and make the changes to each character 
> color individually by using the colorWithAlphaComponent method?

Something like this, perhaps:

NSGraphicsContext* nsContext = [NSGraphicsContext currentContent];
CGContextRef cgContext = (CGContextRef)[nsContext graphicsPort];

[nsContext saveGraphicsState];
[nsContext setCompositingOperation:NSCompositeSourceOver];
CGContextSetAlpha(cgContext, 0.5);

[theString drawAtPoint:thePoint];

[nsContext restoreGraphicsState];

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: draw NSAttributedstring with transparency

2010-07-23 Thread Andreas Mayer


Am 23.07.2010 um 12:53 Uhr schrieb Bernard Knaepen:

I am currently using the drawAtPoint method but I would like to  
specify a global opacity (transparency) to draw the string. Is there  
a way to do this or should I scan the whole string and make the  
changes to each character color individually by using the  
colorWithAlphaComponent method?


You could draw the string to an intermediate image and composite that  
image with the desired opacity onto the target image.



Andreas
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


draw NSAttributedstring with transparency

2010-07-23 Thread Bernard Knaepen
Hello,

I need to draw an NSAttributedString over an image. The characters of the 
string might have different sizes, fonts and colors. 

I am currently using the drawAtPoint method but I would like to specify a 
global opacity (transparency) to draw the string. Is there a way to do this or 
should I scan the whole string and make the changes to each character color 
individually by using the colorWithAlphaComponent method?

Thanks,

Bernard.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com