嵌入字体不显示文字(as3)

问题描述 投票:1回答:1

使用flash开发。所以我从这里下载了“source sans”字体:https://fonts.google.com/specimen/Source+Sans+Pro?selection.family=Source+Sans+Pro

它有一堆ttf文件,“粗体,斜体等”我猜我只需要一个,所以我将常规文件复制到我的src文件夹,将其重命名为“SourceSansPro”,右键单击我的src文件夹并添加新字体图书馆。我把它命名为“SourceSansPro”。现在是我的代码:

主要课程:

    package
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.text.TextField;
    import flash.text.TextFormat;


    public class Main extends Sprite 
    {

        private var format:TextFormat = new TextFormat("SourceSansPro");
        private var text:TextField = new TextField;

        public function Main() 
        {
            text.embedFonts = true;
            text.setTextFormat(format);

            text.text = "abcdefg";

            addChild(text);

        }



    }

}

字体库的东西:

/**
Suggested workflow:
- create a fontLibrary subfolder in your project (NOT in /bin or /src)
- for example: /lib/fontLibrary
- copy font files in this location
- create a FontLibrary class in the same location
- one font library can contain several font classes (duplicate embed and registration code)

FlashDevelop QuickBuild options: (just press Ctrl+F8 to compile this library)
@mxmlc -o bin/SourceSansPro.swf -static-link-runtime-shared-libraries=true -noplay
*/
package 
{
    import flash.display.Sprite;
    import flash.text.Font;

    /**
     * Font library
     * @author 111
     */
    public class SourceSansPro extends Sprite 
    {
        /*
        Common unicode ranges:
        Uppercase   : U+0020,U+0041-U+005A
        Lowercase   : U+0020,U+0061-U+007A
        Numerals    : U+0030-U+0039,U+002E
        Punctuation : U+0020-U+002F,U+003A-U+0040,U+005B-U+0060,U+007B-U+007E
        Basic Latin : 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
        Latin I     : U+0020,U+00A1-U+00FF,U+2000-U+206F,U+20A0-U+20CF,U+2100-U+2183
        Latin Ext. A: U+0100-U+01FF,U+2000-U+206F,U+20A0-U+20CF,U+2100-U+2183
        Latin Ext. B: U+0180-U+024F,U+2000-U+206F,U+20A0-U+20CF,U+2100-U+2183
        Greek       : U+0374-U+03F2,U+1F00-U+1FFE,U+2000-U+206f,U+20A0-U+20CF,U+2100-U+2183
        Cyrillic    : U+0400-U+04CE,U+2000-U+206F,U+20A0-U+20CF,U+2100-U+2183
        Armenian    : U+0530-U+058F,U+FB13-U+FB17
        Arabic      : U+0600-U+06FF,U+FB50-U+FDFF,U+FE70-U+FEFF
        Hebrew      : U+05B0-U+05FF,U+FB1D-U+FB4F,U+2000-U+206f,U+20A0-U+20CF,U+2100-U+2183

        About 'embedAsCFF' attribute:
        - is Flex 4 only (comment out to target Flex 2-3)
        - is 'true' by default, meaning the font is embedded for the new TextLayout engine only
        - you must set explicitely to 'false' for use in regular TextFields

        More information:
        http://help.adobe.com/en_US/Flex/4.0/UsingSDK/WS2db454920e96a9e51e63e3d11c0bf69084-7f5f.html
        */


        [Embed(source="SourceSansPro.ttf"
        ,fontFamily  ='SourceSansPro'
        ,fontStyle   ='normal' // normal|italic
        ,fontWeight  ='normal' // normal|bold
        ,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'
        )]
        public static const fontClass:Class;

        public function SourceSansPro() 
        {
            Font.registerFont(fontClass);

        }

    }

}

所以在main中,如果text.embedFonts为false,它将显示默认字体,如果为true,它将显示为空白。

任何帮助?

编辑 - 新代码

package
{

    import flash.display.Sprite;
    import flash.events.Event;
    import flash.text.TextField;
    import flash.text.TextFormat;
    import flash.text.Font;

    public class Main extends Sprite 
    {

        private var format:TextFormat = new TextFormat("libel");
        private var text:TextField = new TextField;

        public function Main() 
        {



            [Embed(source="libel.ttf"
        ,fontFamily  ='libel'
        ,fontStyle   ='normal' // normal|italic
        ,fontWeight  ='normal' // normal|bold
        ,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'
        )]

        Font.registerFont();

            text.embedFonts = true;
            text.setTextFormat(format);

            text.text = "abcdefg";

            addChild(text);

        }



    }

}
actionscript-3 flashdevelop
1个回答
1
投票

这是你可能想要的。

package
{
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFormat;
    import flash.text.Font;

    public class Main extends Sprite 
    {
        // After the [Embed] tag you need
        // a variable definition it is linked to.
        [Embed(source="libel.ttf", fontFamily='libel')]
        private var Libel:Class;

        public function Main() 
        {
            // In order to share the font with the whole application,
            // you need to provide its class to the method.
            Font.registerFont(Libel);

            var aFormat:TextFormat = new TextFormat;

            aFormat.font = "libel";
            // ... other format properties here.

            var aField:TextField = new TextField;

            // This way you will see that
            // TextField even if fonts don't render.
            aField.border = true;

            // Setting the default text format is a good idea here.
            aField.embedFonts = true;
            aField.setTextFormat(aFormat);
            aField.defaultTextFormat = aFormat;

            aField.text = "abcdefg";

            addChild(aField);
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.