<< Click to display table of contents >> TRVStyleTemplate.ApplyToTextStyle |
Changes properties of ATextStyle according to the properties of this style template.
procedure ApplyToTextStyle(ATextStyle: TCustomRVFontInfo;
ParaStyleTemplate: TRVStyleTemplate);
The method changes only properties of ATextStyle not listed in ATextStyle.ModifiedProperties. If you want to change all properties, assign ATextStyle.ModifiedProperties=[] before calling this method. If you want to change only properties controlled by style templates, call UpdateModifiedTextStyleProperties before calling this method.
Applying a style template means applying properties of its TextStyle listed in ValidTextProperties, and properties inherited from Parent.
Kind of this style template must be either rvstkText or rvstkParaText.
Up to two style templates can be applied to ATextStyle: this style template and ParaStyleTemplate. This style template has a higher priority than ParaStyleTemplate: if some property is defined both in this style template and in ParaStyleTemplate, properties of this style template are applied. Both this style template and ParaStyleTemplate may be nil.
The sequence of operations:
1.The method applies this style template (and its parents) to ATextStyle. The method assigns ATextStyle.StyleTemplateId = Id. This method may be called for nil-objects; in this case, it just assigns ATextStyle.StyleTemplateId = -1.
2.Then it applies ParaStyleTemplate (if not nil) to remaining properties. The method does NOT assign ATextStyle.ParaStyleTemplateId.
3.Then it resets remaining properties of ATextStyle to default values.
Example: inserting a hyperlink in rve:TRichViewEdit. If possible, this hyperlink is formatted using 'Hyperlink' style template.
var
OldStyleTemplate, NewStyleTemplate, ParaStyleTemplate: TRVStyleTemplate;
TextStyle: TFontInfo;
begin
// making a copy of the current text attributes
// (of the current text style)
TextStyle := TFontInfo.Create(nil);
TextStyle.Assign(rve.Style.TextStyles[rve.CurTextStyleNo]);
// searching for 'Hyperlink' style template
NewStyleTemplate := rve.Style.StyleTemplates.FindItemByName(
'Hyperlink');
if NewStyleTemplate<>nil then begin
// 'Hyperlink' style template exists. applying it to TextStyle
OldStyleTemplate := rve.Style.StyleTemplates.FindItemById(
TextStyle.StyleTemplateId);
ParaStyleTemplate := rve.Style.StyleTemplates.FindItemById(
TextStyle.ParaStyleTemplateId);
OldStyleTemplate.UpdateModifiedTextStyleProperties(
TextStyle, ParaStyleTemplate);
NewStyleTemplate.ApplyToTextStyle(FontInfo, ParaStyleTemplate);
end
else begin
// 'Hyperlink' style template does not exists.
// Applying default hyperlink properties
TextStyle.Color := clBlue;
TextStyle.Style := [fsUnderline];
end;
TextStyle.Jump := True;
// inserting
rve.CurTextStyleNo := rve.Style.FindTextStyle(TextStyle);
rve.InsertStringTag('TRichView.com', 'https://www.trichview.com');
// cleaning up
TextStyle.Free;
end;
See also:
▪ApplyToParaStyle (contains one more example)