flash.text

Class TextRenderer

Object


public class TextRenderer
extends 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. Macromedia 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



Property Summary
static maxLevel : Number
The adaptively sampled distance fields (ADFs) quality level for advanced anti-aliasing.

Properties inherited from class Object
__proto__, __resolve, constructor, prototype


Method Summary
static setAdvancedAntialiasingTable(fontName:String, fontStyle:String, colorType:String, advancedAntialiasingTable:Array) : Void
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

maxLevel Property

public static maxLevel : Number

Player version: Flash Player 8

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

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 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. This is an advanced method.

Flash Player only includes advanced anti-aliasing settings for 10 basic fonts; and for these fonts, advanced anti-aliasing settings are only provided for the font sizes from 6 to 20. For these fonts, all sizes below 6 use the settings for 6; all sizes above 20 use the settings for 20. Other fonts map to the supplied font data. The setAdvancedAntialiasingTable() method lets you set custom anti-aliasing data for other fonts and font sizes, or override the default settings for the provided fonts.

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. Macromedia Flash 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 bilevel 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.

Under most circumstances, a gamma exponent equal to 1 is adequate. However, when subpixel rendering [Liquid Crystal Display mode (LCD)], you use the gamma exponent to mitigate color fringing artifacts that occur when rendering typefaces with thin strokes (for example, Times Roman) and small point sizes. You can also use the gamma exponent to enhance contrast in both Cathode Ray Tube (CRT) and LCD modes.

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;
}