A Question about TextStyles

General TRichView support forum. Please post your questions here
Post Reply
mohsen24000
Posts: 75
Joined: Fri Jan 06, 2012 8:13 pm

A Question about TextStyles

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
Post Reply