Change Font In Table Cell

General TRichView support forum. Please post your questions here
Post Reply
DickBryant
Posts: 148
Joined: Wed Dec 07, 2005 2:02 pm
Contact:

Change Font In Table Cell

Post by DickBryant »

Perhaps rather than showing bad solutions, I should just state the problem :-)

I wish to apply an arbitrary existing style to the text items in a table cell - the text items can be of any style (and multiple styles) and be unicode or not and the existing style I want to apply may be Unicode or not.

The items are originally inserted in the cell by a paste operation having been copied from 'outside' of the application.

I want to repeat this option for a full column in the table without having to do Format operations in between.

Dick
DickBryant
Posts: 148
Joined: Wed Dec 07, 2005 2:02 pm
Contact:

Post by DickBryant »

And the winner is:

for i := Fmain.RichViewEdit1.ItemCount - 1 downto 0 do
begin
case Fmain.RichViewEdit1.GetItemStyle(i) of
rvsTable:
Table := TRVTableItemInfo(Fmain.RichViewEdit1.GetItem(i));
end;
end;
ItemNo := Fmain.RichViewEdit1.GetItemNo(table);
Fmain.RichViewEdit1.BeginItemModify(ItemNo, TableData);


MasterRVTable.SelectCols(1,1);
FMain.RichViewEdit1.ApplyTextStyle(2);
FMain.RichViewEdit1.Deselect;


FMain.RichViewEdit1.EndItemModify(ItemNo, TableData);
FMain.RichViewEdit1.Change;
FMain.RichViewEdit1.Format;
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Sorry for the delay, we were busy preparing a new beta update.
Your code is correct, this is the simplest way (and the user can undo this operation).
Converting the item to/from Unicode without editing methods require using undocumented features.

PS: your code reformat the editor 3 times :)
One time, ApplyTextStyle (it reformat the affected part of the document itself).
EndItemModify reformats the document one more time, if table width is changed.
And Format reformat the document one more time.
So all these methods can be removed (and Change too, because ApplyTextStyle, like any editing operation, calls Change)
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

By the way, your code applies only to MasterRVTable, so the cycle to find table is not useful (and it returns only the first table in the document).
To apply to all tables, use this code:

Code: Select all

for i := Fmain.RichViewEdit1.ItemCount - 1 downto 0 do 
  if Fmain.RichViewEdit1.GetItemStyle(i)=rvsTable then
  begin
    Table := TRVTableItemInfo(Fmain.RichViewEdit1.GetItem(i)); 
    Table.SelectCols(1,1); 
    FMain.RichViewEdit1.ApplyTextStyle(2); 
  end; 
FMain.RichViewEdit1.Deselect; 
DickBryant
Posts: 148
Joined: Wed Dec 07, 2005 2:02 pm
Contact:

Post by DickBryant »

Thank you for your comments, Sergey - I will clean up the code as you suggest. Not necessary to do multiple tables - there is only ONE master :-).

Please see my new post, though - as I've decided it would be nice to allow the user to retain the 'font effects' and change only the typeface - this gets us back into the old issues...

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

Post by Sergey Tkachenko »

You can implement it using ApplyStyleConversion
(or, if you use RichViewActions, with TrvActionFontEx with UserInterface=False)
Post Reply