Packageflash.text
Classpublic class TextRenderer
InheritanceTextRenderer Inheritance Object

Player version: Flash Player 8

The TextRenderer class provides functionality for the advanced anti-aliasing capability of embedded fonts. Advanced anti-aliasing allows font faces to render at very high quality at small sizes. Use advanced anti-aliasing with applications that have a lot of small text. Adobe does not recommend using advanced anti-aliasing for very large fonts (larger than 48 points). Advanced anti-aliasing is available in Flash Player 8 only.

To set advanced anti-aliasing on a text field, set the antiAliasType property of the TextField instance. The following example requires a shared font in the library with a linkage identifier named, "CustomFont".

var txtFormat:TextFormat = new TextFormat();
txtFormat.font = "CustomFont";

var label:TextField = this.createTextField("label", this.getNextHighestDepth(), 10, 10, 200, 20);
label.setNewTextFormat(txtFormat);
label.text = "Hello World";
label.embedFonts = true;
label.antiAliasType = "advanced";

Advanced anti-aliasing provides continuous stroke modulation (CSM), which is continuous modulation of both stroke weight and edge sharpness. As an advanced feature, you can use the setAdvancedAntialiasingTable() method to define settings for specific typefaces and font sizes.

See also

TextField.antiAliasType


Public Properties
 Property
  displayMode : String
[static]Controls the rendering of advanced anti-aliased text.
  maxLevel : Number
[static]Sets the adaptively sampled distance fields (ADFs) quality level for advanced anti-aliasing.
 Properties inherited from class Object
 __proto__, __resolve, constructor, prototype
Public Methods
 Method
  
setAdvancedAntialiasingTable(fontName:String, fontStyle:String, colorType:String, advancedAntialiasingTable:Array):Void
[static]Sets a custom continuous stroke modulation (CSM) lookup table for a font.
 Methods inherited from class Object
 addProperty, hasOwnProperty, isPropertyEnumerable, isPrototypeOf, registerClass, toString, unwatch, valueOf, watch
Property detail
displayModeproperty
public static var displayMode:String

Language version: ActionScript 2.0
Player version: Flash Player 9

Controls the rendering of advanced anti-aliased text. The visual quality of text is very subjective, and while Flash Player tries to use the best settings for various conditions, designers may choose a different look or feel for their text. Also, using displayMode allows a designer to override Flash Player's subpixel choice and create visual consistency independent of the user's hardware.

The following values for displayMode allow the designer to set the global subpixel rendering mode for advanced anti-aliasing:

Note: While this property is available for ActionScript 2.0, you can use it only when publishing to Flash Player 9 or later.

maxLevelproperty 
public static var maxLevel:Number

Player version: Flash Player 8

Sets the adaptively sampled distance fields (ADFs) quality level for advanced anti-aliasing. The only acceptable values are 3, 4, and 7. The default is 4.

Advanced anti-aliasing uses ADFs to represent the outlines that determine a glyph. The higher the quality, the more cache space is required for ADF structures. A value of 3 takes the least amount of memory and provides the lowest quality. Larger fonts require more cache space; at a font size of 64 pixels, the quality level increases from 3 to 4 or from 4 to 7 unless the level is already set to 7.


Example
The following example specifies the maxLevel value for the entire SWF file, and then displays a text field with the value set. For the text in this example to display correctly, there must be a font symbol available with a linkage identifier of "CustomFont".
import flash.text.TextRenderer;
TextRenderer.maxLevel = 3;

var txtFormat:TextFormat = new TextFormat();
txtFormat.font = "CustomFont";
txtFormat.size = 64;

var label:TextField = this.createTextField("label", this.getNextHighestDepth(), 10, 10, 500, 100);
label.setNewTextFormat(txtFormat);
label.text = "Hello World";
label.embedFonts = true;
trace("TextRenderer.maxLevel: " + TextRenderer.maxLevel);

Method detail
setAdvancedAntialiasingTable()method
public static function setAdvancedAntialiasingTable(fontName:String, fontStyle:String, colorType:String, advancedAntialiasingTable:Array):Void

