Page 1 of 1

XHtml to stream export

Posted: Tue Sep 13, 2005 8:04 pm
by wvd_vegt
Hi,

Is there support for exporting xhtml into a stream so I can stream it directly into an embeddedWB from EuroMind without saving to disc first?

Posted: Tue Sep 13, 2005 8:44 pm
by Sergey Tkachenko
rv.SaveHTMLToStreamEx

Posted: Wed Sep 14, 2005 6:58 pm
by wvd_vegt
Thanks

For people interested the following code works like charm:

Code: Select all

procedure T_TaakEditor.DoPreview(rve: TRichViewEdit);
var
  ms                 : TMemoryStream;
begin
  ms := TMemoryStream.Create;

  rve.SaveHTMLToStreamEx(ms,
    ChangeFileExt(Application.ExeName, '.xhtml'),
    'A Title', '', '', '', '',
    [rvsoUTF8, rvsoXHTML]);
  ms.Seek(0, soFromBeginning);

  emBeddedWB1.LoadFromStream(ms);
end;

Posted: Thu Sep 15, 2005 1:41 pm
by wvd_vegt
Hi,

When i stream from TRichViewEdit into EmebbedWb the images are saved on disk. Hyperlinks are present in the generated xhtml but lack path & file:// protocol.

Is there a way to correct this?

Posted: Thu Sep 15, 2005 4:56 pm
by Sergey Tkachenko
TRichView does not save hyperlinks in HTML itself. It's done in OnWriteHyperlink event. Modify code in this event to add protocol prefixes when necessary

Posted: Fri Sep 16, 2005 9:17 am
by wvd_vegt
Hi,

This event isn't fired during the SaveHTMLToStreamEx call. Any suggestions?

Posted: Fri Sep 16, 2005 9:22 am
by Sergey Tkachenko
Sorry, it's not possible.
If this event is not fired, all hyperlink would be written as a plain text (hyperlink target is provided by this event, or by obsolete OnURLNeeded)

Posted: Fri Sep 16, 2005 9:28 am
by wvd_vegt
Hi,

Perhaps i need to clarify, i dropped an image from the file system into a TRichViewEdit and call the streaming function.

The output is:

Code: Select all

<img alt="" hspace="1" vspace="1" src="Pim.xhtml13.jpg" />

I did some digging and found that OnHtmlSaveImage is called but for it to work i need to manually save the Image but can't get the Filename from the ItemNo supplied.

I Also found that setting doDefault to true saves the image to disc (as i want to) but also resets the filename written into the html generated.

Preview content in an EmbeddedWB including disc based Images

Posted: Fri Sep 16, 2005 12:01 pm
by wvd_vegt
Hi,

Finnaly figured it out. The trick lies in the OnSaveImage Event but needs to duplicate some code from TCustomRVData.DoSavePicture.

Only minor flaw is that the OverrideFileNames parameter isn't available so I had to set it to false (but as the calling program passes it in, it's also known inside the eventhandler).

Result is an image save to disc and a correct file:/// type url in the generated xhtml.


The OnSaveImage2 eventhandler:

Code: Select all

procedure TXHtmlEditFrame.RichViewEdit1SaveImage2(Sender: TCustomRichView;
  Graphic: TGraphic; SaveFormat: TRVSaveFormat; const Path,
  ImagePrefix: string; var ImageSaveNo: Integer; var Location: string;
  var DoDefault: Boolean);
var
  ext               : string;
  fn                : string;
begin
  if SaveFormat = rvsfHTML then
    begin
      ext := '.jpg';
      if RV_IsHTMLGraphicFormat(Graphic) then
        ext := '.' + GraphicExtension(TGraphicClass(Graphic.ClassType));
    end
  else
    ext := '.bmp';

  fn := Sender.RVData.GetNextFileName(ImagePrefix, Path, Ext, ImageSaveNo, false); //no OverrideFileNames

  if (SaveFormat = rvsfHTML) and
    ((Graphic is TJpegImage) or RV_IsHTMLGraphicFormat(Graphic)) then
    Graphic.SaveToFile(fn);

//Sample: src="file:///C:/Bureaublad/Joe_s_Garage.gif"

  Location := 'File:///' + StringReplace(fn, '\', '//', [rfReplaceAll]);

  DoDefault := False;
end;
And the calling routine that previews TRichViewEdit content in an EmbeddedWB including disc based images:

Code: Select all

procedure T_TaakEditor.DoPreview(rve: TRichViewEdit);
var
  ms                : TMemoryStream;
begin
  ms := TMemoryStream.Create;

  rve.RVData.Flags := rve.RVData.Flags + [rvflRoot];
  rve.SaveHTMLToStreamEx(ms,
    ExtractFilePath(Application.ExeName),
    'A Title', '', '', '', '',
    [rvsoUTF8, rvsoXHTML]);
  ms.Seek(0, soFromBeginning);

  Preview.LoadFromStream(ms);
end;

Posted: Fri Sep 16, 2005 4:42 pm
by Sergey Tkachenko
That's right, but you initially asked about hyperlinks, not images :)

Posted: Sun Sep 18, 2005 6:07 pm
by wvd_vegt
Hi,

My excuses for mixing them up again. I tend to treat everything with a url as a hyperlink.

But is it possible to change the routines a bit so you can save the image more easily by calling the code already present in TRichView? I find copying peices code to archieve a minor enhancement awkward as the copied piece may change for next releases of a library like TRIchView.

Posted: Sun Sep 18, 2005 7:35 pm
by Sergey Tkachenko

Code: Select all

procedure TForm3.RichViewEdit1SaveImage2(Sender: TCustomRichView;
  Graphic: TGraphic; SaveFormat: TRVSaveFormat; const Path,
  ImagePrefix: String; var ImageSaveNo: Integer; var Location: String;
  var DoDefault: Boolean);
begin
  Location := Sender.RVData.SavePicture(SaveFormat, ImagePrefix, Path, ImageSaveNo, True,
    clWhite, Graphic);
  Location := 'file://' + StringReplace(Path+Location, '\', '/', [rfReplaceAll]);
  DoDefault := False; 
end;
Corrected: '\' should be changed to '/', not to '//'

Posted: Mon Sep 19, 2005 8:31 am
by wvd_vegt
Hi,

Thanks, works like charm (and is much shorter).

Posted: Fri Sep 23, 2005 9:23 am
by Sergey Tkachenko
I have corrected the example