Recipe 9.28. Applying Advanced Anti-Aliasing


Problem

You want to have more precise control over anti-aliasing of text.

Solution

Embed the font, set the antiAliasType property of the text field to flash.text.AntiAliasType.ADVANCED, and set the gridTypeFit and sharpness properties.

Discussion

By default, text displays with normal anti-aliasing settings. For most fonts at sizes 10 and higher the normal anti-aliasing settings make for legible text. However, for smaller font sizes and for certain fonts, the normal anti-aliasing settings make the text less than legible. In those cases, you can set the anti-alias type for the text field to advanced and use the gridFitType and sharpness properties to more precisely control how the text is rendered.

To enable advanced anti-alias settings for a text field, you must use embedded fonts. See Recipe 9.17 for more details on how to embed fonts.


The TextField.antiAliasType property accepts one of the flash.text.AntiAliasType constants of NORMAL (default) or ADVANCED. Set the value of the property to ADVANCED for a text field if you want to enable more precise anti-alias settings:

field.antiAliasType = AntiAliasType.ADVANCED;

The gridFitType property determines how the font outlines snap to whole pixels on the screen. The possible values are the NONE, PIXEL, and SUBPIXEL constants of the flash.text.GridFitType class. The default value of NONE means that the text does not snap to whole pixels. That can cause text to appear blurry at smaller font sizes. The PIXEL setting snaps horizontal and vertical lines of the font outlines to whole pixels on the screen. The PIXEL setting works only when text is left-aligned. If you want center- or right-aligned text to snap to pixels, use the SUBPIXEL setting.

field.gridFitType = GridTypeFit.PIXEL;

The sharpness property ranges from -400 to 400, with a default value of 0; it determines how crisply the edges of the font outlines are rendered. The lower the number, the less sharply the fonts are rendered. The greater the number, the more sharply the fonts are rendered. If the text is not legible because it appears blurry, and you've already set the gridFitType to PIXEL or SUBPIXEL, then increase the sharpness value.

See Also

Recipe 9.17




ActionScript 3. 0 Cookbook
ActionScript 3.0 Cookbook: Solutions for Flash Platform and Flex Application Developers
ISBN: 0596526954
EAN: 2147483647
Year: 2007
Pages: 351

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net