Page 1 of 1

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

Posted: Tue Oct 24, 2006 1:18 am
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:

Posted: Tue Oct 24, 2006 8:18 am
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)

Posted: Tue Oct 24, 2006 1:17 pm
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?

Posted: Tue Oct 24, 2006 5:08 pm
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\

Can you help me out?

Posted: Wed Nov 15, 2006 7:00 am
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

Posted: Wed Nov 15, 2006 4:37 pm
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;

Posted: Wed Nov 15, 2006 4:43 pm
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.

Thank you, Sergey!

Posted: Mon Nov 20, 2006 1:47 am
by uniandy
Hi, Sergey,

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

Andy