Page 1 of 1
A Question about TextStyles
Posted: Sat Mar 01, 2014 6:31 am
by mohsen24000
Hi Dear Sergey,
why we can add textstyles with same properties and why textstyles are not unique!?
and, how can i merge all textstyles with unique properties!?
thanks a lot.
Posted: Sat Mar 01, 2014 11:48 am
by Sergey Tkachenko
1. The component itself cannot provide uniqueness of text styles.
You add a style to the collection, then assign its properties. At which point should the component check if this style is unique?
If you add a new style, you must alway check if such style already exists, and reuse existing styles when possible.
The simplest way to do it is using FindTextStyle method.
For example, this code returns a text style having all properties of the current text style in rve but the specified text color. If such style does not exist, it is added.
Code: Select all
function GetColoredTextStyleNo(rve: TCustomRichViewEdit; Color: TColor): Integer;
var TextStyle: TFontInfo;
begin
TextStyle := TFontInfo.Create(nil);
TextStyle.Assign(rve.Style.TextStyles[rve.CurTextStyleNo]);
TextStyle.Color := Color;
Result := rve.Style.FindTextStyle(TextStyle);
TextStyle.Free;
end;
2. The simplest way to merge styles with identical properties is loading document using InsertRVFFromStream instead of LoadRVF/LoadRVFFromStream.
If RVFTextStylesReadMode=rvf_sInsertMerge, identical text styles will be mapped to the same style.