Player version: Flash Player 8

Sets a custom continuous stroke modulation (CSM) lookup table for a font. Flash Player attempts to detect the best CSM for your font. If you are not satisfied with the CSM that the Flash Player provides, you can customize your own CSM by using the setAdvancedAntialiasingTable() method.

Parameters
fontName:String — The name of the font for which you are applying settings.
 
fontStyle:String — The font style can be "bold", "bolditalic", "italic", and "none".
 
colorType:String — This value can be either "dark" or "light".
 
advancedAntialiasingTable:Array — An array of CSM settings for the specified font. Each setting is an object with the following properties:
  • fontSize
  • insideCutOff
  • outsideCutOff

The advancedAntialiasingTable array can contain multiple entries that specify CSM settings for different font sizes. (See example.)

The fontSize is the size, in pixels, for which the settings apply.

Advanced anti-aliasing uses adaptively sampled distance fields (ADFs) to represent the outlines that determine a glyph. Adobe Flash Player uses an outside cutoff value (outsideCutOff), below which densities are set to zero, and an inside cutoff value (insideCutOff), above which densities are set to a maximum density value (such as 255). Between these two cutoff values, the mapping function is a linear curve ranging from zero at the outside cutoff to the maximum density at the inside cutoff.

Adjusting the outside and inside cutoff values affects stroke weight and edge sharpness. The spacing between these two parameters is comparable to twice the filter radius of classic anti-aliasing methods; a narrow spacing provides a sharper edge, while a wider spacing provides a softer, more filtered edge. When the spacing is zero, the resulting density image is a bi-level bitmap. When the spacing is very wide, the resulting density image has a watercolor-like edge.

Typically, users prefer sharp, high-contrast edges at small point sizes, and softer edges for animated text and larger point sizes.

The outside cutoff typically has a negative value, and the inside cutoff typically has a positive value, and their midpoint typically lies near zero. Adjusting these parameters to shift the midpoint toward negative infinity increases the stroke weight; shifting the midpoint toward positive infinity decreases the stroke weight. Make sure that the outside cutoff value is always less than or equal to the inside cutoff value.


Example
The following example creates two anti-alias entries and two text fields to illustrate them. For this example to work, the SWF file must have a shared font embedded with a linkage identifier of "myArial". To embed the font, follow these steps:
  1. Open your Library.
  2. Click the Library options menu in the upper-right corner of the Library.
  3. Select New Font from the pop-up menu.
  4. Name the font myArial.
  5. Select Arial from the font pop-up menu.
  6. Click OK.
  7. Right-click the newly created font, and select Linkage.
  8. Select the Export for ActionScript check box.
  9. Click OK to accept the default identifier, myArial.
import flash.text.TextRenderer;

var antiAliasEntry_1 = {fontSize:24, insideCutoff:1.61, outsideCutoff:-3.43};
var antiAliasEntry_2 = {fontSize:48, insideCutoff:0.8, outsideCutoff:-0.8};
var arialTable:Array = new Array(antiAliasEntry_1, antiAliasEntry_2);

var lbl_1:TextField = createLabel(0, 0, 300, 100, 24);
var lbl_2:TextField = createLabel(0, 100, 300, 100, 48);

TextRenderer.setAdvancedAntialiasingTable("Arial", "none", "dark", arialTable);

function createLabel(x:Number, y:Number, width:Number, height:Number, fontSize:Number):TextField {
    var depth:Number = this.getNextHighestDepth();
    
    var tmpTxt = this.createTextField("txt_" + depth, depth, x, y, width, height);
    tmpTxt.antiAliasType = "advanced";
    tmpTxt.gridFitType = "pixel";
    tmpTxt.border = true;
    tmpTxt.text = "Hello World";
    tmpTxt.embedFonts = true;
    tmpTxt.setTextFormat(getTextFormat(fontSize));
    return tmpTxt;
}

function getTextFormat(fontSize:Number):TextFormat {
    var tf:TextFormat = new TextFormat();
    tf.align = "center";
    tf.size = fontSize;
    tf.font = "myArial";
    return tf;
}