1 /*****************************************************************************\
2 Copyright (c) 2002 - 2015, HP Co.
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8 1. Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 3. Neither the name of HP nor the names of its
14 contributors may be used to endorse or promote products derived
15 from this software without specific prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
18 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
20 NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
22 TO, PATENT INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
23 OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 \*****************************************************************************/
28 #include "header.h"
29
30 #include "PrinterProperties.h"
31 #include "models.h"
32
PlatformServices()33 PlatformServices::PlatformServices () : SystemServices ()
34 {
35 }
36
~PlatformServices()37 PlatformServices::~PlatformServices ()
38 {
39 }
40
power(float x,float y)41 float PlatformServices::power (float x, float y)
42 {
43 return float (pow (x, y));
44 }
45
AllocMem(int iMemSize)46 BYTE * PlatformServices::AllocMem (int iMemSize)
47 {
48 return (BYTE *) malloc (iMemSize);
49 }
50
FreeMem(BYTE * pMem)51 void PlatformServices::FreeMem (BYTE *pMem)
52 {
53 free (pMem);
54 }
55
GetSystemTickCount(void)56 DWORD PlatformServices::GetSystemTickCount (void)
57 {
58 return 0;
59 }
60
BusyWait(DWORD msec)61 DRIVER_ERROR PlatformServices::BusyWait (DWORD msec)
62 {
63 return NO_ERROR;
64 }
65
DisplayPrinterStatus(DISPLAY_STATUS ePrinterStatus)66 void PlatformServices::DisplayPrinterStatus (DISPLAY_STATUS ePrinterStatus)
67 {
68 }
69
ReadDeviceID(BYTE * strID,int iSize)70 DRIVER_ERROR PlatformServices::ReadDeviceID (BYTE *strID, int iSize)
71 {
72 DRIVER_ERROR eResult = IO_ERROR;
73 return eResult;
74 }
75
GetStatusInfo(BYTE * bStatReg)76 BOOL PlatformServices::GetStatusInfo (BYTE *bStatReg)
77 {
78 BOOL bStatus = FALSE;
79 return bStatus;
80 }
81
FromDevice(BYTE * pReadBuff,DWORD * wReadCount)82 DRIVER_ERROR PlatformServices::FromDevice (BYTE *pReadBuff, DWORD *wReadCount)
83 {
84 return NO_ERROR;
85 }
86
ToDevice(const BYTE * pBuffer,DWORD * dwCount)87 DRIVER_ERROR PlatformServices::ToDevice (const BYTE *pBuffer, DWORD *dwCount)
88 {
89 *dwCount = 0;
90 return NO_ERROR;
91 }
92
CreatePrinterProperties()93 BOOL CreatePrinterProperties ()
94 {
95 pSys = new PlatformServices ();
96 pSys->IOMode.bDevID = FALSE;
97 pSys->IOMode.bStatus = FALSE;
98 pPC = new PrintContext (pSys);
99 iLastPrinter = MAX_PRINTER_TYPE;
100 return TRUE;
101 }
102
GetPrinterProperties(PrinterProperties * pPrinterProperties)103 int GetPrinterProperties (PrinterProperties *pPrinterProperties)
104 {
105 BOOL bResult = TRUE;
106 int i;
107 DRIVER_ERROR err;
108 if (pPrinterProperties == NULL)
109 {
110 return FALSE;
111 }
112 if (pSys == NULL)
113 {
114 bResult = CreatePrinterProperties ();
115 if (bResult == FALSE)
116 {
117 return (int) bResult;
118 }
119 }
120
121 while (1)
122 {
123 iCurrentPrinter++;
124 if (iCurrentPrinter == iLastPrinter)
125 {
126 if (pPC)
127 {
128 delete pPC;
129 }
130 if (pSys)
131 {
132 delete pSys;
133 }
134 return FALSE;
135 }
136 err = pPC->SelectDevice ((PRINTER_TYPE) iCurrentPrinter);
137 if (err != NO_ERROR)
138 {
139 if (iCurrentPrinter < iLastPrinter)
140 {
141 continue;
142 }
143 delete pPC;
144 delete pSys;
145 return FALSE;
146 }
147 strcpy (pPrinterProperties->szClassName, ModelName[iCurrentPrinter]);
148 for (i = 0; i < (int) (sizeof (PaperSizeInfoData) / sizeof (PaperSizeInfo)); i++)
149 {
150 err = pPC->SetPaperSize (PaperSizeInfoData[i].iPaperSize, 0);
151 if (err == WARN_ILLEGAL_PAPERSIZE)
152 {
153 continue;
154 }
155 strcpy (pPrinterProperties->szPaperSize, PaperSizeInfoData[i].szName);
156 pPrinterProperties->fPhysicalWidth = pPC->PhysicalPageSizeX ();
157 pPrinterProperties->fPhysicalHeight = pPC->PhysicalPageSizeY ();
158 pPrinterProperties->fPrintableWidth = pPC->PrintableWidth ();
159 pPrinterProperties->fPrintableHeight = pPC->PrintableHeight ();
160 pPrinterProperties->fTopLeftX = pPC->PrintableStartX ();
161 pPrinterProperties->fTopLeftY = pPC->PrintableStartY ();
162
163 fprintf (stdout, "%s,%s,%.4f,%.4f,%.4f,%.4f,%.4f,%.4f\n",
164 pPrinterProperties->szClassName,
165 pPrinterProperties->szPaperSize,
166 pPrinterProperties->fPhysicalWidth,
167 pPrinterProperties->fPhysicalHeight,
168 pPrinterProperties->fTopLeftX,
169 pPrinterProperties->fTopLeftY,
170 pPrinterProperties->fPrintableWidth,
171 pPrinterProperties->fPrintableHeight);
172
173 }
174 }
175 }
176
main()177 int main ()
178 {
179 PrinterProperties pPrProp;
180 GetPrinterProperties (&pPrProp);
181 return 0;
182 }
183