FlashCS5内嵌Font htmlText粗体:如何使用TLFTextField和TextConverter?
我在这个问题上纠结了很长很长的时间,这个问题已经被提出和讨论过很多次了。这项任务仍然很简单,实际上不应该花费大量的时间:用嵌入字体(Arial 除外)在文本字段中加粗一些单词。
b 标签似乎仅在使用 Flash 似乎能够识别本机粗体粗细的字体(Arial 等)时才起作用 - 但我使用的字体有 4 种粗细:常规、中等、粗体和黑色。我需要中等粗细正文文本中粗体字的黑色粗细。
我确实做了几十次测试,都失败了使用“经典”文本字段,为每个粗细嵌入一次字体并使用 htmlText:尝试了嵌入对话框中可能的所有设置,使用标签 b、span、em - 使用 TextFormat(粗体、字体) ) 或 StyleSheet (fontWeight, fontStyle, fontFamily)...
结论:没有办法在单个文本字段中设置 2 种不同的嵌入字体。
问题肯定与字体的嵌入有关,通过以下调试帮助程序函数进行确认:
/**
* Debug helper: trace embedded fonts
*/
function trace_embedded_fonts():void
{
var fonts:Array = Font.enumerateFonts();
for ( var i:int = 0; i < fonts.length; i++ )
trace( fonts[ i ].fontName + " - " + fonts[ i ].fontStyle + " - " + fonts[ i ].fontType );
}
/**
* Debug helper: Trace format
*/
function trace_classic_textfield_format( tf:TextField ):void
{
trace( "trace_tlf_textfield_format( " + tf.name + " )" );
trace( " font = " + tf.getTextFormat().font );
}
分别输出 Maven Pro - 常规 - 嵌入
(只是这一行,即使我嵌入了 4 倍的字体,一次每个重量 - 是的:我仔细地命名了它们,并尝试在 DF3 和 DF4 中导出 ActionScript,也没有导出),并在场景中的所有 textField 实例上使用 font = Maven Pro
,无论对它们应用哪种样式(也尝试选择嵌入字体 - 末尾带有 *
- 和系统字体)。
总之,字体很奇怪,但我也无能为力。
所以我的问题与新的文本布局框架(TLFTextField)有关:可以用它实现吗?
文本从 XML 加载并包含 em、b 等简单标签,但无法将它们重写为流标签。
我尝试了通过 TextConverter 类提供的转换 - 例如 var tf:TextFlow = TextConverter.importToFlow(hyperText, TextConverter.TEXT_FIELD_HTML_FORMAT);
- cf。 http://help.adobe.com/en_US/as3/dev/WS14c3067b34b57c6d4a97343b122ab36a52f-7ffb.html#WS14c3067b34b57c6d4a97343b122ab36a52f-7ff9 - 但我不明白如何设置每个标签的样式以及如何将 TextFlow 应用于已在 Flash 舞台上手动添加的 TLF 文本字段?
I've been stuck for a very, very long time on this issue, which has already been raised and discussed many times. The task is yet a simple one, and really shouldn't take the insane amount of time it already has: to bold a few words in a textfield with an embedded font (other than Arial).
The b tag only seems to work when using a font in which Flash seems to recognize the bold weight natively (Arial, etc.) - but I use a font that comes in 4 weights: regular, medium, bold, and black. I need the black weight for bold words in the medium weight body text.
I did literally dozens of tests, all failing using "classic" text fields, embedding the font once for each weight and using htmlText: tried every setting possible in the embed dialog, with tags b, span, em - with TextFormat (bold, font) or StyleSheet (fontWeight, fontStyle, fontFamily)...
Conclusion: there is NO way to set 2 different embedded fonts in a single textField.
The problem is surely linked to the embedding of the fonts, confirmed with the following debug helper functions:
/**
* Debug helper: trace embedded fonts
*/
function trace_embedded_fonts():void
{
var fonts:Array = Font.enumerateFonts();
for ( var i:int = 0; i < fonts.length; i++ )
trace( fonts[ i ].fontName + " - " + fonts[ i ].fontStyle + " - " + fonts[ i ].fontType );
}
/**
* Debug helper: Trace format
*/
function trace_classic_textfield_format( tf:TextField ):void
{
trace( "trace_tlf_textfield_format( " + tf.name + " )" );
trace( " font = " + tf.getTextFormat().font );
}
outputting respectively Maven Pro - regular - embedded
(just this single line even though I embedded 4 times the font, once per weight - and yes: I named them carefully, and I tried exporting for actionscript, in DF3 and in DF4, and also without exporting), and font = Maven Pro
on all the textField instances on the scene, whichever style is applied on them (also tried both selecting the embedded font - with *
at the end - and the system font).
In short, the font is weird, but I can't do anything about it.
So my question relates to the new Text Layout Framework (TLFTextField): can it be achieved with it ?
The text is loaded from XML and contains simple tags like em, b, etc., but rewriting them to flow tags is not an option.
I tried the conversion available via the TextConverter class - like var tf:TextFlow = TextConverter.importToFlow(hyperText, TextConverter.TEXT_FIELD_HTML_FORMAT);
- cf. http://help.adobe.com/en_US/as3/dev/WS14c3067b34b57c6d4a97343b122ab36a52f-7ffb.html#WS14c3067b34b57c6d4a97343b122ab36a52f-7ff9 - but I don't understand how to style each tag and how to apply the TextFlow to a TLF Text Field already added manually on the Flash stage ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
作为参考,我放弃了使用 TLFTextFields,并通过使用另一种字体(Flash 能够识别粗体的字体)解决了这个问题 - 这个故事的寓意是,这个问题目前是对 TextFields 的残酷限制在闪存中。
还有一件事:粗体文本在舞台上动态添加的文本字段中不起作用,除非舞台上从一开始就存在文本字段(您需要使用的每种样式)(我在舞台上留下了 2 个带有白色“测试”的文本字段)白色背景来隐藏它们)。
未来注意事项:针对此类问题制作“愤怒的电子游戏书呆子”视频。
For information, I gave up using TLFTextFields and worked around this issue by using another font (one for which Flash understands the bold) - the moral of the story is that this issue is currently a cruel limitation to TextFields in Flash.
One more thing: bold text won't work in textfields dynamically added on stage unless there already are TextFields (in each style you need to use) present on the stage from the start (I left 2 textfields with "test" in white on a white bg to hide them).
Note for the future: make videos à la "Angry Video Game Nerd" for issues like these.