Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to create and insert a *.wmf into an *.rtf file Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
29-Aug-02
Category
Reporting /Printing
Language
Delphi 2.x
Views
99
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

How to create and insert a *.wmf into an *.rtf file

Answer:

Well, create a metafile with the old wmf format (with enhanced = false). Code like 
this works:


1   { ... }
2   var
3     f: TPicture;
4     c: TMetafileCanvas;
5     fs: TMemoryStream;
6   begin
7     f := TPicture.create;
8     f.Metafile.width := 100;
9     f.Metafile.height := 100;
10    f.Metafile.Enhanced := false;
11    c := TMetafileCanvas.create(f.Metafile, 0);
12    c.Ellipse(5, 5, 95, 95);
13    c.Free;
14  end;



Get the bytes of the metafile, put in a buffer and call this function:

15  
16  procedure TRtfWriter.InsertWMFFromBuffer(Buffer: PByte; const BufLen: integer;
17    iWidth, iHeight: integer);
18  var
19    wmfTag: string;
20    HexEncoded: string;
21    i: integer;
22  begin
23    HexEncoded := '';
24    for i := 0 to BufLen - 1 do
25    begin
26      HexEncoded := HexEncoded + IntToHex(Buffer^, 2);
27      Inc(Buffer);
28    end;
29    {You gotta skip the wmf header}
30    HexEncoded := Copy(HexEncoded, (Sizeof(LongInt) + Sizeof(SmallInt) + 
31  Sizeof(TSmallRect) +
32      Sizeof(Word) + Sizeof(LongInt) + Sizeof(Word)) * 2 + 1,
33      Length(HexEncoded));
34    HexEncoded := LowerCase(HexEncoded);
35    wmfTag := '{\pict\wmetafile8\picw%d\pich%d %s }';
36    wmfTag := Format(wmfTag, [iWidth * 20, iHeight * 20, HexEncoded]);
37    fStream.write(wmfTag[1], Length(wmfTag));
38  end;




Note that fStream is a stream with the rtf file my TRtfWriter class is working on. 
You'll have to the the rtf job yourself, but that's the way to inser a wmf file. If 
you want a quick test, place this on the top of the file:



{\rtf1\ansi\ansicpg1252\deff0\deflang1046{\fonttbl{\f0\fswiss\fprq2\fcharset
0 Verdana;}{\f1\fswiss\fcharset0 Arial;}   {\f2\fmodern\fprq1\fcharset0
Courier New;}}\viewkind4\uc1


and this on the bottom


\par}

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC