I need to paste formatted text, but without font face. In my application users can't change font, but can use formatting like bold, italic, can insert images and use bullets and tables. So I need all this things in pasted data, but with default font used in my application.
I understand that I must use OnPaste event, but I don't understand how exactly...
Paste without font formatting
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
1) If you have a very limited set of formatting, you can add all possible formatting in RVStyle.TextStyles (if you use one font, of the same color, of the same size, only 4 items are required: normal, bold, italic, bold italic).
After that, you can assign properties so that new formatting will not be added on pasting RVF or RTF. Instead, the most similar of existing formatting will be used.
The simplest way to do it: at design time, right click RichViewEdit, choose "Settings" in the context menu, select "Use a predefined set of styles".
The only disadvantage: this mode of insertion is not implemented for RTF bullets&numbering, so text will be pasted from RTF without bullets and numbering.
2) In case if you have too many possible formatting options to add them initially (for example, if user can define arbitrary text color), you need using OnPaste.
Create rveHidden: TRichViewEdit, with Visible=False, linked to its own RVStyle control.
After that, you can assign properties so that new formatting will not be added on pasting RVF or RTF. Instead, the most similar of existing formatting will be used.
The simplest way to do it: at design time, right click RichViewEdit, choose "Settings" in the context menu, select "Use a predefined set of styles".
The only disadvantage: this mode of insertion is not implemented for RTF bullets&numbering, so text will be pasted from RTF without bullets and numbering.
2) In case if you have too many possible formatting options to add them initially (for example, if user can define arbitrary text color), you need using OnPaste.
Create rveHidden: TRichViewEdit, with Visible=False, linked to its own RVStyle control.
Code: Select all
procedure TForm1.RichViewEdit1Paste(Sender: TCustomRichViewEdit;
var DoDefault: Boolean);
var Stream: TMemoryStream;
begin
rveHidden.Clear;
rveHidden.DeleteUnusedStyles(True, True, True);
rveHidden.Format;
rveHidden.Paste;
<process rveHidden.Style, changing properties of items in collections of styles;
do not worry that styles with identical properties will appear:
InsertRVFFromStream will "compact" collections
>
Stream := TMemoryStream.Create;
rveHidden.SaveRVFToStream(Stream, False);
Stream.Position := 0;
RichViewEdit1.InsertRVFFromStreamEd(Stream);
Stream.Free;
DoDefault := False;
end;
Last edited by Sergey Tkachenko on Fri Apr 23, 2010 5:20 pm, edited 1 time in total.
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact: