Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2007 Jan : Rotating EMF
| Subject: | Rotating EMF |
| Posted by: | "Devinder Verman" (verman..@hotmail.com) |
| Date: | 2 Jan 2007 07:27:21 |
Hi,
I am generating EMF for print preview. The preview generates a good EMF,
but later when I try to rotate the preview by 90 degree, and process the
records using PlayEnhMetafileRecord, EMR_POLYPOLYGON16 fails. Here is what
i am doing.
I am converting smallpoint to tpoint because with large size paper, buffer
overflows.
Is there a way to record PolyPolygon call to generate EMR_POLYPOLYGON and
not EMR_POLYPOLYGON16 call in EMF?
Function RotateLeftEMF(DC : HDC; ht : PHandleTable;emr : PEnhMetaRecord;
nobj : integer; Data : Pointer): Integer; stdcall;
var
NewPolySize : longint;
PSPnt : PSmallPoint;
PEPolyPoly16 : PEMRPolyPolygon16;
PEPolyPoly : PEMRPolyPolygon;
PEPoly16 : PEMRPolygon16;
PEPoly : PEMRPolygon;
PPnt : Windows.PPoint;
NewRect : TRect;
begin
MaxWidth := longint(Data^);
PEPolyPoly16 := pointer(emr);
newPolySize := sizeof(EMRPOLYPOLYLINE) + (PEPolyPoly16^.nPolys
- 1) * sizeof(DWORD) + (PEPolyPoly16^.cpts - 1) * sizeof(TPoint);
PEPolyPoly := HeapAlloc( GetProcessHeap(),0, newPolySize);
Move(emr^, PEPolyPoly^, emr.nSize);
PEPolyPoly^.emr.iType := EMR_POLYPOLYGON;
PEPolyPoly^.emr.nSize := newPolySize;
PSPnt := PSmallPoint(longword(@PEPolyPoly16^.aPolyCounts) +
(PEPolyPoly16^.nPolys)*sizeof(DWORD));
PPnt := PPoint(longword(@PEPolyPoly^.aPolyCounts) +
(PEPolyPoly^.nPolys)*sizeof(DWORD));
// First convert all smallpoints to points
For loop := 1 to PEPolyPoly16.cpts do
Begin
PPnt^.x := PSPnt^.x;
PPnt^.y := PSPnt^.y;
inc(PSPnt);
inc(PPnt);
End;
// now rotate
NewRect.Left := MaxInt;
NewRect.Bottom := MaxInt;
NewRect.Right := -MaxInt;
NewRect.Top := -MaxInt;
PPnt := PPoint(longword(@PEPolyPoly^.aPolyCounts) +
(PEPolyPoly^.nPolys)*sizeof(DWORD));
For loop := 1 to PEPolyPoly.cptl do
Begin
tmp := PPnt^.x;
PPnt^.x := PPnt^.y;
PPnt^.y := MaxWidth-tmp;
if PPnt^.x<NewRect.Left then
NewRect.Left := PPnt^.x;
if PPnt^.x>NewRect.Right then
NewRect.Right := PPnt^.X;
if PPnt^.y<NewRect.Bottom then
NewRect.Bottom := PPnt^.y;
if PPnt^.y>NewRect.Top then
NewRect.Top := PPnt^.y;
inc(PPnt);
End;
PEPolyPoly^.rclBounds := NewRect;
if not PlayEnhMetafileRecord (DC, ht^,
PEnhMetaRecord(PEPolyPoly)^, nobj) then
showmessage('Error '+inttostr(getlasterror));
HeapFree( GetProcessHeap(), 0, PEPolyPoly );
Thanks
DP