嵌入粗体字体as3

发布于 2024-12-10 14:46:03 字数 1973 浏览 0 评论 0原文

我在使用 FB4 嵌入粗体字体时遇到问题。我使用 TextLayout 字段和 TextLayoutFormat 来执行此操作,我的代码如下:

package
{
import flash.display.Sprite;
import flash.text.AntiAliasType;
import flash.text.Font;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.text.engine.FontLookup;

import flashx.textLayout.container.ContainerController;
import flashx.textLayout.elements.ParagraphElement;
import flashx.textLayout.elements.SpanElement;
import flashx.textLayout.elements.TextFlow;
import flashx.textLayout.formats.TextLayoutFormat;

public class FontEmbedding extends Sprite
{
    [Embed(source='TAHOMA.ttf', fontName='Tahoma', embedAsCFF="true")]
    private var _fontTahoma:Class;
    private const TAHOMA:String = "Tahoma";

    [Embed(source='TAHOMA.ttf', fontWeight = FontWeight.BOLD, fontName='Tahoma Bold', embedAsCFF="true")]
    private var _fontTahomBold:Class;
    private const TAHOMA_BOLD:String = "Tahoma Bold";

    public function FontEmbedding()
    {           
        this.textLayout();
    }

    private function textLayout():void
    {
        var textLayoutFormat:TextLayoutFormat = new TextLayoutFormat();
        textLayoutFormat.fontLookup = FontLookup.EMBEDDED_CFF;
        textLayoutFormat.fontFamily = TAHOMA_BOLD;
        textLayoutFormat.fontSize = 32;

        var textFlow:TextFlow = new TextFlow();
        var paragraphElement:ParagraphElement = new ParagraphElement();
        textFlow.addChild(paragraphElement);

        var span:SpanElement = new SpanElement();
        span.text = "This is an example";
        paragraphElement.addChild(span);

        textFlow.format = textLayoutFormat;

        var containerController:ContainerController = new     ContainerController(this, 400, 100);
        textFlow.flowComposer.addController(containerController);
        textFlow.flowComposer.updateAllControllers();
    }
}
}

字体仅正常显示,'fontWeight' 属性被忽略。有什么想法将不胜感激吗?

I am having trouble embedding a font as bold using FB4. I am using TextLayout fields and TextLayoutFormat to do this and my code is as follows:

package
{
import flash.display.Sprite;
import flash.text.AntiAliasType;
import flash.text.Font;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.text.engine.FontLookup;

import flashx.textLayout.container.ContainerController;
import flashx.textLayout.elements.ParagraphElement;
import flashx.textLayout.elements.SpanElement;
import flashx.textLayout.elements.TextFlow;
import flashx.textLayout.formats.TextLayoutFormat;

public class FontEmbedding extends Sprite
{
    [Embed(source='TAHOMA.ttf', fontName='Tahoma', embedAsCFF="true")]
    private var _fontTahoma:Class;
    private const TAHOMA:String = "Tahoma";

    [Embed(source='TAHOMA.ttf', fontWeight = FontWeight.BOLD, fontName='Tahoma Bold', embedAsCFF="true")]
    private var _fontTahomBold:Class;
    private const TAHOMA_BOLD:String = "Tahoma Bold";

    public function FontEmbedding()
    {           
        this.textLayout();
    }

    private function textLayout():void
    {
        var textLayoutFormat:TextLayoutFormat = new TextLayoutFormat();
        textLayoutFormat.fontLookup = FontLookup.EMBEDDED_CFF;
        textLayoutFormat.fontFamily = TAHOMA_BOLD;
        textLayoutFormat.fontSize = 32;

        var textFlow:TextFlow = new TextFlow();
        var paragraphElement:ParagraphElement = new ParagraphElement();
        textFlow.addChild(paragraphElement);

        var span:SpanElement = new SpanElement();
        span.text = "This is an example";
        paragraphElement.addChild(span);

        textFlow.format = textLayoutFormat;

        var containerController:ContainerController = new     ContainerController(this, 400, 100);
        textFlow.flowComposer.addController(containerController);
        textFlow.flowComposer.updateAllControllers();
    }
}
}

The font just displays as normal and the 'fontWeight' property is ignored. Any ideas would be gratefully received?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小苏打饼 2024-12-17 14:46:03

这段代码对我有用,无论是否使用 textLayoutFormat.fontWeight = FontWeight.BOLD; 行。

