FROM : Troy Stephens
DATE : Fri Mar 28 19:27:17 2008
On Mar 28, 2008, at 9:19 AM, Milen Dzhumerov wrote:
> Hi all,
>
> I've noticed that when using layer backing on a NSTextField the font
> becomes fuzzy - it seems that it switches from subpixel anti-
> aliasing to normal. And indeed this seems to be the case. After
> reading CATextLayer's documentation (assuming that NSTextField uses
> it to draw its text), it becomes apparent that subpixel anti-
> aliasing cannot be used with CATextLayer. Here's the exact wording:
> "Note: CATextLayer disabled sub-pixel antialiasing when rendering
> text. Text can only be drawn using sub-pixel antialiasing when it is
> composited into an existing opaque background at the same time that
> it's rasterized. There is no way to draw subpixel-anialiased text by
> itself, whether into an image or a layer, separately in advance of
> having the background pixels to weave the text pixels into. Setting
> the opacityproperty of the layer to YES does not change the
> rendering mode."
>
> After reading the above note it looks to me that if the CATextLayer
> has an opaque background, it should be able to use sub-pixel anti-
> aliasing *if* we provide the background pixels in advance. The
> question is, is it possible to do this? I tried setting the
> backgroundColor property of a NSTextField's layer and it still
> produced normal anti-aliased text as opposed to subpixel anti-
> aliased. Has anyone else bumped into this issue?
Yes, it's possible, but there are two separate cases here:
Case 1: If you're using a layer-backed NSTextField, then CATextLayer
is not actually involved. Setting the NSTextField's backgroundColor
to an opaque color is on the right track, but you also need to do set
drawsBackground to YES for it to take effect. Then you should see
subpixel AA in the rendered results. (This can even be done in IB
using the NSTextField inspector.)
Case 2: If you're using a CATextLayer directly, you'll need to
subclass CATextLayer and do something like the following in your
drawing code:
- (void)drawInContext:(CGContextRef)ctx
{
CGContextSetRGBFillColor (ctx, r, g, b, a);
CGContextFillRect (ctx, [self bounds]);
CGContextSetShouldSmoothFonts (ctx, true);
[super drawInContext:ctx];
}
> I've also taken a sample screencast of the degradation of the
> quality of the text when using layer backing on a NSTextField - http://www.doc.ic.ac.uk/~md207/ca_bugs/text_render/CA_text_render.mov
> .
>
> Kind regards,
> Milen
> _______________________________________________
>
> Cocoa-dev mailing list (<email_removed>)
>
> 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/<email_removed>
>
> This email sent to <email_removed>
--
Troy Stephens
Cocoa Frameworks
Apple, Inc.
DATE : Fri Mar 28 19:27:17 2008
On Mar 28, 2008, at 9:19 AM, Milen Dzhumerov wrote:
> Hi all,
>
> I've noticed that when using layer backing on a NSTextField the font
> becomes fuzzy - it seems that it switches from subpixel anti-
> aliasing to normal. And indeed this seems to be the case. After
> reading CATextLayer's documentation (assuming that NSTextField uses
> it to draw its text), it becomes apparent that subpixel anti-
> aliasing cannot be used with CATextLayer. Here's the exact wording:
> "Note: CATextLayer disabled sub-pixel antialiasing when rendering
> text. Text can only be drawn using sub-pixel antialiasing when it is
> composited into an existing opaque background at the same time that
> it's rasterized. There is no way to draw subpixel-anialiased text by
> itself, whether into an image or a layer, separately in advance of
> having the background pixels to weave the text pixels into. Setting
> the opacityproperty of the layer to YES does not change the
> rendering mode."
>
> After reading the above note it looks to me that if the CATextLayer
> has an opaque background, it should be able to use sub-pixel anti-
> aliasing *if* we provide the background pixels in advance. The
> question is, is it possible to do this? I tried setting the
> backgroundColor property of a NSTextField's layer and it still
> produced normal anti-aliased text as opposed to subpixel anti-
> aliased. Has anyone else bumped into this issue?
Yes, it's possible, but there are two separate cases here:
Case 1: If you're using a layer-backed NSTextField, then CATextLayer
is not actually involved. Setting the NSTextField's backgroundColor
to an opaque color is on the right track, but you also need to do set
drawsBackground to YES for it to take effect. Then you should see
subpixel AA in the rendered results. (This can even be done in IB
using the NSTextField inspector.)
Case 2: If you're using a CATextLayer directly, you'll need to
subclass CATextLayer and do something like the following in your
drawing code:
- (void)drawInContext:(CGContextRef)ctx
{
CGContextSetRGBFillColor (ctx, r, g, b, a);
CGContextFillRect (ctx, [self bounds]);
CGContextSetShouldSmoothFonts (ctx, true);
[super drawInContext:ctx];
}
> I've also taken a sample screencast of the degradation of the
> quality of the text when using layer backing on a NSTextField - http://www.doc.ic.ac.uk/~md207/ca_bugs/text_render/CA_text_render.mov
> .
>
> Kind regards,
> Milen
> _______________________________________________
>
> Cocoa-dev mailing list (<email_removed>)
>
> 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/<email_removed>
>
> This email sent to <email_removed>
--
Troy Stephens
Cocoa Frameworks
Apple, Inc.
| Related mails | Author | Date |
|---|---|---|
| Milen Dzhumerov | Mar 28, 17:19 | |
| Troy Stephens | Mar 28, 19:27 |






Cocoa mail archive

