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

📄 fallback.cpp

📁 虚拟打印机
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/* * * fallback.cpp * *   Copyright (C) 2006 Michael H. Overlin   This program is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License as published by   the Free Software Foundation; either version 2 of the License, or   (at your option) any later version.   This program is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   GNU General Public License for more details.   You should have received a copy of the GNU General Public License   along with this program; if not, write to the Free Software   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA      Contact at poster_printer@yahoo.com */#include "fallback.h"#include "extDevMode.h"#include "mathutils.h"#include "printResizerCommon.h"#include "utils.h"#include "winstdforms.h"#include <winddi.h>#include <strsafe.h>// ***************************************************************************************// **  MODULE PRIVATE PROTOTYPES AND TYPEDEFS  *******************************************// ***************************************************************************************//typedef CHAR PAPERNAMES[64];//typedef PAPERNAMES *PPAPERNAMES;typedef WCHAR PAPERNAMES[64];typedef PAPERNAMES *PPAPERNAMES;// ***************************************************************************************// **  MODULE PUBLIC ROUTINES  ***********************************************************// ***************************************************************************************DWORD Fallback_GetDeviceCapabilities(	HANDLE hPrinter,    WORD  iDevCap,    VOID  *pvOutput	) {	DWORD dwRet = 0;	switch (iDevCap) {    case DC_BINNAMES:		if (pvOutput != NULL) {			StringCchCopy( (LPTSTR) pvOutput, 24, TEXT("Default Bin"));		}		dwRet = 1;		break;    case DC_BINS:		if (pvOutput != NULL) {			* (PWORD) pvOutput = DMBIN_ONLYONE;		}        dwRet = 1;		break;    case DC_COPIES:        dwRet = PRINTRESIZER_FALLBACK_MAXCOPIES;        break;    case DC_DRIVER:		dwRet = PRINTRESIZER_VERSION;		break;    case DC_COLLATE:		dwRet = 0;		break;    case DC_DUPLEX:		dwRet = 0;        break;    case DC_ENUMRESOLUTIONS:		if (pvOutput != NULL) {			PLONG pl = (PLONG) pvOutput;			pl[0] = PRINTRESIZER_FALLBACK_LOGPIXELS_X;			pl[1] = PRINTRESIZER_FALLBACK_LOGPIXELS_Y;		}        dwRet = 1;        break;    case DC_EXTRA:        dwRet = EXTDM_Get_dmDriverExtra();        break;    case DC_FIELDS:		dwRet = g_dmFallback.dmFields;        break;    case DC_FILEDEPENDENCIES:		// DEBUG / FIX		dwRet = 0;	    break;	case DC_MAXEXTENT: {		PPOINTS ppts = (PPOINTS) &dwRet;		ppts->x = RoundToLong(PRINTRESIZER_FALLBACK_MAXUSERPAPER_DIMENSION * MM_PER_INCH * 10);		ppts->y = RoundToLong(PRINTRESIZER_FALLBACK_MAXUSERPAPER_DIMENSION * MM_PER_INCH * 10);	} break;	case DC_MINEXTENT: {		PPOINTS ppts = (PPOINTS) &dwRet;		ppts->x = RoundToLong(PRINTRESIZER_FALLBACK_MINUSERPAPER_DIMENSION * MM_PER_INCH * 10);		ppts->y = RoundToLong(PRINTRESIZER_FALLBACK_MINUSERPAPER_DIMENSION * MM_PER_INCH * 10);	} break;    case DC_ORIENTATION:        dwRet = 90;        break;    case DC_PAPERNAMES:    case DC_PAPERS:	case DC_PAPERSIZE: {		RECTL rlMargins;		::Fallback_GetPaperMargins(rlMargins);		uint nFormsValid = 0;		uint nForms = ::GetPaperSizeCount();		for(uint kForm = 0; kForm < nForms; ++kForm) {			const ::PAPERSIZEINFO *ppsi = ::GetPaperSizeAtIndex(kForm);			SIZEL szlPaper = { ppsi->dwWidth_Micrometers, ppsi->dwHeight_Micrometers };						if ( ::Fallback_IsPaperSizeValid(szlPaper, rlMargins) ) {				if (pvOutput != NULL) {					switch(iDevCap) {					case DC_PAPERNAMES: {						// FROM DOCS YOU MIGHT THINK PAPERNAMES ARE ANSI CHARS, BUT						// I THINK THEY ARE ACTUALLY IN WCHAR						PPAPERNAMES pPaper = (PPAPERNAMES) pvOutput;						::StringCchCopy(pPaper[nFormsValid], ARRCOUNT(pPaper[nFormsValid]), ppsi->lpszName);					} break;					case DC_PAPERS: {						PWORD pw = (PWORD) pvOutput;						pw[nFormsValid] = ppsi->dmPaperSize;					} break;					case DC_PAPERSIZE: {						PPOINT ppt = (PPOINT) pvOutput;						// 0.1 MM UNITS						ppt[nFormsValid].x = RoundToLong( szlPaper.cx / 100.0 );						ppt[nFormsValid].y = RoundToLong( szlPaper.cy / 100.0 );					} break;					default:						ASSERTFAIL();						break;					} 				}				++ nFormsValid;			}		}		dwRet = nFormsValid;	} break; // case DC_PAPER...    case DC_SIZE:		dwRet = EXTDM_Get_dmSize();		break;    case DC_TRUETYPE:		dwRet = 0;		break;    case DC_VERSION:		dwRet = EXTDM_Get_dmSpecVersion();        break;    case DC_PERSONALITY:		dwRet = 0;        break;    case DC_COLORDEVICE:		dwRet = (g_dmFallback.dmColor == DMCOLOR_COLOR) ? 1 : 0;        break;    case DC_MEDIAREADY:		dwRet = 0;        break;    case DC_STAPLE:		dwRet = 0;		break;    case DC_NUP:		dwRet = 0;        break;	case DC_EMF_COMPLIANT:		dwRet = GDI_ERROR;		break;    default:        dwRet = GDI_ERROR;		break;    }	return dwRet;}BOOL Fallback_GetGDIINFO(PGDIINFO pGDIInfo, PCDEVMODE pdmTargetPrinter) {	RECTL rlMargins;	Fallback_GetPaperMargins(rlMargins);	BOOL bRetValue = FALSE;	::ZeroMemory(pGDIInfo, sizeof(*pGDIInfo));	ULONG ulHorzSize;	ULONG ulVertSize;	ULONG ulHorzRes;	ULONG ulVertRes;	POINTL ptlPhysOffset;	SIZEL szlPhysSize;	BOOL bLandscape =	(pdmTargetPrinter->dmFields & DM_ORIENTATION) && 						(pdmTargetPrinter->dmOrientation == DMORIENT_LANDSCAPE);	if ( ::Fallback_GetPaperGDIINFO(			bLandscape,			pdmTargetPrinter->dmPaperSize,			pdmTargetPrinter->dmPaperWidth,			pdmTargetPrinter->dmPaperLength,			PRINTRESIZER_FALLBACK_LOGPIXELS_X,			PRINTRESIZER_FALLBACK_LOGPIXELS_Y,			rlMargins,			ulHorzSize,			ulVertSize,			ulHorzRes,			ulVertRes,			ptlPhysOffset,			szlPhysSize			)	) {		double dScale = ( pdmTargetPrinter->dmFields & DM_SCALE ) ? pdmTargetPrinter->dmScale / 100.0 : 1.0;		//ulVersion 		//Specifies the driver version number. The byte ordering of ulVersion has the following form. 		// NOTE:  PRINTMIRROR DOES COMMENTED CODE TO RIGHT		pGDIInfo->ulVersion = PRINTRESIZER_GDIINFO_VERSION;	// = GetDeviceCaps(hdc , DRIVERVERSION) ;		//ulTechnology 		//Specifies the device technology. This member can be one of the values listed in the following table. 		// NOTE:  PRINTMIRROR DOES THIS		pGDIInfo->ulTechnology = DT_RASPRINTER;				//ulHorzSize 		//Specifies the width of the physical surface. A positive value indicates that the width is in units of millimeters, while a negative value denotes that the width is in units of micrometers. 		// NOTE:  VERSION COMMENTED OUT WAS TOO INACCURATE.  INSTEAD RETURN IN MICROMETERS USING 		//		  CALCULATED USING LOGPIXELS AND PHYSICAL SURFACE SIZE IN DEVICE UNITS		//pGDIInfo->ulHorzSize = GetDeviceCaps(hdc , HORZSIZE);		{			LONG lHorzSizeTemp = ulHorzSize;			if (lHorzSizeTemp < 0) {				pGDIInfo->ulHorzSize = - RoundToLong( - lHorzSizeTemp / dScale );			} else {				pGDIInfo->ulHorzSize = RoundToLong( lHorzSizeTemp / dScale );			}		}		//ulVertSize 		//Specifies the height of the physical surface. A positive value indicates that the height is in units of millimeters, while a negative value denotes that the height is in units of micrometers. 		// NOTE:  VERSION COMMENTED OUT WAS TOO INACCURATE.  INSTEAD RETURN IN MICROMETERS USING 		//		  CALCULATED USING LOGPIXELS AND PHYSICAL SURFACE SIZE IN DEVICE UNITS		//pGDIInfo->ulVertSize = GetDeviceCaps(hdc , VERTSIZE);		{			LONG lVertSizeTemp = ulVertSize;			if (lVertSizeTemp < 0) {				pGDIInfo->ulVertSize = - RoundToLong( - lVertSizeTemp / dScale );			} else {				pGDIInfo->ulVertSize = RoundToLong( lVertSizeTemp / dScale );			}		}		//ulHorzRes 		//Specifies the width in pixels of the physical surface (display devices), or of the printable surface (printers). 		pGDIInfo->ulHorzRes  = ulHorzRes;		//ulVertRes 		//Specifies the height in pixels of the physical surface (display devices), or of the printable surface (printers). 		pGDIInfo->ulVertRes  = ulVertRes;		//cBitsPixel 		//Specifies the number of adjacent bits in each color plane. The total number of bits per pixel is the product of cBitsPixel and cPlanes. 		pGDIInfo->cBitsPixel = PRINTRESIZER_FALLBACK_BITSPIXEL;		//cPlanes 		//Specifies the number of color planes. 		pGDIInfo->cPlanes    = PRINTRESIZER_FALLBACK_PLANES;		//ulNumColors 		//For palettized devices, ulNumColors specifies the number of entries in the default color palette. For nonpalettized devices (which do not include printers), ulNumColors is set to -1. 		// NOTE:  PRINTMIRROR DID NOT INCLUDE "IF" BLOCK THAT FOLLOWS ASSIGNMENT		pGDIInfo->ulNumColors =  PRINTRESIZER_FALLBACK_NUMCOLORS;		//flRaster 		//Is reserved and must be left set to zero. 		pGDIInfo->flRaster     = 0;  // RESERVED AND MUST BE 0

⌨️ 快捷键说明

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