I am reading and writing Metafiles from/to windows clipboard to exchange objects with other softwares like CorelDraw. When I copy some Bezier curves from CorelDraw (Simpley by Ctrl+C) then I can exactly paste them into my application as Beziers. But I wonder why, when I create a metafile myself and draw some Beziers in my MetaFileCanvas, Beziers are being pasted as polygons (not Beziers) in CorelDraw! This is while I checked all Windows API drawing function like PolyBezier, PolyBezierTo and PolyDraw (by which I can draw lines and Beziers together). I also checked all the available methods in TMetaFileCanvas component, but the result was the same.
I have faced another problem which is the accuracy! Data (points) miss the accuracy. I set MMHeight and MMWidth properties of MetaFile, but it had no effect. I tried to use SetMapMode function and apply MM_HIMETRIC mode to force a 0.01mm accuracy, It affects the units, but still the points are transferred with an accuracy of 0.254mm!
Any idea where I am making a mistake, or which functions and settings I am missing?
Is there any other way to exchange curves other than MetaFiles in Clipboard? I know I can create my own format in clipboard, but it should be readable by other applications.
Any help will highly be appreciated.
Here is a part of my codes by which I create a Metafile and Copy to clipboard
- Code: Select all
MetaFile:= TMetaFile.Create;
MetaFile. Enhanced:= True;
R:= GetSelectedObjectsRect;
MetaFile.Height:= R.Right-R.Left;
MetaFile.width:= R.Bottom - R.Top;
MetaFile.MMWidth:= Abs(InitRect.Right - InitRect.Left) Div 10; //**SEE BELOW
MetaFile.MMHeight:= Abs(InitRect.Top - InitRect.Bottom) Div 10; //**SEE BELOW
MetaCanvas:= TMetafileCanvas.Create(MetaFile, 0);
SetMapMode(MetaFile.Handle, MM_HIMETRIC);
For i:= 0 To Selecteds.Count-1 Do
Begin
// ….. Draw Some Beziers….
//In two below lines, Controls: Array[1..4] of TPoint
MoveTo(MetaCanvas.Handle, Controls[0].x, Controls[0].y);
PolyBezier(MetaCanvas.Handle, Controls, n +1);
End;
MetaCanvas.Free;
MetaFile.SaveToClipboardFormat(Format, DataHandle, PaletteHandle);
Clipboard.Clear;
ClipBoard.Open;
SetClipboardData(CF_ENHMETAFILE, MetaFile.Handle);
ClipBoard.Close;
** My data accuracy is 0.001mm and I use integer type and 1 units means 0.0001mm im my application, for MetaFile I divide it into 10 to drop the accuracy to 0.01, so 1 unit will be 0.01mm