Font Symbols

In the introduction we described how fonts can be applied to text fields and how their characters can be embedded for portable playback. In addition to using system fonts in TextField properties, Flash Studio allows artists to define new font symbols by right-clicking on the library and selecting the “New Font…” item, which displays the following dialog:

Font symbols created this way are added to the library of the FLA file and can later be applied to text fields similar to regular system fonts. For example, if you named your game font “$FixedFont”, you should be able to select that name as a valid font for your TextField.

Adding font names to the library has a benefit of identifying the fonts used in a unique way. When library fonts are displayed in the font list, they will have a star next to them, as in “\(ArialGame*”. If artists only use font names from the library, it will help ensure that other fonts are not referenced in the UI files by mistake. Furthermore, if all fonts’ symbols are named starting with the dollar sign character ‘\)’, they will always show up at the top of the font list in TextField properties, helping development.

A number of websites recommend using the underscore ‘_’ character as a prefix for font symbol names. Although underscore looks cleaner, using it will cause the text field “Font rendering method” selection box to break, since Flash Studio will treat any font name that starts with an underscore as a built-in font. To avoid this problem, we pick the dollar sign character in our examples instead.

Exporting and Importing Font Symbols

Much like other library entries, fonts’ symbols located in an FLA file can be used in other files by either copying their content or relying on the import/export mechanism. To copy a library symbol, right-click on the source FLA library and select “Copy”; after that is done, switch to the target FLA files library, right click on it and select “Paste”. A copy of a symbol will be created, with all of its data content duplicated in the second file.

In order to avoid data duplication, an export/import mechanism can be used in Flash. To export a library symbol, developers can right-click on it and select “Properties” and select “ActionScript” tab, which will display the following properties sheet:

By pressing “OK” button Flash will warn about absence of definition for the class, it is safe to ignore this warning message.

When exporting a symbol, you give it an export identifier and mark it with “Export for runtime sharing”, “Export for ActionScript” and “Export in first frame” flags. It is recommended that you set the import identifier to be the same as the symbol name. The URL should specify the path to this SWF file that will be used when this symbol is imported; if the font symbol is going to be substituted through a GFx::FontLib object, the URL field should be set to your default font library. We will use “fonts_en.swf” as a default name in this document; however, any other name can be used. Please note that you must set the default font library in GFx to use font substitution. For example

Loader.SetDefaultFontLibName(“fonts_en.swf”);

You can set the default font library for the GFxPlayer you in the fonconfig.txt

fontlib "fonts_en.swf"

The first fontlib appearance will be used as the default library

Once a symbol is exported, it will be marked with an “Export: $identifier” label in the library “AS Linkage” column. If the Copy / Paste or drag and drop operations are applied to an imported library symbol, they will no longer make a copy of it but will rather create an import link in the target file. This means that the target file will be smaller and when it is loaded into memory it will pull its imported data from the source SWF. In Scaleform, imported SWF data will be loaded only once even if it is imported from multiple files, potentially saving a significant amount of system memory.

Font symbol names will not be returned as a part of the TextField.htmlText string or as a font name in TextFormat; the original system font name, such as “Arial” will be returned instead. Similarly, symbol names cannot be assigned through ActionScript unless they match import names for an exported font (not recommended).

Exported Fonts and Character Embedding

Up to version CS4 Flash Studio did not allow to specify which characters to embed for exported fonts. Instead, the character set to be embedded was determined by the system locale setting. On Windows, this was controlled by the “Language for non-Unicode programs” setting in the Control Panel\Regional and Language Options\Advanced panel. If the language was set to “English”, only 243 glyphs were exported for every font. If Korean language was selected, 11,920 characters were exported. Clearly this was not convenient for game development, and therefore the whole approach with ‘gfxfontlib.swf’ was created.

Fortunately, starting from Flash CS5, it is possible to specify which glyphs to be exported and therefore ‘gfxfontlib.swf’ is not necessary anymore. Instead, developer can create language specific font libraries (such as ‘fonts_en.swf’, ‘fonts_jp.swf’, etc) and directly specify which glyphs should be embedded in each of them.

However, if CS4 Flash Studio (or older) is still used you must use the ‘gfxfontlib.swf’ approach (it is still supported thought not recommended in the current version). Refer to older revision of this document for GFx 4.0 and below for further details about the approach.