home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 October / Chip_2001-10_cd1.bin / zkuste / delphi / kompon / d123456 / CHEMPLOT.ZIP / TPlot / Metafile.PAS < prev    next >
Pascal/Delphi Source File  |  2000-02-17  |  2KB  |  80 lines

  1. unit Metafile;
  2.  
  3. {This is the D1 implementation of TMetafileCanvas for TSciGraph}
  4. {}
  5. {It is based on TMetafileCanvas in the graphics unit of D4 Pro.}
  6.  
  7. interface
  8.  
  9. uses
  10.   graphics, SysUtils, WinProcs, WinTypes;
  11.  
  12. type
  13.   TMetafileCanvas = class(TCanvas)
  14.   private
  15.     FMetafile: TMetafile;
  16.   public
  17.     constructor Create(AMetafile: TMetafile; ReferenceDevice: HDC);
  18.     destructor Destroy; override;
  19.   end;
  20.  
  21. implementation
  22.  
  23. constructor TMetafileCanvas.Create(AMetafile: TMetafile; ReferenceDevice: HDC);
  24. var
  25.   RefDC: HDC;
  26.   R: TRect;
  27.   Temp: HDC;
  28.   P: PChar;
  29. begin
  30.   inherited Create;
  31.   FMetafile := AMetafile;
  32.   RefDC := ReferenceDevice;
  33.   if ReferenceDevice = 0 then RefDC := GetDC(0);
  34.   try
  35.  {   if FMetafile.MMWidth = 0 then
  36.       if FMetafile.Width = 0 then
  37.         FMetafile.MMWidth := GetDeviceCaps(RefDC, HORZSIZE)*100
  38.       else
  39.         FMetafile.MMWidth := MulDiv(FMetafile.Width,
  40.           GetDeviceCaps(RefDC, HORZSIZE)*100, GetDeviceCaps(RefDC, HORZRES));
  41.     if FMetafile.MMHeight = 0 then
  42.       if FMetafile.Height = 0 then
  43.         FMetafile.MMHeight := GetDeviceCaps(RefDC, VERTSIZE)*100
  44.       else
  45.         FMetafile.MMHeight := MulDiv(FMetafile.Height,
  46.           GetDeviceCaps(RefDC, VERTSIZE)*100, GetDeviceCaps(RefDC, VERTRES));}
  47.     R.Left := 0;
  48.     R.Top := 0;
  49.     R.Right := FMetafile.Width;
  50.     R.Bottom := FMetafile.Height;
  51.     {if (Length(CreatedBy) > 0) or (Length(Description) > 0) then
  52.       P := PChar(CreatedBy+#0+Description+#0#0)
  53.     else
  54.       P := nil;}
  55.     {Temp := CreateMetafile(RefDC, nil, @R, P);}
  56.     Temp := CreateMetafile(nil);
  57.     if Temp = 0 then raise
  58.       EOutOfMemory.Create('Could not create metafile !');
  59.     Handle := Temp;
  60.     SetMapMode(Handle, MM_TEXT);
  61.     SetWindowExt(Handle, FMetafile.Width, FMetafile.Height);
  62.     SetViewportExt(Handle, FMetafile.Width, FMetafile.Height);
  63.   finally
  64.     if ReferenceDevice = 0 then ReleaseDC(0, RefDC);
  65.   end;
  66. end;
  67.  
  68. destructor TMetafileCanvas.Destroy;
  69. var
  70.   Temp: HDC;
  71. begin
  72.   Temp := Handle;
  73.   Handle := 0;
  74.   FMetafile.Handle := CloseMetafile(Temp);
  75.   inherited Destroy;
  76. end;
  77.  
  78.  
  79. end.
  80.