Line No. | Rev | Author | Line |
---|---|---|---|
1 | 32 | kaklik | /****************************************************************************** |
2 | PCL 5 Printer Language Support |
||
3 | |||
4 | Summary: |
||
5 | This file provides support for the PCL 5 printer language when using the |
||
6 | USB Embedded Host Printer Client Driver. |
||
7 | |||
8 | Description: |
||
9 | This file provides support for the PCL 5 printer language when using the |
||
10 | USB Embedded Host Printer Client Driver. |
||
11 | |||
12 | There are several versions of the PCL printer language. This file is |
||
13 | targetted to support PCL 5. Unfortunately, printer language support is not |
||
14 | always advertised correctly by the printer. Some printers advertise only |
||
15 | PCL 6 support when they also support PCL 5. Therefore, the default value |
||
16 | for the LANGUAGE_ID_STRING_PCL string used in the routine |
||
17 | USBHostPrinterLanguagePCL5IsSupported() is set such that the routine will |
||
18 | return TRUE if any PCL language support is advertised. It is highly |
||
19 | recommended to test the target application with the specific printer(s) |
||
20 | that will be utilized, and, if possible, populate the |
||
21 | usbPrinterSpecificLanguage[] array in usb_config.c via the configuration |
||
22 | tool to manually select the printer language and its functional support. |
||
23 | |||
24 | Notes: |
||
25 | The PCL 5 coordinate origin is located at the top left corner of the paper. |
||
26 | The HP-GL/2 coordinate origin, however, is located at the bottom left corner |
||
27 | of the page. For consistency for the user, HP-GL/2 coordinate system is |
||
28 | adjusted to match the PCL coordinate system. This also matches the |
||
29 | coordinate system use by the Microchip Graphics library. |
||
30 | |||
31 | The black and white bit image polarity is 0=white, 1=black, which is |
||
32 | reversed from the Microchip Graphics Library polarity. This driver will |
||
33 | automatically convert the image data to the required format, as long as the |
||
34 | image data is located in ROM (USB_PRINTER_TRANSFER_FROM_ROM) or it is |
||
35 | copied from a RAM buffer (USB_PRINTER_TRANSFER_COPY_DATA). If the data is |
||
36 | to be sent directly from its original RAM location, the data must already |
||
37 | be in the format required by the printer language. |
||
38 | |||
39 | PCL 5 is not compatible with PCL 6; PCL 5 utilizes ASCII input, whereas |
||
40 | PCL 6 utilizes binary data. However, some printers that advertise support |
||
41 | for only PCL 5 do support PCL 6. |
||
42 | |||
43 | PCL 3 printers utilize many of the PCL 5 commands. The following |
||
44 | limitations exist with PCL 3: |
||
45 | * PCL 3 does not support vector graphics |
||
46 | * PCL 3 does not support image printing in landscape mode. The |
||
47 | page print will fail. |
||
48 | * Items must be sent to the page in the order that they are to be |
||
49 | printed from top to bottom. The printer cannot return to a |
||
50 | higher position on the page. |
||
51 | * PCL 3 does not support the USB_PRINTER_EJECT_PAGE command. Use the |
||
52 | USB_PRINTER_JOB_STOP and USB_PRINTER_JOB_START commands instead. |
||
53 | |||
54 | *******************************************************************************/ |
||
55 | //DOM-IGNORE-BEGIN |
||
56 | /****************************************************************************** |
||
57 | |||
58 | FileName: usb_host_printer_pcl_5.c |
||
59 | Dependencies: None |
||
60 | Processor: PIC24F/PIC32MX |
||
61 | Compiler: C30/C32 |
||
62 | Company: Microchip Technology, Inc. |
||
63 | |||
64 | Software License Agreement |
||
65 | |||
66 | The software supplied herewith by Microchip Technology Incorporated |
||
67 | (the Company) for its PICmicro® Microcontroller is intended and |
||
68 | supplied to you, the Companys customer, for use solely and |
||
69 | exclusively on Microchip PICmicro Microcontroller products. The |
||
70 | software is owned by the Company and/or its supplier, and is |
||
71 | protected under applicable copyright laws. All rights are reserved. |
||
72 | Any use in violation of the foregoing restrictions may subject the |
||
73 | user to criminal sanctions under applicable laws, as well as to |
||
74 | civil liability for the breach of the terms and conditions of this |
||
75 | license. |
||
76 | |||
77 | THIS SOFTWARE IS PROVIDED IN AN AS IS CONDITION. NO WARRANTIES, |
||
78 | WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED |
||
79 | TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
||
80 | PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, |
||
81 | IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR |
||
82 | CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
||
83 | |||
84 | Change History: |
||
85 | Rev Description |
||
86 | ---------- ---------------------------------------------------------- |
||
87 | 2.6 - 2.6a No change |
||
88 | |||
89 | 2.7 Changed the interface to _SetCurrentPosition to be able to |
||
90 | take in the printer number as a parameter. |
||
91 | |||
92 | 2.7a Provided macro wrapped versions of malloc() and free() |
||
93 | so that a user can override these functions easily. |
||
94 | *******************************************************************************/ |
||
95 | //DOM-IGNORE-END |
||
96 | |||
97 | #include <stdio.h> |
||
98 | #include <stdlib.h> |
||
99 | #include <string.h> |
||
100 | #include "GenericTypedefs.h" |
||
101 | #include "USB\usb.h" |
||
102 | #include "USB\usb_host_printer.h" |
||
103 | #include "USB\usb_host_printer_pcl_5.h" |
||
104 | |||
105 | //#define DEBUG_MODE |
||
106 | #if defined( DEBUG_MODE ) |
||
107 | #include "uart2.h" |
||
108 | #endif |
||
109 | |||
110 | |||
111 | #ifdef USB_PRINTER_LANGUAGE_PCL_5 |
||
112 | |||
113 | // ***************************************************************************** |
||
114 | // ***************************************************************************** |
||
115 | // Section: Configuration |
||
116 | // ***************************************************************************** |
||
117 | // ***************************************************************************** |
||
118 | |||
119 | #if !defined(USB_ENABLE_TRANSFER_EVENT) |
||
120 | #error The USB Host Printer Client Driver requires transfer events. |
||
121 | #endif |
||
122 | |||
123 | |||
124 | // ***************************************************************************** |
||
125 | // ***************************************************************************** |
||
126 | // Section: Constants |
||
127 | // ***************************************************************************** |
||
128 | // ***************************************************************************** |
||
129 | |||
130 | #define PCL_PAGE_BOTTOM 792 |
||
131 | #define PCL_PAGE_LEFT 0 |
||
132 | #define PCL_PAGE_RIGHT 612 |
||
133 | #define PCL_PAGE_TOP 0 |
||
134 | |||
135 | #define ESCAPE "\033" |
||
136 | #define ESCAPE_CHAR '\033' |
||
137 | |||
138 | #define COMMAND_ASCII ESCAPE "(0U" // Zero |
||
139 | #define COMMAND_FONT_BOLD ESCAPE "(s3B" |
||
140 | #define COMMAND_FONT_BOLD_VG "6,3,7," |
||
141 | #define COMMAND_FONT_ITALIC ESCAPE "(s1S" |
||
142 | #define COMMAND_FONT_ITALIC_VG "5,1," |
||
143 | #define COMMAND_FONT_MEDIUM ESCAPE "(s0B" |
||
144 | #define COMMAND_FONT_MEDIUM_VG "6,0,7," |
||
145 | #define COMMAND_FONT_UPRIGHT ESCAPE "(s0S" |
||
146 | #define COMMAND_FONT_UPRIGHT_VG "5,0," |
||
147 | #define COMMAND_SELECT_STANDARD "SS;" |
||
148 | #define COMMAND_STANDARD_FONT "SD1,277,2," |
||
149 | #define COMMAND_STANDARD_FONT_FIXED "0,3," |
||
150 | #define COMMAND_STANDARD_FONT_PROPORTIONAL "1,4," |
||
151 | #define COMMAND_TEXT_START "LB" |
||
152 | #define COMMAND_TEXT_STOP "\003;" |
||
153 | |||
154 | #define COMMAND_GRAPHICS_ANCHOR_CORNER "AC%d,%d;" |
||
155 | #define COMMAND_GRAPHICS_ARC_RELATIVE "AR%d,%d,%d;" |
||
156 | #define COMMAND_GRAPHICS_BAR "RA%d,%d;" |
||
157 | #define COMMAND_GRAPHICS_CIRCLE "CI%d;" |
||
158 | #define COMMAND_GRAPHICS_CIRCLE_FILLED "WG%d,0,360;" |
||
159 | #define COMMAND_GRAPHICS_COLOR_BLACK "SP1;" |
||
160 | #define COMMAND_GRAPHICS_COLOR_WHITE "SP0;" |
||
161 | #define COMMAND_GRAPHICS_FILL_TYPE_SOLID "FT1;" |
||
162 | #define COMMAND_GRAPHICS_FILL_TYPE_SHADE "FT10,%d;" |
||
163 | #define COMMAND_GRAPHICS_FILL_TYPE_HATCH "FT3,%d,%d;" |
||
164 | #define COMMAND_GRAPHICS_LINE "PA%d,%d;PD%d,%d;" |
||
165 | #define COMMAND_GRAPHICS_LINE_END_BUTT "LA1,1;" |
||
166 | #define COMMAND_GRAPHICS_LINE_END_ROUND "LA1,4;" |
||
167 | #define COMMAND_GRAPHICS_LINE_END_SQUARE "LA1,2;" |
||
168 | #define COMMAND_GRAPHICS_LINE_JOIN_BEVEL "LA2,5;" |
||
169 | #define COMMAND_GRAPHICS_LINE_JOIN_MITER "LA2,1;" |
||
170 | #define COMMAND_GRAPHICS_LINE_JOIN_ROUND "LA2,4;" |
||
171 | #define COMMAND_GRAPHICS_LINE_TO "PD%d,%d;" |
||
172 | #define COMMAND_GRAPHICS_LINE_TO_RELATIVE "PD;PR%d,%d;" |
||
173 | #define COMMAND_GRAPHICS_LINE_TYPE_DASHED "LT2,4,0;" |
||
174 | #define COMMAND_GRAPHICS_LINE_TYPE_DOTTED "LT1,4,0;" |
||
175 | #define COMMAND_GRAPHICS_LINE_TYPE_SOLID "LT;" |
||
176 | #define COMMAND_GRAPHICS_LINE_WIDTH_NORMAL "PW;" |
||
177 | #define COMMAND_GRAPHICS_LINE_WIDTH_THICK "PW1.059;" // 3 points |
||
178 | #define COMMAND_GRAPHICS_MOVE_TO "PA%d,%d;" |
||
179 | #define COMMAND_GRAPHICS_MOVE_RELATIVE "PR%d,%d;" |
||
180 | #define COMMAND_GRAPHICS_ORIENT_LANDSCAPE ESCAPE "*p0x0Y" ESCAPE "*c7920x5760Y" ESCAPE "*c0T" ESCAPE "%1B;IN;SP1;TR0;SC0,1.411,0,-1.411,2;IR0,100,0,100;" //"RO270;IP;" |
||
181 | #define COMMAND_GRAPHICS_ORIENT_PORTRAIT ESCAPE "*p0x0Y" ESCAPE "*c5760x7920Y" ESCAPE "*c0T" ESCAPE "%1B;IN;SP1;TR0;SC0,1.411,0,-1.411,2;IR0,100,0,100;" //"RO;IP;" |
||
182 | #define COMMAND_GRAPHICS_PEN_UP "PU;" |
||
183 | #define COMMAND_GRAPHICS_PEN_DOWN "PD;" |
||
184 | #define COMMAND_GRAPHICS_RECTANGLE "EA%d,%d;" |
||
185 | #define COMMAND_GRAPHICS_TERMINATE ESCAPE "%1A" |
||
186 | #define COMMAND_GRAPHICS_WEDGE "WG%d,%d,%d;" |
||
187 | |||
188 | #define COMMAND_JOB_START ESCAPE "%-12345X" ESCAPE "E" ESCAPE "&l0E" ESCAPE "&l0F" ESCAPE "&a0L" ESCAPE "&a0M" //ESCAPE "&a0N" |
||
189 | #define COMMAND_JOB_STOP ESCAPE "E" ESCAPE "%-12345X" |
||
190 | #define COMMAND_LANDSCAPE ESCAPE "&l1O" // Little L, one, Capital o |
||
191 | #define COMMAND_PORTRAIT ESCAPE "&l0O" // Little L, zero, Capital o |
||
192 | #define COMMAND_NEXT_PAGE ESCAPE "&a1G" |
||
193 | #define COMMAND_POSITION_HORIZONTAL ESCAPE "&a%dH" |
||
194 | #define COMMAND_POSITION_VERTICAL ESCAPE "&a%dV" |
||
195 | #define COMMAND_PROPORTIONAL ESCAPE "(s1P" |
||
196 | #define COMMAND_FIXED ESCAPE "(s0P" |
||
197 | #define COMMAND_RASTER_COMPRESSION_ADAPT ESCAPE "*b5M" |
||
198 | #define COMMAND_RASTER_COMPRESSION_DELTA ESCAPE "*b3M" |
||
199 | #define COMMAND_RASTER_COMPRESSION_NONE ESCAPE "*b0M" |
||
200 | #define COMMAND_RASTER_COMPRESSION_RES ESCAPE "*b4M" |
||
201 | #define COMMAND_RASTER_COMPRESSION_RLE ESCAPE "*b1M" |
||
202 | #define COMMAND_RASTER_COMPRESSION_TIFF ESCAPE "*b2M" |
||
203 | #define COMMAND_RASTER_DATA ESCAPE "*b%dW" // In bytes of data |
||
204 | #define COMMAND_RASTER_END ESCAPE "*rC" |
||
205 | #define COMMAND_RASTER_HEIGHT ESCAPE "*r%dT" // In pixels |
||
206 | #define COMMAND_RASTER_PRESENTATION ESCAPE "*r0F" |
||
207 | #define COMMAND_RASTER_RESOLUTION ESCAPE "*t%dR" |
||
208 | #define COMMAND_RASTER_START ESCAPE "*r1A" |
||
209 | #define COMMAND_RASTER_WIDTH ESCAPE "*r%dS" // In pixels |
||
210 | //#define COMMAND_RASTER_Y_OFFSET ESCAPE "*b%dY" // In pixels |
||
211 | |||
212 | // ***************************************************************************** |
||
213 | // ***************************************************************************** |
||
214 | // Section: Data Structures |
||
215 | // ***************************************************************************** |
||
216 | // ***************************************************************************** |
||
217 | |||
218 | //----------------------------------------------------------------------------- |
||
219 | /* Printer Status Structure |
||
220 | |||
221 | This structure holds the information about an attached printer. One instance |
||
222 | of this structure is needed for each attached printer. |
||
223 | */ |
||
224 | |||
225 | typedef struct _PRINTER_STATUS_PCL |
||
226 | { |
||
227 | USB_PRINTER_FUNCTION_SUPPORT support; // The functions supported by this printer. |
||
228 | |||
229 | WORD currentHeight; // The current height of the page in points. |
||
230 | WORD currentWidth; // The current width of the page in points. |
||
231 | |||
232 | WORD currentX; // Current X-axis position. |
||
233 | WORD currentY; // Current Y-axis position. |
||
234 | |||
235 | BYTE deviceAddress; // Address of the attached printer |
||
236 | BYTE fontName; // Currently selected font |
||
237 | BYTE fontSize; // Size of the current font |
||
238 | |||
239 | BYTE imageEndMask; // Some PCL printers do not ignore bits after the specified |
||
240 | // image width. We must explicitly set these to 0, or we |
||
241 | // will get a line down the right side of the image. |
||
242 | |||
243 | union |
||
244 | { |
||
245 | BYTE value; |
||
246 | |||
247 | struct |
||
248 | { |
||
249 | BYTE isLandscape : 1; // Landscape(1) or portrait(0) |
||
250 | BYTE isBold : 1; // If the font is bold |
||
251 | BYTE isItalic : 1; // If the font is italic |
||
252 | BYTE penIsWhite : 1; // Current selected pen is white. |
||
253 | }; |
||
254 | } printerFlags; |
||
255 | |||
256 | } PRINTER_STATUS_PCL; |
||
257 | |||
258 | |||
259 | // ***************************************************************************** |
||
260 | // ***************************************************************************** |
||
261 | // Section: Global Variables |
||
262 | // ***************************************************************************** |
||
263 | // ***************************************************************************** |
||
264 | |||
265 | const char _pclFontNames[USB_PRINTER_FONT_MAX_FONT][10] = { |
||
266 | ESCAPE "(s24607T", // Avant Garde |
||
267 | ESCAPE "(s24623T", // Bookman |
||
268 | ESCAPE "(s3T", // Courier |
||
269 | ESCAPE "(s24580T", // Helvetica |
||
270 | ESCAPE "(s24580T", // Helvetica Narrow |
||
271 | ESCAPE "(s24703T", // New Century Schoolbook |
||
272 | ESCAPE "(s24591T", // Palatino |
||
273 | ESCAPE "(s25093T" }; // Times Roman |
||
274 | |||
275 | const char _pclFontNamesVG[USB_PRINTER_FONT_MAX_FONT][4] = { |
||
276 | "31", // Avant Garde |
||
277 | "47", // Bookman |
||
278 | "3", // Courier |
||
279 | "4", // Helvetica |
||
280 | "4", // Helvetica Narrow |
||
281 | "23", // New Century Schoolbook |
||
282 | "15", // Palatino |
||
283 | "5" }; // Times Roman (277) |
||
284 | |||
285 | PRINTER_STATUS_PCL printerListPCL[USB_MAX_PRINTER_DEVICES]; |
||
286 | |||
287 | |||
288 | // ***************************************************************************** |
||
289 | // ***************************************************************************** |
||
290 | // Section: Macros |
||
291 | // ***************************************************************************** |
||
292 | // ***************************************************************************** |
||
293 | |||
294 | #define PAGE_IS_LANDSCAPE(x) ((x & 0x01) == 0x01) |
||
295 | #define PAGE_IS_PORTRAIT(x) ((x & 0x01) == 0x00) |
||
296 | #define FONT_IS_BOLD(x) ((x & 0x02) == 0x02) |
||
297 | #define FONT_IS_ITALIC(x) ((x & 0x04) == 0x04) |
||
298 | |||
299 | #define USING_VECTOR_GRAPHICS (printerListPCL[printer].support.supportFlags.supportsVectorGraphics) |
||
300 | |||
301 | #define X_COORDINATE_IN_RANGE(x) ((0 <= (x)) && ((x) <= printerListPCL[printer].currentWidth)) |
||
302 | #define Y_COORDINATE_IN_RANGE(y) ((0 <= (y)) && ((y) <= printerListPCL[printer].currentHeight)) |
||
303 | |||
304 | |||
305 | #define _SetCurrentPosition(p,x,y) \ |
||
306 | { \ |
||
307 | printerListPCL[(p)].currentX = (x); \ |
||
308 | printerListPCL[(p)].currentY = (y); \ |
||
309 | } |
||
310 | |||
311 | #ifndef USB_MALLOC |
||
312 | #define USB_MALLOC(size) malloc(size) |
||
313 | #endif |
||
314 | |||
315 | #ifndef USB_FREE |
||
316 | #define USB_FREE(ptr) free(ptr) |
||
317 | #endif |
||
318 | |||
319 | #define USB_FREE_AND_CLEAR(ptr) {USB_FREE(ptr); ptr = NULL;} |
||
320 | |||
321 | // ***************************************************************************** |
||
322 | // ***************************************************************************** |
||
323 | // Section: Local Prototypes |
||
324 | // ***************************************************************************** |
||
325 | // ***************************************************************************** |
||
326 | |||
327 | static BYTE _PrintFontCommand( BYTE printer, BYTE transferFlags ); |
||
328 | static BYTE _PrintStaticCommand( BYTE address, char *command, BYTE transferFlags ); |
||
329 | |||
330 | |||
331 | // ***************************************************************************** |
||
332 | // ***************************************************************************** |
||
333 | // Section: Interface Functions |
||
334 | // ***************************************************************************** |
||
335 | // ***************************************************************************** |
||
336 | |||
337 | /**************************************************************************** |
||
338 | Function: |
||
339 | BYTE USBHostPrinterLanguagePCL5( BYTE address, |
||
340 | USB_PRINTER_COMMAND command, USB_DATA_POINTER data, DWORD size, BYTE transferFlags ) |
||
341 | |||
342 | Summary: |
||
343 | This function executes printer commands for a PCL 5 printer. |
||
344 | |||
345 | Description: |
||
346 | This function executes printer commands for a PCL 5 printer. When |
||
347 | the application issues a printer command, the printer client driver |
||
348 | determines what language to use to communicate with the printer, and |
||
349 | transfers the command to that language support routine. As much as |
||
350 | possible, commands are designed to produce the same output regardless |
||
351 | of what printer language is used. |
||
352 | |||
353 | Not all printer commands support data from both RAM and ROM. Unless |
||
354 | otherwise noted, the data pointer is assumed to point to RAM, regardless of |
||
355 | the value of transferFlags. Refer to the specific command to see if ROM |
||
356 | data is supported. |
||
357 | |||
358 | Preconditions: |
||
359 | None |
||
360 | |||
361 | Parameters: |
||
362 | BYTE address - Device's address on the bus |
||
363 | USB_PRINTER_COMMAND command - Command to execute. See the enumeration |
||
364 | USB_PRINTER_COMMAND for the list of |
||
365 | valid commands and their requirements. |
||
366 | USB_DATA_POINTER data - Pointer to the required data. Note that |
||
367 | the caller must set transferFlags |
||
368 | appropriately to indicate if the pointer is |
||
369 | a RAM pointer or a ROM pointer. |
||
370 | DWORD size - Size of the data. For some commands, this |
||
371 | parameter is used to hold the data itself. |
||
372 | BYTE transferFlags - Flags that indicate details about the |
||
373 | transfer operation. Refer to these flags |
||
374 | * USB_PRINTER_TRANSFER_COPY_DATA |
||
375 | * USB_PRINTER_TRANSFER_STATIC_DATA |
||
376 | * USB_PRINTER_TRANSFER_NOTIFY |
||
377 | * USB_PRINTER_TRANSFER_FROM_ROM |
||
378 | * USB_PRINTER_TRANSFER_FROM_RAM |
||
379 | |||
380 | Return Values: |
||
381 | USB_PRINTER_SUCCESS - The command was executed successfully. |
||
382 | USB_PRINTER_UNKNOWN_DEVICE - A printer with the indicated address is not |
||
383 | attached |
||
384 | USB_PRINTER_TOO_MANY_DEVICES - The printer status array does not have |
||
385 | space for another printer. |
||
386 | USB_PRINTER_OUT_OF_MEMORY - Not enough available heap space to |
||
387 | execute the command. |
||
388 | other - See possible return codes from the |
||
389 | function USBHostPrinterWrite(). |
||
390 | |||
391 | Remarks: |
||
392 | When developing new commands, keep in mind that the function |
||
393 | USBHostPrinterCommandReady() will be used before calling this function to |
||
394 | see if there is space available in the output transfer queue. |
||
395 | USBHostPrinterCommandReady() will routine TRUE if a single space is |
||
396 | available in the output queue. Therefore, each command can generate only |
||
397 | one output transfer. |
||
398 | |||
399 | Multiple printer languages may be used in a single application. The USB |
||
400 | Embedded Host Printer Client Driver will call the routine required for the |
||
401 | attached device. |
||
402 | ***************************************************************************/ |
||
403 | |||
404 | BYTE USBHostPrinterLanguagePCL5( BYTE address, |
||
405 | USB_PRINTER_COMMAND command, USB_DATA_POINTER data, DWORD size, BYTE transferFlags ) |
||
406 | { |
||
407 | char *buffer; |
||
408 | BYTE printer = 0; |
||
409 | |||
410 | if (command != USB_PRINTER_ATTACHED) |
||
411 | { |
||
412 | // Try to find the current printer. If we can't find the printer in the list, |
||
413 | // put it in the list at the first available location. |
||
414 | for (printer=0; (printer<USB_MAX_PRINTER_DEVICES) && (printerListPCL[printer].deviceAddress != address); printer++ ); |
||
415 | if (printer == USB_MAX_PRINTER_DEVICES) |
||
416 | { |
||
417 | return USB_PRINTER_UNKNOWN_DEVICE; |
||
418 | } |
||
419 | } |
||
420 | |||
421 | // The USB_PRINTER_SET_POSITION should be used only when not using vector graphics. |
||
422 | if ((command == USB_PRINTER_SET_POSITION) && (USING_VECTOR_GRAPHICS)) |
||
423 | { |
||
424 | command = USB_PRINTER_GRAPHICS_MOVE_TO; |
||
425 | } |
||
426 | |||
427 | // If we are connected to a PCL printer that does not support vector graphis, |
||
428 | // such as PCL 3, return an error if the command is a vector graphics command. |
||
429 | if ((command > USB_PRINTER_VECTOR_GRAPHICS_START) && (command < USB_PRINTER_VECTOR_GRAPHICS_END) && !USING_VECTOR_GRAPHICS) |
||
430 | { |
||
431 | return USB_PRINTER_UNKNOWN_COMMAND; |
||
432 | } |
||
433 | |||
434 | switch( command ) |
||
435 | { |
||
436 | //--------------------------------------------------------------------- |
||
437 | case USB_PRINTER_ATTACHED: |
||
438 | for (printer=0; (printer<USB_MAX_PRINTER_DEVICES) && (printerListPCL[printer].deviceAddress != 0); printer++ ); |
||
439 | if (printer != USB_MAX_PRINTER_DEVICES) |
||
440 | { |
||
441 | printerListPCL[printer].deviceAddress = address; |
||
442 | printerListPCL[printer].support = *((USB_PRINTER_FUNCTION_SUPPORT *)(data.pointerRAM)); |
||
443 | return USB_PRINTER_SUCCESS; |
||
444 | } |
||
445 | return USB_PRINTER_TOO_MANY_DEVICES; |
||
446 | break; |
||
447 | |||
448 | //--------------------------------------------------------------------- |
||
449 | case USB_PRINTER_DETACHED: |
||
450 | for (printer=0; (printer<USB_MAX_PRINTER_DEVICES) && (printerListPCL[printer].deviceAddress != address); printer++ ); |
||
451 | if (printer != USB_MAX_PRINTER_DEVICES) |
||
452 | { |
||
453 | printerListPCL[printer].deviceAddress = 0; |
||
454 | } |
||
455 | return USB_PRINTER_SUCCESS; |
||
456 | break; |
||
457 | |||
458 | //--------------------------------------------------------------------- |
||
459 | case USB_PRINTER_JOB_START: |
||
460 | printerListPCL[printer].fontName = USB_PRINTER_FONT_HELVETICA; |
||
461 | printerListPCL[printer].fontSize = 12; |
||
462 | printerListPCL[printer].printerFlags.value = 0; |
||
463 | printerListPCL[printer].currentHeight = PRINTER_PAGE_PORTRAIT_HEIGHT; |
||
464 | printerListPCL[printer].currentWidth = PRINTER_PAGE_PORTRAIT_WIDTH; |
||
465 | _SetCurrentPosition( printer, 0, 0 ); |
||
466 | if (USING_VECTOR_GRAPHICS) |
||
467 | { |
||
468 | return _PrintStaticCommand( address, COMMAND_JOB_START COMMAND_GRAPHICS_ORIENT_PORTRAIT, transferFlags ); |
||
469 | } |
||
470 | else |
||
471 | { |
||
472 | return _PrintStaticCommand( address, COMMAND_JOB_START, transferFlags ); |
||
473 | } |
||
474 | break; |
||
475 | |||
476 | //--------------------------------------------------------------------- |
||
477 | case USB_PRINTER_JOB_STOP: |
||
478 | if (USING_VECTOR_GRAPHICS) |
||
479 | { |
||
480 | return _PrintStaticCommand( address, COMMAND_GRAPHICS_TERMINATE COMMAND_JOB_STOP, transferFlags | USB_PRINTER_TRANSFER_NOTIFY); |
||
481 | } |
||
482 | else |
||
483 | { |
||
484 | return _PrintStaticCommand( address, COMMAND_JOB_STOP, transferFlags | USB_PRINTER_TRANSFER_NOTIFY); |
||
485 | } |
||
486 | break; |
||
487 | |||
488 | //--------------------------------------------------------------------- |
||
489 | case USB_PRINTER_ORIENTATION_PORTRAIT: |
||
490 | printerListPCL[printer].printerFlags.isLandscape = 0; |
||
491 | printerListPCL[printer].currentHeight = PRINTER_PAGE_PORTRAIT_HEIGHT; |
||
492 | printerListPCL[printer].currentWidth = PRINTER_PAGE_PORTRAIT_WIDTH; |
||
493 | if (USING_VECTOR_GRAPHICS) |
||
494 | { |
||
495 | return _PrintStaticCommand( address, COMMAND_GRAPHICS_TERMINATE COMMAND_PORTRAIT COMMAND_GRAPHICS_ORIENT_PORTRAIT, transferFlags ); |
||
496 | } |
||
497 | else |
||
498 | { |
||
499 | return _PrintStaticCommand( address, COMMAND_PORTRAIT, transferFlags ); |
||
500 | } |
||
501 | break; |
||
502 | |||
503 | //--------------------------------------------------------------------- |
||
504 | case USB_PRINTER_ORIENTATION_LANDSCAPE: |
||
505 | printerListPCL[printer].printerFlags.isLandscape = 1; |
||
506 | printerListPCL[printer].currentHeight = PRINTER_PAGE_LANDSCAPE_HEIGHT; |
||
507 | printerListPCL[printer].currentWidth = PRINTER_PAGE_LANDSCAPE_WIDTH; |
||
508 | if (USING_VECTOR_GRAPHICS) |
||
509 | { |
||
510 | return _PrintStaticCommand( address, COMMAND_GRAPHICS_TERMINATE COMMAND_LANDSCAPE COMMAND_GRAPHICS_ORIENT_LANDSCAPE, transferFlags ); |
||
511 | } |
||
512 | else |
||
513 | { |
||
514 | return _PrintStaticCommand( address, COMMAND_LANDSCAPE, transferFlags ); |
||
515 | } |
||
516 | break; |
||
517 | |||
518 | //--------------------------------------------------------------------- |
||
519 | case USB_PRINTER_FONT_NAME: |
||
520 | // Font name is passed in the size parameter. |
||
521 | printerListPCL[printer].fontName = (BYTE)size; |
||
522 | return _PrintFontCommand( printer, transferFlags ); |
||
523 | break; |
||
524 | |||
525 | //--------------------------------------------------------------------- |
||
526 | case USB_PRINTER_FONT_SIZE: |
||
527 | // Font size is passed in the size parameter. |
||
528 | printerListPCL[printer].fontSize = (BYTE)size; |
||
529 | return _PrintFontCommand( printer, transferFlags ); |
||
530 | break; |
||
531 | |||
532 | //--------------------------------------------------------------------- |
||
533 | case USB_PRINTER_FONT_ITALIC: |
||
534 | printerListPCL[printer].printerFlags.isItalic = 1; |
||
535 | return _PrintFontCommand( printer, transferFlags ); |
||
536 | break; |
||
537 | |||
538 | //--------------------------------------------------------------------- |
||
539 | case USB_PRINTER_FONT_UPRIGHT: |
||
540 | printerListPCL[printer].printerFlags.isItalic = 0; |
||
541 | return _PrintFontCommand( printer, transferFlags ); |
||
542 | break; |
||
543 | |||
544 | //--------------------------------------------------------------------- |
||
545 | case USB_PRINTER_FONT_BOLD: |
||
546 | printerListPCL[printer].printerFlags.isBold = 1; |
||
547 | return _PrintFontCommand( printer, transferFlags ); |
||
548 | break; |
||
549 | |||
550 | //--------------------------------------------------------------------- |
||
551 | case USB_PRINTER_FONT_MEDIUM: |
||
552 | printerListPCL[printer].printerFlags.isBold = 0; |
||
553 | return _PrintFontCommand( printer, transferFlags ); |
||
554 | break; |
||
555 | |||
556 | //--------------------------------------------------------------------- |
||
557 | case USB_PRINTER_EJECT_PAGE: |
||
558 | _SetCurrentPosition( printer, 0, 0 ); |
||
559 | if (USING_VECTOR_GRAPHICS) |
||
560 | { |
||
561 | if ( printerListPCL[printer].printerFlags.isLandscape) |
||
562 | { |
||
563 | return _PrintStaticCommand( address, COMMAND_GRAPHICS_TERMINATE COMMAND_NEXT_PAGE COMMAND_GRAPHICS_ORIENT_LANDSCAPE, transferFlags ); |
||
564 | } |
||
565 | else |
||
566 | { |
||
567 | return _PrintStaticCommand( address, COMMAND_GRAPHICS_TERMINATE COMMAND_NEXT_PAGE COMMAND_GRAPHICS_ORIENT_PORTRAIT, transferFlags ); |
||
568 | } |
||
569 | } |
||
570 | // If not using vector graphics, then this command is not supported. |
||
571 | // Use USB_PRINTER_JOB_STOP and USB_PRINTER_JOB_START instead. |
||
572 | break; |
||
573 | |||
574 | //--------------------------------------------------------------------- |
||
575 | case USB_PRINTER_TEXT_START: |
||
576 | if (USING_VECTOR_GRAPHICS) |
||
577 | { |
||
578 | return _PrintStaticCommand( address, COMMAND_TEXT_START, transferFlags ); |
||
579 | } |
||
580 | else |
||
581 | { |
||
582 | // No processing required. |
||
583 | return USB_PRINTER_SUCCESS; |
||
584 | } |
||
585 | break; |
||
586 | |||
587 | //--------------------------------------------------------------------- |
||
588 | case USB_PRINTER_TEXT: |
||
589 | case USB_PRINTER_TRANSPARENT: |
||
590 | // If the user's data is in ROM, we have to copy it to RAM first, |
||
591 | // so the USB Host routines can read it. |
||
592 | if (transferFlags & USB_PRINTER_TRANSFER_FROM_ROM) |
||
593 | { |
||
594 | USBHOSTPRINTER_SETFLAG_COPY_DATA( transferFlags ); |
||
595 | } |
||
596 | if (transferFlags & USB_PRINTER_TRANSFER_COPY_DATA) |
||
597 | { |
||
598 | buffer = (char *)USB_MALLOC( size ); |
||
599 | if (buffer == NULL) |
||
600 | { |
||
601 | return USB_PRINTER_OUT_OF_MEMORY; |
||
602 | } |
||
603 | |||
604 | if (transferFlags & USB_PRINTER_TRANSFER_FROM_ROM) |
||
605 | { |
||
606 | #if defined( __C30__ ) |
||
607 | char __prog__ *ptr; |
||
608 | #elif defined( __PIC32MX__ ) |
||
609 | const char *ptr; |
||
610 | #endif |
||
611 | DWORD i; |
||
612 | |||
613 | ptr = ((USB_DATA_POINTER)data).pointerROM; |
||
614 | for (i=0; i<size; i++) |
||
615 | { |
||
616 | buffer[i] = *ptr++; |
||
617 | } |
||
618 | } |
||
619 | else |
||
620 | { |
||
621 | char *ptr; |
||
622 | DWORD i; |
||
623 | |||
624 | ptr = ((USB_DATA_POINTER)data).pointerRAM; |
||
625 | for (i=0; i<size; i++) |
||
626 | { |
||
627 | buffer[i] = *ptr++; |
||
628 | } |
||
629 | } |
||
630 | } |
||
631 | else |
||
632 | { |
||
633 | buffer = ((USB_DATA_POINTER)data).pointerRAM; |
||
634 | } |
||
635 | |||
636 | return USBHostPrinterWrite( address, buffer, size, transferFlags ); |
||
637 | break; |
||
638 | |||
639 | //--------------------------------------------------------------------- |
||
640 | case USB_PRINTER_TEXT_STOP: |
||
641 | if (USING_VECTOR_GRAPHICS) |
||
642 | { |
||
643 | return _PrintStaticCommand( address, COMMAND_TEXT_STOP, transferFlags ); |
||
644 | } |
||
645 | else |
||
646 | { |
||
647 | // No processing required. |
||
648 | return USB_PRINTER_SUCCESS; |
||
649 | } |
||
650 | break; |
||
651 | |||
652 | //--------------------------------------------------------------------- |
||
653 | case USB_PRINTER_SET_POSITION: |
||
654 | // Used only when not doing vector graphics. |
||
655 | // This command sets the cursor to the specified position. Note |
||
656 | // that we must convert the specification to use decipoints. |
||
657 | buffer = (char *)USB_MALLOC( 10 + 10 ); |
||
658 | if (buffer == NULL) |
||
659 | { |
||
660 | return USB_PRINTER_OUT_OF_MEMORY; |
||
661 | } |
||
662 | |||
663 | sprintf( buffer, COMMAND_POSITION_HORIZONTAL COMMAND_POSITION_VERTICAL, (WORD)(size >> 16) * 10, (WORD)size * 10 ); |
||
664 | _SetCurrentPosition( printer, (WORD)(size >> 16), (WORD)size ); |
||
665 | USBHOSTPRINTER_SETFLAG_COPY_DATA( transferFlags ); |
||
666 | return USBHostPrinterWrite( printerListPCL[printer].deviceAddress, buffer, strlen(buffer), transferFlags ); |
||
667 | break; |
||
668 | |||
669 | //--------------------------------------------------------------------- |
||
670 | case USB_PRINTER_IMAGE_START: |
||
671 | // This command sets up the printer for printing raster data. |
||
672 | buffer = (char *)USB_MALLOC( 4 + 8 + 8 + 6 + 11 + 11 + 11 ); |
||
673 | if (buffer == NULL) |
||
674 | { |
||
675 | return USB_PRINTER_OUT_OF_MEMORY; |
||
676 | } |
||
677 | |||
678 | { |
||
679 | BYTE usedBits; |
||
680 | USB_PRINTER_IMAGE_INFO *info; |
||
681 | BYTE mask; |
||
682 | WORD resolution; |
||
683 | |||
684 | info = (USB_PRINTER_IMAGE_INFO *)(data.pointerRAM); |
||
685 | |||
686 | // Determine the mask for the last image byte, so we don't get a spurious |
||
687 | // line on some printers. |
||
688 | printerListPCL[printer].imageEndMask = 0; |
||
689 | mask = 0x80; |
||
690 | usedBits = info->width & 0x07; |
||
691 | if (!usedBits) |
||
692 | { |
||
693 | usedBits = 8; |
||
694 | } |
||
695 | while (usedBits > 0) |
||
696 | { |
||
697 | printerListPCL[printer].imageEndMask |= mask; |
||
698 | mask >>= 1; |
||
699 | usedBits--; |
||
700 | } |
||
701 | |||
702 | // Set the resolution to a known good value. |
||
703 | if (info->resolution >= 600) |
||
704 | { |
||
705 | resolution = 600; |
||
706 | } |
||
707 | else if (info->resolution >= 300) |
||
708 | { |
||
709 | resolution = 300; |
||
710 | } |
||
711 | else if (info->resolution >= 200) |
||
712 | { |
||
713 | resolution = 200; |
||
714 | } |
||
715 | else if (info->resolution >= 150) |
||
716 | { |
||
717 | resolution = 150; |
||
718 | } |
||
719 | else if (info->resolution >= 100) |
||
720 | { |
||
721 | resolution = 100; |
||
722 | } |
||
723 | else |
||
724 | { |
||
725 | resolution = 75; |
||
726 | } |
||
727 | |||
728 | if (USING_VECTOR_GRAPHICS) |
||
729 | { |
||
730 | strcpy( buffer, COMMAND_GRAPHICS_TERMINATE ); |
||
731 | sprintf( &(buffer[strlen(buffer)]), COMMAND_POSITION_HORIZONTAL COMMAND_POSITION_VERTICAL COMMAND_RASTER_PRESENTATION COMMAND_RASTER_RESOLUTION COMMAND_RASTER_HEIGHT COMMAND_RASTER_WIDTH COMMAND_RASTER_START, |
||
732 | info->positionX * 10, info->positionY * 10, resolution, info->height, info->width ); |
||
733 | } |
||
734 | else |
||
735 | { |
||
736 | sprintf( buffer, COMMAND_POSITION_HORIZONTAL COMMAND_POSITION_VERTICAL COMMAND_RASTER_PRESENTATION COMMAND_RASTER_RESOLUTION COMMAND_RASTER_HEIGHT COMMAND_RASTER_WIDTH COMMAND_RASTER_START, |
||
737 | info->positionX * 10, info->positionY * 10, resolution, info->height, info->width ); |
||
738 | } |
||
739 | } |
||
740 | USBHOSTPRINTER_SETFLAG_COPY_DATA( transferFlags ); |
||
741 | return USBHostPrinterWrite( printerListPCL[printer].deviceAddress, buffer, strlen(buffer), transferFlags ); |
||
742 | break; |
||
743 | |||
744 | //--------------------------------------------------------------------- |
||
745 | case USB_PRINTER_IMAGE_DATA_HEADER: |
||
746 | // This command sends the command for the raster data. Therefore, the |
||
747 | // command USB_PRINTER_IMAGE_DATA must follow this command. |
||
748 | buffer = (char *)USB_MALLOC( 20 ); |
||
749 | if (buffer == NULL) |
||
750 | { |
||
751 | return USB_PRINTER_OUT_OF_MEMORY; |
||
752 | } |
||
753 | |||
754 | sprintf( buffer, COMMAND_RASTER_COMPRESSION_NONE COMMAND_RASTER_DATA, (WORD)((size+7)/8) ); |
||
755 | USBHOSTPRINTER_SETFLAG_COPY_DATA( transferFlags ); |
||
756 | return USBHostPrinterWrite( printerListPCL[printer].deviceAddress, buffer, strlen(buffer), transferFlags ); |
||
757 | break; |
||
758 | |||
759 | //--------------------------------------------------------------------- |
||
760 | case USB_PRINTER_IMAGE_DATA: |
||
761 | // The polarity of PCL raster graphics (0=white, 1=black) is |
||
762 | // backwards from other printer languages and the graphics library. |
||
763 | // To maintain compatibility, the values will be flipped for all |
||
764 | // copied data. |
||
765 | |||
766 | // ??? Do we want to mandate the flip? It will maintain consistency, |
||
767 | // but will not allow direct access to RAM data, and will be slower. |
||
768 | |||
769 | // Determine the number of data bytes. We might have a size that is |
||
770 | // not an even multiple of 8 bits. To account for this, add 7 to the |
||
771 | // size, and then divide by 8. |
||
772 | size += 7; |
||
773 | size /= 8; |
||
774 | |||
775 | // If the user's data is in ROM, we have to copy it to RAM first, |
||
776 | // so the USB Host routines can read it. |
||
777 | if (transferFlags & USB_PRINTER_TRANSFER_FROM_ROM) |
||
778 | { |
||
779 | USBHOSTPRINTER_SETFLAG_COPY_DATA( transferFlags ); |
||
780 | } |
||
781 | if (transferFlags & USB_PRINTER_TRANSFER_COPY_DATA) |
||
782 | { |
||
783 | DWORD i; |
||
784 | |||
785 | buffer = (char *)USB_MALLOC( size ); |
||
786 | if (buffer == NULL) |
||
787 | { |
||
788 | return USB_PRINTER_OUT_OF_MEMORY; |
||
789 | } |
||
790 | |||
791 | if (transferFlags & USB_PRINTER_TRANSFER_FROM_ROM) |
||
792 | { |
||
793 | #if defined( __C30__ ) |
||
794 | char __prog__ *ptr; |
||
795 | #elif defined( __PIC32MX__ ) |
||
796 | const char *ptr; |
||
797 | #endif |
||
798 | |||
799 | ptr = ((USB_DATA_POINTER)data).pointerROM; |
||
800 | for (i=0; i<size; i++) |
||
801 | { |
||
802 | buffer[i] = ~(*ptr++); |
||
803 | } |
||
804 | } |
||
805 | else |
||
806 | { |
||
807 | char *ptr; |
||
808 | |||
809 | ptr = ((USB_DATA_POINTER)data).pointerRAM; |
||
810 | for (i=0; i<size; i++) |
||
811 | { |
||
812 | buffer[i] = ~(*ptr++); |
||
813 | } |
||
814 | } |
||
815 | buffer[i-1] &= printerListPCL[printer].imageEndMask; |
||
816 | } |
||
817 | else |
||
818 | { |
||
819 | buffer = ((USB_DATA_POINTER)data).pointerRAM; |
||
820 | } |
||
821 | |||
822 | return USBHostPrinterWrite( address, buffer, size, transferFlags ); |
||
823 | break; |
||
824 | |||
825 | //--------------------------------------------------------------------- |
||
826 | case USB_PRINTER_IMAGE_STOP: |
||
827 | if (USING_VECTOR_GRAPHICS) |
||
828 | { |
||
829 | if (printerListPCL[printer].printerFlags.isLandscape) |
||
830 | { |
||
831 | return _PrintStaticCommand( address, COMMAND_RASTER_END COMMAND_LANDSCAPE COMMAND_GRAPHICS_ORIENT_LANDSCAPE, transferFlags ); |
||
832 | } |
||
833 | else |
||
834 | { |
||
835 | return _PrintStaticCommand( address, COMMAND_RASTER_END COMMAND_PORTRAIT COMMAND_GRAPHICS_ORIENT_PORTRAIT, transferFlags ); |
||
836 | } |
||
837 | } |
||
838 | else |
||
839 | { |
||
840 | return _PrintStaticCommand( address, COMMAND_RASTER_END, transferFlags ); |
||
841 | } |
||
842 | break; |
||
843 | |||
844 | //--------------------------------------------------------------------- |
||
845 | case USB_PRINTER_GRAPHICS_LINE_TYPE: |
||
846 | if (size == PRINTER_LINE_TYPE_SOLID) |
||
847 | { |
||
848 | return _PrintStaticCommand( address, COMMAND_GRAPHICS_LINE_TYPE_SOLID, transferFlags ); |
||
849 | } |
||
850 | else //PRINTER_LINE_TYPE_DASHED |
||
851 | { |
||
852 | return _PrintStaticCommand( address, COMMAND_GRAPHICS_LINE_TYPE_DASHED, transferFlags ); |
||
853 | } |
||
854 | break; |
||
855 | |||
856 | //--------------------------------------------------------------------- |
||
857 | case USB_PRINTER_GRAPHICS_LINE_WIDTH: |
||
858 | if (size == PRINTER_LINE_WIDTH_NORMAL) |
||
859 | { |
||
860 | return _PrintStaticCommand( address, COMMAND_GRAPHICS_LINE_WIDTH_NORMAL, transferFlags ); |
||
861 | } |
||
862 | else //PRINTER_LINE_WIDTH_THICK |
||
863 | { |
||
864 | return _PrintStaticCommand( address, COMMAND_GRAPHICS_LINE_WIDTH_THICK, transferFlags ); |
||
865 | } |
||
866 | break; |
||
867 | |||
868 | //--------------------------------------------------------------------- |
||
869 | case USB_PRINTER_GRAPHICS_LINE_END: |
||
870 | if (size == PRINTER_LINE_END_BUTT) |
||
871 | return _PrintStaticCommand( address, COMMAND_GRAPHICS_LINE_END_BUTT, transferFlags ); |
||
872 | else if (size == PRINTER_LINE_END_ROUND) |
||
873 | return _PrintStaticCommand( address, COMMAND_GRAPHICS_LINE_END_ROUND, transferFlags ); |
||
874 | else //PRINTER_LINE_END_SQUARE |
||
875 | return _PrintStaticCommand( address, COMMAND_GRAPHICS_LINE_END_SQUARE, transferFlags ); |
||
876 | break; |
||
877 | |||
878 | //--------------------------------------------------------------------- |
||
879 | case USB_PRINTER_GRAPHICS_LINE_JOIN: |
||
880 | if (size == PRINTER_LINE_JOIN_BEVEL) |
||
881 | return _PrintStaticCommand( address, COMMAND_GRAPHICS_LINE_JOIN_BEVEL, transferFlags ); |
||
882 | if (size == PRINTER_LINE_JOIN_MITER) |
||
883 | return _PrintStaticCommand( address, COMMAND_GRAPHICS_LINE_JOIN_MITER, transferFlags ); |
||
884 | else // PRINTER_LINE_JOIN_ROUND |
||
885 | return _PrintStaticCommand( address, COMMAND_GRAPHICS_LINE_JOIN_ROUND, transferFlags ); |
||
886 | break; |
||
887 | |||
888 | //--------------------------------------------------------------------- |
||
889 | case USB_PRINTER_GRAPHICS_FILL_TYPE: |
||
890 | if ((((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sFillType.fillType == PRINTER_FILL_SHADED) || |
||
891 | (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sFillType.fillType == PRINTER_FILL_HATCHED) || |
||
892 | (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sFillType.fillType == PRINTER_FILL_CROSS_HATCHED)) |
||
893 | { |
||
894 | buffer = (char *)USB_MALLOC( 14 ); |
||
895 | if (buffer == NULL) |
||
896 | { |
||
897 | return USB_PRINTER_OUT_OF_MEMORY; |
||
898 | } |
||
899 | |||
900 | if (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sFillType.fillType == PRINTER_FILL_SHADED) |
||
901 | { |
||
902 | sprintf( buffer, COMMAND_GRAPHICS_FILL_TYPE_SHADE, ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sFillType.shading ); |
||
903 | } |
||
904 | else |
||
905 | { |
||
906 | sprintf( buffer, COMMAND_GRAPHICS_FILL_TYPE_HATCH, ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sFillType.spacing, |
||
907 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sFillType.angle ); |
||
908 | if (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sFillType.fillType == PRINTER_FILL_CROSS_HATCHED) |
||
909 | { |
||
910 | buffer[2] = '4'; |
||
911 | } |
||
912 | } |
||
913 | USBHOSTPRINTER_SETFLAG_COPY_DATA( transferFlags ); |
||
914 | return USBHostPrinterWrite( printerListPCL[printer].deviceAddress, buffer, strlen(buffer), transferFlags ); |
||
915 | } |
||
916 | else // Default to PRINTER_FILL_SOLID. |
||
917 | { |
||
918 | return _PrintStaticCommand( address, COMMAND_GRAPHICS_FILL_TYPE_SOLID, transferFlags ); |
||
919 | } |
||
920 | break; |
||
921 | |||
922 | //--------------------------------------------------------------------- |
||
923 | case USB_PRINTER_GRAPHICS_COLOR: |
||
924 | if (size == PRINTER_COLOR_BLACK) |
||
925 | { |
||
926 | printerListPCL[printer].printerFlags.penIsWhite = 0; |
||
927 | return _PrintStaticCommand( address, COMMAND_GRAPHICS_COLOR_BLACK, transferFlags ); |
||
928 | } |
||
929 | else //PRINTER_COLOR_WHITE |
||
930 | { |
||
931 | printerListPCL[printer].printerFlags.penIsWhite = 1; |
||
932 | return _PrintStaticCommand( address, COMMAND_GRAPHICS_COLOR_WHITE, transferFlags ); |
||
933 | } |
||
934 | break; |
||
935 | |||
936 | //--------------------------------------------------------------------- |
||
937 | case USB_PRINTER_GRAPHICS_MOVE_TO: |
||
938 | #ifdef PRINTER_GRAPHICS_COORDINATE_CHECKING |
||
939 | if (!X_COORDINATE_IN_RANGE((WORD)(size >> 16)) || !Y_COORDINATE_IN_RANGE((WORD)size )) |
||
940 | { |
||
941 | return USB_PRINTER_BAD_PARAMETER; |
||
942 | } |
||
943 | #endif |
||
944 | |||
945 | buffer = (char *)USB_MALLOC( 14 ); |
||
946 | if (buffer == NULL) |
||
947 | { |
||
948 | return USB_PRINTER_OUT_OF_MEMORY; |
||
949 | } |
||
950 | |||
951 | sprintf( buffer, COMMAND_GRAPHICS_MOVE_TO, (WORD)(size >> 16) * 10, (WORD)size * 10); |
||
952 | _SetCurrentPosition( printer, (WORD)(size >> 16), (WORD)size ); |
||
953 | USBHOSTPRINTER_SETFLAG_COPY_DATA( transferFlags ); |
||
954 | return USBHostPrinterWrite( printerListPCL[printer].deviceAddress, buffer, strlen(buffer), transferFlags ); |
||
955 | break; |
||
956 | |||
957 | //--------------------------------------------------------------------- |
||
958 | case USB_PRINTER_GRAPHICS_MOVE_RELATIVE: |
||
959 | #ifdef PRINTER_GRAPHICS_COORDINATE_CHECKING |
||
960 | if (!X_COORDINATE_IN_RANGE( printerListPCL[printer].currentX + (int)(size >> 16) ) || !Y_COORDINATE_IN_RANGE( printerListPCL[printer].currentY + (int)(size & 0xFFFF) )) |
||
961 | { |
||
962 | return USB_PRINTER_BAD_PARAMETER; |
||
963 | } |
||
964 | #endif |
||
965 | |||
966 | buffer = (char *)USB_MALLOC( 16 ); |
||
967 | if (buffer == NULL) |
||
968 | { |
||
969 | return USB_PRINTER_OUT_OF_MEMORY; |
||
970 | } |
||
971 | |||
972 | sprintf( buffer, COMMAND_GRAPHICS_MOVE_RELATIVE, (int)(size >> 16) * 10, (int)(size & 0xFFFF) * 10 ); |
||
973 | _SetCurrentPosition( printer, printerListPCL[printer].currentX + (int)(size >> 16), printerListPCL[printer].currentY + (int)(size & 0xFFFF) ); |
||
974 | USBHOSTPRINTER_SETFLAG_COPY_DATA( transferFlags ); |
||
975 | return USBHostPrinterWrite( printerListPCL[printer].deviceAddress, buffer, strlen(buffer), transferFlags ); |
||
976 | break; |
||
977 | |||
978 | //--------------------------------------------------------------------- |
||
979 | case USB_PRINTER_GRAPHICS_LINE: |
||
980 | #ifdef PRINTER_GRAPHICS_COORDINATE_CHECKING |
||
981 | if (!X_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sLine.x1) || !Y_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sLine.y1) || |
||
982 | !X_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sLine.x2) || !Y_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sLine.y2)) |
||
983 | { |
||
984 | return USB_PRINTER_BAD_PARAMETER; |
||
985 | } |
||
986 | #endif |
||
987 | |||
988 | buffer = (char *)USB_MALLOC( 28 ); |
||
989 | if (buffer == NULL) |
||
990 | { |
||
991 | return USB_PRINTER_OUT_OF_MEMORY; |
||
992 | } |
||
993 | |||
994 | sprintf( buffer, COMMAND_GRAPHICS_LINE COMMAND_GRAPHICS_PEN_UP, |
||
995 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sLine.x1 * 10, ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sLine.y1 * 10, |
||
996 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sLine.x2 * 10, ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sLine.y2 * 10); |
||
997 | _SetCurrentPosition( printer, ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sLine.x2, ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sLine.y2 ); |
||
998 | USBHOSTPRINTER_SETFLAG_COPY_DATA( transferFlags ); |
||
999 | return USBHostPrinterWrite( printerListPCL[printer].deviceAddress, buffer, strlen(buffer), transferFlags ); |
||
1000 | break; |
||
1001 | |||
1002 | //--------------------------------------------------------------------- |
||
1003 | case USB_PRINTER_GRAPHICS_LINE_TO: |
||
1004 | #ifdef PRINTER_GRAPHICS_COORDINATE_CHECKING |
||
1005 | if (!X_COORDINATE_IN_RANGE( (int)(size >> 16) ) || !Y_COORDINATE_IN_RANGE( (int)(size & 0xFFFF) )) |
||
1006 | { |
||
1007 | return USB_PRINTER_BAD_PARAMETER; |
||
1008 | } |
||
1009 | #endif |
||
1010 | buffer = (char *)USB_MALLOC( 18 ); |
||
1011 | if (buffer == NULL) |
||
1012 | { |
||
1013 | return USB_PRINTER_OUT_OF_MEMORY; |
||
1014 | } |
||
1015 | |||
1016 | sprintf( buffer, COMMAND_GRAPHICS_LINE_TO COMMAND_GRAPHICS_PEN_UP, (int)(size >> 16) * 10, (int)(size & 0xFFFF) * 10) ; |
||
1017 | _SetCurrentPosition( printer, (int)(size >> 16), (int)(size & 0xFFFF) ); |
||
1018 | USBHOSTPRINTER_SETFLAG_COPY_DATA( transferFlags ); |
||
1019 | return USBHostPrinterWrite( printerListPCL[printer].deviceAddress, buffer, strlen(buffer), transferFlags ); |
||
1020 | break; |
||
1021 | |||
1022 | //--------------------------------------------------------------------- |
||
1023 | case USB_PRINTER_GRAPHICS_LINE_TO_RELATIVE: |
||
1024 | #ifdef PRINTER_GRAPHICS_COORDINATE_CHECKING |
||
1025 | if (!X_COORDINATE_IN_RANGE( printerListPCL[printer].currentX + (int)(size >> 16) ) || !Y_COORDINATE_IN_RANGE( printerListPCL[printer].currentY + (int)(size & 0xFFFF) )) |
||
1026 | { |
||
1027 | return USB_PRINTER_BAD_PARAMETER; |
||
1028 | } |
||
1029 | #endif |
||
1030 | buffer = (char *)USB_MALLOC( 22 ); |
||
1031 | if (buffer == NULL) |
||
1032 | { |
||
1033 | return USB_PRINTER_OUT_OF_MEMORY; |
||
1034 | } |
||
1035 | |||
1036 | sprintf( buffer, COMMAND_GRAPHICS_LINE_TO_RELATIVE COMMAND_GRAPHICS_PEN_UP, (int)(size >> 16) * 10, (int)(size & 0xFFFF) * 10 ) ; |
||
1037 | _SetCurrentPosition( printer, printerListPCL[printer].currentX + (int)(size >> 16), printerListPCL[printer].currentY + (int)(size & 0xFFFF) ); |
||
1038 | USBHOSTPRINTER_SETFLAG_COPY_DATA( transferFlags ); |
||
1039 | return USBHostPrinterWrite( printerListPCL[printer].deviceAddress, buffer, strlen(buffer), transferFlags ); |
||
1040 | break; |
||
1041 | |||
1042 | //--------------------------------------------------------------------- |
||
1043 | case USB_PRINTER_GRAPHICS_ARC: |
||
1044 | #ifdef PRINTER_GRAPHICS_COORDINATE_CHECKING |
||
1045 | if (!X_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sArc.xL) || !Y_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sArc.yT) || |
||
1046 | !X_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sArc.xR) || !Y_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sArc.yB)) |
||
1047 | { |
||
1048 | return USB_PRINTER_BAD_PARAMETER; |
||
1049 | } |
||
1050 | #endif |
||
1051 | |||
1052 | buffer = (char *)USB_MALLOC( (30 + 3)* 2 + 4 ); |
||
1053 | if (buffer == NULL) |
||
1054 | { |
||
1055 | return USB_PRINTER_OUT_OF_MEMORY; |
||
1056 | } |
||
1057 | |||
1058 | { |
||
1059 | int a1; |
||
1060 | int a2; |
||
1061 | BYTE mask; |
||
1062 | BYTE maskPrevious; |
||
1063 | |||
1064 | // Find the angles that define the arc. |
||
1065 | |||
1066 | if (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sArc.octant == 0) |
||
1067 | { |
||
1068 | a1 = 0; |
||
1069 | a2 = 0; |
||
1070 | } |
||
1071 | else if (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sArc.octant == 0xFF) |
||
1072 | { |
||
1073 | a1 = 0; |
||
1074 | a2 = 360; |
||
1075 | } |
||
1076 | else |
||
1077 | { |
||
1078 | // Look for the first edge of the arc. |
||
1079 | a1 = 0; |
||
1080 | mask = 0x02; |
||
1081 | maskPrevious = 0x04; |
||
1082 | while (!((mask & ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sArc.octant) && !(maskPrevious & ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sArc.octant))) |
||
1083 | { |
||
1084 | a1 += 45; |
||
1085 | maskPrevious = mask; |
||
1086 | mask >>= 1; |
||
1087 | if (mask == 0) |
||
1088 | { |
||
1089 | mask = 0x80; |
||
1090 | } |
||
1091 | } |
||
1092 | |||
1093 | // Look for the second edge of the arc. Note that the second angle is the sweep, not position. |
||
1094 | a2 = 0; |
||
1095 | while (mask & ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sArc.octant) |
||
1096 | { |
||
1097 | a2 += 45; |
||
1098 | mask >>= 1; |
||
1099 | if (mask == 0) |
||
1100 | { |
||
1101 | mask = 0x80; |
||
1102 | } |
||
1103 | } |
||
1104 | } |
||
1105 | |||
1106 | // Draw the outer circle of the arc. |
||
1107 | |||
1108 | sprintf( buffer, COMMAND_GRAPHICS_MOVE_TO COMMAND_GRAPHICS_WEDGE, |
||
1109 | (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sArc.xR + ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sArc.xL) * 10 / 2, |
||
1110 | (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sArc.yT + ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sArc.yB) * 10 / 2, |
||
1111 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sArc.r2 * 10, a1, a2 ); |
||
1112 | |||
1113 | if (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sArc.r1 != 0) |
||
1114 | { |
||
1115 | // Change pens |
||
1116 | |||
1117 | if (printerListPCL[printer].printerFlags.penIsWhite) |
||
1118 | { |
||
1119 | strcat( buffer, COMMAND_GRAPHICS_COLOR_BLACK ); |
||
1120 | } |
||
1121 | else |
||
1122 | { |
||
1123 | strcat( buffer, COMMAND_GRAPHICS_COLOR_WHITE ); |
||
1124 | } |
||
1125 | |||
1126 | // Draw the inner circle to erase the interior. |
||
1127 | |||
1128 | sprintf( &(buffer[strlen(buffer)]), COMMAND_GRAPHICS_MOVE_TO COMMAND_GRAPHICS_WEDGE, |
||
1129 | (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sArc.xR + ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sArc.xL) * 10 / 2, |
||
1130 | (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sArc.yT + ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sArc.yB) * 10 / 2, |
||
1131 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sArc.r1 * 10, a1, a2 ); |
||
1132 | |||
1133 | // Put the original pen back. |
||
1134 | |||
1135 | if (printerListPCL[printer].printerFlags.penIsWhite) |
||
1136 | { |
||
1137 | strcat( buffer, COMMAND_GRAPHICS_COLOR_WHITE ); |
||
1138 | } |
||
1139 | else |
||
1140 | { |
||
1141 | strcat( buffer, COMMAND_GRAPHICS_COLOR_BLACK ); |
||
1142 | } |
||
1143 | } |
||
1144 | |||
1145 | strcat ( buffer, COMMAND_GRAPHICS_PEN_UP ); |
||
1146 | } |
||
1147 | _SetCurrentPosition( printer, ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sArc.xL, ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sArc.yT ); |
||
1148 | USBHOSTPRINTER_SETFLAG_COPY_DATA( transferFlags ); |
||
1149 | return USBHostPrinterWrite( printerListPCL[printer].deviceAddress, buffer, strlen(buffer), transferFlags ); |
||
1150 | break; |
||
1151 | |||
1152 | //--------------------------------------------------------------------- |
||
1153 | case USB_PRINTER_GRAPHICS_CIRCLE: |
||
1154 | #ifdef PRINTER_GRAPHICS_COORDINATE_CHECKING |
||
1155 | if (!X_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.x + ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.r) || |
||
1156 | !X_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.x - ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.r) || |
||
1157 | !Y_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.y + ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.r) || |
||
1158 | !Y_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.y - ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.r)) |
||
1159 | { |
||
1160 | #ifdef DEBUG_MODE |
||
1161 | UART2PutHexWord(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.x); |
||
1162 | UART2PutChar( ' ' ); |
||
1163 | UART2PutHexWord(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.y); |
||
1164 | UART2PutChar( ' ' ); |
||
1165 | UART2PutHexWord(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.r); |
||
1166 | UART2PutChar( ' ' ); |
||
1167 | #endif |
||
1168 | return USB_PRINTER_BAD_PARAMETER; |
||
1169 | } |
||
1170 | #endif |
||
1171 | |||
1172 | buffer = (char *)USB_MALLOC( 12 + 8 + 4 ); |
||
1173 | if (buffer == NULL) |
||
1174 | { |
||
1175 | return USB_PRINTER_OUT_OF_MEMORY; |
||
1176 | } |
||
1177 | |||
1178 | sprintf( buffer, COMMAND_GRAPHICS_MOVE_TO COMMAND_GRAPHICS_CIRCLE COMMAND_GRAPHICS_PEN_UP, |
||
1179 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.x * 10, ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.y * 10, |
||
1180 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.r * 10 ); |
||
1181 | _SetCurrentPosition( printer, ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.x, ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.y ); |
||
1182 | USBHOSTPRINTER_SETFLAG_COPY_DATA( transferFlags ); |
||
1183 | return USBHostPrinterWrite( printerListPCL[printer].deviceAddress, buffer, strlen(buffer), transferFlags ); |
||
1184 | break; |
||
1185 | |||
1186 | //--------------------------------------------------------------------- |
||
1187 | case USB_PRINTER_GRAPHICS_CIRCLE_FILLED: |
||
1188 | #ifdef PRINTER_GRAPHICS_COORDINATE_CHECKING |
||
1189 | if (!X_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.x + ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.r) || |
||
1190 | !X_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.x - ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.r) || |
||
1191 | !Y_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.y + ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.r) || |
||
1192 | !Y_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.y - ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.r)) |
||
1193 | { |
||
1194 | #ifdef DEBUG_MODE |
||
1195 | UART2PutHexWord(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.x); |
||
1196 | UART2PutChar( ' ' ); |
||
1197 | UART2PutHexWord(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.y); |
||
1198 | UART2PutChar( ' ' ); |
||
1199 | UART2PutHexWord(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.r); |
||
1200 | UART2PutChar( ' ' ); |
||
1201 | #endif |
||
1202 | return USB_PRINTER_BAD_PARAMETER; |
||
1203 | } |
||
1204 | #endif |
||
1205 | |||
1206 | buffer = (char *)USB_MALLOC( 12 + 12+ 14 + 4 ); |
||
1207 | if (buffer == NULL) |
||
1208 | { |
||
1209 | return USB_PRINTER_OUT_OF_MEMORY; |
||
1210 | } |
||
1211 | |||
1212 | sprintf( buffer, COMMAND_GRAPHICS_MOVE_TO COMMAND_GRAPHICS_ANCHOR_CORNER COMMAND_GRAPHICS_CIRCLE_FILLED COMMAND_GRAPHICS_PEN_UP, |
||
1213 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.x * 10, ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.y * 10, |
||
1214 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.x * 10, ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.y * 10, |
||
1215 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.r * 10 ); |
||
1216 | _SetCurrentPosition( printer, ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.x, ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sCircle.y ); |
||
1217 | USBHOSTPRINTER_SETFLAG_COPY_DATA( transferFlags ); |
||
1218 | return USBHostPrinterWrite( printerListPCL[printer].deviceAddress, buffer, strlen(buffer), transferFlags ); |
||
1219 | break; |
||
1220 | |||
1221 | //--------------------------------------------------------------------- |
||
1222 | case USB_PRINTER_GRAPHICS_BEVEL: |
||
1223 | #ifdef PRINTER_GRAPHICS_COORDINATE_CHECKING |
||
1224 | if (!X_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.xL) || !Y_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.yT) || |
||
1225 | !X_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.xR) || !Y_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.yB)) |
||
1226 | { |
||
1227 | return USB_PRINTER_BAD_PARAMETER; |
||
1228 | } |
||
1229 | #endif |
||
1230 | |||
1231 | buffer = (char *)USB_MALLOC( 12 + (24 + 18) * 4 + 4 ); |
||
1232 | if (buffer == NULL) |
||
1233 | { |
||
1234 | return USB_PRINTER_OUT_OF_MEMORY; |
||
1235 | } |
||
1236 | |||
1237 | // PAxL,yB-r;PDxL,yB-r,xL,yT+r; |
||
1238 | sprintf( buffer, COMMAND_GRAPHICS_MOVE_TO COMMAND_GRAPHICS_LINE, |
||
1239 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.xL * 10, |
||
1240 | (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.yB - ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.r) * 10, |
||
1241 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.xL * 10, |
||
1242 | (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.yB - ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.r) * 10, |
||
1243 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.xL * 10, |
||
1244 | (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.yT + ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.r) * 10 ); |
||
1245 | |||
1246 | // ARr,0,-90; |
||
1247 | sprintf( &(buffer[strlen(buffer)]), COMMAND_GRAPHICS_ARC_RELATIVE, |
||
1248 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.r * 10, 0, 90 ); |
||
1249 | |||
1250 | // PDxL+r,yT,xR-r,yT; |
||
1251 | sprintf( &(buffer[strlen(buffer)]), COMMAND_GRAPHICS_LINE, |
||
1252 | (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.xL + ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.r) * 10, |
||
1253 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.yT * 10, |
||
1254 | (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.xR - ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.r) * 10, |
||
1255 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.yT * 10 ); |
||
1256 | |||
1257 | // AR0,r,-90; |
||
1258 | sprintf( &(buffer[strlen(buffer)]), COMMAND_GRAPHICS_ARC_RELATIVE, |
||
1259 | 0, ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.r * 10, 90 ); |
||
1260 | |||
1261 | // PDxR,yT+r,xR,yB-r; |
||
1262 | sprintf( &(buffer[strlen(buffer)]), COMMAND_GRAPHICS_LINE, |
||
1263 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.xR * 10, |
||
1264 | (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.yT + ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.r) * 10, |
||
1265 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.xR * 10, |
||
1266 | (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.yB - ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.r) * 10 ); |
||
1267 | |||
1268 | // AR-r,0,-90; |
||
1269 | sprintf( &(buffer[strlen(buffer)]), COMMAND_GRAPHICS_ARC_RELATIVE, |
||
1270 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.r * -1 * 10, 0, 90 ); |
||
1271 | |||
1272 | // PDxR-r,yB,xL+r;yB; |
||
1273 | sprintf( &(buffer[strlen(buffer)]), COMMAND_GRAPHICS_LINE, |
||
1274 | (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.xR - ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.r) * 10, |
||
1275 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.yB * 10, |
||
1276 | (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.xL + ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.r) * 10, |
||
1277 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.yB * 10 ); |
||
1278 | |||
1279 | // AR0,-r,-90;PU; |
||
1280 | sprintf( &(buffer[strlen(buffer)]), COMMAND_GRAPHICS_ARC_RELATIVE COMMAND_GRAPHICS_PEN_UP, |
||
1281 | 0, ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.r * -1 * 10, 90 ); |
||
1282 | |||
1283 | _SetCurrentPosition( printer, ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.xL, ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.yB ); |
||
1284 | USBHOSTPRINTER_SETFLAG_COPY_DATA( transferFlags ); |
||
1285 | return USBHostPrinterWrite( printerListPCL[printer].deviceAddress, buffer, strlen(buffer), transferFlags ); |
||
1286 | break; |
||
1287 | |||
1288 | //--------------------------------------------------------------------- |
||
1289 | case USB_PRINTER_GRAPHICS_BEVEL_FILLED: |
||
1290 | #ifdef PRINTER_GRAPHICS_COORDINATE_CHECKING |
||
1291 | if (!X_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.xL) || !Y_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.yT) || |
||
1292 | !X_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.xR) || !Y_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.yB)) |
||
1293 | { |
||
1294 | return USB_PRINTER_BAD_PARAMETER; |
||
1295 | } |
||
1296 | #endif |
||
1297 | |||
1298 | buffer = (char *)USB_MALLOC( 12 + 2 * (12 + 12) + 4 * (12 + 13) + 4 ); |
||
1299 | if (buffer == NULL) |
||
1300 | { |
||
1301 | return USB_PRINTER_OUT_OF_MEMORY; |
||
1302 | } |
||
1303 | |||
1304 | // PAxL+r,yB; RAxR-r,yT; |
||
1305 | sprintf( buffer, COMMAND_GRAPHICS_MOVE_TO COMMAND_GRAPHICS_ANCHOR_CORNER COMMAND_GRAPHICS_BAR, |
||
1306 | (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.xL + ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.r) * 10, |
||
1307 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.yB * 10, |
||
1308 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.xL, |
||
1309 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.yT * 10, |
||
1310 | (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.xR - ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.r) * 10, |
||
1311 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.yT * 10); |
||
1312 | |||
1313 | // PAxL,yB-r; RAxR,yT+r; |
||
1314 | sprintf( &(buffer[strlen(buffer)]), COMMAND_GRAPHICS_MOVE_TO COMMAND_GRAPHICS_BAR, |
||
1315 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.xL * 10, |
||
1316 | (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.yB - ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.r) * 10, |
||
1317 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.xR * 10, |
||
1318 | (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.yT + ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.r) * 10); |
||
1319 | |||
1320 | // PAxL+r,yB-r; WGr,180,90; |
||
1321 | sprintf( &(buffer[strlen(buffer)]), COMMAND_GRAPHICS_MOVE_TO COMMAND_GRAPHICS_WEDGE, |
||
1322 | (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.xL + ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.r) * 10, |
||
1323 | (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.yB - ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.r) * 10, |
||
1324 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.r * 10, 180, -90 ); |
||
1325 | |||
1326 | // PAxL+r,yT+r; WGr,90,90; |
||
1327 | sprintf( &(buffer[strlen(buffer)]), COMMAND_GRAPHICS_MOVE_TO COMMAND_GRAPHICS_WEDGE, |
||
1328 | (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.xL + ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.r) * 10, |
||
1329 | (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.yT + ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.r) * 10, |
||
1330 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.r * 10, 270, -90 ); |
||
1331 | |||
1332 | // PAxR-r,yT+r; WGr,0,90; |
||
1333 | sprintf( &(buffer[strlen(buffer)]), COMMAND_GRAPHICS_MOVE_TO COMMAND_GRAPHICS_WEDGE, |
||
1334 | (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.xR - ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.r) * 10, |
||
1335 | (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.yT + ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.r) * 10, |
||
1336 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.r * 10, 0, -90 ); |
||
1337 | |||
1338 | // PAxR-r,yB-r; WGr,270,90; PU; |
||
1339 | sprintf( &(buffer[strlen(buffer)]), COMMAND_GRAPHICS_MOVE_TO COMMAND_GRAPHICS_WEDGE, |
||
1340 | (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.xR - ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.r) * 10, |
||
1341 | (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.yB - ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.r) * 10, |
||
1342 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.r * 10, 90, -90 ); |
||
1343 | |||
1344 | _SetCurrentPosition( printer, ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.xL, ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sBevel.yB ); |
||
1345 | USBHOSTPRINTER_SETFLAG_COPY_DATA( transferFlags ); |
||
1346 | return USBHostPrinterWrite( printerListPCL[printer].deviceAddress, buffer, strlen(buffer), transferFlags ); |
||
1347 | break; |
||
1348 | |||
1349 | //--------------------------------------------------------------------- |
||
1350 | case USB_PRINTER_GRAPHICS_RECTANGLE: |
||
1351 | #ifdef PRINTER_GRAPHICS_COORDINATE_CHECKING |
||
1352 | if (!X_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sRectangle.xL) || !Y_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sRectangle.yT) || |
||
1353 | !X_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sRectangle.xR) || !Y_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sRectangle.yB)) |
||
1354 | { |
||
1355 | return USB_PRINTER_BAD_PARAMETER; |
||
1356 | } |
||
1357 | #endif |
||
1358 | |||
1359 | buffer = (char *)USB_MALLOC( 12 + 12 + 4 ); |
||
1360 | if (buffer == NULL) |
||
1361 | { |
||
1362 | return USB_PRINTER_OUT_OF_MEMORY; |
||
1363 | } |
||
1364 | |||
1365 | sprintf( buffer, COMMAND_GRAPHICS_MOVE_TO COMMAND_GRAPHICS_RECTANGLE COMMAND_GRAPHICS_PEN_UP, |
||
1366 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sRectangle.xL * 10, |
||
1367 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sRectangle.yT * 10, |
||
1368 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sRectangle.xR * 10, |
||
1369 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sRectangle.yB * 10 ); |
||
1370 | _SetCurrentPosition( printer, ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sRectangle.xL, ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sRectangle.yB ); |
||
1371 | USBHOSTPRINTER_SETFLAG_COPY_DATA( transferFlags ); |
||
1372 | return USBHostPrinterWrite( printerListPCL[printer].deviceAddress, buffer, strlen(buffer), transferFlags ); |
||
1373 | break; |
||
1374 | |||
1375 | //--------------------------------------------------------------------- |
||
1376 | case USB_PRINTER_GRAPHICS_RECTANGLE_FILLED: |
||
1377 | #ifdef PRINTER_GRAPHICS_COORDINATE_CHECKING |
||
1378 | if (!X_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sRectangle.xL) || !Y_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sRectangle.yT) || |
||
1379 | !X_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sRectangle.xR) || !Y_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sRectangle.yB)) |
||
1380 | { |
||
1381 | return USB_PRINTER_BAD_PARAMETER; |
||
1382 | } |
||
1383 | #endif |
||
1384 | |||
1385 | buffer = (char *)USB_MALLOC( 12 + 12 + 12 + 4 ); |
||
1386 | if (buffer == NULL) |
||
1387 | { |
||
1388 | return USB_PRINTER_OUT_OF_MEMORY; |
||
1389 | } |
||
1390 | |||
1391 | sprintf( buffer, COMMAND_GRAPHICS_MOVE_TO COMMAND_GRAPHICS_ANCHOR_CORNER COMMAND_GRAPHICS_BAR COMMAND_GRAPHICS_PEN_UP, |
||
1392 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sRectangle.xL * 10, |
||
1393 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sRectangle.yT * 10, |
||
1394 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sRectangle.xL * 10, |
||
1395 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sRectangle.yT * 10, |
||
1396 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sRectangle.xR * 10, |
||
1397 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sRectangle.yB * 10); |
||
1398 | _SetCurrentPosition( printer, ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sRectangle.xL, ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sRectangle.yB ); |
||
1399 | USBHOSTPRINTER_SETFLAG_COPY_DATA( transferFlags ); |
||
1400 | return USBHostPrinterWrite( printerListPCL[printer].deviceAddress, buffer, strlen(buffer), transferFlags ); |
||
1401 | break; |
||
1402 | |||
1403 | //--------------------------------------------------------------------- |
||
1404 | case USB_PRINTER_GRAPHICS_POLYGON: |
||
1405 | #ifdef PRINTER_GRAPHICS_COORDINATE_CHECKING |
||
1406 | { |
||
1407 | WORD i; |
||
1408 | |||
1409 | for (i = 0; i < ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sPolygon.numPoints * 2; i+=2) |
||
1410 | { |
||
1411 | if (!X_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sPolygon.points[i]) || !Y_COORDINATE_IN_RANGE(((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sPolygon.points[i+1])) |
||
1412 | { |
||
1413 | return USB_PRINTER_BAD_PARAMETER; |
||
1414 | } |
||
1415 | } |
||
1416 | } |
||
1417 | #endif |
||
1418 | |||
1419 | buffer = (char *)USB_MALLOC( 12 + (10 * (((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sPolygon.numPoints + 1)) + 4 ); |
||
1420 | if (buffer == NULL) |
||
1421 | { |
||
1422 | return USB_PRINTER_OUT_OF_MEMORY; |
||
1423 | } |
||
1424 | |||
1425 | { |
||
1426 | WORD i = 0; |
||
1427 | |||
1428 | sprintf( buffer, COMMAND_GRAPHICS_MOVE_TO "PD", |
||
1429 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sPolygon.points[0] * 10, |
||
1430 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sPolygon.points[1] * 10 ); |
||
1431 | |||
1432 | // xn,yn, |
||
1433 | while (i < ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sPolygon.numPoints * 2) |
||
1434 | { |
||
1435 | sprintf( &(buffer[strlen(buffer)]), "%d,%d,", |
||
1436 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sPolygon.points[i] * 10, |
||
1437 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sPolygon.points[i+1] * 10); |
||
1438 | i += 2; |
||
1439 | } |
||
1440 | |||
1441 | sprintf( &(buffer[strlen(buffer)]), "%d,%d;" COMMAND_GRAPHICS_PEN_UP, |
||
1442 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sPolygon.points[0] * 10, |
||
1443 | ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sPolygon.points[1] * 10); |
||
1444 | } |
||
1445 | |||
1446 | _SetCurrentPosition( printer, ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sPolygon.points[0], ((USB_PRINTER_GRAPHICS_PARAMETERS *)(data.pointerRAM))->sPolygon.points[1] ); |
||
1447 | USBHOSTPRINTER_SETFLAG_COPY_DATA( transferFlags ); |
||
1448 | return USBHostPrinterWrite( printerListPCL[printer].deviceAddress, buffer, strlen(buffer), transferFlags ); |
||
1449 | break; |
||
1450 | |||
1451 | //--------------------------------------------------------------------- |
||
1452 | default: |
||
1453 | return USB_PRINTER_UNKNOWN_COMMAND; |
||
1454 | break; |
||
1455 | } |
||
1456 | return USB_PRINTER_UNKNOWN_COMMAND; |
||
1457 | } |
||
1458 | |||
1459 | |||
1460 | /**************************************************************************** |
||
1461 | Function: |
||
1462 | BOOL USBHostPrinterLanguagePCL5IsSupported( char *deviceID, |
||
1463 | USB_PRINTER_FUNCTION_SUPPORT *support ) |
||
1464 | |||
1465 | Summary: |
||
1466 | This function determines if the printer with the given device ID string |
||
1467 | supports the PCL 5 printer language. |
||
1468 | |||
1469 | Description: |
||
1470 | This function determines if the printer with the given device ID string |
||
1471 | supports the PCL 5 printer language. |
||
1472 | |||
1473 | Unfortunately, printer language support is not always advertised correctly |
||
1474 | by the printer. Some printers advertise only PCL 6 support when they also |
||
1475 | support PCL 5. Therefore, this routine will return TRUE if any PCL |
||
1476 | language support is advertised. It is therefore highly recommended to test |
||
1477 | the target application with the specific printer(s) that will be utilized. |
||
1478 | |||
1479 | Preconditions: |
||
1480 | None |
||
1481 | |||
1482 | Parameters: |
||
1483 | char *deviceID - Pointer to the "COMMAND SET:" portion of the device ID |
||
1484 | string of the attached printer. |
||
1485 | USB_PRINTER_FUNCTION_SUPPORT *support - Pointer to returned information |
||
1486 | about what types of functions this printer supports. |
||
1487 | |||
1488 | Return Values: |
||
1489 | TRUE - The printer supports PCL 5. |
||
1490 | FALSE - The printer does not support PCL 5. |
||
1491 | |||
1492 | Remarks: |
||
1493 | The caller must first locate the "COMMAND SET:" section of the device ID |
||
1494 | string. To ensure that only the "COMMAND SET:" section of the device ID |
||
1495 | string is checked, the ";" at the end of the section should be temporarily |
||
1496 | replaced with a NULL. Otherwise, this function may find the printer |
||
1497 | language string in the comments or other section, and incorrectly indicate |
||
1498 | that the printer supports the language. |
||
1499 | |||
1500 | Device ID strings are case sensitive. |
||
1501 | ***************************************************************************/ |
||
1502 | |||
1503 | BOOL USBHostPrinterLanguagePCL5IsSupported( char *deviceID, |
||
1504 | USB_PRINTER_FUNCTION_SUPPORT *support ) |
||
1505 | { |
||
1506 | if (strstr( deviceID, LANGUAGE_ID_STRING_PCL )) |
||
1507 | { |
||
1508 | // When we add checks for PCL 3, this will have to change. PCL3 does |
||
1509 | // not support vector graphics. |
||
1510 | support->val = LANGUAGE_SUPPORT_FLAGS_PCL5; |
||
1511 | return TRUE; |
||
1512 | } |
||
1513 | return FALSE; |
||
1514 | } |
||
1515 | |||
1516 | |||
1517 | // ***************************************************************************** |
||
1518 | // ***************************************************************************** |
||
1519 | // Section: Local Functions |
||
1520 | // ***************************************************************************** |
||
1521 | // ***************************************************************************** |
||
1522 | |||
1523 | /**************************************************************************** |
||
1524 | Function: |
||
1525 | static BYTE _PrintFontCommand( BYTE printer, BYTE transferFlags ) |
||
1526 | |||
1527 | Description: |
||
1528 | This function generates the command needed to select the desired font |
||
1529 | and sends it to the printer. The font specification includes typeface, |
||
1530 | size, and bold and italic indications. |
||
1531 | |||
1532 | Preconditions: |
||
1533 | None |
||
1534 | |||
1535 | Parameters: |
||
1536 | BYTE printer - Index of the desired printer in the printer support array. |
||
1537 | BYTE transferFlags - Transfer control flags. |
||
1538 | |||
1539 | Return Values: |
||
1540 | USB_PRINTER_SUCCESS - Command completed successfully. |
||
1541 | USB_PRINTER_OUT_OF_MEMORY - Not enough dynamic memory to perform the |
||
1542 | command. |
||
1543 | others - See the return values for the function |
||
1544 | USBHostPrinterWrite(). |
||
1545 | |||
1546 | Remarks: |
||
1547 | HP-GL/2 requires font spacing awareness. If the font has fixed spacing, |
||
1548 | the Font Spacing parameter must be set to 0. If the font has proportional |
||
1549 | spacing, then the Font Spacing parameter must be set to 1. Otherwise, the |
||
1550 | correct font may not be selected. |
||
1551 | |||
1552 | If the font has fixed spacing, pitch must be specified to select the font |
||
1553 | size. The formula is pitch = 120/points, and points is stored in the |
||
1554 | fontSize structure member. |
||
1555 | ***************************************************************************/ |
||
1556 | |||
1557 | static BYTE _PrintFontCommand( BYTE printer, BYTE transferFlags ) |
||
1558 | { |
||
1559 | char *buffer; |
||
1560 | BYTE font; |
||
1561 | |||
1562 | buffer = (char *)USB_MALLOC( 40 ); |
||
1563 | if (buffer == NULL) |
||
1564 | { |
||
1565 | return USB_PRINTER_OUT_OF_MEMORY; |
||
1566 | } |
||
1567 | |||
1568 | font = printerListPCL[printer].fontName; |
||
1569 | if (font > USB_PRINTER_FONT_MAX_FONT) |
||
1570 | { |
||
1571 | font = USB_PRINTER_FONT_COURIER; |
||
1572 | } |
||
1573 | |||
1574 | if (USING_VECTOR_GRAPHICS) |
||
1575 | { |
||
1576 | strcpy( buffer, COMMAND_STANDARD_FONT ); |
||
1577 | if (printerListPCL[printer].fontName == USB_PRINTER_FONT_COURIER) |
||
1578 | { |
||
1579 | strcat( buffer, COMMAND_STANDARD_FONT_FIXED ); |
||
1580 | sprintf( &(buffer[strlen(buffer)]), "%d,", 120 / printerListPCL[printer].fontSize ); |
||
1581 | } |
||
1582 | else |
||
1583 | { |
||
1584 | strcat( buffer, COMMAND_STANDARD_FONT_PROPORTIONAL ); |
||
1585 | sprintf( &(buffer[strlen(buffer)]), "%d,", printerListPCL[printer].fontSize ); |
||
1586 | } |
||
1587 | |||
1588 | if (FONT_IS_ITALIC( printerListPCL[printer].printerFlags.value )) |
||
1589 | { |
||
1590 | strcat( buffer, COMMAND_FONT_ITALIC_VG ); |
||
1591 | } |
||
1592 | else |
||
1593 | { |
||
1594 | strcat( buffer, COMMAND_FONT_UPRIGHT_VG ); |
||
1595 | } |
||
1596 | |||
1597 | if (FONT_IS_BOLD( printerListPCL[printer].printerFlags.value )) |
||
1598 | { |
||
1599 | strcat( buffer, COMMAND_FONT_BOLD_VG ); |
||
1600 | } |
||
1601 | else |
||
1602 | { |
||
1603 | strcat( buffer, COMMAND_FONT_MEDIUM_VG ); |
||
1604 | } |
||
1605 | |||
1606 | strcat( buffer, &(_pclFontNamesVG[font][0]) ); |
||
1607 | |||
1608 | strcat( buffer, ";" COMMAND_SELECT_STANDARD ); |
||
1609 | } |
||
1610 | else |
||
1611 | { |
||
1612 | strcpy( buffer, COMMAND_ASCII ); |
||
1613 | if (printerListPCL[printer].fontName == USB_PRINTER_FONT_COURIER) |
||
1614 | { |
||
1615 | strcat( buffer, COMMAND_FIXED ); |
||
1616 | strcat( buffer, ESCAPE "(s" ); |
||
1617 | sprintf( &(buffer[strlen(buffer)]), "%d", 120 / printerListPCL[printer].fontSize ); |
||
1618 | strcat( buffer, "H" ); |
||
1619 | } |
||
1620 | else |
||
1621 | { |
||
1622 | strcat( buffer, COMMAND_PROPORTIONAL ); |
||
1623 | strcat( buffer, ESCAPE "(s" ); |
||
1624 | sprintf( &(buffer[strlen(buffer)]), "%d", printerListPCL[printer].fontSize ); |
||
1625 | strcat( buffer, "V" ); |
||
1626 | } |
||
1627 | |||
1628 | if (FONT_IS_ITALIC( printerListPCL[printer].printerFlags.value )) |
||
1629 | { |
||
1630 | strcat( buffer, COMMAND_FONT_ITALIC ); |
||
1631 | } |
||
1632 | else |
||
1633 | { |
||
1634 | strcat( buffer, COMMAND_FONT_UPRIGHT ); |
||
1635 | } |
||
1636 | |||
1637 | if (FONT_IS_BOLD( printerListPCL[printer].printerFlags.value )) |
||
1638 | { |
||
1639 | strcat( buffer, COMMAND_FONT_BOLD ); |
||
1640 | } |
||
1641 | else |
||
1642 | { |
||
1643 | strcat( buffer, COMMAND_FONT_MEDIUM ); |
||
1644 | } |
||
1645 | |||
1646 | strcat( buffer, &(_pclFontNames[font][0]) ); |
||
1647 | } |
||
1648 | |||
1649 | USBHOSTPRINTER_SETFLAG_COPY_DATA( transferFlags ); |
||
1650 | |||
1651 | return USBHostPrinterWrite( printerListPCL[printer].deviceAddress, buffer, strlen(buffer), transferFlags ); |
||
1652 | } |
||
1653 | |||
1654 | |||
1655 | /**************************************************************************** |
||
1656 | Function: |
||
1657 | static BYTE _PrintStaticCommand( BYTE address, char *command, BYTE transferFlags ) |
||
1658 | |||
1659 | Description: |
||
1660 | This function sends a hard-coded command to the printer. Many printer |
||
1661 | commands are constant text strings that require no parameters. This |
||
1662 | routine allocates dynamic memory for a copy of the command, copies the |
||
1663 | command into the string, and sends the command to the printer. |
||
1664 | |||
1665 | Preconditions: |
||
1666 | None |
||
1667 | |||
1668 | Parameters: |
||
1669 | BYTE address - Address of the attached printer. |
||
1670 | char *command - Printer command string. |
||
1671 | BYTE transferFlags - Transfer control string. |
||
1672 | |||
1673 | Return Values: |
||
1674 | USB_PRINTER_SUCCESS - Command completed successfully. |
||
1675 | USB_PRINTER_OUT_OF_MEMORY - Not enough dynamic memory to perform the |
||
1676 | command. |
||
1677 | others - See the return values for the function |
||
1678 | USBHostPrinterWrite(). |
||
1679 | |||
1680 | Remarks: |
||
1681 | None |
||
1682 | ***************************************************************************/ |
||
1683 | |||
1684 | static BYTE _PrintStaticCommand( BYTE address, char *command, BYTE transferFlags ) |
||
1685 | { |
||
1686 | char *buffer; |
||
1687 | |||
1688 | USBHOSTPRINTER_SETFLAG_COPY_DATA( transferFlags ); |
||
1689 | |||
1690 | buffer = (char *)USB_MALLOC( strlen(command) + 1 ); |
||
1691 | if (buffer == NULL) |
||
1692 | { |
||
1693 | return USB_PRINTER_OUT_OF_MEMORY; |
||
1694 | } |
||
1695 | strcpy( buffer, command ); |
||
1696 | return USBHostPrinterWrite( address, buffer, strlen(buffer), transferFlags ); |
||
1697 | } |
||
1698 | |||
1699 | |||
1700 | #endif |
Powered by WebSVN v2.8.3