Overwrite font of a range when inserting tags

General TRichView support forum. Please post your questions here
Post Reply
Toni Santa
Posts: 3
Joined: Tue Nov 14, 2006 10:42 am

Overwrite font of a range when inserting tags

Post by Toni Santa »

Hi,
I've a style (FieldStyle) with ModifyProtect = true; when inserting 'Fields' (InsertStringTag..) this style is applied first (CurTextStyleNo = noFieldStyle). Now I would have the need that the inserted 'tags' (fields) are automatically formatted with the same font as it has the position (range) where I'm inserting. How can this be applied without loosing the 'FieldStyle' of the inserted tag?
best regards
Toni
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

You cannot, because text style defines all font properties.
But you can create protected style with the desired attributes:

Code: Select all

function GetProtectedStyle(RVStyle: TRVStyle; StyleNo: Integer): Integer;
var TextStyle: TFontInfo;
begin
  TextStyle := TFontInfo.Create(nil);
  try
    TextStyle.Assign(RVStyle.TextStyles[StyleNo]);
    TextStyle.Protection := [rvprModifyProtect {,rvprDoNotAutoSwitch}];
    Result := RVStyle.TextStyles.FindSuchStyle(StyleNo, TextStyle, RVAllFontInfoProperties);
    if Result<0 then begin
      RVStyle.TextStyles.Add;
      Result := RVStyle.TextStyles.Count-1;
      RVStyle.TextStyles[Result].Assign(TextStyle);
      RVStyle.TextStyles[Result].Standard := False;
    end;
  finally
    TextStyle.Free;
  end;
end;

OldStyleNo := rve.CurTextStyleNo;
rve.CurTextStyleNo := GetProtectedStyle(rve.Style, OldStyleNo);
rve.InsertStringTag(...);
rve.CurTextStyleNo := OldStyleNo;

Post Reply