RTF-problems

General TRichView support forum. Please post your questions here
Post Reply
Lina
Posts: 9
Joined: Wed Jan 10, 2007 9:06 am

RTF-problems

Post by Lina »

Hi!

I have a problem when using RVEdit imbedded in a form. I set a RTF text for example (test written in red font color):

Code: Select all

'{\rtf1\ansi\ansicpg0\uc1\deff0\deflang0\deflangfe0{\fonttbl{\f0\fnil\fcharset1 Arial;}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;\red192\green192\blue192;}'#$D#$A#$D#$A'\uc0'#$D#$A'\pard\fi0\li0\ql\ri0\sb0\sa0\itap0 \plain \f0\fs20\cf6 test}'
I set the RTF to RVEdit with:

Code: Select all

procedure TCustomRichViewEdit.SetText(sText: string);
var
 rtfStream : TStringStream;
begin
  rtfStream := TStringStream.Create(sText);
  Self.Clear;
  Self.LoadFromStream(rtfStream, rvynaNo);
  Self.Format;
  Self.Modified := false;
  rtfStream.Free;
end;
The text shown is “test” but without formatting (ie color = black). When I get the text from RVEdit with:

Code: Select all

function TCustomRichViewEdit.GetText: string;
var
  rtfStream : TMemoryStream;
  rtfBuffer : string;
tesbegin
  begin
    rtfStream := TMemoryStream.Create();
    rtfBuffer := '';
    try
      Self.SaveRTFToStream(rtfStream, false);
      rtfStream.Position := 0;
      SetLength(rtfBuffer, rtfStream.Size);
      rtfStream.ReadBuffer(Pointer(rtfBuffer)^, rtfStream.Size);
      Result := rtfBuffer;
    finally
      rtfStream.Free;
    end;
  end
end;
I get the following RTF:

Code: Select all

'{\rtf1\ansi\ansicpg0\uc1\deff0\deflang0\deflangfe0{\fonttbl{\f0\fnil\fcharset1 Arial;}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;\red192\green192\blue192;}'#$D#$A#$D#$A'\uc1'#$D#$A'\pard\fi0\li0\ql\ri0\sb0\sa0\itap0 \plain \f0\fs20 test}'
The problem doesn’t occur when I use the whole editor with menu and buttons and the only thing I can see is different between these two is that my RVEdit object has the style property set to an empty TRVStyle (TRVStyle.Create(nil)) (My editor componenten has the RVEdit object that is in the RichActions project). May that be the cause to the fault?

I also have a question about the section '#$D#$A#$D#$A'\uc1'#$D#$A' in the RTF. When I save the RTF and open it in Word the example above is translated with '#$D#$A#$D#$A'\uc1'#$D#$A' test.

Any suggestions of how I can change my code to make it work?


Thanks!
Sergey Tkachenko
Site Admin
Posts: 17564
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Make sure that both rve.RTFReaderProperties.TextStyleMode and rve.RTFReaderProperties.ParaStyleMode are set to rvrsAddIfNeeded.

Line break characters are ignored by RTF readers.
Lina
Posts: 9
Joined: Wed Jan 10, 2007 9:06 am

Post by Lina »

Thank you :)
Post Reply