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.
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;