Class XbpPrinter() Foundation

Class function of the XbpPrinter class.

Description

Objects of the XbpPrinter() class are used to output graphics that are created using functions of the GRA engine. To allow this, a printer driver (printer object) must be installed that controls the physical printer. If several printer drivers, or printer objects, respectively, are installed, the default printer can be set using the context menu of the printer object. For each installed printer object a separate XbpPrinter object can be created that is then used to perform output using the applicable print driver.

Generally print output is asynchronous in GUI applications. This means that data for the printer is stored in a file or "spooled". The actual task of printing is handled by the spooler. The spooler takes each print job and sends it to the printer as soon as it is ready to process. This means that the program does not need to wait until everything is printed, but can continue as soon as the print job is handed to the spooler. The spooler is automatically managed by the operating system.

Graphic output in an Xbase++ program is performed in a presentation space that must be linked with a device context (an output device). An XbpPrinter object represents the device context for a presentation space whose graphic output will be printed. To allow this, the name of a printer object installed on the desktop must be specified to the XbpPrinter object. This XbpPrinter object must also be linked with the presentation space where the graphic output occurs (see example).

The start of print output is signalled by the :startDoc() method of the XbpPrinter object. All subsequent calls to Gra...() functions in the print job are combined and spooled together. The end of the print output (more precisely: the end of spooling) is indicated using the :endDoc() method. Data from the spooler is sent on to the printer only after the :endDoc() method is executed.

Class methods
:new()
Creates an instance of the XbpPrinter class.
:list()
Returns a list with the names of all installed printer objects.
Instance variables
:comment
Contains the Comment property of a printer object.
:devName
Determines the name of the printer.
:devParams
Additional parameters for certain printer drivers.
:devPort
Contains the Port property of a printer object.
:driverName
Determines the name of the printer driver.
:location
Contains the Location property of a printer object.
:spoolFormat
The format of the spool file.
:spoolJobName
The default name assigned to a spool job.
Life cycle
:create()
Requests system resources for the printer device context.
:configure()
This method has no effect in the XbpPrinter() class.
:destroy()
Releases system resources.
Device properties
:getHDC()
Retrieves the handle of a printer's device context
:forms()
Retrieves the forms selectable on the printer device.
:paperBins()
Retrieves the paper bins installed in the printer device.
:paperSize()
Returns the paper size in 1/10 millimeters.
:printerStatus()
Determine the current status of a printer.
:resolutions()
Retrieves the resolutions supported by the current printer device.
Printer settings

All methods in this group should only be called before a XbpPrinter object is associated with a presentation space. Calling them after an XbpPresSpace object is associated with the device context requires to :configure() the presentation space.

:setCollationMode()
Retrieves or sets the collation mode of the current printer device.
:setColorMode()
Sets or retrieves the mode for colored printing in color-capable printers.
:setDefault()
Sets the system's default printer.
:setDuplexMode()
Sets or retrieves the mode for duplex printing
:setFontMode()
Retrieves or sets the font options for this printer.
:setFormSize()
Retrieves or sets the size of the output media.
:setNumCopies()
Sets or retrieves the number of copies per print job.
:setOrientation()
Retrieves or sets the paper orientation for a printer.
:setPaperBin()
Selects the bin to load the paper from.
:setPrintFile()
Set file to print to.
:setResolution()
Retrieves or sets the print resolution.
:setupDialog()
Activates a dialog that allows the user to select attributes for the print job.
Output
:abort()
Deletes output spooled since :startDoc().
:endDoc()
Signals the end of graphic output (the end of a document).
:newPage()
Indicates a page break.
:startPage()
Indicates the beginning of a page.
:endPage()
Indicates that the current page has ended.
:startDoc()
Signals the beginning of graphic output (the start of a document).
Examples
Printing an image

// This example demonstrates the basic process of 
// printing images. A presentation space is created 
// in the UDF PrinterPS() that is linked to a device 
// context for a printer. 

#include "Gra.ch" 
#include "Xbp.ch" 

PROCEDURE Main 
   LOCAL oPS 

   // Create presentation space for default printer 
   oPS := PrinterPS() 

   // Activate spooling 
   oPS:device():startDoc() 

   // Spool graphic output 
   GraBox( oPS, {10,10}, {400,100} ) 
   GraStringAt( oPS, {20,50}, "Image is printed") 

   // End spooling 
   oPS:device():endDoc() 

   DestroyDevice( oPS ) 
RETURN 

// Create presentation space and link to 
// device context for printer. The coordinate 
// system unit is 1/10 millimeter. 
// 
FUNCTION PrinterPS( cPrinterObjectName ) 
   LOCAL oPS, oDC := XbpPrinter():New() 
   LOCAL aSize 

   oDC:Create( cPrinterObjectName ) 

   oPS := XbpPresSpace():New() 
   aSize := oDC:paperSize() 

   // Size of printable region on paper 
   aSize := { aSize[5] - aSize[3], ; 
              aSize[6] - aSize[4]  } 
   oPS:Create( oDC, aSize, GRA_PU_LOMETRIC ) 
RETURN oPS 

PROCEDURE DestroyDevice( oPS ) 
   LOCAL oDC := oPS:device() 

   IF oDC <> NIL 
      oPS:configure() 
      oDC:destroy() 
   ENDIF 
RETURN 
Print text using different fonts

// In this example, the array aFontlist is filled with 
// all of the fonts that can be displayed on the screen. 
// All of these fonts that are device independent vector 
// fonts are then output to the printer. The type size is 
// incremented as fonts are printed. 

#include "Gra.ch" 

PROCEDURE Main 
   LOCAL oWindowPS, oPrinterPS, oFont, aFontList 
   LOCAL i, imax, nY, nPointSize, cText, aSize 

   // Presentation space for window and printer 
   oWindowPS  := SetAppWindow():presSpace() 
   oPrinterPS := PrinterPS() 

   // Creat font object 
   oFont := XbpFont():new( oWindowPS ) 

   // Build list of available fonts 
   aFontList := oFont:list() 

   // Output fonts to printer 
   oPrinterPS:device():startDoc() 

   imax       := Len( aFontList ) 
   nY         := oPrinterPS:device():paperSize()[2] - 100 
   nPointSize := 1 
   FOR i:=1 TO imax 

      // Print only generic vector fonts 
      IF aFontList[i]:generic .AND. aFontList[i]:vector 

         oFont := aFontList[i] 
         oFont:nominalPointSize := ++nPointSize 
         oFont:configure() 

         // Set font for printer 
         GraSetFont( oPrinterPS, oFont ) 

         cText := Str( nPointSize, 2 ) + "." + ; 
                       oFont:compoundName 

         // Calculate size and new y position for string 
         aSize := GraQueryTextBox( oPrinterPS, cText ) 
         nY    := nY - aSize[1,2] 

         // Print string and release font 
         GraStringAt( oPrinterPS, {20,nY}, cText ) 
         oFont:destroy() 

      ENDIF 
   NEXT 

   oPrinterPS:device():endDoc() 
RETURN 

FUNCTION PrinterPS() 
   LOCAL oPS, oDC := XbpPrinter():New() 
   LOCAL aSize 

   oDC:Create() 

   oPS   := XbpPresSpace():New() 
   aSize := oDC:paperSize() 

   // Size of printable region on paper 
   aSize := { aSize[5] - aSize[3], ; 
              aSize[6] - aSize[4]  } 
   oPS:Create( oDC, aSize , GRA_PU_LOMETRIC ) 
RETURN oPS 
Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.