Class Printer
- All Implemented Interfaces:
Drawable
new GC(printer)
and then draw on the printer GC using the usual graphics calls.
A Printer object may be constructed by providing
a PrinterData object which identifies the printer.
A PrintDialog presents a print dialog to the user
and returns an initialized instance of PrinterData.
Alternatively, calling new Printer() will construct a
printer object for the user's default printer.
Application code must explicitly invoke the Printer.dispose()
method to release the operating system resources managed by each instance
when those instances are no longer required.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) long(package private) PrinterData(package private) static boolean(package private) static int(package private) static PrinterData(package private) static long(package private) static final String(package private) static final String(package private) booleanwhether or not a GC was created for this printer(package private) long(package private) long(package private) static PrinterData[](package private) long(package private) long(package private) static byte[](package private) static int(package private) longFields inherited from class Device
CHANGE_SCALEFACTOR, CurrentDevice, DEBUG, DeviceFinder, xDisplay -
Constructor Summary
ConstructorsConstructorDescriptionPrinter()Constructs a new printer representing the default printer.Printer(PrinterData data) Constructs a new printer given aPrinterDataobject representing the desired printer. -
Method Summary
Modifier and TypeMethodDescriptionvoidCancels a print job in progress.(package private) static DeviceDatacheckNull(PrinterData data) computeTrim(int x, int y, int width, int height) Given a client area (as described by the arguments), returns a rectangle, relative to the client area's coordinates, that is the client area expanded by the printer's trim (or minimum margins).protected voidcreate(DeviceData deviceData) Creates the printer handle.protected voiddestroy()Destroys the printer handle.voidendJob()Ends the current print job.voidendPage()Ends the current page.Returns a rectangle describing the receiver's size and location.Returns a rectangle which describes the area of the receiver which is capable of displaying data.static PrinterDataReturns aPrinterDataobject representing the default printer ornullif there is no default printer.getDPI()Returns a point whose x coordinate is the horizontal dots per inch of the printer, and whose y coordinate is the vertical dots per inch of the printer.(package private) PointReturns aPrinterDataobject representing the target printer for this print job.static PrinterData[]Returns an array ofPrinterDataobjects representing all available printers.(package private) static voidgtk_init()(package private) static long(package private) static longGtkPrinterFunc_Default(long printer, long user_data) (package private) static longGtkPrinterFunc_FindNamedPrinter(long printer, long user_data) (package private) static longGtkPrinterFunc_List(long printer, long user_data) protected voidinit()Initializes any internal resources needed by the device.voidinternal_dispose_GC(long hDC, GCData data) Invokes platform specific functionality to dispose a GC handle.longinternal_new_GC(GCData data) Invokes platform specific functionality to allocate a new GC handle.booleanReturnstrueiff coordinates can be auto-scaled on this drawable andfalseif not.(package private) static PrinterDataprinterDataFromGtkPrinter(long printer) (package private) static voidrestore(byte[] data, long settings, long page_setup) (package private) static booleanrestoreBoolean(String key) (package private) static byte[]restoreBytes(String key, boolean nullTerminate) (package private) static doublerestoreDouble(String key) (package private) static intrestoreInt(String key) booleanStarts a print job and returns true if the job started successfully and false otherwise.booleanStarts a page and returns true if the page started successfully and false otherwise.(package private) static byte[]uriFromFilename(String filename) Methods inherited from class Device
checkDevice, dispose, getDepth, getDeviceData, getDeviceZoom, getFontList, getSystemColor, getSystemFont, getWarnings, isDisposed, isTracking, loadFont, release, setTracking, setWarnings
-
Field Details
-
printerList
-
findPrinter
static long findPrinter -
findData
-
data
PrinterData data -
printer
long printer -
printJob
long printJob -
settings
long settings -
pageSetup
long pageSetup -
surface
long surface -
cairo
long cairo -
isGCCreated
boolean isGCCreatedwhether or not a GC was created for this printer -
settingsData
static byte[] settingsData -
start
static int start -
end
static int end -
GTK_LPR_BACKEND
- See Also:
-
GTK_FILE_BACKEND
- See Also:
-
disablePrinting
static boolean disablePrinting
-
-
Constructor Details
-
Printer
public Printer()Constructs a new printer representing the default printer.Note: You must dispose the printer when it is no longer required.
- Throws:
SWTError-- ERROR_NO_HANDLES - if there is no valid default printer
- See Also:
-
Printer
Constructs a new printer given aPrinterDataobject representing the desired printer. If the argument is null, then the default printer will be used.Note: You must dispose the printer when it is no longer required.
- Parameters:
data- the printer data for the specified printer, or null to use the default printer- Throws:
IllegalArgumentException-- ERROR_INVALID_ARGUMENT - if the specified printer data does not represent a valid printer
SWTError-- ERROR_NO_HANDLES - if there are no valid printers
- See Also:
-
-
Method Details
-
gtk_init
static void gtk_init() -
getPrinterList
Returns an array ofPrinterDataobjects representing all available printers. If there are no printers, the array will be empty.- Returns:
- an array of PrinterData objects representing the available printers
-
GtkPrinterFunc_List
static long GtkPrinterFunc_List(long printer, long user_data) -
getDefaultPrinterData
Returns aPrinterDataobject representing the default printer ornullif there is no default printer.- Returns:
- the default printer data or null
- Since:
- 2.1
-
GtkPrinterFunc_Default
static long GtkPrinterFunc_Default(long printer, long user_data) -
gtkPrinterFromPrinterData
-
GtkPrinterFunc_FindNamedPrinter
static long GtkPrinterFunc_FindNamedPrinter(long printer, long user_data) -
printerDataFromGtkPrinter
-
restore
static void restore(byte[] data, long settings, long page_setup) -
uriFromFilename
-
checkNull
-
restoreInt
-
restoreDouble
-
restoreBoolean
-
restoreBytes
-
internal_new_GC
Invokes platform specific functionality to allocate a new GC handle.IMPORTANT: This method is not part of the public API for
Printer. It is marked public only so that it can be shared within the packages provided by SWT. It is not available on all platforms, and should never be called from application code.- Specified by:
internal_new_GCin interfaceDrawable- Specified by:
internal_new_GCin classDevice- Parameters:
data- the platform specific GC data- Returns:
- the platform specific GC handle
-
internal_dispose_GC
Invokes platform specific functionality to dispose a GC handle.IMPORTANT: This method is not part of the public API for
Printer. It is marked public only so that it can be shared within the packages provided by SWT. It is not available on all platforms, and should never be called from application code.- Specified by:
internal_dispose_GCin interfaceDrawable- Specified by:
internal_dispose_GCin classDevice- Parameters:
hDC- the platform specific GC handledata- the platform specific GC data
-
isAutoScalable
public boolean isAutoScalable()Description copied from interface:DrawableReturnstrueiff coordinates can be auto-scaled on this drawable andfalseif not. E.g. aGCmethod should not auto-scale the bounds of a figure drawn on a Printer device, but it may have to auto-scale when drawing on a high-DPI Display monitor.- Returns:
trueif auto-scaling is enabled for this drawable
-
startJob
Starts a print job and returns true if the job started successfully and false otherwise.This must be the first method called to initiate a print job, followed by any number of startPage/endPage calls, followed by endJob. Calling startPage, endPage, or endJob before startJob will result in undefined behavior.
- Parameters:
jobName- the name of the print job to start- Returns:
- true if the job started successfully and false otherwise.
- Throws:
SWTException-- ERROR_DEVICE_DISPOSED - if the receiver has been disposed
- See Also:
-
destroy
-
endJob
public void endJob()Ends the current print job.- Throws:
SWTException-- ERROR_DEVICE_DISPOSED - if the receiver has been disposed
- See Also:
-
cancelJob
public void cancelJob()Cancels a print job in progress.- Throws:
SWTException-- ERROR_DEVICE_DISPOSED - if the receiver has been disposed
-
startPage
public boolean startPage()Starts a page and returns true if the page started successfully and false otherwise.After calling startJob, this method may be called any number of times along with a matching endPage.
- Returns:
- true if the page started successfully and false otherwise.
- Throws:
SWTException-- ERROR_DEVICE_DISPOSED - if the receiver has been disposed
- See Also:
-
endPage
public void endPage()Ends the current page.- Throws:
SWTException-- ERROR_DEVICE_DISPOSED - if the receiver has been disposed
- See Also:
-
getDPI
Returns a point whose x coordinate is the horizontal dots per inch of the printer, and whose y coordinate is the vertical dots per inch of the printer.- Overrides:
getDPIin classDevice- Returns:
- the horizontal and vertical DPI
- Throws:
SWTException-- ERROR_DEVICE_DISPOSED - if the receiver has been disposed
-
getBounds
Returns a rectangle describing the receiver's size and location.For a printer, this is the size of the physical page, in pixels.
- Overrides:
getBoundsin classDevice- Returns:
- the bounding rectangle
- Throws:
SWTException-- ERROR_DEVICE_DISPOSED - if the receiver has been disposed
- See Also:
-
getClientArea
Returns a rectangle which describes the area of the receiver which is capable of displaying data.For a printer, this is the size of the printable area of the page, in pixels.
- Overrides:
getClientAreain classDevice- Returns:
- the client area
- Throws:
SWTException-- ERROR_DEVICE_DISPOSED - if the receiver has been disposed
- See Also:
-
getIndependentDPI
Point getIndependentDPI() -
computeTrim
Given a client area (as described by the arguments), returns a rectangle, relative to the client area's coordinates, that is the client area expanded by the printer's trim (or minimum margins).Most printers have a minimum margin on each edge of the paper where the printer device is unable to print. This margin is known as the "trim." This method can be used to calculate the printer's minimum margins by passing in a client area of 0, 0, 0, 0 and then using the resulting x and y coordinates (which will be <= 0) to determine the minimum margins for the top and left edges of the paper, and the resulting width and height (offset by the resulting x and y) to determine the minimum margins for the bottom and right edges of the paper, as follows:
- The left trim width is -x pixels
- The top trim height is -y pixels
- The right trim width is (x + width) pixels
- The bottom trim height is (y + height) pixels
- Parameters:
x- the x coordinate of the client areay- the y coordinate of the client areawidth- the width of the client areaheight- the height of the client area- Returns:
- a rectangle, relative to the client area's coordinates, that is the client area expanded by the printer's trim (or minimum margins)
- Throws:
SWTException-- ERROR_DEVICE_DISPOSED - if the receiver has been disposed
- See Also:
-
create
Creates the printer handle. This method is called internally by the instance creation mechanism of theDeviceclass. -
init
-
getPrinterData
Returns aPrinterDataobject representing the target printer for this print job.- Returns:
- a PrinterData object describing the receiver
-