locked
RichEditBox does strange things to RTF input and adds extra line endings to paragraphs.

    Question

  • Hello All,

    I'm currently having an issue with RichEditBox's interpretation of the RTF string that I feed it. I try to feed it the following string with SetText and TextGetOptions.FormatRtf (new lines added for easier reading):

    {\rtf1\ansi\deff0{\fonttbl{\f0 Arial;}}{\colortbl;}
    {\pard \b Japanese folklore\b0 encompasses the folk traditions of Japan and the Japanese people.\par}
    {\pard In Japanese, the term \i minkan densh\u333;\i0 (\u27665;\u38291;\u20253;\u25215;, \i "transmissions among the folk"\i0 )
    is used to describe folklore; the study of folkloristics is known as \i minzokugaku\i0 (\u27665;\u20439;\u23398;). Folklorists
    also employ the term \i minzoku shiry\u333;\i0 (\u27665;\u20439;\u36039;\u26009;) or "folklore material"
    (\u27665;\u20439;\u36039;\u26009;) to refer to objects and arts they study.\par}}


    However, when the RichEditBox displays the text, there is a noticeable new line added at the very end of the document. I inspected the rtf that RichEditBox made by using GetText and TextGetOptions.FormatRtf, and the following is produced:

    {\rtf1\fbidis\ansi\ansicpg1252\deff0\nouicompat\deflang1033{\fonttbl{\f0\fnil\fcharset0 Arial;}{\f1\fnil Arial;}{\f2\fnil\fcharset238 Arial;}{\f3\fnil\fcharset134 Meiryo UI;}}
    {\colortbl ;\red0\green0\blue0;}
    {\*\generator Riched20 6.3.9600}\viewkind4\uc1 
    \pard\ltrpar\b\fs24 Japanese folklore\b0  encompasses the folk traditions of Japan and the Japanese people.\par
    \f1 In Japanese, the term \i minkan densh\f2\u333?\i0  (\f3\'c3\'f1\'e9\'67\'81\'bb\'b3\'d0, \i "transmissions among the folk"\i0 ) is used to describe folklore; the study of folkloristics is known as \i minzokugaku\i0  (\'c3\'f1\'cb\'d7\'d1\'a7). Folklorists also employ the term \i minzoku shiry\f2\u333?\i0  (\f3\'c3\'f1\'cb\'d7\'d9\'59\'c1\'cf) or "folklore material" (\'c3\'f1\'cb\'d7\'d9\'59\'c1\'cf) to refer to objects and arts they study.\par
    
    \pard\ltrpar\tx720\cf1\fweight200\f1\par
    }

    As you can see, my second \pard tag has been removed and visually the two paragraphs merged, albeit with the second paragraph now on a new line. Also, a random new line is entered here and a strange new paragraph is created.

    Is there a way to remove this extra text from the textbox itself so it doesn't visually show up and is there a way to get it to not merge my two paragraphs? This text is being fed back to the RichEditBox on every opening of the app, so this results in new lines being added every time the app is opened.

    Please let me know if you need any more information, and thanks!


    • Edited by John Goen Friday, March 06, 2015 11:12 PM Formatting
    Friday, March 06, 2015 11:10 PM

Answers

  • Different RTF engines will deal with the RTF differently. As you can see from the generated RTF, RichEditBox is using a version from an old lineage (generator Riched20 6.3.9600) and won't have the capabilities of current versions of Word.

    There isn't anything straightforward you can do to change how the editor interprets or generates RTF.

    The extra line at the end appears in the display for initial RTF as well: the editor adds a blank line for further entry. Knowing that exists you could trim whitespace from the end of the RichEditBox either when reading in or when saving out.

    Friday, March 13, 2015 1:56 AM
    Owner

All replies

  • It is not expected that you'll get the same RTF out of a RTF control that you put in. The original RTF is not saved when it is interpreted, only the results, and then new RTF is generated when it is read out.

    How are you setting this RTF into the RichEditBox? I suspect that is where the extra line is added.

    Saturday, March 07, 2015 2:14 AM
    Owner
  • Sorry for the delayed reply, but I'm setting the RTF with the following command:

    richBlock.Document.SetText(TextSetOptions.FormatRtf, richText);

    Where richBlock is my RichEditBox and richText is my RTF formatted string.

    On the expected behavior, I understand that my RTF is not saved, but I am unsure why it is taking shortcuts with interpreting my RTF and refusing to convert my two \pard delimited paragraphs into two separate formatted paragraphs and instead is making them a single paragraph with only a newline separating them.

    Tuesday, March 10, 2015 5:51 PM
  • Different RTF engines will deal with the RTF differently. As you can see from the generated RTF, RichEditBox is using a version from an old lineage (generator Riched20 6.3.9600) and won't have the capabilities of current versions of Word.

    There isn't anything straightforward you can do to change how the editor interprets or generates RTF.

    The extra line at the end appears in the display for initial RTF as well: the editor adds a blank line for further entry. Knowing that exists you could trim whitespace from the end of the RichEditBox either when reading in or when saving out.

    Friday, March 13, 2015 1:56 AM
    Owner