我无法使用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'
属性被忽略。会不会有任何想法?
答案 0 :(得分:1)
此代码适用于我,行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();
}
}
}
答案 1 :(得分:0)
应用粗体类型字体肯定存在问题。
如果您稍后在代码中的某处动态更新文本,则字体不会设置为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
答案 2 :(得分:-1)
var myFormat:TextFormat = new TextFormat();
myFormat.color = 0x000000;
myFormat.font = "Arial Bold";
myFormat.bold = true;
txt.defaultTextFormat = myFormat;