Board index » delphi » Clipping of a metafile

Clipping of a metafile


2005-01-28 06:49:56 PM
delphi99
Hello,
I use a TMetaFile and I want to draw another metaFile into it. But Since it
is vectorial I can not "clip" it precisely.
Do you have an Idea to clip the metafile without rendering it on a TBitmap?
Thank you..
 
 

Re:Clipping of a metafile

You can enumerate a metafile and then analyse all the metafile records,
which are just drawing commands in fact, and clip the ones that need
clipping (e.g. line/polyline drawing commands). After clipping you then
regenerate the metafile again by drawing all records to a Metafile TCanvas.
However, it is quite tricky to do it right for all metafiles, because there
are a zillion of drawing commands, and often the transformation from
coordinates to bitmap is changed (SetWorldTransform, SetViewportOrg/Size,
SetWindowOrg/Size). Since you want to clip at coordinate level you will have
to keep track of this too.
Nils
www.simdesign.nl
"Bob" <XXXX@XXXXX.COM>writes
Quote
Hello,
I use a TMetaFile and I want to draw another metaFile into it. But Since
it
is vectorial I can not "clip" it precisely.
Do you have an Idea to clip the metafile without rendering it on a
TBitmap?

Thank you..


 

Re:Clipping of a metafile

OK, that is seems a good way to solve my problem because most of the time,
it's only lines that need to be clipped.
How can I enumerate the drawing command of the metafile ?
Thanx..
"Nils Haeck" <XXXX@XXXXX.COM>a écrit dans le message de
Quote
You can enumerate a metafile and then analyse all the metafile records,
which are just drawing commands in fact, and clip the ones that need
clipping (e.g. line/polyline drawing commands). After clipping you then
regenerate the metafile again by drawing all records to a Metafile
TCanvas.

However, it is quite tricky to do it right for all metafiles, because there
are a zillion of drawing commands, and often the transformation from
coordinates to bitmap is changed (SetWorldTransform, SetViewportOrg/Size,
SetWindowOrg/Size). Since you want to clip at coordinate level you will have
to keep track of this too.

Nils
www.simdesign.nl

"Bob" <XXXX@XXXXX.COM>writes
news:41fa18a3$XXXX@XXXXX.COM...
>Hello,
>I use a TMetaFile and I want to draw another metaFile into it. But Since
it
>is vectorial I can not "clip" it precisely.
>Do you have an Idea to clip the metafile without rendering it on a
TBitmap?
>
>Thank you..
>
>


 

Re:Clipping of a metafile

Hi Bob,
For enumeration without using a canvas:
EnumEnhMetafile(0, AMeta.Handle, @EnhMetafileProc, Self, PRect(nil)^);
example of callback function:
// This function is called from EnumEnhMetaFile
function EnhMetafileProc(DC: HDC; lpHTable: PHANDLETABLE; lpEMFR:
PENHMETARECORD;
nObj: Integer; AImport: TpgEmfImport): Integer; stdcall;
begin
// Use the aux parameter to call the object's function
Result := AImport.DrawMetaRecord(DC, lpHTable, lpEMFR, nObj);
end;
example of drawing metafile records:
function TpgEmfImport.DrawMetaRecord(DC: HDC; lpHTable: PHANDLETABLE;
lpEMFR: PENHMETARECORD; nObj: integer): integer;
begin
case lpEMFR.iType of
EMR_HEADER:
begin
// your code
end;
EMR_SETWINDOWEXTEX:
begin
// your code
end;
EMR_POLYGON16:
begin
// your code
end;
..etcetera
else
// some error or message that record types are not supported
end;
// Conclude with non-zero result to continue enumeration
Result := 1;
end;
By the way I have an EMF import function almost 100% implemented for the
successor of our DtpDocuments component. It also imports SVG and PDF. Once
done, this component could potentially save you a lot of work.
Nils
www.simdesign.nl
"Bob" <XXXX@XXXXX.COM>writes
Quote
OK, that is seems a good way to solve my problem because most of the time,
it's only lines that need to be clipped.
How can I enumerate the drawing command of the metafile ?

Thanx..

"Nils Haeck" <XXXX@XXXXX.COM>a écrit dans le message de
news:41fa1b7b$XXXX@XXXXX.COM...
>You can enumerate a metafile and then analyse all the metafile records,
>which are just drawing commands in fact, and clip the ones that need
>clipping (e.g. line/polyline drawing commands). After clipping you then
>regenerate the metafile again by drawing all records to a Metafile
TCanvas.
>
>However, it is quite tricky to do it right for all metafiles, because
there
>are a zillion of drawing commands, and often the transformation from
>coordinates to bitmap is changed (SetWorldTransform,
SetViewportOrg/Size,
>SetWindowOrg/Size). Since you want to clip at coordinate level you'll
have
>to keep track of this too.
>
>Nils
>www.simdesign.nl
>
>"Bob" <XXXX@XXXXX.COM>writes
>news:41fa18a3$XXXX@XXXXX.COM...
>>Hello,
>>I use a TMetaFile and I want to draw another metaFile into it. But
Since
>it
>>is vectorial I can not "clip" it precisely.
>>Do you have an Idea to clip the metafile without rendering it on a
>TBitmap?
>>
>>Thank you..
>>
>>
>
>


 

Re:Clipping of a metafile

In article <41fa18a3$XXXX@XXXXX.COM>, Bob writes:
Quote
I use a TMetaFile and I want to draw another metaFile into it. But Since it
is vectorial I can not "clip" it precisely.
Do you have an Idea to clip the metafile without rendering it on a TBitmap?
SelectClipRgn perhaps?
Peter Below (TeamB)
Use the newsgroup archives :
www.mers.com/searchsite.html
www.tamaracka.com/search.htm
groups.google.com
www.prolix.be