Skip to main content
Participant
August 20, 2008
Answered

Line breaks ignored when using HTML text CSS and embedded fonts

  • August 20, 2008
  • 1 reply
  • 1523 views
Anyone come accross this.
When using a StyleSheet with html text in a dynamic textfield with embedded fonts line breaks are ignored. It is as if TextField.condenseWhite is being set to true. Essentially the <p> tags are being treated as a <br/> tag.

If I dont embed fonts it works fine. Another weird thing is if i add an empty paragraph <p></p> between the first two paragraphs it makes any subsequent paragraph behave correctly. e.g.

<p>first paragraph text here</p>
<p>second paragraph text here</p>
<p>third paragraph text here</p>

displays as if there are <br/> between each one.

But

<p>first paragraph text here</p>
<p></p>
<p>second paragraph text here</p>
<p>third paragraph text here</p>

behaves correctly even for the third paragraph.

Here is the code i am working with (using XML as i am dynamically populating the textfield from XML)

any help much appreciated

UPDATE:
After reading http://www.kirupa.com/forum/showthread.php?t=307326
i tried the same experiment using a TF drawn in the IDE, the results for each, even though the TextFields are essentially the same are totally different.

updated CODE accordingly - just need a TF on stage, called "ideTextField" with font 'Arial'



This topic has been closed for replies.
Correct answer moonface-Lz59CC
OK,
I have given up messing with stylesheets, trying display: block, inline, different ways of formatting the XML, messing with XML.ignoreWhiteSpace, and XML.prettyPrinting etc.

I went down the route of encodeURI, using a RegExp to strip out all tabs, linefeeds and carriage returns. This now gives consistent results for all situations, even embedded and none embedded fonts.

e.g.
_text:String = TEXT FROM XML, HTML TEXT etc

var st:String = encodeURI(_text);

var pattern:RegExp = /(%09)+|(%0A)+|(%0D)+/g;

st = st.replace(pattern, "");
st = decodeURI(st);

YOUTEXTFIELD.htmlText = st;


The <p> tags still behave as a <br/> tag, but you can add an extra <br/> to simulate a paragraph.

Here is the example again with the updates,



Hope this helps someone

1 reply

moonface-Lz59CCAuthorCorrect answer
Participant
September 4, 2008
OK,
I have given up messing with stylesheets, trying display: block, inline, different ways of formatting the XML, messing with XML.ignoreWhiteSpace, and XML.prettyPrinting etc.

I went down the route of encodeURI, using a RegExp to strip out all tabs, linefeeds and carriage returns. This now gives consistent results for all situations, even embedded and none embedded fonts.

e.g.
_text:String = TEXT FROM XML, HTML TEXT etc

var st:String = encodeURI(_text);

var pattern:RegExp = /(%09)+|(%0A)+|(%0D)+/g;

st = st.replace(pattern, "");
st = decodeURI(st);

YOUTEXTFIELD.htmlText = st;


The <p> tags still behave as a <br/> tag, but you can add an extra <br/> to simulate a paragraph.

Here is the example again with the updates,



Hope this helps someone