Embedding fonts for AS3. How?

爱⌒轻易说出口 提交于 2019-12-22 20:59:17

问题


I embedded font using Flash Professional CS5, but I still can't use it in my AS code. How should I embed the font to be able to use it in AS3 as well in Flash Professional CS5?


回答1:


  1. Embed the font inside your fonts.fla file. http://www.adobe.com/devnet/flash/quickstart/embedding_fonts.html

  2. Export fonts.fla to the SWC library. ( under export settings check the SWC box in Flash CS5 )

  3. Use the swc with the code!

Then you should be able to see it:




回答2:


I do something slightly more different. :D embedAsCFF should be false if you wish to use old TextFields or true of you use the new text engine.

public class Font_Arial
{

    [Embed(source   = 'Arial.ttf'
    ,fontFamily     ='_Arial_'
    ,fontStyle      = 'normal'  // normal|italic
    ,fontWeight     = 'normal'  // normal|bold
    ,mimeType       = "application/x-font-truetype"
    ,unicodeRange   = 'U+0020-U+002F,U+0030-U+0039,U+003A-U+0040,U+0041-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E'
    ,embedAsCFF     = 'false'
    )]
    private const _regular:Class;

    [Embed(source   = 'Arial_i.ttf'
    ,fontFamily     ='_Arial_'
    ,fontStyle      = 'italic'  // normal|italic
    ,fontWeight     = 'normal'  // normal|bold
    ,mimeType       = "application/x-font-truetype"
    ,unicodeRange   = 'U+0020-U+002F,U+0030-U+0039,U+003A-U+0040,U+0041-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E'
    ,embedAsCFF     = 'false'
    )]
    private const _italic:Class;

    [Embed(source   = 'Arial_b.ttf'
    ,fontFamily     ='_Arial_'
    ,fontStyle      = 'normal'  // normal|italic
    ,fontWeight     = 'bold'    // normal|bold
    ,mimeType       = "application/x-font-truetype"
    ,unicodeRange   = 'U+0020-U+002F,U+0030-U+0039,U+003A-U+0040,U+0041-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E'
    ,embedAsCFF     = 'false'
    )]
    private const _bold:Class;

    [Embed(source   = 'Arial_bi.ttf'
    ,fontFamily     ='_Arial_'
    ,fontStyle      = 'italic'  // normal|italic
    ,fontWeight     = 'bold'    // normal|bold
    ,mimeType       = "application/x-font-truetype"
    ,unicodeRange   = 'U+0020-U+002F,U+0030-U+0039,U+003A-U+0040,U+0041-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E'
    ,embedAsCFF     = 'false'
    )]
    private const _boldItalic:Class;

    public static const name:String = "_Arial_";

    public function Font_Arial()
    {
        Font.registerFont(_regular);
        Font.registerFont(_italic);
        Font.registerFont(_bold);
        Font.registerFont(_boldItalic);
    }
}

Then you can use something like

var _format:TextFormat = new TextFormat(Font_Arial.name, 16,....)

You will need to make sure the name static constant is identical to the fontFamily within the font. They are all given the same name so they all act as 1 font, the textfield will pick the correct style to use if the textfield is set to bold or italic or bold and italic or just plain old regular.

I would then make a different class for different font "sets"



来源:https://stackoverflow.com/questions/7412379/embedding-fonts-for-as3-how

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!