⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 printer.java

📁 源码为Eclipse开源开发平台桌面开发工具SWT的源代码,
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
 * and false otherwise. * <p> * 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. * </p> *  * @param jobName the name of the print job to start * @return true if the job started successfully and false otherwise. * * @exception SWTException <ul> *    <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> * </ul> * * @see #startPage * @see #endPage * @see #endJob */public boolean startJob(String jobName) {	checkDevice();	DOCINFO di = new DOCINFO();	di.cbSize = DOCINFO.sizeof;	int hHeap = OS.GetProcessHeap();	int lpszDocName = 0;	if (jobName != null && jobName.length() != 0) {		/* Use the character encoding for the default locale */		TCHAR buffer = new TCHAR(0, jobName, true);		int byteCount = buffer.length() * TCHAR.sizeof;		lpszDocName = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, byteCount);		OS.MoveMemory(lpszDocName, buffer, byteCount);		di.lpszDocName = lpszDocName;	}	int lpszOutput = 0;	if (data.printToFile && data.fileName != null) {		/* Use the character encoding for the default locale */		TCHAR buffer = new TCHAR(0, data.fileName, true);		int byteCount = buffer.length() * TCHAR.sizeof;		lpszOutput = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, byteCount);		OS.MoveMemory(lpszOutput, buffer, byteCount);		di.lpszOutput = lpszOutput;	}	int rc = OS.StartDoc(handle, di);	if (lpszDocName != 0) OS.HeapFree(hHeap, 0, lpszDocName);	if (lpszOutput != 0) OS.HeapFree(hHeap, 0, lpszOutput);	return rc > 0;}/** * Ends the current print job. * * @exception SWTException <ul> *    <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> * </ul> * * @see #startJob * @see #startPage * @see #endPage */public void endJob() {	checkDevice();	OS.EndDoc(handle);}/** * Cancels a print job in progress.  * * @exception SWTException <ul> *    <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> * </ul> */public void cancelJob() {	checkDevice();	OS.AbortDoc(handle);}/** * Starts a page and returns true if the page started successfully * and false otherwise. * <p> * After calling startJob, this method may be called any number of times * along with a matching endPage. * </p> *  * @return true if the page started successfully and false otherwise. * * @exception SWTException <ul> *    <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> * </ul> * * @see #endPage * @see #startJob * @see #endJob */public boolean startPage() {	checkDevice();	int rc = OS.StartPage(handle);	if (rc <= 0) OS.AbortDoc(handle);	return rc > 0;}/** * Ends the current page. * * @exception SWTException <ul> *    <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> * </ul> * * @see #startPage * @see #startJob * @see #endJob */public void endPage() {	checkDevice();	OS.EndPage(handle);}/** * 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. * * @return the horizontal and vertical DPI * * @exception SWTException <ul> *    <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> * </ul> */public Point getDPI() {	checkDevice();	int dpiX = OS.GetDeviceCaps(handle, OS.LOGPIXELSX);	int dpiY = OS.GetDeviceCaps(handle, OS.LOGPIXELSY);	return new Point(dpiX, dpiY);}/** * Returns a rectangle describing the receiver's size and location. * For a printer, this is the size of a page, in pixels. * * @return the bounding rectangle * * @exception SWTException <ul> *    <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> * </ul> * * @see #getClientArea * @see #computeTrim */public Rectangle getBounds() {	checkDevice();	int width = OS.GetDeviceCaps(handle, OS.PHYSICALWIDTH);	int height = OS.GetDeviceCaps(handle, OS.PHYSICALHEIGHT);	return new Rectangle(0, 0, width, height);}/** * 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 a page, in pixels. *  * @return the client area * * @exception SWTException <ul> *    <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> * </ul> * * @see #getBounds * @see #computeTrim */public Rectangle getClientArea() {	checkDevice();	int width = OS.GetDeviceCaps(handle, OS.HORZRES);	int height = OS.GetDeviceCaps(handle, OS.VERTRES);	return new Rectangle(0, 0, width, height);}/** * Given a desired <em>client area</em> for the receiver * (as described by the arguments), returns the bounding * rectangle which would be required to produce that client * area. * <p> * In other words, it returns a rectangle such that, if the * receiver's bounds were set to that rectangle, the area * of the receiver which is capable of displaying data * (that is, not covered by the "trimmings") would be the * rectangle described by the arguments (relative to the * receiver's parent). * </p> * Note that there is no setBounds for a printer. This method * is usually used by passing in the client area (the 'printable * area') of the printer. It can also be useful to pass in 0, 0, 0, 0. *  * @param x the desired x coordinate of the client area * @param y the desired y coordinate of the client area * @param width the desired width of the client area * @param height the desired height of the client area * @return the required bounds to produce the given client area * * @exception SWTException <ul> *    <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> * </ul> * * @see #getBounds * @see #getClientArea */public Rectangle computeTrim(int x, int y, int width, int height) {	checkDevice();	int printX = -OS.GetDeviceCaps(handle, OS.PHYSICALOFFSETX);	int printY = -OS.GetDeviceCaps(handle, OS.PHYSICALOFFSETY);	int printWidth = OS.GetDeviceCaps(handle, OS.HORZRES);	int printHeight = OS.GetDeviceCaps(handle, OS.VERTRES);	int paperWidth = OS.GetDeviceCaps(handle, OS.PHYSICALWIDTH);	int paperHeight = OS.GetDeviceCaps(handle, OS.PHYSICALHEIGHT);	int hTrim = paperWidth - printWidth;	int vTrim = paperHeight - printHeight;	return new Rectangle(x + printX, y + printY, width + hTrim, height + vTrim);}/** * Returns a <code>PrinterData</code> object representing the * target printer for this print job. *  * @return a PrinterData object describing the receiver */public PrinterData getPrinterData() {	return data;}/** * Checks the validity of this device. * * @exception SWTException <ul> *    <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> * </ul> */protected void checkDevice() {	if (handle == 0) SWT.error(SWT.ERROR_DEVICE_DISPOSED);}/**	  * Releases any internal state prior to destroying this printer. * This method is called internally by the dispose * mechanism of the <code>Device</code> class. */protected void release() {	super.release();	data = null;}/**	  * Destroys the printer handle. * This method is called internally by the dispose * mechanism of the <code>Device</code> class. */protected void destroy() {	if (handle != 0) OS.DeleteDC(handle);	handle = 0;}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -