Brief situation overview:
The program allows the user to edit RichTextEditors and other classes in order to create presentable documents. The program handles printing the document so when the user wants a print preview or to actually print they select that option from the program's menu. Calling a print preview requests the printable data from all the elements in the document and puts them into formats that look more presentable (without editing controls).
Problem:
When the RichTextEditor's htmltext is retrieved it gets imported into an instance of RichText but the whitespace gets collapsed.
Example:
This (in RTE):
Table
Key Value
1 2
3 4
5 6
Becomes (in RT):
Table
Key Value
1 2
3 4
5 6
Relevant code:
if(data is String) {
var curElem:RichText = new RichText();
var importer:ITextImporter = TextConverter.getImporter(TextConverter.TEXT_FIELD_HTML_FORMAT);
curElem.textFlow = importer.importToFlow(data);
//Some curElem.textFlow leaf color and baselineShift changes
addToPage(curElem);
} else ...
What I've tried/noticed:
I have tried putting in
XML.ignoreProcessingInstructions = false;
XML.ignoreWhitespace = false;
XML.prettyPrinting = false;
and
curElem.textFlow.whiteSpaceCollapse = WhiteSpaceCollapse.PRESERVE;
before the importer.importToFlow() function gets called but it hasn't changed the results at all. Although changing the textFlow.whiteSpaceCollapse value wouldn't have done anything since the importer just creates a new textFlow (I thought I'd mention that I tried it anyway). When I tracked the values for XML that I changed during this process I made sure that they weren't getting reset to true at some point. Having said that I didn't do a depth step through the whole importToFlow() call so if it reset the values and changed them back (I don't know why it would do that) I probably wouldn't have noticed.
Sorry if I'm unclear about anything, if you need any more information then please let me know.
-Devin
Sorry I didn't mean by writing Table in there that I was indicating any html table tags, only that the example should resemble two columns that are spaced apart using space or tab characters.
To try to be more clear here is the String for data (I took out the word table):
<TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Arial" SIZE="12" COLOR="#000000" LETTERSPACING="0" KERNING="0">Key Value</FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Arial" SIZE="12" COLOR="#000000" LETTERSPACING="0" KERNING="0">1 2</FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Arial" SIZE="12" COLOR="#000000" LETTERSPACING="0" KERNING="0">3 4</FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Arial" SIZE="12" COLOR="#000000" LETTERSPACING="0" KERNING="0"></FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Arial" SIZE="12" COLOR="#000000" LETTERSPACING="0" KERNING="0">5 6</FONT></P></TEXTFORMAT>
Which should look like (as it does in the RTE):
Key Value
1 2
3 4
5 6
Looks like (in the RT):
Key Value
1 2
3 4
5 6
Also, the empty line was intentional. I wanted to add some more varied input at the time.
-Devin
Pls make your code as follows, then the whitespace will be preserved.
var format:TextLayoutFormat = new TextLayoutFormat();
format.whiteSpaceCollapse = WhiteSpaceCollapse.PRESERVE;
var config:Configuration = new Configuration();
config.textFlowInitialFormat = format;
var importer:ITextImporter = TextConverter.getImporter(TextConverter.TEXT_FIELD_HTML_FORMAT, config);
var textFlow:TextFlow = importer.importToFlow(markup);
Hello,
This doesn't seem to work for me. I'm using the 4.1 SDK.
My markup looks like: " abc".
Here are my settings:
var format:TextLayoutFormat=new TextLayoutFormat();
format.whiteSpaceCollapse=WhiteSpaceCollapse.PRESERVE;
var config:Configuration=new Configuration();
config.textFlowInitialFormat=format;
var importer:ITextImporter=TextConverter.getImporter(TextConverter.TEXT_F IELD_HTML_FORMAT,config);
But what gets shown is "abc".
this is the way to solve this bug and no need for changing any xml settings , simple and it works
exporting the textflow:
var richTextXML:xml = new XML("<"+"richTextXML"+"/>");
richTextXML.appendChild(getCdataXMl());
private function getCdataXMl():xml{
var textFlowStr:String = TextConverter.export(textFlow,TextConverter.TEXT_FIELD_HTML_FORMAT
, ConversionType.STRING_TYPE).toString();
var textFlowXMl:xml = new XMl("<![CDATA["+textFlowStr+"]]>");
return textFlowXMl;
}
importing TextFlow from XMl :
var htmlTextInStr:String = richTextXMl.text();
var importtedTextFlow:TextFlow = TextConverter.importToFlow(htmlTextInStr,TextConverter.TEXT_FIELD_HTM L_FORMAT);
textArea.textFlow = importtedTextFlow;
North America
Europe, Middle East and Africa
Asia Pacific