Встраивание жирного шрифта as3 - PullRequest
1 голос
/ 19 октября 2011

У меня проблемы с встраиванием шрифта как полужирного, используя 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' игнорируется.Любые идеи будут с благодарностью приняты?

Ответы [ 3 ]

1 голос
/ 19 октября 2011

Этот код работал для меня со строкой 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();
        }
    }
}
0 голосов
/ 20 января 2015
var myFormat:TextFormat = new TextFormat();
myFormat.color = 0x000000;
myFormat.font = "Arial Bold";
myFormat.bold = true;
txt.defaultTextFormat = myFormat;
0 голосов
/ 02 июля 2012

Определенно существует проблема с применением полужирного шрифта типа.

Шрифт не установлен как BOLD со следующим кодом, если вы динамически обновляете текст позже где-нибудь в коде.

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

...