How to make a fontstyle format brush like in MS Word?

General TRichView support forum. Please post your questions here
Post Reply
uniandy
Posts: 12
Joined: Thu Oct 12, 2006 4:27 am

How to make a fontstyle format brush like in MS Word?

Post by uniandy »

Hi, Sergey,

How to make a fontstyle format brush in Richviewedit by using a button, the functionality is just like in Microsoft Word?

I have no any idea of implementing this in my test, can you please help me out?

Andy :lol:
Sergey Tkachenko
Site Admin
Posts: 17561
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

RichViewActions ( http://www.trichview.com/resources/actions/ ) implements something like this. But not exactly like in MS Word (In MS Word, this is a combo button, displaying the last applying color, and it allows to reapply the last color on single click; this is not impemented yet)
uniandy
Posts: 12
Joined: Thu Oct 12, 2006 4:27 am

Post by uniandy »

Hi, Sergey,

Thank you, but I mean, how to get all the fontstyle for the cursor position in the text, the fontstyle is not limited to color, but all the style like color, fontname, font size etc.

When I get the style and saved it to an object like fs:Tfontstyle, then I can apply this fs to any text selected and change the text selection style exactly like the fontstyle I want.

can there be some methods to do this?
Sergey Tkachenko
Site Admin
Posts: 17561
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

You can do it using ApplyStyleConversion method.
This method calls OnStyleConversion event for all text item in the selection, allowing to change font style properties.

See the demo in Demos\Editors\Editor 2\
uniandy
Posts: 12
Joined: Thu Oct 12, 2006 4:27 am

Can you help me out?

Post by uniandy »

HI, Sergey-

After some tries I still cannot find a way to make fontstyle format brush like in MS Word?

How can I get all the font style which i selected and how to apply them to another text selection?

Can you possibily indicate me with code samples?

Thank you very much!
Andy
Sergey Tkachenko
Site Admin
Posts: 17561
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Ok, let we have RichViewEdit1: TRichViewEdit, linked to RVStyle1: TRVStyle.

Code: Select all

TextStyle: TFontInfo; // form's variable
Reading current text format:

Code: Select all

TextStyle.Free;
TextStyle := TFontInfo.Create(nil);
TextStyle.Assign(RVStyle.TextStyles[RichViewEdit1.CurTextStyleNo]);
Applying to the selection:

Code: Select all

var StyleNo: Integer;

if TextStyle<>nil then begin
  StyleNo := RVStyle1.TextStyles.FindSuchStyle(0, RVAllFontInfoProperties);
  if StyleNo<0 then begin
    RVStyle1.TextStyles.Add;
    StyleNo := RVStyle1.TextStyles.Count-1;
    RVStyle1.TextStyles[StyleNo].Assign(TextStyle);
    RVStyle1.TextStyles[StyleNo].Standard := False;
  end;
  RichViewEdit1.ApplyTextStyle(StyleNo);
end;
On destroying the form:

Code: Select all

TextStyle.Free;
Sergey Tkachenko
Site Admin
Posts: 17561
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Well, there is a simpler solution.

Code: Select all

StyleNo: Integer; // form's variable 
On form's creation:

Code: Select all

StyleNo := -1;
Reading the current text format:

Code: Select all

StyleNo := RichViewEdit1.CurTextStyleNo;
Applying to the selection:

Code: Select all

if StyleNo>=0 then
  RichViewEdit1.ApplyTextStyle(StyleNo);
The only problem with this solution is: the stored value of StyleNo becomes invalid after creating a new document (File | New) or loading another document (File | Open), so you should reset it to -1.
uniandy
Posts: 12
Joined: Thu Oct 12, 2006 4:27 am

Thank you, Sergey!

Post by uniandy »

Hi, Sergey,

I have done with the font format brush, thank you for your kind hints and help.

Andy
Post Reply