Page 1 of 1

StyleLoadingMode in TRichViewXML

Posted: Mon Dec 10, 2007 1:55 pm
by martindholmes
Hi there,

I'm working with RVXML, and trying to figure out how to get this to happen:

1. Save styles in the XML (this works fine).

2. Reload styles from the XML in such a way that if they're standard styles, they DON'T overwrite the standard styles in the TRVStyle component, but when they're non-standard styles, they load.

The problem I'm having is this:

Let's say I have two standard styles 0 and 1, called "NormalText" and "Hyperlink". Then I have a bit of bold text, which is based off style 0 but has bolding. Then the output XML looks like this:

<font backcolor="clWhite" color="clBlack" fontname="Arial Unicode MS" name="NormalText" unicode="1"></font>

<font color="clBlue" fontname="Arial Unicode MS" jump="1" hovercolor="clRed" nextstyleno="0" underline="1" name="Hyperlink" unicode="1"></font>

<font standard="0" italic="1" unicode="1"></font>

Now, in the application, the standard styles are changed such that the font for style 0 becomes Times New Roman. When the document is loaded back in, the base text DOES become Times New Roman, but the bolding is lost. This happens if I use

StyleLoadingMode = slmMap

If I use

StyleLoadingMode = slmMerge

then the text comes in as Arial Unicode MS, and not as Times New Roman. I'm not really sure from the documentation exactly what slmMap and slmMerge are supposed to do. Shouldn't slmMap map all standard styles to the existing styles in the TRVStyle, but also load any non-standard styles based on them? That doesn't seem to be happening.

Cheers,
Martin

Posted: Thu Dec 13, 2007 1:07 pm
by martindholmes
I've done some further investigation into this, and it looks as though some code may be missing from RVStyle.pas:

When RVXML tries to merge styles using slmMerge, it calls RVStyle.TextStyles.MergeWith, passing rvs_merge_SmartMerge as the MergeMode.

The comments at the head of RVStyle.TextStyles.MergeWith say this:
* in rvs_merge_SmartMerge mode:
- the method tries to map the style to the style with the same index,
if possible;
- IsSimpleEqualEx method of items is used;
IsSimpleEqualEx is called for each style as it's added to the list, to determine if it should be added, or if it should be mapped to an existing style. However, IsSimpleEqualEx simply returns false, as far as I can see:
function TCustomRVInfo.IsSimpleEqualEx(Value: TCustomRVInfo; Mapping: TRVIntegerList): Boolean;
begin
Result := False;
end;
Am I misunderstanding here? It seems to me that:
  • IsSimpleEqualEx should be comparing the styles to see if they should be mapped;

    If the style is a standard style, and the new style has the same name, then it should be mapped (this would be what I understand by "merging" styles).
Sergey, what am I missing here?

All help appreciated,
Martin