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.
A Question about TextStyles
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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.
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.
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;
If RVFTextStylesReadMode=rvf_sInsertMerge, identical text styles will be mapped to the same style.