2
votes

I have a dynamic textfield which uses html text loaded form an XML file:

XML:

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

As you can see, this uses regular and italic. I have embedded my font in all it's varieties, every single glyph, but the italic text isn't showing. My AS3:

Font var: private var regularFont:Font = new myFontRegular();

myFontRegular is embedded using the embedding dialogue, but is set to regular, not italic.

Textfield formatting: bodyFormat.font = regularFont.fontName;

To set up the textfield:

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

I then set the textfield to htmlText and give it content:

bodyField.htmlText = pageBody;

pageBody is a var that is fed from the XML.

OK, so that's set up but italic text doesn't show, which I guess is because the embedded font is set to regular, not italic. So how can I use italic half way through a sentence for example? I've Googled and tried various methods to embed the font directly in code, same problem.

This has worked fine for me before, I don't understand what is wrong with this. If I need to post more, please let me know.

Thanks.

1
Without the CDATA tags an <i> and </i> are behaving like line breaks.mrEmpty
It seems if I don't embed the fonts in code, they work.mrEmpty
if you don't embed, it is using device fonts, if you're using a common font like arial, then likely everyone has the font and it will look fine, but you do risk people not seeing the font the same way.Daniel

1 Answers

2
votes

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