嵌入粗体字体as3
我在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这段代码对我有用,无论是否使用
textLayoutFormat.fontWeight = FontWeight.BOLD;
行。This code worked for me, with the line
textLayoutFormat.fontWeight = FontWeight.BOLD;
or not.应用粗体字体肯定存在问题。
如果您稍后在代码中的某个位置动态更新文本,则以下代码中的字体不会设置为粗体。
相反,您需要在每次更新文本时应用文本格式。
但是,我通常将其设置为默认字体,如下所示,
这不是健壮项目的完美方法,但它有效。
报告此问题,
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.
Instead, you need to apply the text format each time you update the text.
But, i generally set it as default font as shown below,
Not a perfect way for robust project but it works.
Report this issue on,
bugs.adobe.com