LoadFromStream RTF is losing font info (default attributes)

  • Hi Julian,

    I'm iterating through the text in a wpRichText component and picking out the various bits of info, including all the font properties on a par by par and char by char basis as follows:

    This works fine if you call the conversion routine for text you've just typed into the editor. If you save it to stream without specifying a format and then load it from that stream there is a problem which I describe below. If you save the stream as wptools format there is no problem.

    The problem is with the par.charattr[i]. If you query this it return the size of the font as 0. LoadToStream without format doesn't seem to be formatting the text properly or refreshing the richtext properly. I've tried refresh and reformatall but these don't help.

    It's not an immediate problem for me, but I thought you might want to know so you can have a look at this.

    Cheers,

    Mark

    • Offizieller Beitrag

    Hi,

    the RTF reader reduces the loaded information after loading the text. In fact it removes all information which is redundant. This is the font name and size of the default font (DefaultAttr) and the font/size defined in an attached paragraph style.

    This special handling should work reliable but you need to be prepared that it is inplace. You can disable it by defining compiler symbols DONT_FIX_STYLES and DONT_FIX_DEFSTYLE (used by unit ReadRTF).
    I do not suggest to enable this defines in general!

    The mentioned handling is crucial for the usability of paragraph styles since attributes from the styles will be only used if not overridden on a higher level, i.e. by the character attributes.

    Since RTF does not differentiate between redundant (automatic) and important (manually defined) attributes the fix has to be performed by the RTF reader.

    So, no bug here :-)

    • Offizieller Beitrag

    It is not so complicated,

    if you have a RTF file which uses a style sheet, say

    {\s1\f1 name}

    and that style sheet is used by a paragraph, in RTF code the font will be also set in that paragraph

    \par\plain\s1\f1 some text\par

    So all characters in the paragraph also define the font '1'

    If you now change the style sheet to use a different font you will not see a change because the \f1 overrides any font change in the style. (You can change the color, the size etc, but not the font)

    To solve this problem the RTF reader removes the \f1 from the paragraph since \f1 is already defined in the style (GetFont will return FALSE). So if the style defines a different font the change is visible at once since the font is not overridden.

    I hope this helps,

    Julian