2

我有一个动态文本字段,它使用从 XML 文件加载的 html 文本:

XML:

<someText><![CDATA[I am <i>some</i> text.]]></someText>

如您所见,这使用常规和斜体。我已经将我的字体嵌入到它的所有品种中,每一个字形,但斜体文本没有显示。我的 AS3:

字体变量:private var regularFont:Font = new myFontRegular();

myFontRegular 使用嵌入对话框嵌入,但设置为常规,而不是斜体。

文本字段格式:bodyFormat.font = regularFont.fontName;

要设置文本字段:

bodyField.embedFonts = true;
bodyField.defaultTextFormat = bodyFormat;
bodyField.multiline = true;
bodyField.wordWrap = true;
bodyField.antiAliasType = "advanced";
bodyField.selectable = false;

然后我将文本字段设置为 htmlText 并为其提供内容:

bodyField.htmlText = pageBody;

pageBody 是一个从 XML 提供的 var。

好的,这样就设置好了,但斜体文本没有显示,我猜这是因为嵌入的字体设置为常规字体,而不是斜体。那么,例如,如何在句子中使用斜体?我已经用谷歌搜索并尝试了各种方法将字体直接嵌入代码中,同样的问题。

这对我来说以前很好用,我不明白这有什么问题。如果我需要发布更多内容,请告诉我。

谢谢。

4

1 回答 1

2

it is better to use proper setup of the embedded font, you should use the familyName to give a name of the font famiy set (it will be the same for italic, bold and normal) like below:

    [Embed(source="asset/arial.ttf",
        fontFamily = "Arial",
        unicodeRange = "U+0009,    U+00A9,U+00AE,U+00B0,U+00B7,U+00A3,U+00A7,    U+0021-U+002F,    U+003A-U+0040,     U+005B-U+0060,      U+007B-U+007D,       U+00A0,      U+00B4,       U+0030-U+0039,      U+0041-U+005A,      U+0061-U+007A,     U+00B4,U+2032,U+2033,U+2019,U+2013, U+00E9,U+00C9, U+2022, U+2026",
        mimeType="application/x-font-truetype",
        embedAsCFF="false"
        )]
    private var arialImported:Class;
    [Embed(source="asset/arialbd.ttf",
        fontFamily = "Arial",
        fontWeight = "bold",
        unicodeRange = "U+0009,    U+00A9,U+00AE,U+00B0,U+00B7,U+00A3,U+00A7,    U+0021-U+002F,    U+003A-U+0040,     U+005B-U+0060,      U+007B-U+007D,       U+00A0,      U+00B4,       U+0030-U+0039,      U+0041-U+005A,      U+0061-U+007A,     U+00B4,U+2032,U+2033,U+2019,U+2013, U+00E9,U+00C9, U+2022",
        mimeType="application/x-font-truetype",
        embedAsCFF="false"
        )]
    private var arialBoldImported:Class

then it should work e.g. bodyFormat.font = "myFontFamilyName";, but I feel that also you need to have stylesheet object applied and wrap everything (content) with P tag

var m_oStylesheet = new StyleSheet();
m_oStylesheet.parseCSS("P{font-family:myFontFamilyName; }");
bodyField.styleSheet = m_oStylesheet;

You may also look at this entry about StyleSheet

best regards

于 2012-09-05T13:48:21.797 回答