home *** CD-ROM | disk | FTP | other *** search
- program EpsPrintDemo;
-
- uses
- Objects,WinTypes,WinProcs,OWindows,ODialogs,OPrinter,EpsPrint;
-
- {$R EPSDEMO.RES}
- {$I EPSDEMO.INC}
-
- type
- tEpsDemo = object (tApplication)
- procedure InitMainWindow; virtual;
- end;
-
- pMainWindow = ^tMainWindow;
- tMainWindow = object (tDlgWindow)
- Printer: pEpsPrinter;
- constructor Init (aParent: pWindowsObject; aTitle: pChar);
- destructor Done; virtual;
- procedure Ok (var Msg: tMessage); virtual id_First + id_OK;
- end;
-
- pEpsPrintout = ^tEpsPrintout;
- tEpsPrintout = object (tPrintout)
- EpsImages: pCollection;
- constructor Init (aTitle: pChar);
- destructor Done; virtual;
- procedure PrintPage (Page: Word; var Rect: tRect; Flags: Word); virtual;
- end;
-
- {--tEpsDemo------------------------------------------------------------------}
-
- procedure tEpsDemo.InitMainWindow;
-
- begin
- MainWindow := New (pMainWindow,Init (nil,MakeIntResource (drMainDialog)));
- end;
-
- {--tMainWindow---------------------------------------------------------------}
-
- { The main window is a dialog with two buttons: Ok and Cancel. When the
- program is run, pressing Ok causes the Printer object to print itself;
- pressing Cancel aborts. }
-
- { During initialization, tMainWindow verifies that the default printer is
- capable of printing PostScript, and aborts if not. }
-
- constructor tMainWindow.Init (aParent: pWindowsObject; aTitle: pChar);
-
- begin
- inherited Init (aParent,aTitle);
- Printer := New (pEpsPrinter,Init);
- if not Printer^.IsPostScriptCapable then
- begin
- Dispose (Printer,Done);
- MessageBox (0,'The default printer driver does not support PostScript',nil,
- MB_ICONSTOP + MB_OK);
- Fail;
- end;
- end;
-
- destructor tMainWindow.Done;
-
- begin
- Dispose (Printer,Done);
- inherited Done;
- end;
-
- { The actual printing is taken care of in the Ok method. }
-
- procedure tMainWindow.Ok (var Msg: tMessage);
-
- var
- Printout: pEpsPrintout;
- Eps: pEps;
-
- begin
-
- { Initialize a tEpsPrintout object. }
-
- Printout := New (PEpsPrintout,Init ('EPS Print Demo'));
-
- { And a tEps object associated with the EPS file that we're going to print.
- The image contained in EPSDEMO.EPS is a 20% gray rectangle, 8.0 inches
- tall and 10.0 inches wide, with a narrow black border. Centered in the
- rectangle is a smaller white rectangle containing the phrase "This is an
- EPS image". EPSDEMO.EPS was created using CorelDRAW 3.0. EPSDEMOX.EPS is
- identical to EPSDEMO.EPS, except that its preview header has been removed.
- If you want to see what the original EPS image looks like, you can copy
- EPSDEMOX.EPS directly to a PostScript printer. }
-
- Eps := New (pEps,Init ('EPSDEMO.EPS'));
-
- { The tEps initialization will fail if the tEps object could not be
- initialized because (1) the EPS file could not be opened, or (2) the EPS
- file does not contain a valid %%BoundingBox comment. }
-
- if not Assigned (Eps) then
- MessageBox (0,'The EPS file could not be initialized',nil,MB_ICONSTOP +
- MB_OK)
- else begin
-
- { If all goes well with initialization of the tEpsPrintout and tEps objects,
- insert three copies of the EPS image into the printout. The first is 0.25x
- original size, and positioned so that its lower left corner is 1 inch
- above and 1 inch to the right of the lower left corner of the page. The
- second is distorted, so that its width is 0.75x original size, its height
- is 0.10x original size, it is rotated counterclockwise 90 degrees, and it
- is centered on the page. The third is scaled identically to the first, but
- it is rotated 180 degrees and positioned so that its upper right corner is
- 1 inch below and 1 inch to the left of the upper right corner of the page. }
-
- Printout^.EpsImages^.Insert (New (pImage,Init (Eps,0,1.0,1.0,2.5,2.0)));
- Printout^.EpsImages^.Insert (New (pImage,Init (Eps,90,4.65,1.75,7.50,
- 0.80)));
- Printout^.EpsImages^.Insert (New (pImage,Init (Eps,180,7.5,10.0,2.5,2.0)));
- Printer^.Print (@Self,Printout);
- Dispose (Eps,Done);
- end;
- Dispose (Printout,Done);
- inherited Ok (Msg);
- end;
-
- {--tEpsPrintout--------------------------------------------------------------}
-
- constructor tEpsPrintout.Init (aTitle: pChar);
-
- begin
- inherited Init (aTitle);
- EpsImages := New (pCollection,Init (5,0));
- end;
-
- destructor tEpsPrintout.Done;
-
- begin
- Dispose (EpsImages,Done);
- inherited Done;
- end;
-
- procedure tEpsPrintout.PrintPage (Page: Word; var Rect: tRect; Flags: Word);
-
- procedure SendImage (Image: pImage); far;
-
- begin
- Image^.Send (DC);
- end;
-
- var
- ScaleX,ScaleY,MarginX,MarginY: Word;
- Dimension,Offset: tPoint;
- OldPen,NewPen: hPen;
- L,R,T,B: Integer;
-
- begin
-
- { The first thing to do is to send the EPS images to the printer DC. }
-
- EpsImages^.ForEach (@SendImage);
-
- { Now that the EPS images have been taken care of, we can add various GDI
- elements to the page (text, graphics, etc.); as an example, we will draw a
- rectangular black frame, with a line width of 0.05 inch, centered on the
- page, with 0.5 inch margins all around. First we need to get some
- information concerning the logical units for this printer, as well as the
- dimensions of the physical page and the location of the logical page
- within the physical page. }
-
- ScaleX := GetDeviceCaps (DC,LOGPIXELSX); { units/inch }
- ScaleY := GetDeviceCaps (DC,LOGPIXELSY);
- Escape (DC,GETPHYSPAGESIZE,0,nil,@Dimension);
- Escape (DC,GETPRINTINGOFFSET,0,nil,@Offset);
-
- { Create and select a solid black pen, 0.05 inch wide. }
-
- NewPen := CreatePen (PS_SOLID,Round (0.05 * ScaleX),0);
- OldPen := SelectObject (DC,NewPen);
-
- { Define the 0.5 inch margins and calculate the locations of the sides of
- the rectangular frame. }
-
- MarginX := Round (0.5 * ScaleX);
- MarginY := Round (0.5 * ScaleY);
- L := MarginX - Offset.X;
- R := Dimension.X - MarginX - Offset.X;
- T := MarginY - Offset.Y;
- B := Dimension.Y - MarginY - Offset.Y;
-
- { Draw the rectangular frame. }
-
- MoveTo (DC,L,T);
- LineTo (DC,R,T);
- LineTo (DC,R,B);
- LineTo (DC,L,B);
- LineTo (DC,L,T);
-
- { Put back the original pen. }
-
- SelectObject (DC,OldPen);
- DeleteObject (NewPen);
- end;
-
- {--main----------------------------------------------------------------------}
-
- { Here it is--what you've all been waiting for--the main block! }
-
- var
- EpsDemo: tEpsDemo;
-
- begin
- EpsDemo.Init ('EPS Print Demo');
- if Assigned (EpsDemo.MainWindow) then
- begin
- EpsDemo.Run;
- EpsDemo.Done;
- end;
- end.
-