Board index » delphi » Printing RTF-text via Canvas or RichEdit

Printing RTF-text via Canvas or RichEdit

Hi,
 I'm trying to copy formatted text (incl diff. fontcolors, tables,
underlined, bold en italic text, etc.) from a TRichEdit to a TCanvas, so
that when I print the Canvas using Canvas.TextOut(x,y,string), the printes
prints the formatted text.

I've been playing with streaming (TRichEdit.Lines.SaveToStream(Stream)) to
copy teh text to another TRicEdit and then use PaintTo to paint the text to
the handle of the printer. This works well enough. The problem is that I'm
building an in-system object so I don't want to use a Form. But then I won't
be able to use TRichtEdit cause it's a VCL-component (right ?).

In fact what I'm really trying to do is print an incoming, RTF-formatted
text (that is, plain text surrounded by RTF-codes, such as "{{rtf/1}...")
and via a TCanvas print it (TCanvas.TextOut(x,y,string) or TCanvas.Paint).

It seems unimaginable that no one has tried this before, so there should be
some neat tricks to it. Can anyone help me out here ?

Thanx in advance

Rick

 

Re:Printing RTF-text via Canvas or RichEdit


Quote
In article <3b41afa3$2_2@dnews>, Rick Kegel wrote:
>  I'm trying to copy formatted text (incl diff. fontcolors, tables,
> underlined, bold en italic text, etc.) from a TRichEdit to a TCanvas, so
> that when I print the Canvas using Canvas.TextOut(x,y,string), the printes
> prints the formatted text.

That is not the way to do it. The only means to manipulate rich text offered
by the Windows API is the rich edit control. Once the text is loaded into the
control you can use the EM_FORMATRANGE message to output the text formatted
onto a device context (canvas). Search the archives below for this message,
there should be lots of examples of use.

http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be

If you want to do this without involving a rich edit control you would
basically have to write your own RTF parser and renderer, and that is
definitely not a weekend project <g>.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: I'm unable to visit the newsgroups every day at the moment,
so be patient if you don't get a reply immediately.

Other Threads