10 Replies Latest reply on Apr 9, 2012 11:16 AM by azeem878

    Preserving whitespace when importing an html String into a RichText

    Devin Warren

      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).



           When the RichTextEditor's htmltext is retrieved it gets imported into an instance of RichText but the whitespace gets collapsed.



      This (in RTE):


           Key     Value

           1         2

           3         4


           5         6


      Becomes (in RT):


           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



           } else ...


      What I've tried/noticed:

           I have tried putting in

                XML.ignoreProcessingInstructions = false;

                XML.ignoreWhitespace = false;

                XML.prettyPrinting = false;


                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.