Skip navigation
Currently Being Moderated

Preserving whitespace when importing an html String into a RichText

Apr 27, 2011 11:39 AM

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

 
Replies
  • Currently Being Moderated
    Apr 27, 2011 7:24 PM   in reply to Devin Warren

    Firstly, TLF now does not support *Table*. If you import an html string including <tr> <td>, those tags will be ignored and all the data in <td> and <tr> will be showed in one line.

     

    If you meet some other problems,  pls attach the html string you import.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 27, 2011 10:21 PM   in reply to Devin Warren

    It seems a bug. Let us double check it.

     
    |
    Mark as:
  • Currently Being Moderated
    May 2, 2011 6:47 PM   in reply to Devin Warren

    I have logged a bug of TEXT_FIELD_HTML_FORMAT importer.

    Thanks for your report.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 31, 2011 9:07 PM   in reply to Jin-Huang

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

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 12, 2011 1:06 AM   in reply to Jin-Huang

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

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 12, 2011 2:24 AM   in reply to BogdanMarian

    It works for me... I think you need at least TLF 2.0.0.232.

    Our fixes will only be in the new version.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 16, 2011 2:06 AM   in reply to Jin-Huang

    Hi,

     

    Sorry for the dumb question, but how do I find out what the exact version of my TLF is?

     

    Thank you.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 16, 2011 2:49 AM   in reply to BogdanMarian

    Have a look at \frameworks\rsls folder under the Flex SDK you are using.

    In SDK 4.5, there is a textLayout_2.0.0.232.swf. It means build 232 of TLF 2.0.

     

    PS:

    In some old threads of this forum, there are methods about how to replace TLF lib in Flex SDK.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 9, 2012 11:16 AM   in reply to Devin Warren

    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;

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points