package
{
    import flash.display.Sprite;
    import flash.text.AntiAliasType;
    import flash.text.Font;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;
    import flash.text.engine.FontLookup;
    import flash.text.engine.FontWeight;

    import flashx.textLayout.container.ContainerController;
    import flashx.textLayout.elements.ParagraphElement;
    import flashx.textLayout.elements.SpanElement;
    import flashx.textLayout.elements.TextFlow;
    import flashx.textLayout.formats.TextLayoutFormat;

    public class FontEmbedding extends Sprite
    {
        [Embed(source='ChaparralPro-Bold.otf', fontWeight = FontWeight.BOLD, fontName='ChaparralPro-Bold', embedAsCFF="true")]
        private var _fontGillSans:Class;
        private const FONT_CHAP:String = "ChaparralPro-Bold";

        public function FontEmbedding()
        {           
            this.textLayout();
        }

        private function textLayout():void
        {
            var textLayoutFormat:TextLayoutFormat = new TextLayoutFormat();
            textLayoutFormat.fontLookup = FontLookup.EMBEDDED_CFF;
            textLayoutFormat.fontFamily = FONT_CHAP;
            textLayoutFormat.fontSize = 32;
            textLayoutFormat.fontWeight = FontWeight.BOLD;

            var textFlow:TextFlow = new TextFlow();
            var paragraphElement:ParagraphElement = new ParagraphElement();
            textFlow.addChild(paragraphElement);

            var span:SpanElement = new SpanElement();
            span.text = "This is an example";
            paragraphElement.addChild(span);

            textFlow.format = textLayoutFormat;

            var containerController:ContainerController = new     ContainerController(this, 400, 100);
            textFlow.flowComposer.addController(containerController);
            textFlow.flowComposer.updateAllControllers();
        }
    }
}

This code worked for me, with the line textLayoutFormat.fontWeight = FontWeight.BOLD; or not.

package
{
    import flash.display.Sprite;
    import flash.text.AntiAliasType;
    import flash.text.Font;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;
    import flash.text.engine.FontLookup;
    import flash.text.engine.FontWeight;

    import flashx.textLayout.container.ContainerController;
    import flashx.textLayout.elements.ParagraphElement;
    import flashx.textLayout.elements.SpanElement;
    import flashx.textLayout.elements.TextFlow;
    import flashx.textLayout.formats.TextLayoutFormat;

    public class FontEmbedding extends Sprite
    {
        [Embed(source='ChaparralPro-Bold.otf', fontWeight = FontWeight.BOLD, fontName='ChaparralPro-Bold', embedAsCFF="true")]
        private var _fontGillSans:Class;
        private const FONT_CHAP:String = "ChaparralPro-Bold";

        public function FontEmbedding()
        {           
            this.textLayout();
        }

        private function textLayout():void
        {
            var textLayoutFormat:TextLayoutFormat = new TextLayoutFormat();
            textLayoutFormat.fontLookup = FontLookup.EMBEDDED_CFF;
            textLayoutFormat.fontFamily = FONT_CHAP;
            textLayoutFormat.fontSize = 32;
            textLayoutFormat.fontWeight = FontWeight.BOLD;

            var textFlow:TextFlow = new TextFlow();
            var paragraphElement:ParagraphElement = new ParagraphElement();
            textFlow.addChild(paragraphElement);

            var span:SpanElement = new SpanElement();
            span.text = "This is an example";
            paragraphElement.addChild(span);

            textFlow.format = textLayoutFormat;

            var containerController:ContainerController = new     ContainerController(this, 400, 100);
            textFlow.flowComposer.addController(containerController);
            textFlow.flowComposer.updateAllControllers();
        }
    }
}
习惯成性 2024-12-17 14:46:03

应用粗体字体肯定存在问题。

如果您稍后在代码中的某个位置动态更新文本,则以下代码中的字体不会设置为粗体。

var myTextFormat:TextFormat = new TextFormat();
myTextFormat.font = "Arial";
myTextFormat.bold = true;
myTextField.setTextFormat(myTextFormat);

//
myTextField.text = "some dynamic text";

相反,您需要在每次更新文本时应用文本格式。

var myTextFormat:TextFormat = new TextFormat();
myTextFormat.font = "Arial";
myTextFormat.bold = true;

//
myTextField.text = "some dynamic text";
myTextField.setTextFormat(myTextFormat);

但是,我通常将其设置为默认字体,如下所示,

var myTextFormat:TextFormat = new TextFormat();
myTextFormat.font = "Arial";
myTextFormat.bold = true;
myTextField.defaultTextFormat = myTextFormat;

//
myTextField.text = "some dynamic text";

这不是健壮项目的完美方法,但它有效。

报告此问题,
bugs.adobe.com

There is definitely an issue with applying Bold type font.

The font is not set as BOLD with following code, if you dynamically update the text later on somewhere in the code.

var myTextFormat:TextFormat = new TextFormat();
myTextFormat.font = "Arial";
myTextFormat.bold = true;
myTextField.setTextFormat(myTextFormat);

//
myTextField.text = "some dynamic text";

Instead, you need to apply the text format each time you update the text.

var myTextFormat:TextFormat = new TextFormat();
myTextFormat.font = "Arial";
myTextFormat.bold = true;

//
myTextField.text = "some dynamic text";
myTextField.setTextFormat(myTextFormat);

But, i generally set it as default font as shown below,

var myTextFormat:TextFormat = new TextFormat();
myTextFormat.font = "Arial";
myTextFormat.bold = true;
myTextField.defaultTextFormat = myTextFormat;

//
myTextField.text = "some dynamic text";

Not a perfect way for robust project but it works.

Report this issue on,
bugs.adobe.com

疏忽 2024-12-17 14:46:03
var myFormat:TextFormat = new TextFormat();
myFormat.color = 0x000000;
myFormat.font = "Arial Bold";
myFormat.bold = true;
txt.defaultTextFormat = myFormat;
var myFormat:TextFormat = new TextFormat();
myFormat.color = 0x000000;
myFormat.font = "Arial Bold";
myFormat.bold = true;
txt.defaultTextFormat = myFormat;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文