Setting a Style

General TRichView support forum. Please post your questions here
Post Reply
standay
Posts: 332
Joined: Fri Jun 18, 2021 3:07 pm

Setting a Style

Post by standay »

Sergey,

Sorry, another styles question!

Say I paste some text in my rve, and it has the Georgia font. If I select the whole paragraph and then use the style combo to set a style, it sets the selcted style and keeps the Georgia font. That's what I want.

But if I select one word and then use the style combo to set a style, it sets the style but does not keep the Georgia font, it keeps using the Arial font. I want it to keep the Georgia font.

Is there a way to do that? I've tried a lot of things today and can't seem to get around that behavior. It does it in the ActionTest demo as well.

Thanks Sergy

Stan
Sergey Tkachenko
Site Admin
Posts: 18032
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Setting a Style

Post by Sergey Tkachenko »

This is by design,

Your text has font "Georgia" applied on top of properties defined by its styletemplate.

When you apply a styletemplate, the results depend on the selection. If the selection contains multiple paragraphs, the styletemplate is applied only to paragraph properties. Text properties that were set on top of styletemplate are not reset.
If the selection is inside a single paragraph, a styletemplate is applied to text properties. If this is "Normal" styletemplate, text properties are simply reset.

(The explanation above are simpliefied, because results depend on the styletemplate kind (paragraph style, text style, or text & paragraph style), with some special processing for "Normal" styletemplate.)

The best solution is style modification. If you want the default font "Georgia", specify it in the "Normal" styletemplate. In ActionTest demo, use the menu "Format | Styles", select "Normal (standard)", click the link "Edit" in the font section, and select "Georgia".
standay
Posts: 332
Joined: Fri Jun 18, 2021 3:07 pm

Re: Setting a Style

Post by standay »

Sergey Tkachenko wrote: Wed Jan 28, 2026 9:49 am The best solution is style modification. If you want the default font "Georgia", specify it in the "Normal" styletemplate. In ActionTest demo, use the menu "Format | Styles", select "Normal (standard)", click the link "Edit" in the font section, and select "Georgia".
OK, is there a way to set the Normal style font name from code? I tried and couldn't do it. I also tried assigning the font name and valid properties at design time but it apparently doesn't stay that way once the app is running. If we can't change it from code that's OK, just wanted to be sure I'm not missiing something.

Stan
Sergey Tkachenko
Site Admin
Posts: 18032
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Setting a Style

Post by Sergey Tkachenko »

1) Do you want to apply the default font to new documents?
Find "Normal" item in rvActionNew.StyleTemplates, and assign it properties:

Code: Select all

TextStyle.FontName := 'Georgia';
ValidTextProperties := ValidTextProperties + [rvfiFontName];
You can do it at designtime, or at runtime before the first execution of this action. We discussed it here: https://trichview.com/forums/viewtopic.php?t=15287

2) If you want to apply changes to the existing document, with changing font, you can do it as an editing (undoable operation), like we discussed here:
https://trichview.com/forums/viewtopic.php?t=15289

Let you have RVStyleTmp: TRVStyle not linked to any TRichView.

Code: Select all

var
  ST: TRVStyleTemplate;

RVStyleTmp.Units := RichViewEdit1.Style.Units;
RVStyleTmp.StyleTemplates.AssignStyleTemplates(RichViewEdit1.Style.StyleTemplates, True);
ST := RVStyleTmp.StyleTemplates.FindItemByName('Normal');
ST.TextStyle.FontName := 'Georgia';
ST.ValidTextProperties := ST.ValidTextProperties + [rvfiFontName];
RichViewEdit1.ChangeStyleTemplates(RVStyleTmp.StyleTemplates);
3) In existing document, you can simply find 'Normal' item in RichViewEdit1.Style.StyleTemplates and change its TextStyle.FontName and ValidTextProperties. This change does not affect font existing text, but new propeerty values will be used in operations related to style templates.
standay
Posts: 332
Joined: Fri Jun 18, 2021 3:07 pm

Re: Setting a Style

Post by standay »

Sergey,

Yes, you were right this was working when I tried it in my small test app. What I wound up using in my main app was a TRVStyle not linked to any TRichView. That worked the way I wanted it to work.

Thanks

Stan
Post Reply