Setting tables for fonts

If you create fonts for use in SWF files or for distribution to Flash developers, you may need to set tables for fonts to control how they render on the Stage.

Advanced anti-aliasing uses adaptively sampled distance fields (ADFs) to represent the outlines that determine a glyph (a character). Flash uses two values:

Between these two cutoff values, the mapping function is a linear curve ranging from 0 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 0, 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, the inside cutoff has a positive value, and their midpoint lies near 0. Adjusting these parameters to shift the midpoint toward negative infinity increases the stroke weight; shifting the midpoint toward positive infinity decreases the stroke weight.

NOTE

The outside cutoff should always be less than or equal to the inside cutoff.

Flash Player includes advanced anti-aliasing settings for ten basic fonts; and for these fonts, advanced anti-aliasing settings are provided only for the font sizes from 6 to 20. For these fonts, all sizes below 6 use the settings for 6, and 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 to override the default settings for the provided fonts. For more information on creating an anti-aliasing table, see the following example:

To create an advanced anti-aliasing table for an embedded font:

  1. Create a new Flash document and save it as advancedaatable.fla.
  2. Select New Font from the Library panel pop-up menu.
  3. Select Arial from the Font pop-up menu, and then set the font size to 32 points.
  4. Select both the Bold and Italics options.
  5. Enter the font name Arial (embedded) in the Name text box and click OK.
  6. Right-click (Windows) or Control-click (Macintosh) the font symbol in the library, and select Linkage.
  7. In the Linkage Properties dialog box:
    1. Type Arial-embedded in the Identifier text box.
    2. Select Export for ActionScript and Export in First Frame.
    3. Click OK.
  8. Select Frame 1 of the main Timeline, and add the following ActionScript in the Actions panel:
    import flash.text.TextRenderer;
    var arialTable:Array = new Array();
    arialTable.push({fontSize:16.0, insideCutoff:0.516, outsideCutoff:0.416});
    arialTable.push({fontSize:32.0, insideCutoff:2.8, outsideCutoff:-2.8});
    TextRenderer.setAdvancedAntialiasingTable("Arial", "bolditalic", "dark", arialTable);
    
    var my_fmt:TextFormat = new TextFormat();
    my_fmt.align = "justify";
    my_fmt.font = "Arial-embedded";
    my_fmt.size = 32;
    
    this.createTextField("my_txt", 999, 10, 10, Stage.width-20, Stage.height-20);
    my_txt.antiAliasType = "advanced";
    my_txt.embedFonts = true;
    my_txt.multiline = true;
    my_txt.setNewTextFormat(my_fmt);
    my_txt.sharpness = 0;
    my_txt.thickness = 0;
    my_txt.wordWrap = true;
    
    var lorem_lv:LoadVars = new LoadVars();
    lorem_lv.onData = function(src:String):Void {
        if (src != undefined) {
            my_txt.text = src + "\n\n" + src;
        } else {
            trace("error downloading text file");
        }
    };
    lorem_lv.load("http://www.helpexamples.com/flash/lorem.txt");
    

    The preceding code is separated into four sections. The first section of code imports the TextRenderer class and defines a new anti-aliasing table for two different sizes of the Arial font. The second section of code defines a new TextFormat object, which you use to apply text formatting to the text field (that you create in the next section of code). The next section of code creates a new text field with a my_txt instance name, enables advanced anti-aliasing, applies the text format object (created earlier), and enables multiline text and word wrapping. The final block of code defines a LoadVars object that you use to load text from an external text file, and populate the text field on the Stage.

  9. Select Control > Test movie to test the Flash document.

    After the text loads from the remote server, Flash displays some text in the text field, and you can see the advanced anti-aliasing table properties applied to your text field. The embedded font on the Stage should appear like it has a slight blur effect because of the current insideCutoff and outsideCutoff values.