1 /* HPPageColor.c -- Vector Driver for HP Color LaserJet Printer.
2  * Copyright (C) 2003 EPSON KOWA Corporation
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18 
19 /* $Id: HPPageColor.c,v 1.1.1.1 2004/10/22 08:37:08 gishi Exp $ */
20 
21 
22 /* system include files */
23 
24 #include <sys/types.h>
25 #include <unistd.h>
26 
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <errno.h>
30 #include <string.h>
31 #include <stdarg.h>
32 #include <math.h>
33 
34 /* local */
35 #include "pdapi.h"
36 
37 typedef int bool;
38 
39 #ifndef FALSE
40 #define FALSE 0
41 #endif
42 
43 #ifndef TRUE
44 #define TRUE (!FALSE)
45 #endif
46 
47 #ifndef NULL
48 #ifdef __cplusplus
49 #define NULL 0
50 #else
51 #define NULL (void *)0
52 #endif
53 #endif
54 
55 typedef double floatp;
56 
57 
58 #define GS              (0x1b)
59 #define PCL_ESC         "\033"
60 #define PCL_FF          "\014"
61 #define PCL_CR          "\015"
62 #define PCL_LF          "\012"
63 #define PCL_BS          "\010"
64 
65 #define POINT                           72
66 #define PCLUNIT                         720
67 #define MMETER_PER_INCH                 25.4
68 
69 #define HP_DEFAULT_WIDTH                (4840)
70 #define HP_DEFAULT_HEIGHT               (6896)
71 
72 #define HP_LEFT_MARGIN_DEFAULT          5. / (MMETER_PER_INCH / POINT)
73 #define HP_BOTTOM_MARGIN_DEFAULT        5. / (MMETER_PER_INCH / POINT)
74 #define HP_RIGHT_MARGIN_DEFAULT         5. / (MMETER_PER_INCH / POINT)
75 #define HP_TOP_MARGIN_DEFAULT           5. / (MMETER_PER_INCH / POINT)
76 
77 struct node {
78     long                byte;
79     char                *buf;
80     struct node         *next;
81 };
82 
83 
84 #define         BUFCHECK(x)             \
85         if (strlen(obuf) > x) {         \
86             (void)DebugPrint("overflow %d : LINE %d\n", strlen(obuf), __LINE__); \
87         }
88 
89 
90 
91 #define HP_OPTION_MANUALFEED            "ManualFeed"            /* �ѻ�ȥ쥤 */
92 #define HP_OPTION_CASSETFEED            "Casset"                /* ���ȥ쥤 */
93 #define HP_OPTION_FACEUP                "FU"                    /* �ӻ�ȥ쥤 Face Up */
94 #define HP_OPTION_FACEDOWN              "FD"                    /* �ӻ�ȥ쥤 Face Down */
95 #define HP_OPTION_DUPLEX                "Duplex"                /* ξ�̰��� */
96 #define HP_OPTION_DUPLEX_TUMBLE         "Tumble"                /* �Ȥ����� */
97 #define HP_OPTION_MEDIATYPE             "MediaType"             /* ��� */
98 #define HP_OPTION_RIT                   "RITOff"                /* RIT */
99 #define HP_OPTION_LANDSCAPE             "Landscape"             /* LANDSCAPE */
100 #define HP_OPTION_TONERDENSITY          "TonerDensity"          /* �ȥʡ�ǻ�� */
101 #define HP_OPTION_TONERSAVING           "TonerSaving"           /* �ȥʡ������� */
102 #define HP_OPTION_COLLATE               "Collate"               /* �������� */
103 
104 #define HP_TUMBLE_DEFAULT               FALSE                   /* Long age */
105 #define HP_RIT_DEFAULT                  FALSE
106 #define HP_FACEUP_DEFAULT               FALSE
107 #define HP_FACEUP_DEFAULT               FALSE
108 
109 #define HP_MEDIATYPE_DEFAULT            0                       /* NORMAL */
110 #define HP_MEDIACHAR_MAX                32
111 
112 #define HP_MANUALFEED_DEFAULT           FALSE
113 #define HP_CASSETFEED_DEFAULT           0
114 
115 #define HP_DPI_MIN                      60
116 #define HP_DPI_MAX                      600
117 #define HP_DPI_SUPERFINE                1200
118 
119 #define HP_A3_HEIGHT                    1190
120 #define HP_A3_WIDTH                     842
121 #define HP_POSTCARD_HEIGHT              419
122 #define HP_POSTCARD_WIDTH               284
123 #define HP_LETTER_HEIGHT                792
124 #define HP_LETTER_WIDTH                 612
125 #define HP_LEDGER_HEIGHT                1224
126 #define HP_LEDGER_WIDTH                 HP_LETTER_HEIGHT
127 
128 #define HP_HEIGHT_MAX                   HP_A3_HEIGHT
129 #define HP_WIDTH_MAX                    HP_A3_WIDTH
130 #define HP_HEIGHT_MIN                   HP_POSTCARD_HEIGHT
131 #define HP_WIDTH_MIN                    HP_POSTCARD_WIDTH
132 
133 #define EP_COMPRESS5                    (5 << 16)
134 #define EP_COMPRESS20                   (20 << 16)
135 #define EP_COMPRESS30                   (30 << 16)
136 
137 #define RES1200                         HP_DPI_SUPERFINE
138 #define RES600                          HP_DPI_MAX
139 #define RES300                          300
140 
141 #define JPN                             TRUE
142 #define ENG                             FALSE
143 
144 #define HP_COLOR_ID_STROKE              2
145 #define HP_COLOR_ID_FILL                3
146 #define HP_COLOR_ID_BACK                4
147 
148 #define HP_DEFAULT_PRINTER              "default"       /* �ǥե���ȥץ��̾�� */
149 #define HP_OPTION_FACE_UP               "UPPER"         /* �ӻ�ȥ쥤 Face Up */
150 #define HP_OPTION_FACE_DOWN             "LOWER"         /* �ӻ�ȥ쥤 Face Down */
151 
152 #define HP_OPTION_ON                    "ON"            /* ON ʸ���� */
153 #define HP_OPTION_OFF                   "OFF"           /* OFF ʸ���� */
154 
155 
156 typedef struct PaperTable_s
157 {
158     int         width;                  /* paper width (unit: dot(300dpi)) */
159     int         height;                 /* paper height (unit: dot(300dpi)) */
160     int         distwidth;              /* distance logical area (unit: dot(300dpi)) */
161     int         distheight;             /* distance picture frame area (unit: dot(300dpi)) */
162     int         distdraw;               /* distance printable area (unit: dot(300dpi)) */
163     int         pcl;                    /* number of papersize in PCL */
164     char        *name;                  /* paper Name */
165 } PaperTable;
166 
167 static const PaperTable HpPaperTable[] =
168 {
169     {2480, 3507, 71, 150, 50, 26, "A4"},              /* A4 */
170     {3507, 4960, 71, 150, 50, 27, "A3"},              /* A3 */
171     {2550, 3300, 75, 150, 50, 2, "LETTER"},           /* Letter */
172     {2550, 4200, 75, 150, 50, 3, "LEGAL"},            /* Legal */
173 //    {2175, 3150, 75, 150, 50, 1, "EXECUTIVE"},      /* Executive */
174 //    {3300, 5100, 75, 150, 50, 6, "LEDGER"},         /* Ledger */
175     {0, 0, 0, 0, 0, -1, NULL}                    /* Undefined */
176 };
177 
178 
179 /* Vector Driver API Proc. Entries */
180 typedef struct  _OPVP_api_procs {
181         int     (*OpenPrinter)(int,char *,int *,struct _OPVP_api_procs **);
182         int     (*ClosePrinter)(int);
183         int     (*StartJob)(int,char *);
184         int     (*EndJob)(int);
185         int     (*StartDoc)(int,char *);
186         int     (*EndDoc)(int);
187         int     (*StartPage)(int,char *);
188         int     (*EndPage)(int);
189 #ifndef OLD_API
190         int     (*QueryDeviceCapability)(int, int, int, char *);
191         int     (*QueryDeviceInfo)(int, int, int, char *);
192 #endif /* OLD_API */
193         int     (*ResetCTM)(int);
194         int     (*SetCTM)(int,CTM *);
195         int     (*GetCTM)(int,CTM *);
196         int     (*InitGS)(int);
197         int     (*SaveGS)(int);
198         int     (*RestoreGS)(int);
199         int     (*QueryColorSpace)(int,ColorSpace *,int *);
200         int     (*SetColorSpace)(int,ColorSpace);
201         int     (*GetColorSpace)(int,ColorSpace *);
202         int     (*QueryROP)(int,int *,int *);
203         int     (*SetROP)(int,int);
204         int     (*GetROP)(int,int *);
205         int     (*SetFillMode)(int,FillMode);
206         int     (*GetFillMode)(int,FillMode *);
207         int     (*SetAlphaConstant)(int,float);
208         int     (*GetAlphaConstant)(int,float *);
209         int     (*SetLineWidth)(int,Fix);
210         int     (*GetLineWidth)(int,Fix *);
211         int     (*SetLineDash)(int,Fix *,int);
212         int     (*GetLineDash)(int,Fix *,int *);
213         int     (*SetLineDashOffset)(int,Fix);
214         int     (*GetLineDashOffset)(int,Fix *);
215         int     (*SetLineStyle)(int,LineStyle);
216         int     (*GetLineStyle)(int,LineStyle *);
217         int     (*SetLineCap)(int,LineCap);
218         int     (*GetLineCap)(int,LineCap *);
219         int     (*SetLineJoin)(int,LineJoin);
220         int     (*GetLineJoin)(int,LineJoin *);
221         int     (*SetMiterLimit)(int,Fix);
222         int     (*GetMiterLimit)(int,Fix *);
223         int     (*SetPaintMode)(int,PaintMode);
224         int     (*GetPaintMode)(int,PaintMode *);
225         int     (*SetStrokeColor)(int,Brush *);
226         int     (*SetFillColor)(int,Brush *);
227         int     (*SetBgColor)(int,Brush *);
228         int     (*NewPath)(int);
229         int     (*EndPath)(int);
230         int     (*StrokePath)(int);
231         int     (*FillPath)(int);
232         int     (*StrokeFillPath)(int);
233         int     (*SetClipPath)(int,ClipRule);
234 #ifndef OLD_API
235         int     (*ResetClipPath)(int);
236 #endif /* OLD_API */
237         int     (*SetCurrentPoint)(int,Fix,Fix);
238         int     (*LinePath)(int,int,int,Point *);
239         int     (*PolygonPath)(int,int,int *,Point *);
240         int     (*RectanglePath)(int,int,Rectangle *);
241         int     (*RoundRectanglePath)(int,int,RoundRectangle *);
242         int     (*BezierPath)(int,int *,Point *);
243         int     (*ArcPath)(int,int,int,Fix,Fix,Fix,Fix,
244                            Fix,Fix,Fix,Fix);
245         int     (*DrawBitmapText)(int,int,int,int,void *);
246         int     (*DrawImage)(int,int,int,int,
247                              ImageFormat,Rectangle,int,void *);
248         int     (*StartDrawImage)(int,int,int,int,
249                                   ImageFormat,Rectangle);
250         int     (*TransferDrawImage)(int,int,void *);
251         int     (*EndDrawImage)(int);
252         int     (*StartScanline)(int,int);
253         int     (*Scanline)(int,int,int *);
254         int     (*EndScanline)(int);
255         int     (*StartRaster)(int,int);
256         int     (*TransferRasterData)(int,int,unsigned char *);
257         int     (*SkipRaster)(int,int);
258         int     (*EndRaster)(int);
259         int     (*StartStream)(int);
260         int     (*TransferStreamData)(int,int,void *);
261         int     (*EndStream)(int);
262 } OPVP_api_procs;
263 
264 /* �ꥹ�ȤΥΡ��� */
265 typedef struct ItemList_s {
266         void *item;
267         size_t length;
268         struct ItemList_s *next;
269 } ItemList;
270 
271 /*
272  * GraphicsState
273  *      ����˴ؤ������Ƥξ����������빽¤��
274  */
275 typedef struct GraphicsState_s {
276         /* Graphic State Object Operations */
277         CTM             ctm;
278         ColorSpace      colorSpace;
279         FillMode        fillMode;
280         Fix             lineWidth;
281         LineCap         lineCap;
282         LineJoin        lineJoin;
283         Brush           strokeBrush;
284         Brush           fillBrush;
285         Brush           bgBrush;
286         bool            useBgBrush;
287         int             rop;
288         PaintMode       paintMode;
289 
290         /* Path */
291         bool        pathActive; /* Path������Ǥ����TRUE�������Ǥʤ����FALSE */
292         bool        subpathActive; /* SubPath������Ǥ����TRUE�������Ǥʤ����FALSE */
293         ItemList    *pathList; /* Path���ޥ�ɤ��Ǽ����ꥹ�Ȥ���Ƭ���ɥ쥹 */
294         ItemList    *pathEndPoint; /* Path���ޥ�ɥꥹ�Ȥν�ü���ɥ쥹 */
295         Fix         miterlimit; /* MiterLimit������ */
296 
297         /* Image */
298         bool        imageActive; /* Image������Ǥ����TRUE�������Ǥʤ����FALSE */
299         ImageFormat imageFormat;
300         int         imageWidth;
301         int         imageHeight;
302         int         imageDepth;
303         int         imageDestWidth;
304         int         imageDestHeight;
305 } GraphicsState;
306 
307 
308 /*
309  * GraphicsStateList
310  *      GraphicsState �δ����ѥꥹ��
311  *      next �Ǥ��ɤä��Ǹ夬�����Ȥ� GraphicsState ��ɽ��
312  */
313 typedef struct GraphicsStateList_s {
314         GraphicsState                           *gstate;
315         struct GraphicsStateList_s      *next;
316 } GraphicsStateList;
317 
318 /*
319  * JobInfo
320  *      Job �δ����ѹ�¤��
321  */
322 typedef struct JobInfo_s {
323         GraphicsStateList               gstateList;     /* Graphics State */
324 } JobInfo;
325 
326 /*
327  * DeviceInfo
328  *      �ץ���ΥǥХ��������ɽ��
329  *      ���Ĥ� printerContext �ˣ��Ĥ���¸�ߤ���
330  */
331 typedef struct DeviceInfo_s {
332         bool            manualFeed;                     /* Use manual feed */
333         int             cassetFeed;                     /* Input Casset */
334         bool            RITOff;                         /* RIT Control */
335         bool            Collate;                        /* �������� */
336         int             toner_density;                  /* �ȥʡ�ǻ�� */
337         bool            toner_saving;                   /* �ȥʡ������� */
338         int             prev_paper_size;
339         int             prev_paper_width;
340         int             prev_paper_height;
341         int             prev_num_copies;
342         int             prev_feed_mode;
343         int             orientation;                    /* ���� */
344         int             MediaType;                      /* ��� */
345 
346         bool            first_page;
347         bool            Tumble;                         /* �Ȥ����� */
348         int             ncomp;
349         int             MaskReverse;                    /* ȿž���� */
350         int             MaskState;
351         bool            c4map;                          /* 4bit ColorMap */
352         bool            c8map;                          /* 8bit ColorMap */
353         int             prev_x;
354         int             prev_y;
355 
356         /* for Font Downloading */
357         long            reverse_x;
358         long            reverse_y;
359         int             bx, by;
360         int             w, h;
361         int             roll;
362         float           sx, sy;
363         long            dd;
364 
365         unsigned char   *printerName;                   /* �ץ��̾�� */
366         int             resolution;                     /* ����ֲ����� */
367         int             maxRes;                         /* ��������� */
368         int             country;                        /* ���̾��� */
369         char            *duplex;                        /* ξ�̰��� */
370         char            *face;                          /* �ե��������� */
371         int             pageSize;                       /* �ѻ極���� */
372 
373 } DeviceInfo;
374 
375 
376 /*
377  * Printer
378  *      �ץ�������Ƥξ����������뤿��ι�¤�Τ�ɽ��
379  *      ���Ĥ� printerContext �ˣ��Ĥ���¸�ߤ���
380  */
381 typedef struct Printer_s {
382         DeviceInfo              dev;                            /* Device */
383         JobInfo                 job;                            /* job infomation */
384         int                     outputFD;                       /* �����ǡ����ν����� */
385         bool                    jobStarted;                     /* StartJob����λ���Ƥ��뤫 */
386 //      PageInfo                page;                           /* page information */
387 //      DocInfo                 doc;                            /* document information */
388 } Printer;
389 
390 /*
391  * PrinterList
392  *      Printer �Υꥹ�Ȥ�������뤿��ι�¤�Τ�ɽ��
393  */
394 typedef struct PrinterList_s {
395         Printer                 printer;                        /* Device */
396         int                     printerContext;         /* printerContext */
397         struct PrinterList_s    *next;
398 } PrinterList;
399 
400 /* ---------------- global valiable(s) ---------------- */
401 /* Printer �δ����� */
402 PrinterList             *gPrinterList = NULL;
403 
404 /* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
405 
406 /*
407  * ScaleInfo
408  *      �����ΰ������;����ɽ��
409  */
410 typedef struct ScaleInfo_s {
411         int             pictFrame_x;                    /* PCL PictureFrame X */
412         int             pictFrame_y;                    /* PCL PictureFrame Y */
413         int             pictOffs;                       /* PCL PictureOffset */
414         int             glScale_x;                      /* GL Scale X */
415         int             glScale_y;                      /* GL Scale Y */
416         int             glScale_min;                    /* GL Scale Min */
417 } ScaleInfo;
418 
419 
420 
421 /* static functions */
422 static void DebugPrint(const char *fmt, ...);
423 static ItemList *NewList(void *item, size_t length);
424 static void DeleteList(ItemList *node);
425 static ItemList *AddList(void *list, void *item, size_t length);
426 static void DeleteListAll(ItemList *node);
427 static int Write(int printerContext, const void *buf, size_t nBytes);
428 static int CheckWrite(int printerContext, const void *buf, size_t nBytes);
429 
430 static Printer *GetPrinter(int printerContext);
431 static GraphicsState *GetGraphicsState(int printerContext);
432 static int NewPrinterContext(void);
433 static DeviceInfo *GetDeviceInfo(int printerContext);
434 
435 //static int WriteLineAttributes(int printerContext) ;
436 static int CopyBrush(Brush* dest, Brush* src);
437 static bool IsSameBrush(Brush *pb1, Brush *pb2);
438 
439 static int SetPrinterName(int printerContext, char *printerModel);
440 static int SetBrushData(int printerContext, Brush *pbrush, int brushID);
441 
442 static int GetScaleInfo(DeviceInfo *pdev, ScaleInfo *pscl);
443 
444 /* #### ���Υɥ饤�Фǡ����ݡ��Ȥ���Ƥ���ؿ��ꥹ�� */
445 static const void *VectorProcs[] =
446 {
447         /* Creating and Managing Print Contexts */
448         OpenPrinter,
449         ClosePrinter,
450 
451         /* Job Control Operations */
452         StartJob,
453         EndJob,
454         StartDoc,
455         EndDoc,
456         StartPage,
457         EndPage,
458 #ifndef OLD_API
459         NULL, /* QueryDeviceCapability, */
460         NULL, /* QueryDeviceInfo, */
461 #endif /* OLD_API */
462 
463         /* Graphics State Object Operations */
464         ResetCTM,
465         SetCTM,
466         GetCTM,
467         InitGS,
468         SaveGS,
469         RestoreGS,
470         QueryColorSpace,
471         SetColorSpace,
472         GetColorSpace,
473         QueryROP,
474         SetROP,
475         GetROP,
476         SetFillMode,
477         GetFillMode,
478         NULL, /* SetAlphaConstant, */
479         NULL, /* GetAlphaConstant, */
480         SetLineWidth,
481         GetLineWidth,
482         NULL, /* SetLineDash, */
483         NULL, /* GetLineDash, */
484         NULL, /* SetLineDashOffset, */
485         NULL, /* GetLineDashOffset, */
486         NULL, /* SetLineStyle, */
487         NULL, /* GetLineStyle, */
488         SetLineCap,
489         GetLineCap,
490         SetLineJoin,
491         GetLineJoin,
492         SetMiterLimit,
493         GetMiterLimit,
494         SetPaintMode,
495         GetPaintMode,
496         SetStrokeColor,
497         SetFillColor,
498         SetBgColor,
499 
500         /* Path Operations */
501         NewPath,
502         EndPath,
503         StrokePath,
504         FillPath,
505         StrokeFillPath,
506         NULL, /* SetClipPath */
507 #ifndef OLD_API
508         NULL, /* ResetClipPath */
509 #endif
510         SetCurrentPoint,
511         LinePath,
512         PolygonPath,
513         RectanglePath,
514         RoundRectanglePath,
515         BezierPath,
516         NULL, /* ArchPath, */
517 
518         /* Text Operations */
519         NULL, /* DrawBitmapText, */
520 
521         /* Bitmap Image Operations */
522         NULL, /* DrawImage, */
523         StartDrawImage,
524         TransferDrawImage,
525         EndDrawImage,
526 
527         /* Scan Line Operations */
528         NULL, /* StartScanline, */
529         NULL, /* Scanline, */
530         NULL, /* EndScanline, */
531 
532         /* Raster Image Operations */
533         StartRaster,
534         TransferRasterData,
535         SkipRaster,
536         EndRaster,
537 
538         /* Stream Data Operations */
539         NULL, /* StartStream, */
540         NULL, /* TransferStreamData, */
541         NULL, /* EndStream */
542 };
543 
544 /* ���顼�����ɳ�Ǽ�ѤΥ����Х��ѿ� */
545 int     errorno;
546 
547 
548 /* ----------------------------------------------------------------
549 
550     Static Functions
551 
552  * ---------------------------------------------------------------- */
553 /* ----------------------------------------------------------------
554  *
555  *      DebugPrint
556  *
557  * Name
558  *      DebugPrint - Debug�ѥ�å��������ϴؿ�
559  *
560  * Arguments
561  *      printf��Ʊ��
562  *
563  * Description
564  *      �ܴؿ��ϡ�"DEBUG"��define����Ƥ����硢��å�������stderr��
565  *      ���Ϥ��롣"DEBUG"��define����Ƥ��ʤ���С�����Ԥ�ʤ���
566  *
567  * Return Value
568  *      ̵��
569  * ---------------------------------------------------------------- */
DebugPrint(const char * fmt,...)570 static void DebugPrint(const char *fmt, ...)
571 {
572 #ifdef DEBUG
573         va_list ap;
574 
575         va_start(ap, fmt);
576         vfprintf(stderr, fmt, ap);
577         va_end(ap);
578         fflush(stderr);
579 #endif
580         return;
581 }
582 
583 /* ----------------------------------------------------------------
584  *
585  *      NewList
586  *
587  * Name
588  *      NewList - �ꥹ�ȤΥΡ��ɤ��������
589  *
590  * Arguments
591  *      item - item(data)��Ǽ���ؤΥݥ���
592  *      length - item�Υ�����
593  *
594  * Description
595  *      ItemList��¤�Τ��ΰ����ݤ���item���Ǽ�����ꥹ�ȤΥΡ��ɤ�
596  *      �����˺�������
597  *
598  * Return Value
599  *      ��������к��������Ρ��ɤؤΥݥ��������Ԥʤ�NULL���֤�
600  * ---------------------------------------------------------------- */
NewList(void * item,size_t length)601 static ItemList *NewList(void *item, size_t length)
602 {
603         ItemList *node;
604 
605         if (item == NULL) {
606                 errorno = FATALERROR;
607                 return (NULL);
608         }
609 
610         node = (ItemList *)malloc(sizeof(ItemList)+length);
611         if (node == NULL) {
612                 errorno = FATALERROR;
613                 return (NULL);
614         }
615 
616         if (length == 0) {
617                 node->item = NULL;
618         } else {
619                 node->item = node + 1;
620                 memcpy (node->item, item, length);
621         }
622 
623         node->length = length;
624         node->next = NULL;
625 
626         return (node);
627 }
628 
629 /* ----------------------------------------------------------------
630  *
631  *      DeleteList
632  *
633  * Name
634  *      DeleteList - �ꥹ�ȤΥΡ��ɤ�������
635  *
636  * Arguments
637  *      node - �������ItemList��¤�ΤؤΥݥ���
638  *
639  * Description
640  *      �Ρ��ɤ��ΰ��������ޤ�
641  *
642  * Return Value
643  *      ̵��
644  * ---------------------------------------------------------------- */
DeleteList(ItemList * node)645 static void DeleteList(ItemList *node)
646 {
647         if (node != NULL) {
648                 free(node);
649         }
650         return;
651 }
652 
653 /* ----------------------------------------------------------------
654  *
655  *      AddList
656  *
657  * Name
658  *      AddList - �Ρ��ɤ���������ꥹ�Ȥ��ɲä���
659  *
660  * Arguments
661  *      list - list�ؤΥݥ���
662  *      item - item(data)��Ǽ���ؤΥݥ���
663  *      length - item�Υ�����
664  *
665  * Description
666  *      list�κǸ�˥Ρ��ɤ��ɲä���
667  *
668  * Return Value
669  *      ��������к��������Ρ��ɤؤΥݥ��������Ԥʤ�NULL���֤�
670  * ---------------------------------------------------------------- */
AddList(void * list,void * item,size_t length)671 static ItemList *AddList(void *list, void *item, size_t length)
672 {
673         ItemList *node;
674 
675         if (list == NULL) {
676                 errorno = FATALERROR;
677                 return (NULL);
678         }
679 
680         node = list;
681         while (node->next != NULL) {
682                 node = node->next;
683         }
684 
685         node->next = NewList(item, length);
686         return (node->next);
687 }
688 
689 /* ----------------------------------------------------------------
690  *
691  *      DeleteListAll
692  *
693  * Name
694  *      DeleteListAll - �ꥹ�Ȥ˴ޤޤ�����ƤΥΡ��ɤ�������
695  *
696  * Arguments
697  *      node - �������ꥹ�Ȥ���Ƭ��ItemList��¤�ΤؤΥݥ���
698  *
699  * Description
700  *      �ꥹ�����ƤΥΡ��ɤ�������ޤ�
701  *
702  * Return Value
703  *      ̵��
704  * ---------------------------------------------------------------- */
DeleteListAll(ItemList * node)705 static void DeleteListAll(ItemList *node)
706 {
707         if (node == NULL) {
708                 return;
709         }
710 
711         while (node != NULL) {
712                 ItemList *next;
713 
714                 next = node->next;
715                 DeleteList(node);
716                 node = next;
717         }
718         return;
719 }
720 
721 
722 /* ----------------------------------------------------------------
723  *
724  *      GetPrinter
725  *
726  * Name
727  *      GetPrinter - get specified printer context.
728  *                                              ���ꤵ�줿 printerContext ����ץ��������֤���
729  *
730  * Arguments
731  *      printerContext - OpenPrinter �����ֵѤ��줿�ץ������ƥ�����
732  *                                              �ͤ���ꤹ�롣
733  *
734  * Description
735  *      ���ꤵ�줿 printerContext ����ץ���Ѿ���δ�ؤΥݥ������֤���
736  *
737  * Return Value
738  *      ����˽�λ����ȥץ������ؤΥݥ������֤���롣
739  *      ���顼�����ä����� NULL ���֤���롣
740  *
741  * ---------------------------------------------------------------- */
GetPrinter(int printerContext)742 static Printer *GetPrinter(int printerContext)
743 {
744         PrinterList             *list;
745 
746         for (list = gPrinterList; list != NULL; list = list->next) {
747                 if (list->printerContext == printerContext) {
748                         break;
749                 }
750         }
751         if (list == NULL) {
752                 errorno = BADCONTEXT;
753                 return(NULL);
754         }
755         return(&(list->printer));
756 }
757 
758 /* ----------------------------------------------------------------
759  *
760  *      GetGraphicsState
761  *
762  * Name
763  *      GetGraphicsState - get specified graphics state
764  *                                              printerContext �ǻ��ꤵ�줿 Graphics State ���֤���
765  *
766  * Arguments
767  *      printerContext - OpenPrinter �����ֵѤ��줿�ץ������ƥ�����
768  *                                              �ͤ���ꤹ�롣
769  *
770  * Description
771  *      ���ꤵ�줿 printerContext �Ǥ� �����Ȥ� Graphics State ���֤���
772  *
773  * Return Value
774  *      ����˽�λ����ȥץ���� Graphics State �ؤΥݥ������֤���롣
775  *      ���顼�����ä����� NULL ���֤���롣
776  *
777  * ---------------------------------------------------------------- */
GetGraphicsState(int printerContext)778 static GraphicsState *GetGraphicsState(int printerContext)
779 {
780         Printer                         *printer;
781         GraphicsStateList       *gl;
782 
783         printer = GetPrinter(printerContext);
784         if (printer == NULL) {
785                 return(NULL);
786         }
787 
788         for (gl = &(printer->job.gstateList); gl->next != NULL; gl = gl->next) {
789                 ;
790         }
791 
792         return(gl->gstate);
793 }
794 
795 /* ----------------------------------------------------------------
796  *
797  *      CopyGraphicsState
798  *
799  * Name
800  *      CopyGraphicsState - copy graphics state to destination GraphicsState
801  *                                              printerContext �ǻ��ꤵ�줿 Graphics State ���֤���
802  *
803  * Arguments
804  *      printerContext - OpenPrinter �����ֵѤ��줿�ץ������ƥ�����
805  *                                              �ͤ���ꤹ�롣
806  *
807  * Description
808  *      ���ꤵ�줿 printerContext �Ǥ� �����Ȥ� Graphics State ���֤���
809  *
810  * Return Value
811  *      ����˽�λ����ȥץ���� Graphics State �ؤΥݥ������֤���롣
812  *      ���顼�����ä����� NULL ���֤���롣
813  *
814  * ---------------------------------------------------------------- */
CopyGraphicsState(GraphicsState * dst,GraphicsState * src)815 static void CopyGraphicsState(GraphicsState *dst, GraphicsState *src)
816 {
817         if (dst->strokeBrush.pbrush)
818                 free(dst->strokeBrush.pbrush);
819         if (dst->fillBrush.pbrush)
820                 free(dst->fillBrush.pbrush);
821 
822         memcpy(dst, src, sizeof(GraphicsState));
823 
824         if (src->strokeBrush.pbrush) {
825                 dst->strokeBrush.pbrush = malloc(sizeof(BrushData));
826                 if (dst->strokeBrush.pbrush == NULL) {
827                         return;
828                 }
829                 memcpy(dst->strokeBrush.pbrush, src->strokeBrush.pbrush, sizeof(BrushData));
830         }
831 
832         if (src->fillBrush.pbrush) {
833                 dst->fillBrush.pbrush = malloc(sizeof(BrushData));
834                 if (dst->fillBrush.pbrush == NULL) {
835                         return;
836                 }
837                 memcpy(dst->fillBrush.pbrush, src->fillBrush.pbrush, sizeof(BrushData));
838         }
839 
840         /* ����� */
841         dst->pathList = NULL;
842         dst->pathEndPoint = NULL;
843 
844         return;
845 }
846 
847 /* ----------------------------------------------------------------
848  *
849  *      NewGraphicsState
850  *
851  * Name
852  *      NewGraphicsState - create new graphics state
853  *
854  * Arguments
855  *      �ʤ�
856  *
857  * Description
858  *      ������ GraphicsState ���������
859  *
860  * Return Value
861  *      ����˽�λ����ȿ����˺������줿 Graphics State �ؤΥݥ������֤���롣
862  *      ���顼�����ä����� NULL ���֤���롣
863  *
864  * ---------------------------------------------------------------- */
NewGraphicsState(void)865 static GraphicsState *NewGraphicsState(void)
866 {
867         GraphicsState   *gs;
868 
869         gs = malloc(sizeof(GraphicsState));
870         if (gs == NULL) {
871                 errorno = FATALERROR;
872                 return(NULL);
873         }
874 
875         gs->strokeBrush.pbrush = NULL;
876         gs->fillBrush.pbrush = NULL;
877         gs->bgBrush.pbrush = NULL;
878         gs->pathList = NULL;
879         gs->pathActive = FALSE;
880 
881         return(gs);
882 }
883 
884 /* ----------------------------------------------------------------
885  *
886  *      DeleteGraphicsState
887  *
888  * Name
889  *      DeleteGraphicsState - delete specified graphics state
890  *
891  * Arguments
892  *      GraphicsState - ����оݤ� GraphicsState ����ꤹ�롣
893  *
894  * Description
895  *      ���ꤵ�줿 GraphicsState �ˤ֤餵���äƤ��� malloc() �dz��ݤ��줿��Τ������롣
896  *
897  * Return Value
898  *      �ʤ�
899  *
900  * ---------------------------------------------------------------- */
DeleteGraphicsState(GraphicsState * gs)901 static void DeleteGraphicsState(GraphicsState *gs)
902 {
903         if (gs == NULL) {
904                 return;
905         }
906 
907         DeleteListAll(gs->pathList);                    /* �ѥ��κ�� */
908 
909         if (gs->strokeBrush.pbrush)
910                 free(gs->strokeBrush.pbrush);           /* �֥饷�κ�� */
911         if (gs->fillBrush.pbrush)
912                 free(gs->fillBrush.pbrush);
913 
914         free(gs);
915 
916         return;
917 }
918 
919 /* ----------------------------------------------------------------
920  *
921  *      PushGraphicsState
922  *
923  * Name
924  *      PushGraphicsState - push graphics state and create new graphics state
925  *                                              printerContext �ǻ��ꤵ�줿�ץ���� Graphics State ���ɲä��롣
926  *
927  * Arguments
928  *      printerContext - �оݤΥץ������ƥ�����
929  *
930  * Description
931  *      ���ꤵ�줿 printerContext �˥����Ȥ�Ʊ��� Graphics State ���ɲä��롣
932  *
933  * Return Value
934  *      ����˽�λ����ȥץ���� Graphics State �ؤΥݥ������֤���롣
935  *      ���顼�����ä����� NULL ���֤���롣
936  *
937  *      #### �Ȥꤢ����
938  *      ���ͽ�Ǥ� "n��" �ȤʤäƤ��뤬�Ϥä��ꤷ�Ƥ��ʤ��Τǡ����������̤�����å�
939  *
940  * ---------------------------------------------------------------- */
PushGraphicsState(int printerContext)941 static int PushGraphicsState(int printerContext)
942 {
943         Printer                         *printer;
944         GraphicsStateList       *gl;
945         GraphicsState           *gs;
946 
947         printer = GetPrinter(printerContext);
948         if (printer == NULL) {
949                 return(ERROR);
950         }
951 
952         for (gl = &(printer->job.gstateList); gl->next != NULL; gl = gl->next) {
953                 ;
954         }
955         gl->next = malloc(sizeof(GraphicsStateList));
956         if (gl->next == NULL) {
957                 errorno = JOBCANCELED;
958                 return(ERROR);
959         }
960         gl->next->next = NULL;
961 
962         gs = NewGraphicsState();
963         if (gs == NULL) {
964                 free(gl->next);                                                 /* ���� */
965                 gl->next = NULL;
966                 errorno = JOBCANCELED;
967                 return(ERROR);
968         }
969         gl->next->gstate = gs;
970 
971         /* ������ GraphicsState �˥����Ȥ� GraphicsState ���ԡ����� */
972         CopyGraphicsState(gs, gl->gstate);
973 
974         return(OK);
975 }
976 
977 /* ----------------------------------------------------------------
978  *
979  *      PopGraphicsState
980  *
981  * Name
982  *      PopGraphicsState - pop graphics state
983  *                                              printerContext �ǻ��ꤵ�줿�ץ���� Graphics State ���ɲä��롣
984  *
985  * Arguments
986  *      printerContext - �оݤΥץ������ƥ�����
987  *
988  * Description
989  *      ���ꤵ�줿 printerContext �˥����Ȥ�Ʊ��� Graphics State ���ɲä��롣
990  *
991  * Return Value
992  *      ����˽�λ����ȥץ���� Graphics State �ؤΥݥ������֤���롣
993  *      ���顼�����ä����� NULL ���֤���롣
994  *
995  * ---------------------------------------------------------------- */
PopGraphicsState(int printerContext)996 static int PopGraphicsState(int printerContext)
997 {
998         Printer                         *printer;
999         GraphicsStateList       *gl;
1000         GraphicsStateList       *prev;
1001 
1002         printer = GetPrinter(printerContext);
1003         if (printer == NULL) {
1004                 return(ERROR);
1005         }
1006 
1007         prev = &(printer->job.gstateList);
1008         for (gl = prev; gl->next != NULL; gl = gl->next) {
1009                 prev = gl;
1010         }
1011         if (prev == &(printer->job.gstateList)) {
1012                 /* ���顼: pop �Ǥ��ʤ� */
1013                 errorno = PARAMERROR;
1014                 return(ERROR);
1015         }
1016 
1017         prev->next = NULL;
1018         DeleteGraphicsState(gl->gstate);
1019         free(gl);
1020 
1021         return(OK);
1022 }
1023 
1024 /* ----------------------------------------------------------------
1025  *
1026  *      DeleteDevice
1027  *
1028  * Name
1029  *      DeleteDevice - delete a printer device information.
1030  *                                              �ץ���� �ǥХ��������Ѥδ�������롣
1031  *
1032  * Arguments
1033  *      printer - �ץ���� �ǥХ��������Ѥδ����ꤹ�롣
1034  *
1035  * Description
1036  *      ���ꤵ�줿�ץ���ΥǥХ�������δ��������
1037  *
1038  * Return Value
1039  *      �ʤ�
1040  *
1041  * ---------------------------------------------------------------- */
DeleteDevice(DeviceInfo * dev)1042 static void DeleteDevice(DeviceInfo *dev)
1043 {
1044 
1045         /* �����Ϻ�����٤���Τϲ���ʤ� */
1046 
1047         return;
1048 }
1049 
1050 /* ----------------------------------------------------------------
1051  *
1052  *      DeleteJob
1053  *
1054  * Name
1055  *      DeleteJob - delete a job information.
1056  *                                              �ץ���� JOB �����Ѥδ�������롣
1057  *
1058  * Arguments
1059  *      printer - �ץ���� JOB �����Ѥδ����ꤹ�롣
1060  *
1061  * Description
1062  *      ���ꤵ�줿�ץ���� JOB ����δ��������
1063  *
1064  * Return Value
1065  *      �ʤ�
1066  *
1067  * ---------------------------------------------------------------- */
DeleteJob(JobInfo * job)1068 static void DeleteJob(JobInfo *job)
1069 {
1070         GraphicsStateList       *gl;
1071 
1072         /* GraphicsState �ϥꥹ�ȤˤʤäƤ����ǽ�������� */
1073         gl = &(job->gstateList);
1074         for (gl = gl->next; gl != NULL; gl = gl->next) {
1075                 DeleteGraphicsState(gl->gstate);
1076         }
1077         job->gstateList.next = NULL;
1078 
1079         return;
1080 }
1081 
1082 /* ----------------------------------------------------------------
1083  *
1084  *      DeletePrinterContext
1085  *
1086  * Name
1087  *      DeletePrinterContext - delete a printer context.
1088  *                                              �ץ�������Ѥδ�������롣
1089  *
1090  * Arguments
1091  *      printerContext - �ץ������ƥ������ͤ���ꤹ�롣
1092  *
1093  * Description
1094  *      ���ꤵ�줿�ץ������ƥ����ȤΥץ���Ѿ���δ��������
1095  *
1096  * Return Value
1097  *      ����˽�λ����ȿ����˺������줿���ؤ� printerContext �ͤ��֤���롣
1098  *      ���顼�����ä����� -1 ���֤���롣
1099  *
1100  * ---------------------------------------------------------------- */
DeletePrinterContext(int printerContext)1101 static int DeletePrinterContext(int printerContext)
1102 {
1103         PrinterList             *list;
1104         PrinterList             *prev;
1105         int                             i;
1106 
1107         list = gPrinterList;
1108         prev = list;
1109         for (i = 0; (i < printerContext) && (list->next != NULL); i++) {
1110                 prev = list;
1111                 list = list->next;
1112         }
1113         if (printerContext == 0) {
1114                 // ��Ƭ
1115                 gPrinterList = gPrinterList->next;
1116         } else {
1117                 if (i == printerContext) {
1118                         prev->next = list->next;
1119                 } else {
1120                         errorno = BADCONTEXT;
1121                         return(ERROR);
1122                 }
1123         }
1124 
1125         /* ��������Τ� list ���� */
1126         /* dev �ʲ� */
1127         DeleteDevice(&(list->printer.dev));
1128 
1129         /* job �ʲ� */
1130         DeleteJob(&(list->printer.job));
1131 
1132         free(list);
1133 
1134         return(OK);
1135 }
1136 
1137 /* ----------------------------------------------------------------
1138  *
1139  *      NewPrinterContext
1140  *
1141  * Name
1142  *      NewPrinterContext - create a new printer context.
1143  *                                              �����˥ץ�������Ѥδ����ݤ��롣
1144  *
1145  * Arguments
1146  *      �ʤ�
1147  *
1148  * Description
1149  *      �ץ���Ѿ���δ���������
1150  *
1151  * Return Value
1152  *      ����˽�λ����ȿ����˺������줿���ؤ� printerContext �ͤ��֤���롣
1153  *      ���顼�����ä����� -1 ���֤���롣
1154  *
1155  * ---------------------------------------------------------------- */
NewPrinterContext(void)1156 static int NewPrinterContext(void)
1157 {
1158         PrinterList                     *list;
1159         PrinterList                     *next;
1160         GraphicsStateList       *gl;
1161         int                                     printerContext;
1162         int                                     result;
1163 
1164         /* device �������ΰ�γ��� */
1165         list = malloc(sizeof(PrinterList));
1166         if (list == NULL) {
1167                 /* ������­ */
1168                 errorno = FATALERROR;
1169                 return(ERROR);
1170         }
1171 
1172         list->next = NULL;
1173 
1174         if (gPrinterList == NULL) {
1175                 /* ���� */
1176                 gPrinterList = list;
1177                 printerContext = 0;
1178                 list->printerContext = printerContext;
1179         } else {
1180                 /* �����ܰʹ� */
1181                 for (next = gPrinterList; next->next != NULL; next = next->next) {
1182                         ;
1183                 }
1184                 printerContext = next->printerContext;
1185                 printerContext++;
1186                 list->printerContext = printerContext;
1187                 next->next = list;
1188         }
1189 
1190 
1191         gl = &(list->printer.job.gstateList);
1192         gl->gstate = NewGraphicsState();
1193         if (gl->gstate == NULL) {
1194                 /* ������­ */
1195                 errorno = FATALERROR;
1196 
1197                 (void)DeletePrinterContext(printerContext);
1198 
1199                 return(ERROR);
1200         }
1201         gl->next = NULL;
1202         list->printer.jobStarted = FALSE;
1203 
1204         /* Graphics State �ν������Ԥʤ� */
1205         result = InitGS(printerContext);
1206         if (result < 0) {
1207                 (void)DeletePrinterContext(printerContext);
1208 
1209                 return(ERROR);
1210         }
1211 
1212         return(printerContext);
1213 }
1214 
1215 /* ----------------------------------------------------------------
1216  *
1217  *      GetDeviceInfo
1218  *
1219  * Name
1220  *      GetDeviceInfo - get specified device information.
1221  *                                      ���ꤵ�줿 printerContext ����ץ��������֤���
1222  *
1223  * Arguments
1224  *      printerContext - OpenPrinter �����ֵѤ��줿�ץ������ƥ�����
1225  *                                              �ͤ���ꤹ�롣
1226  *
1227  * Description
1228  *      ���ꤵ�줿 printerContext ����ץ���ΥǥХ������� ���֤���
1229  *
1230  * Return Value
1231  *      ����˽�λ����ȥץ���ΥǥХ�������ؤΥݥ������֤���롣
1232  *      ���顼�����ä����� NULL ���֤���롣
1233  *
1234  * ---------------------------------------------------------------- */
GetDeviceInfo(int printerContext)1235 static DeviceInfo *GetDeviceInfo(int printerContext)
1236 {
1237         Printer         *printer;
1238 
1239         printer = GetPrinter(printerContext);
1240         if (printer == NULL) {
1241                 return(NULL);
1242         }
1243 
1244         return(&(printer->dev));
1245 }
1246 
1247 /* ----------------------------------------------------------------
1248  *
1249  *      Write
1250  *
1251  * Name
1252  *      Write - �ǡ����ν����ߤ�Ԥ��ޤ�
1253  *
1254  * Arguments
1255  *      printerContext - OpenPrinter �����ֵѤ��줿�ץ������ƥ�����
1256  *                                              �ͤ���ꤹ�롣
1257  *      buf - �����ߤ�Ԥ��ǡ����ؤΥݥ���
1258  *      nBytes - �����ߤ�Ԥ��ǡ����Υ�����
1259  *
1260  * Description
1261  *      printerContext�ǻ��ꤵ�줿������ˡ��ǡ���������ߤޤ���
1262  *      ���ƤΥǡ�������Ф��ޤǡ��ܴؿ��ϥ֥�å����ޤ���
1263  *
1264  * Return Value
1265  *      ����˽�λ�����OK ���֤���롣���顼�����ä�����-1 ���֤��졢
1266  *      errorno �˥��顼�����ɤ���Ǽ����롣
1267  *
1268  * ---------------------------------------------------------------- */
Write(int printerContext,const void * buf,size_t nBytes)1269 static int Write(int printerContext, const void *buf, size_t nBytes)
1270 {
1271         Printer *pl;
1272         int fd;
1273 
1274         pl = GetPrinter(printerContext);
1275         if (pl == NULL) {
1276                 /* Printer Context�������Ǥ��� */
1277                 DebugPrint("pdapi: %s,%d\n", __FUNCTION__, __LINE__);
1278                 errorno = FATALERROR;
1279                 return (ERROR);
1280         }
1281 
1282         fd = pl->outputFD;
1283         while (0 < nBytes) {
1284                 ssize_t wBytes;
1285 
1286                 wBytes = write(fd, buf, nBytes);
1287                 if (wBytes < 0) {
1288                         /* �����ƥॳ���륨�顼 */
1289                         if((errno != EINTR) && (errno != EAGAIN) && (errno != EIO)) {
1290                                 /* ��������ʤ����顼��ȯ������ */
1291                                 DebugPrint("pdapi: %s,%d\n", __FUNCTION__, __LINE__);
1292                                 errorno = FATALERROR;
1293                                 return (ERROR);
1294                         }
1295                 } else {
1296                         /* ���������� */
1297                         buf += wBytes;
1298                         nBytes -= wBytes;
1299                 }
1300         }
1301         return (OK);
1302 }
1303 
1304 /* ----------------------------------------------------------------
1305  *
1306  *      CheckWrite
1307  *
1308  * Name
1309  *      CheckWrite - StartJob()����λ���Ƥ����硢�ǡ����ν�����(Write())��Ԥ��ޤ�
1310  *               ��λ���Ƥ��ʤ���硢�ʤˤ⤻�������ェλ���ޤ�
1311  *
1312  * Arguments
1313  *      printerContext - OpenPrinter �����ֵѤ��줿�ץ������ƥ�����
1314  *                                              �ͤ���ꤹ�롣
1315  *      buf - �����ߤ�Ԥ��ǡ����ؤΥݥ���
1316  *      nBytes - �����ߤ�Ԥ��ǡ����Υ�����
1317  *
1318  * Description
1319  *      printerContext�ǻ��ꤵ�줿������ˡ��ǡ���������ߤޤ���
1320  *      ���ƤΥǡ�������Ф��ޤǡ��ܴؿ��ϥ֥�å����ޤ���
1321  *
1322  * Return Value
1323  *      ����˽�λ�����OK ���֤���롣���顼�����ä�����-1 ���֤��졢
1324  *      errorno �˥��顼�����ɤ���Ǽ����롣
1325  *
1326  * ---------------------------------------------------------------- */
CheckWrite(int printerContext,const void * buf,size_t nBytes)1327 static int CheckWrite(int printerContext, const void *buf, size_t nBytes) {
1328 
1329         Printer *pPrinter;
1330 
1331         pPrinter = GetPrinter(printerContext);
1332         if (pPrinter == NULL) {
1333                 errorno = FATALERROR;
1334                 return(ERROR);
1335         }
1336         // StartJob�Ͻ�λ���Ƥ��뤫
1337         if (!pPrinter->jobStarted) {
1338                 // �ޤ����ޥ�ɤ��Ǥ�������ˤʤ�
1339                 return (OK);
1340         }
1341         return Write(printerContext, buf, nBytes);
1342 }
1343 
1344 /* ----------------------------------------------------------------
1345  *
1346  *      CopyBrush
1347  *
1348  * Name
1349  *      CopyBrush -
1350  *
1351  * Arguments
1352  *      pDest - ���ԡ���Brush��¤��
1353  *      pSrc - ���ԡ���Brush��¤��
1354  *
1355  * Description
1356  *      Brush��¤�ΤΥ��ԡ���Ԥʤ���
1357  *      Brush��¤�����BrushData��¤�Τ����Ƥ⥳�ԡ�����롣
1358  *      pDest�ϡ����˳��ݤ��줿��¤�Τ���Ƭ���ɥ쥹�Ǥ��뤳�ȡ�
1359  *      BrushData.data�ˤĤ��Ƥϡ�̤���ݡ��ȡ����NULL�����ꤵ��롣
1360  *
1361  * Return Value
1362  *      ����˽�λ�����OK ���֤���롣���顼�����ä�����-1 ���֤��졢
1363  *      errorno �˥��顼�����ɤ���Ǽ����롣
1364  *
1365  * ---------------------------------------------------------------- */
CopyBrush(Brush * pDest,Brush * pSrc)1366 static int CopyBrush(Brush *pDest, Brush *pSrc)
1367 {
1368         if (pDest == NULL || pSrc == NULL) {
1369                 DebugPrint("pdapi: %s,%d pDest=%p or pSrc=%p is NULL.\n", __FUNCTION__, __LINE__, pDest, pSrc);
1370                 errorno = FATALERROR;
1371                 return(ERROR);
1372         }
1373 
1374         pDest->colorSpace = pSrc->colorSpace;
1375 
1376         pDest->color[0] = pSrc->color[0];
1377         pDest->color[1] = pSrc->color[1];
1378         pDest->color[2] = pSrc->color[2];
1379         pDest->color[3] = pSrc->color[3];
1380 
1381         pDest->xorg = pSrc->xorg;
1382         pDest->yorg = pSrc->yorg;
1383 
1384         if (pSrc->pbrush) {
1385                 BrushData *pSrcBD;
1386                 BrushData *pDestBD;
1387 
1388                 if (pDest->pbrush == NULL) {
1389                         pDest->pbrush = malloc(sizeof(BrushData));
1390                         if (pDest->pbrush == NULL) {
1391                                 errorno = FATALERROR;
1392                                 return(ERROR);
1393                         }
1394                 }
1395                 pSrcBD = pSrc->pbrush;
1396                 pDestBD = pDest->pbrush;
1397 
1398                 pDestBD->type = pSrcBD->type;
1399                 pDestBD->width = pSrcBD->width;
1400                 pDestBD->height = pSrcBD->height;
1401                 pDestBD->pitch = pSrcBD->pitch;
1402                 pDestBD->data = NULL; /* Not Supported this Version. */
1403         }
1404         else {
1405                 if (pDest->pbrush) {
1406                         free(pDest->pbrush);
1407                         pDest->pbrush = NULL;
1408                 }
1409         }
1410         return(OK);
1411 }
1412 
1413 /* ----------------------------------------------------------------
1414  *
1415  *      IsSameBrush
1416  *
1417  * Name
1418  *      IsSameBrush -
1419  *
1420  * Arguments
1421  *      pb1 - Brush��¤��1
1422  *      pb2 - Brush��¤��2
1423  *
1424  * Description
1425  *      Brush��¤�Τ���Ӥ��롣
1426  *
1427  * Return Value
1428  *      Ʊ��Brush�ξ��TRUE���֤���롣�ۤʤ����FALSE���֤���롣
1429  *
1430  * ---------------------------------------------------------------- */
IsSameBrush(Brush * pb1,Brush * pb2)1431 static bool IsSameBrush(Brush *pb1, Brush *pb2)
1432 {
1433         if (pb1->pbrush == NULL && pb2->pbrush == NULL) {
1434                 if ((pb1->colorSpace == pb2->colorSpace)
1435                         && (pb1->color[0] == pb2->color[0])
1436                         && (pb1->color[1] == pb2->color[1])
1437                         && (pb1->color[2] == pb2->color[2])
1438                         && (pb1->color[3] == pb2->color[3])) {
1439                         return (TRUE);
1440                 }
1441                 return (FALSE);
1442         }
1443         /* pbrush != NULL �ξ��Υ����å��Ͼ�ά */
1444 
1445         return (FALSE);
1446 }
1447 
1448 
1449 /* ----------------------------------------------------------------
1450  *
1451  *      SetPrinterName
1452  *
1453  * Name
1454  *      SetPrinterName - set printer name.
1455  *
1456  * Arguments
1457  *      printerContext - OpenPrinter �����ֵѤ��줿�ץ������ƥ�����
1458  *                                              �ͤ���ꤹ�롣
1459  *      printerModel - �ץ����ǥ�̾����ꤹ��(UTF-8)��
1460  *                                      NULL �ξ��ϥɥ饤�Ф����ꤹ��ǥե���ȤΥ�ǥ�
1461  *                                      �Ȥʤ롣
1462  *
1463  * Description
1464  *      �ץ��̾�Τ� Graphics State �����ꤷ��̾�Τˤ�ä�ɬ�פ������Ԥʤ���
1465  *      �ץ��̾�Τ��ԡ����ƥ�����˻��ġ� (ɬ�פ�����Τ��ʡ�)
1466  *
1467  * Return Value
1468  *      ����˽�λ����ȡ�OK ���֤���롣
1469  *      ���顼�����ä�����-1 ���֤��졢errorno �˥��顼�����ɤ���Ǽ����롣
1470  *
1471  * ---------------------------------------------------------------- */
SetPrinterName(int printerContext,char * printerModel)1472 static int SetPrinterName(int printerContext, char *printerModel)
1473 {
1474 
1475         /* �Ƶ�����θ�ͭ�ξ���ν���������� */
1476         struct PrinterDeviceInfo_s {
1477                 char    *name;                                  /* �ץ��̾�� (Glue �����Ϥ����̾�Τ�Ʊ��) */
1478                 int     maxRes;                                 /* ��������� */
1479                 int     country;                                /* ���̾��� */
1480                 char    *duplex;                                /* ξ�̰��� */
1481                 char    *face;                                  /* �ե��������� */
1482         } PrinterDeviceList[] = {
1483                 { "clj4600", RES600, JPN, HP_OPTION_OFF, HP_OPTION_FACE_DOWN },
1484                 { "clj5500", RES600, JPN, HP_OPTION_OFF, HP_OPTION_FACE_DOWN },
1485 
1486                 /* default ��������
1487                  *      ����κǸ�ˤʤ���Фʤ�ʤ�
1488                  */
1489                 { HP_DEFAULT_PRINTER, RES300, JPN, HP_OPTION_OFF, HP_OPTION_FACE_DOWN },
1490         };
1491 
1492         DeviceInfo      *dev;
1493         int                     i;
1494 
1495         DebugPrint("pdapi: %s,%d (printerContext=%d, printerModel=%s\n", __FUNCTION__, __LINE__, printerContext, printerModel);
1496 
1497         dev = GetDeviceInfo(printerContext);
1498         if (dev == NULL) {
1499                 return(ERROR);
1500         }
1501 
1502         /* �ץ��̾ */
1503         /* ����˱����ơ�Ŭ�ڤ������ͤˤ��� */
1504         for (i = 0; strcmp(PrinterDeviceList[i].name, HP_DEFAULT_PRINTER) != 0; i++) {
1505                 if (printerModel != NULL
1506                     && strcmp(printerModel, PrinterDeviceList[i].name) == 0) {
1507                         break;
1508                 }
1509         }
1510 
1511         dev->printerName = PrinterDeviceList[i].name;
1512         dev->maxRes =  PrinterDeviceList[i].maxRes;
1513         dev->country  = PrinterDeviceList[i].country;
1514         dev->duplex = PrinterDeviceList[i].duplex;
1515         dev->face = PrinterDeviceList[i].face;
1516 
1517         return(OK);
1518 }
1519 
1520 
1521 /* ----------------------------------------------------------------
1522  *
1523  *      SetBrushData
1524  *
1525  * Name
1526  *      SetBrushData - download a brush data to printer.
1527  *
1528  * Arguments
1529  *      printerContext - OpenPrinter �����ֵѤ��줿�ץ������ƥ�����
1530  *                                              �ͤ���ꤹ�롣
1531  *      pbrush - Brush����ꤹ�롣
1532  *      brushID - ����(Stroke, Fill, Background)����ꤹ�롣
1533  *
1534  * Description
1535  *      ���ꤵ�줿BrushData��ץ������Ͽ���롣
1536  *
1537  * Return Value
1538  *      ����˽�λ����ȡ�OK ���֤���롣
1539  *      ���顼�����ä�����-1 ���֤��졢errorno �˥��顼�����ɤ���Ǽ����롣
1540  *
1541  * ---------------------------------------------------------------- */
SetBrushData(int printerContext,Brush * pbrush,int brushID)1542 static int SetBrushData(int printerContext, Brush *pbrush, int brushID)
1543 {
1544         char obuf[64];
1545         BrushData *pBrushData;
1546         char *pData;
1547         int dataSize;
1548         DeviceInfo *dev;
1549 
1550         pBrushData = pbrush->pbrush;
1551 
1552         /* Enter PCL mode(GL/2 pen position) and specify pattern ID */
1553         (void)sprintf(obuf, PCL_ESC "%%1A" PCL_ESC "*c%dG", brushID);
1554         if (CheckWrite(printerContext, obuf, strlen(obuf)) != OK) {
1555                 return(ERROR);
1556         }
1557 
1558         DebugPrint("width=%d,height=%d\n", pBrushData->width, pBrushData->height);
1559         dataSize = (pBrushData->width + 7) / 8;
1560         dataSize *= pBrushData->height;
1561         dataSize += 12; /* Add header size */
1562 
1563         /* Download pattern */
1564         (void)sprintf(obuf, PCL_ESC "*c%dW", dataSize);
1565         if (CheckWrite(printerContext, obuf, strlen(obuf)) != OK) {
1566                 return(ERROR);
1567         }
1568 
1569         dev = GetDeviceInfo(printerContext);
1570         if (dev == NULL) {
1571                 return(ERROR);
1572         }
1573 
1574         pData = malloc(dataSize);
1575         if (pData == NULL) {
1576                 errorno = FATALERROR;
1577                 return(ERROR);
1578         }
1579 
1580         *(pData + 0) = 20;
1581         *(pData + 1) = 0;
1582         *(pData + 2) = 1;
1583         *(pData + 3) = 0;
1584         *(pData + 4) = pBrushData->height >> 8;
1585         *(pData + 5) = pBrushData->height & 0xff;
1586         *(pData + 6) = pBrushData->width >> 8;
1587         *(pData + 7) = pBrushData->width & 0xff;
1588         *(pData + 8) = dev->resolution >> 8;
1589         *(pData + 9) = dev->resolution & 0xff;
1590         *(pData + 10) = dev->resolution >> 8;
1591         *(pData + 11) = dev->resolution & 0xff;
1592         memcpy(pData + 12, pBrushData->data, dataSize-12);
1593         if (CheckWrite(printerContext, pData, dataSize) != OK) {
1594                 free(pData);
1595                 return(ERROR);
1596         }
1597         free(pData);
1598 
1599         (void)sprintf(obuf,
1600                         PCL_ESC "&f0S"  /* Push curent position */
1601                         PCL_ESC "%%0B"  /* Enter GL/2 mode */
1602                         "PU%d,%d"       /* Move to brush origin position */
1603                         PCL_ESC "%%1A"  /* Enter PCL mode(GL/2 pen position) */
1604                         PCL_ESC "*p0R"  /* Set pattern reference point */
1605                         PCL_ESC "&f1S"  /* Restore current position */
1606                         PCL_ESC "%%1B"  /* Enter GL/2 mode(PCL current position) */
1607                                 , pbrush->xorg, pbrush->yorg);
1608         if (CheckWrite(printerContext, obuf, strlen(obuf)) != OK) {
1609                 return(ERROR);
1610         }
1611 
1612         return(OK);
1613 }
1614 
1615 
1616 /* ----------------------------------------------------------------
1617  *
1618  *      GetScaleInfo
1619  *
1620  * Name
1621  *      GetScaleInfo - set PCL/GL scaling information.
1622  *
1623  * Arguments
1624  *      pdev - �ץ���ΥǥХ�������
1625  *      pscl - �������������γ�Ǽ�衣
1626  *
1627  * Description
1628  *      �����٤��ѻ極������ꡢPCL/GL��Scale�ͤ���롣
1629  *
1630  * Return Value
1631  *      ����˽�λ�����OK ���֤���롣���顼�����ä�����-1 ���֤��졢
1632  *      errorno �˥��顼�����ɤ���Ǽ����롣
1633  *
1634  * ---------------------------------------------------------------- */
GetScaleInfo(DeviceInfo * pdev,ScaleInfo * pscl)1635 static int GetScaleInfo(DeviceInfo *pdev, ScaleInfo *pscl)
1636 {
1637         if (pdev == NULL || pscl == NULL) {
1638                 return(ERROR);
1639         }
1640 
1641         pscl->glScale_min = HpPaperTable[pdev->pageSize].distdraw * pdev->resolution / RES300;
1642         pscl->pictFrame_x = (HpPaperTable[pdev->pageSize].width * PCLUNIT / RES300) + 1;
1643         pscl->pictFrame_y = (HpPaperTable[pdev->pageSize].height * PCLUNIT / RES300) + 1;
1644         pscl->pictOffs = HpPaperTable[pdev->pageSize].distheight * PCLUNIT / RES300;
1645         pscl->glScale_x = (HpPaperTable[pdev->pageSize].width * pdev->resolution / RES300)
1646                             + pscl->glScale_min;
1647         pscl->glScale_y = (HpPaperTable[pdev->pageSize].height * pdev->resolution / RES300)
1648                             + pscl->glScale_min;
1649 
1650         return(OK);
1651 }
1652 
1653 
1654 /* ----------------------------------------------------------------
1655  *
1656  *      OutputCurrentGS
1657  *
1658  * Name
1659  *      OutputCurrentGS - output current Graphics State to printer.
1660  *
1661  * Arguments
1662  *      printerContext - �ץ������ƥ������ͤ���ꤹ�롣
1663  *
1664  * Description
1665  *      �����Ȥ� GraphicsState �ǥץ���� (����) ���ꤹ�롣
1666  *      RestoreGS �ξ��ʤɤ˸ƤФ�롣
1667  *
1668  * Return Value
1669  *      ����˽�λ����ȡ�OK ���֤���롣
1670  *      ���顼�����ä�����-1 ���֤��졢errorno �˥��顼�����ɤ���Ǽ����롣
1671  *
1672  * ---------------------------------------------------------------- */
1673 // �����Ȥ� GS �����Ƥ�ץ�������ꤹ��
OutputCurrentGS(int printerContext)1674 static int OutputCurrentGS(int printerContext)
1675 {
1676         GraphicsState   *gs;
1677         int             result;
1678 
1679         // Get pointer to current GraphicsState.
1680         gs = GetGraphicsState(printerContext);
1681         if (gs == NULL) {
1682                 return(ERROR);
1683         }
1684 
1685         result = SetFillMode(printerContext, gs->fillMode);
1686         if (result < 0) {
1687                 return(ERROR);
1688         }
1689         result = SetLineWidth(printerContext, gs->lineWidth);
1690         if (result < 0) {
1691                 return(ERROR);
1692         }
1693         result = SetLineCap(printerContext, gs->lineCap);
1694         if (result < 0) {
1695                 return(ERROR);
1696         }
1697         result = SetLineJoin(printerContext, gs->lineJoin);
1698         if (result < 0) {
1699                 return(ERROR);
1700         }
1701         result = SetStrokeColor(printerContext, &gs->strokeBrush);
1702         if (result < 0) {
1703                 return(ERROR);
1704         }
1705         result = SetFillColor(printerContext, &gs->fillBrush);
1706         if (result < 0) {
1707                 return(ERROR);
1708         }
1709 
1710         result = SetBgColor(printerContext, &gs->bgBrush);
1711         if (result < 0) {
1712                 return(ERROR);
1713         }
1714 
1715         result = SetMiterLimit(printerContext, gs->miterlimit);
1716         if (result < 0) {
1717                 return(ERROR);
1718         }
1719 
1720         return(OK);
1721 }
1722 
1723 /* ----------------------------------------------------------------
1724  *
1725  * Creating and Managing Print Contexts
1726  *
1727  * ---------------------------------------------------------------- */
1728 
OpenPrinter(int outputFD,char * printerModel,int * nApiEntry,void * apiEntry[])1729 int OpenPrinter(int outputFD, char *printerModel, int *nApiEntry, void *apiEntry[])
1730 {
1731         int                     printerContext;
1732         Printer         *printer;
1733         int                     result;
1734 
1735         DebugPrint("pdapi: %s,%d outputFD=%d, printerModel=%s, nApiEntry=%p, apiEntry=%p\n", __FUNCTION__, __LINE__, outputFD, printerModel, nApiEntry, apiEntry);
1736 
1737         /* device �������ΰ�γ��� */
1738         printerContext = NewPrinterContext();
1739         if (printerContext < 0) {
1740                 /* ���顼 */
1741                 errorno = FATALERROR;
1742                 return(ERROR);
1743         }
1744 
1745         /* ����ͤ����� */
1746 
1747         /* �ؿ�����ȥ�ؤ���Ͽ */
1748         *apiEntry = VectorProcs;
1749         *nApiEntry = sizeof(VectorProcs) / sizeof(int);
1750 
1751         /* �ץ��̾�����ꤹ�� */
1752         result = SetPrinterName(printerContext, printerModel);
1753         if (result < 0) {
1754                 /* ���顼 */
1755                 errorno = FATALERROR;
1756                 return(ERROR);
1757         }
1758 
1759         /* ������ */
1760         printer = GetPrinter(printerContext);
1761         printer->outputFD = outputFD;
1762 
1763         return(printerContext);
1764 }
1765 
1766 
ClosePrinter(int printerContext)1767 int ClosePrinter(int printerContext)
1768 {
1769         int             result;
1770 
1771         result = 0;
1772 
1773         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
1774 
1775         result = DeletePrinterContext(printerContext);
1776 
1777         return(result);
1778 }
1779 
1780 
1781 
1782 typedef struct NByte_s {
1783         int                             length;         /* Ĺ�� */
1784         unsigned char   *p;                     /* �Х�����ؤΥݥ��� */
1785 } NByte;
1786 
1787 
1788 
StartJob(int printerContext,char * jobInfo)1789 int StartJob(int printerContext, char *jobInfo)
1790 {
1791         DeviceInfo      *dev;
1792         char    obuf[128];
1793         int resolution;
1794         int pageSize;
1795 
1796         DebugPrint("pdapi: %s,%d (printerContext=%d, jobInfo=[%s])\n",
1797                            __FUNCTION__,
1798                            __LINE__,
1799                            printerContext,
1800                            jobInfo);
1801 
1802         resolution = 300; // default��
1803         pageSize = 0;     // default��(HpPaperTable��0����)
1804 
1805         if (jobInfo != NULL) {
1806                 int i;
1807                 char* p;
1808                 char* q;
1809                 char tmp[16]; // TBD
1810 
1811                 // resolutionʸ����μ���
1812                 p = &jobInfo[0];
1813                 q = &tmp[0];
1814 
1815                 while ((*p != '\0') && (*p != ';')) {
1816                         *q++ = *p++;
1817                 }
1818                 *q = '\0';
1819 
1820                 if (strcmp(tmp, "600x600") == 0) {
1821                         resolution = 600;
1822                 }
1823                 // else resolution = default;
1824 
1825 
1826                 if (p != NULL) {
1827                         p++;
1828                 }
1829 
1830                 q = &tmp[0];
1831                 while ((*p != '\0') && (*p != ';')) {
1832                         *q++ = *p++;
1833                 }
1834                 *q = '\0';
1835 
1836                 i = 0;
1837                 for (i = 0; HpPaperTable[i].name != NULL; i++) {
1838                         DebugPrint("serching paper size - %d [%s] [%s]\n",
1839                                            i,
1840                                            HpPaperTable[i].name,
1841                                            tmp);
1842                         if (strcmp(HpPaperTable[i].name, tmp) == 0) {
1843                                 pageSize = i;
1844                         }
1845                 }
1846         }
1847 
1848         DebugPrint("pdapi: %s,%d resolution=%d, pagesize=%d[%s]\n",
1849                            __FUNCTION__,
1850                            __LINE__,
1851                            resolution,
1852                            pageSize,
1853                            HpPaperTable[pageSize].name);
1854 
1855         dev = GetDeviceInfo(printerContext);
1856         if (dev == NULL) {
1857                 errorno = BADCONTEXT;
1858                 return(ERROR);
1859         }
1860 
1861         // ������/PaperSize��StartPage()�Ǥ���Ѥ��뤿�ᡢ
1862         // DeviceInfo�����ꤷ�Ƥ���
1863         dev->resolution = resolution;
1864         dev->pageSize = pageSize;
1865 
1866         /**
1867          * PJL���ޥ�ɤϰ����ǡ���(Job)����Ƭ�ˤ������֤Ǥ��ʤ�
1868          * PJL���ޥ�ɤΥѥ�᡼����jobInfo�˰�¸���롣
1869          * jobInfo�����Ƥ˹�碌��PJL���ѹ����롣
1870          */
1871         /**
1872          * ���ޥ�������Τ����Write�ǥ��顼��ȯ����������
1873          * ³���Բ�ǽ�Ǥ���Τǡ��ʹߤν����ϹԤʤ�ʤ���
1874          */
1875 
1876         sprintf(obuf,
1877                 PCL_ESC "%%-12345X"                     //�귿��
1878                 "@PJL JOB\012"                          //STARTJOB���ޥ��
1879                 "@PJL SET RESOLUTION=%d\012"            //������
1880                 "@PJL SET PAPER=%s\012"                 //�ѻ極����
1881                 "@PJL SET ORIENTATION=PORTRAIT\012"     //Orientation
1882                 "@PJL ENTER LANGUAGE=PCL\015\012",      //���쥹������
1883                 resolution,
1884                 HpPaperTable[pageSize].name);
1885         if (ERROR == Write(printerContext, obuf, strlen(obuf))) {
1886                 return(ERROR);
1887         }
1888 
1889         /* ������ȥ쥤 */
1890         //sprintf(obuf, "@PJL SET OUTBIN=%s\012", dev->face);
1891         //if (ERROR == Write(printerContext, obuf, strlen(obuf))) {
1892         //      return(ERROR);
1893         //}
1894 
1895         /* MEDIASOURCE */
1896         //p = "@PJL SET AUTOSELECT=ON\012";
1897         //if (ERROR == Write(printerContext, p, strlen(p))) {
1898         //      return(ERROR);
1899         //}
1900 
1901         /* ξ�̰���On/Off */
1902         //sprintf(obuf, "@PJL SET DUPLEX=%s\012", dev->duplex);
1903         //if (ERROR == Write(printerContext, obuf, strlen(obuf))) {
1904         //      return(ERROR);
1905         //}
1906 
1907         /* QTY */
1908         //p = "@PJL SET QTY=1\012";
1909         //if (ERROR == Write(printerContext, p, strlen(p))) {
1910         //      return(ERROR);
1911         //}
1912 
1913         /* ���� */
1914         //p = "@PJL SET COPIES=1\012";
1915         //if (ERROR == Write(printerContext, p, strlen(p))) {
1916         //      return(ERROR);
1917         //}
1918 
1919         /* RIT(RET) */
1920         //p = "@PJL SET RET=ON\012";
1921         //if (ERROR == Write(printerContext, p, strlen(p))) {
1922         //      return(ERROR);
1923         //}
1924 
1925         ///* �ѻ楿���� */
1926         //p = "@PJL SET MEDIATYPE=PAPER\012";
1927         //if (ERROR == Write(printerContext, p, strlen(p))) {
1928         //      return(ERROR);
1929         //}
1930 
1931         /* EconoMode */
1932         //p = "@PJL SET ECONOMODE=OFF\012";
1933         //if (ERROR == Write(printerContext, p, strlen(p))) {
1934         //      return(ERROR);
1935         //}
1936 
1937         /* ���� */
1938         //p = " ZOOM=OFF";
1939         //if (ERROR == Write(printerContext, p, strlen(p))) {
1940         //      return(ERROR);
1941         //}
1942 
1943         /* ���顼������ */
1944         //p = " ERRORCODE=ON";
1945         //if (ERROR == Write(printerContext, p, strlen(p))) {
1946         //      return(ERROR);
1947         //}
1948 
1949         /* SIZEIGNORE */
1950         //p = " SIZEIGNORE=OFF";
1951         //if (ERROR == Write(printerContext, p, strlen(p))) {
1952         //      return(ERROR);
1953         //}
1954 
1955         /* ������� */
1956         //p = " SKIPBLANKPAGE=YES";
1957         //if (ERROR == Write(printerContext, p, strlen(p))) {
1958         //      return(ERROR);
1959         //}
1960 
1961         /* �奪�ե��å� */
1962         //p = " TOPOFFSET=0";
1963         //if (ERROR == Write(printerContext, p, strlen(p))) {
1964         //      return(ERROR);
1965         //}
1966 
1967         /* �����ե��å� */
1968         //p = " LEFTOFFSET=0" "\012"; // SET���ޥ�ɽ�λ
1969         //if (ERROR == Write(printerContext, p, strlen(p))) {
1970         //      return(ERROR);
1971         //}
1972 
1973         /* StartJob()��λ */
1974         {
1975                 Printer* pPrinter;
1976                 pPrinter = GetPrinter(printerContext);
1977                 if (pPrinter == NULL) {
1978                         return(ERROR);
1979                 }
1980                 pPrinter->jobStarted = TRUE;
1981         }
1982 
1983         DebugPrint("pdapi: %s,%d\n", __FUNCTION__, __LINE__);
1984         /* ��������λ */
1985         return(OK);
1986 }
1987 
1988 
EndJob(int printerContext)1989 int EndJob(int printerContext)
1990 {
1991         int     result;
1992         char    *cmd = PCL_ESC "%-12345X";
1993 
1994         result = 0;
1995 
1996         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
1997 
1998         {
1999                 Printer *pPrinter;
2000 
2001                 pPrinter = GetPrinter(printerContext);
2002                 if (pPrinter == NULL) {
2003                         errorno = FATALERROR;
2004                         return(ERROR);
2005                 }
2006                 pPrinter->jobStarted = FALSE;
2007         }
2008 
2009         result = Write(printerContext, cmd, strlen(cmd));
2010 
2011         return(result);
2012 }
2013 
2014 
StartDoc(int printerContext,char * docInfo)2015 int StartDoc(int printerContext, char *docInfo)
2016 {
2017         int             result;
2018         result = 0;
2019 
2020         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2021 
2022         return(result);
2023 }
2024 
2025 
EndDoc(int printerContext)2026 int EndDoc(int printerContext)
2027 {
2028         int             result;
2029         result = 0;
2030 
2031         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2032 
2033         return(result);
2034 }
2035 
2036 
StartPage(int printerContext,char * pageInfo)2037 int StartPage(int printerContext, char *pageInfo)
2038 {
2039         DeviceInfo      *dev;
2040         char            obuf[128];
2041         ScaleInfo       scl;
2042 
2043         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2044 
2045         dev = GetDeviceInfo(printerContext);
2046         if (dev == NULL) {
2047                 return(ERROR);
2048         }
2049 
2050         if (ERROR == GetScaleInfo(dev, &scl)) {
2051                 return(ERROR);
2052         }
2053 
2054         // �ڡ���ñ�̤Υ��ޥ������
2055         sprintf(obuf,
2056                 "\033E"                 //RESET���ޥ��
2057                 PCL_ESC "&u%dD"         //PCL Unit���ꥳ�ޥ��
2058                 PCL_ESC "*t%dR"         //�饹�������������ꥳ�ޥ��
2059                 PCL_ESC "&l-%dZ"        //���ե��å����ꥳ�ޥ��
2060                 PCL_ESC "*c%dx%dY"      //�ԥ����㡼�ե졼�����ꥳ�ޥ��
2061                 "\033*c0T"              //�������ݥ�������ꥳ�ޥ��
2062                 "\033%%0B"              //GL�⡼�ɰܹԥ��ޥ��
2063                 "IN"                    //GL�⡼�� ���˥���饤�����ޥ��
2064                 "SC%d,%d,%d,%d,1",      //GL�⡼�� ������������ꥳ�ޥ��
2065                 dev->resolution,
2066                 dev->resolution,
2067                 scl.pictOffs,
2068                 scl.pictFrame_x, scl.pictFrame_y,
2069                 scl.glScale_min, scl.glScale_x, scl.glScale_y, scl.glScale_min);
2070         if (ERROR == Write(printerContext, obuf, strlen(obuf))) {
2071                 return(ERROR);
2072         }
2073 
2074         /* Graphics State �ν������Ԥʤ� */
2075         if (ERROR == InitGS(printerContext)) {
2076                 return(ERROR);
2077         }
2078 
2079         return(OK);
2080 }
2081 
2082 
EndPage(int printerContext)2083 int EndPage(int printerContext)
2084 {
2085         char            *cmd = PCL_ESC "E";
2086 
2087         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2088 
2089         return Write(printerContext, cmd, strlen(cmd));
2090 }
2091 
2092 
2093 
2094 #ifndef OLD_API
2095 /* Ver 0.2 pre���ɲ� */
QueryDeviceCapability(int printerContext,int queryflag,int buflen,char * infoBuf)2096 int QueryDeviceCapability(int printerContext, int queryflag, int buflen, char *infoBuf)
2097 {
2098         int             result;
2099         result = 0;
2100 
2101         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2102 
2103         return(result);
2104 }
2105 
2106 
2107 /* Ver 0.2 pre���ɲ� */
QueryDeviceInfo(int printerContext,int queryflag,int buflen,char * infoBuf)2108 int QueryDeviceInfo(int printerContext, int queryflag, int buflen, char *infoBuf)
2109 {
2110         int             result;
2111         result = 0;
2112 
2113         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2114 
2115         return(result);
2116 }
2117 #endif /* OLD_API */
2118 
2119 
ResetCTM(int printerContext)2120 int ResetCTM(int printerContext)
2121 {
2122         GraphicsState *gs;
2123 
2124         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2125 
2126         gs = GetGraphicsState(printerContext);
2127         if (gs == NULL) {
2128                 return(ERROR);
2129         }
2130 
2131         /* �ǥե������ */
2132         {
2133                 CTM ctm;
2134 
2135                 ctm.a = 1;
2136                 ctm.b = 0;
2137                 ctm.c = 0;
2138                 ctm.d = 1;
2139                 ctm.e = 0;
2140                 ctm.f = 0;
2141                 SetCTM(printerContext, &ctm);
2142         }
2143 
2144         return(OK);
2145 }
2146 
2147 
SetCTM(int printerContext,CTM * pCTM)2148 int SetCTM(int printerContext, CTM *pCTM)
2149 {
2150         GraphicsState *gs;
2151         CTM *pCurCTM;
2152 
2153         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2154 
2155         if (pCTM == NULL) {
2156                 errorno = PARAMERROR;
2157                 return(ERROR);
2158         }
2159 
2160         // Get pointer to current CTM.
2161         gs = GetGraphicsState(printerContext);
2162         if (gs == NULL) {
2163                 return(ERROR);
2164         }
2165 
2166         pCurCTM = &(gs->ctm);
2167 
2168         {
2169                 // Copy CTM.
2170                 pCurCTM->a = pCTM->a;
2171                 pCurCTM->b = pCTM->b;
2172                 pCurCTM->c = pCTM->c;
2173                 pCurCTM->d = pCTM->d;
2174                 pCurCTM->e = pCTM->e;
2175                 pCurCTM->f = pCTM->f;
2176         }
2177 
2178         return(OK);
2179 }
2180 
2181 
GetCTM(int printerContext,CTM * pCTM)2182 int GetCTM(int printerContext, CTM *pCTM)
2183 {
2184         GraphicsState *gs;
2185         CTM *pCurCTM;
2186 
2187         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2188 
2189         if (pCTM == NULL) {
2190                 errorno = PARAMERROR;
2191                 return(ERROR);
2192         }
2193 
2194         // Get pointer to current CTM.
2195         gs = GetGraphicsState(printerContext);
2196         if (gs == NULL) {
2197                 return(ERROR);
2198         }
2199         pCurCTM = &(gs->ctm);
2200 
2201         {
2202                 pCTM->a = pCurCTM->a;
2203                 pCTM->b = pCurCTM->b;
2204                 pCTM->c = pCurCTM->c;
2205                 pCTM->d = pCurCTM->d;
2206                 pCTM->e = pCurCTM->e;
2207                 pCTM->f = pCurCTM->f;
2208         }
2209 
2210         return(OK);
2211 }
2212 
2213 
InitGS(int printerContext)2214 int InitGS(int printerContext)
2215 {
2216 
2217         DebugPrint("pdapi: %s,%d (printerContext=%d)\n", __FUNCTION__, __LINE__, printerContext);
2218 
2219         /* CTM */
2220         // �ǥե������
2221         if (ResetCTM(printerContext) != OK) {
2222                 return(ERROR);
2223         }
2224 
2225         /* ColorSpace */
2226         // �ǥե������
2227         if (SetColorSpace(printerContext, cspaceStandardRGB) != OK) {
2228                 return(ERROR);
2229         }
2230 
2231         /* FillMode */
2232         // �ǥե������
2233         if (SetFillMode(printerContext, fillModeEvenOdd) != OK) {
2234                 return(ERROR);
2235         }
2236 
2237 
2238         /* LineWidth */
2239         // �ǥե������(1.0)
2240         {
2241                 Fix defaultLineWidth;
2242                 i2Fix(1, defaultLineWidth);
2243                 if (SetLineWidth(printerContext, defaultLineWidth) != OK) {
2244                         return(ERROR);
2245                 }
2246         }
2247 
2248         /* LineCap */
2249         // �ǥե������
2250         if (SetLineCap(printerContext, lineCapButt) != OK) {
2251                 return(ERROR);
2252         }
2253 
2254         /* LineJoin */
2255         // �ǥե������
2256         if (SetLineJoin(printerContext, lineJoinMiter) != OK) {
2257                 return(ERROR);
2258         }
2259 
2260         /* Brush (Stroke/Fill Common) */
2261         {
2262                 // Create Default Brush.
2263                 Brush brush;
2264                 int defaultColor[4] = { 0, 0, 0, 0 };
2265                 int defaultBgColor[4] = { 255, 255, 255, 0 };
2266                 GraphicsState *gs;
2267 
2268                 // Get pointer to current CTM.
2269                 gs = GetGraphicsState(printerContext);
2270                 if (gs == NULL) {
2271                         return(ERROR);
2272                 }
2273 
2274                 brush.colorSpace = cspaceStandardRGB;
2275 
2276                 brush.color[0] = defaultColor[0];
2277                 brush.color[1] = defaultColor[1];
2278                 brush.color[2] = defaultColor[2];
2279                 brush.color[3] = defaultColor[3];
2280 
2281                 brush.pbrush = NULL;
2282                 brush.xorg = 0;
2283                 brush.yorg = 0;
2284 
2285                 // ����Ʊ����ͤ��������ꤵ��Ƥ���ȥ��ޥ�ɤ��Ǥ��ʤ�����
2286                 // ���ꤷ�褦�Ȥ����ͤȰۤʤ��ͤ��ѹ����Ƥ���������Ū�˽����������
2287                 gs->strokeBrush.colorSpace = !cspaceStandardRGB;
2288                 gs->fillBrush.colorSpace = !cspaceStandardRGB;
2289 
2290 
2291                 // Set Default Brush.
2292                 if (SetStrokeColor(printerContext, &brush) != OK) {
2293                         return(ERROR);
2294                 }
2295                 if (SetFillColor(printerContext, &brush) != OK) {
2296                         return(ERROR);
2297                 }
2298                 brush.color[0] = defaultBgColor[0];
2299                 brush.color[1] = defaultBgColor[1];
2300                 brush.color[2] = defaultBgColor[2];
2301                 brush.color[3] = defaultBgColor[3];
2302 
2303                 if (SetBgColor(printerContext, &brush) != OK) {
2304                         return(ERROR);
2305                 }
2306                 gs->useBgBrush = FALSE;
2307         }
2308 
2309         /* MiterLimit */
2310         {
2311                 Fix defaultMiterLimit;
2312                 i2Fix(10, defaultMiterLimit);  /* default miterlimit */
2313                 if (SetMiterLimit(printerContext, defaultMiterLimit) != OK) {
2314                         return(ERROR);
2315                 }
2316         }
2317 
2318         /* rop */
2319         {
2320                 // �ǥե�����ͤ�252
2321                 if (SetROP(printerContext, 252) != OK) {
2322                         return (ERROR);
2323                 }
2324         }
2325 
2326         /* PaintMode */
2327         {
2328                 // �ǥե�����ͤ�paintModeOpaque
2329                 if (SetPaintMode(printerContext, paintModeOpaque) != OK) {
2330                         return (ERROR);
2331                 }
2332         }
2333 
2334         DebugPrint("pdapi: %s,%d end of InitGS()\n", __FUNCTION__, __LINE__);
2335         return(OK);
2336 }
2337 
2338 
SaveGS(int printerContext)2339 int SaveGS(int printerContext)
2340 {
2341         int             result;
2342 
2343         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2344 
2345         result = PushGraphicsState(printerContext);
2346 
2347         return(result);
2348 }
2349 
2350 
RestoreGS(int printerContext)2351 int RestoreGS(int printerContext)
2352 {
2353         int             result;
2354 
2355         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2356 
2357         result = PopGraphicsState(printerContext);
2358 
2359         if (result < 0) {
2360                 errorno = FATALERROR;
2361                 return(ERROR);
2362         }
2363 
2364         result = OutputCurrentGS(printerContext);
2365         if (result < 0) {
2366                 errorno = FATALERROR;
2367         }
2368 
2369         return(result);
2370 }
2371 
2372 
QueryColorSpace(int printerContext,ColorSpace * pcspace,int * pnum)2373 int QueryColorSpace(int printerContext, ColorSpace *pcspace, int *pnum)
2374 {
2375         /* ���ݡ��Ȥ��륫�顼���ڡ��� */
2376         int     num = 1;
2377         ColorSpace support[] = { cspaceStandardRGB };
2378 
2379         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2380 
2381         /* ���顼���ڡ����ο����֤� */
2382         if (*pnum < num) {
2383                 *pnum = num;
2384 
2385                 errorno = PARAMERROR;
2386                 return (ERROR);
2387         }
2388 
2389         /* ���顼���ڡ����������֤� */
2390         *pnum = num;
2391         {
2392                 int i;
2393                 for (i = 0; i < num; i++) {
2394                         pcspace[i] = support[i];
2395                 }
2396         }
2397         return (OK);
2398 }
2399 
2400 
SetColorSpace(int printerContext,ColorSpace cspace)2401 int SetColorSpace(int printerContext, ColorSpace cspace)
2402 {
2403         GraphicsState *gs;
2404 
2405         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2406 
2407         gs = GetGraphicsState(printerContext);
2408         if (gs == NULL) {
2409                 return(ERROR);
2410         }
2411         gs->colorSpace = cspace;
2412 
2413         return(OK);
2414 }
2415 
2416 
GetColorSpace(int printerContext,ColorSpace * pcspace)2417 int GetColorSpace(int printerContext, ColorSpace *pcspace)
2418 {
2419         GraphicsState *gs;
2420 
2421         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2422 
2423         gs = GetGraphicsState(printerContext);
2424         if (gs == NULL) {
2425                 return(ERROR);
2426         }
2427         *pcspace = gs->colorSpace;
2428 
2429         return(OK);
2430 }
2431 
2432 
QueryROP(int printerContext,int * pnum,int * prop)2433 int QueryROP(int printerContext, int *pnum, int *prop)
2434 {
2435         DebugPrint("pdapi: %s,%d (printerContext=%d, pnum=%d, prop=%p)\n",
2436                            __FUNCTION__,
2437                            __LINE__,
2438                            printerContext,
2439                            *pnum,
2440                            prop);
2441 
2442         // ROP�����ɤ�������䤤��碌
2443         if (prop == NULL) {
2444                 *pnum = 256;
2445                 return (OK);
2446         }
2447 
2448         // ���Ѳ�ǽ��ROP�����ɤμ���
2449         if (*pnum < 256) {
2450                 *pnum = 256; // ɬ�פʸĿ��������
2451                 errorno = PARAMERROR;
2452                 return (ERROR);
2453         }
2454 
2455         // 0����255��256�Ĥ��٤ƤΥ����ɤ�ͭ����
2456         *pnum = 256;
2457         {
2458                 int i;
2459                 for (i = 0; i < *pnum; i++) {
2460                         prop[i] = i;
2461                 }
2462         }
2463         return (OK);
2464 }
2465 
2466 
SetROP(int printerContext,int rop)2467 int SetROP(int printerContext, int rop)
2468 {
2469         GraphicsState *gs;
2470         char obuf[128];
2471 
2472         DebugPrint("pdapi: %s,%d (printerContext=%d, rop=%d)\n",
2473                            __FUNCTION__,
2474                            __LINE__,
2475                            printerContext,
2476                            rop);
2477 
2478         gs = GetGraphicsState(printerContext);
2479         if (gs == NULL) {
2480                 return(ERROR);
2481         }
2482 
2483         // ľ���������ͤ�Ʊ�����ϡ�̵�뤹��
2484         if (gs->rop == rop) {
2485                 return (OK);
2486         }
2487 
2488         gs->rop = rop;
2489 
2490         (void)sprintf(obuf, "MC0,%d", rop);
2491         DebugPrint("pdapi: %s,%d comm=[%s]\n", __FUNCTION__, __LINE__, obuf);
2492         return CheckWrite(printerContext, obuf, strlen(obuf));
2493 }
2494 
2495 
GetROP(int printerContext,int * prop)2496 int GetROP(int printerContext, int *prop)
2497 {
2498         GraphicsState *gs;
2499 
2500         DebugPrint("pdapi: %s,%d (printerContext=%d, prop=%p)\n",
2501                 __FUNCTION__,
2502                 __LINE__,
2503                 printerContext,
2504                 prop);
2505 
2506         gs = GetGraphicsState(printerContext);
2507         if (gs == NULL) {
2508                 return(ERROR);
2509         }
2510         *prop = gs->rop;
2511 
2512         return(OK);
2513 }
2514 
2515 
SetFillMode(int printerContext,FillMode fillmode)2516 int SetFillMode(int printerContext, FillMode fillmode)
2517 {
2518         GraphicsState *gs;
2519 
2520         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2521 
2522         gs = GetGraphicsState(printerContext);
2523         if (gs == NULL) {
2524                 return(ERROR);
2525         }
2526         gs->fillMode = fillmode;
2527 
2528         return(OK);
2529 }
2530 
2531 
GetFillMode(int printerContext,FillMode * pfillmode)2532 int GetFillMode(int printerContext, FillMode* pfillmode)
2533 {
2534         GraphicsState *gs;
2535 
2536         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2537 
2538         gs = GetGraphicsState(printerContext);
2539         if (gs == NULL) {
2540                 return(ERROR);
2541         }
2542         *pfillmode = gs->fillMode;
2543 
2544         return(OK);
2545 }
2546 
2547 
SetAlphaConstant(int printerContext,float alpha)2548 int SetAlphaConstant(int printerContext, float alpha)
2549 {
2550         int             result;
2551         result = 0;
2552 
2553         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2554 
2555         return(result);
2556 }
2557 
2558 
GetAlphaConstant(int printerContext,float * palpha)2559 int GetAlphaConstant(int printerContext, float *palpha)
2560 {
2561         int             result;
2562         result = 0;
2563 
2564         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2565 
2566         return(result);
2567 }
2568 
2569 
SetLineWidth(int printerContext,Fix width)2570 int SetLineWidth(int printerContext, Fix width)
2571 {
2572         int             i;
2573         float           f;
2574         char            obuf[128];
2575         GraphicsState   *gs;
2576         DeviceInfo      *dev;
2577 
2578         Fix2f(width, f);
2579         DebugPrint("pdapi: %s,%d printerContext=%d, width=(%d/%f)\n", __FUNCTION__, __LINE__, printerContext, Fix2i(width), f);
2580 
2581         gs = GetGraphicsState(printerContext);
2582         if (gs == NULL) {
2583                 return(ERROR);
2584         }
2585 
2586         dev = GetDeviceInfo(printerContext);
2587         if (dev == NULL) {
2588                 return(ERROR);
2589         }
2590 
2591         // GraphicState�ι���
2592         memcpy(&(gs->lineWidth), &width, sizeof(Fix));
2593 
2594         // ����°���ѹ��Υ����ɤ�ץ��������
2595         i= Fix2i(gs->lineWidth);
2596         if (i <= 0) {
2597                 // ����ͤϥ��꡼���롢0��°���ѹ����Ԥʤ��ʤ�
2598                 f = 1.0;
2599         }
2600 
2601         f = f/dev->resolution*MMETER_PER_INCH; /* width/Reso*Inch */
2602 
2603         // Line°���ѹ����ޥ�ɤ�����
2604         (void)sprintf(obuf, "WUPW%f", f);
2605         DebugPrint("pdapi: %s,%d comm=[%s]\n", __FUNCTION__, __LINE__, obuf);
2606         return CheckWrite(printerContext, obuf, strlen(obuf));
2607 }
2608 
2609 
GetLineWidth(int printerContext,Fix * pwidth)2610 int GetLineWidth(int printerContext, Fix *pwidth)
2611 {
2612         GraphicsState *gs;
2613 
2614         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2615 
2616         gs = GetGraphicsState(printerContext);
2617         if (gs == NULL) {
2618                 return(ERROR);
2619         }
2620 
2621         *pwidth = gs->lineWidth;
2622 
2623         return(OK);
2624 }
2625 
2626 
SetLineDash(int printerContext,Fix pdash[],int num)2627 int SetLineDash(int printerContext, Fix pdash[], int num)
2628 {
2629         int             result;
2630         result = 0;
2631 
2632         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2633 
2634         return(result);
2635 }
2636 
2637 
GetLineDash(int printerContext,Fix pdash[],int * pnum)2638 int GetLineDash(int printerContext, Fix pdash[], int *pnum)
2639 {
2640         int             result;
2641         result = 0;
2642 
2643         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2644 
2645         return(result);
2646 }
2647 
2648 
SetLineDashOffset(int printerContext,Fix offset)2649 int SetLineDashOffset(int printerContext, Fix offset)
2650 {
2651         int             result;
2652         result = 0;
2653 
2654         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2655 
2656         return(result);
2657 }
2658 
2659 
GetLineDashOffset(int printerContext,Fix * poffset)2660 int GetLineDashOffset(int printerContext, Fix *poffset)
2661 {
2662         int             result;
2663         result = 0;
2664 
2665         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2666 
2667         return(result);
2668 }
2669 
2670 
SetLineStyle(int printerContext,LineStyle linestyle)2671 int SetLineStyle(int printerContext, LineStyle linestyle)
2672 {
2673         int             result;
2674         result = 0;
2675 
2676         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2677 
2678         return(result);
2679 }
2680 
2681 
GetLineStyle(int printerContext,LineStyle * plinestyle)2682 int GetLineStyle(int printerContext, LineStyle *plinestyle)
2683 {
2684         int             result;
2685         result = 0;
2686 
2687         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2688 
2689         return(result);
2690 }
2691 
2692 
SetLineCap(int printerContext,LineCap linecap)2693 int SetLineCap(int printerContext, LineCap linecap)
2694 {
2695         GraphicsState *gs;
2696         char            obuf[128];
2697         int             cap;
2698 
2699         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2700 
2701         gs = GetGraphicsState(printerContext);
2702         if (gs == NULL) {
2703                 return(ERROR);
2704         }
2705 
2706         // GraphicsContext�ι���
2707         gs->lineCap = linecap;
2708 
2709         switch (gs->lineCap) {
2710                 case lineCapButt:
2711                         cap = 1;
2712                         break;
2713                 case lineCapRound:
2714                         cap = 4;
2715                         break;
2716                 case lineCapSquare:
2717                         cap = 2;
2718                         break;
2719                 default:
2720                         cap = 3; // Triangular
2721                         break;
2722         }
2723 
2724         // Line°���ѹ����ޥ�ɤ�����
2725         (void)sprintf(obuf, "LA1,%d", cap);
2726         DebugPrint("pdapi: %s,%d comm=[%s]\n", __FUNCTION__, __LINE__, obuf);
2727         return CheckWrite(printerContext, obuf, strlen(obuf));
2728 }
2729 
2730 
GetLineCap(int printerContext,LineCap * plinecap)2731 int GetLineCap(int printerContext, LineCap *plinecap)
2732 {
2733         GraphicsState *gs;
2734 
2735         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2736 
2737         gs = GetGraphicsState(printerContext);
2738         if (gs == NULL) {
2739                 return(ERROR);
2740         }
2741 
2742         *plinecap = gs->lineCap;
2743 
2744         return(OK);
2745 }
2746 
2747 
SetLineJoin(int printerContext,LineJoin linejoin)2748 int SetLineJoin(int printerContext, LineJoin linejoin)
2749 {
2750         GraphicsState *gs;
2751         char                    obuf[128];
2752         int                     join;
2753 
2754         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2755 
2756         gs = GetGraphicsState(printerContext);
2757         if (gs == NULL) {
2758                 return(ERROR);
2759         }
2760 
2761         // GraphicsContext�ι���
2762         gs->lineJoin = linejoin;
2763 
2764         switch (gs->lineJoin) {
2765                 case lineJoinMiter:
2766                         join = 1;
2767                         break;
2768                 case lineJoinRound:
2769                         join = 4;
2770                         break;
2771                 case lineJoinBevel:
2772                         join = 5;
2773                         break;
2774                 default:
2775                         join = 3;
2776                         break;
2777         }
2778 
2779         // Line°���ѹ����ޥ�ɤ�����
2780         (void)sprintf(obuf, "LA2,%d", join);
2781         DebugPrint("pdapi: %s,%d comm=[%s]\n", __FUNCTION__, __LINE__, obuf);
2782         return CheckWrite(printerContext, obuf, strlen(obuf));
2783 }
2784 
2785 
GetLineJoin(int printerContext,LineJoin * plinejoin)2786 int GetLineJoin(int printerContext, LineJoin *plinejoin)
2787 {
2788         GraphicsState *gs;
2789 
2790         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2791 
2792         gs = GetGraphicsState(printerContext);
2793         if (gs == NULL) {
2794                 return(ERROR);
2795         }
2796 
2797         *plinejoin = gs->lineJoin;
2798         return(OK);
2799 }
2800 
2801 
SetMiterLimit(int printerContext,Fix miterlimit)2802 int SetMiterLimit(int printerContext, Fix miterlimit)
2803 {
2804         GraphicsState *gs;
2805         char obuf[128];
2806         float f;
2807 
2808         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2809 
2810         gs = GetGraphicsState(printerContext);
2811         if (gs == NULL) {
2812                 return(ERROR);
2813         }
2814 
2815         // GraphicState�ι���
2816         memcpy(&(gs->miterlimit), &miterlimit, sizeof(Fix));
2817 
2818         Fix2f(miterlimit, f);
2819 
2820         // Line°���ѹ����ޥ�ɤ�����
2821         (void)sprintf(obuf, "LA3,%f", f);
2822         DebugPrint("pdapi: %s,%d comm=[%s]\n", __FUNCTION__, __LINE__, obuf);
2823         return CheckWrite(printerContext, obuf, strlen(obuf));
2824 }
2825 
2826 
GetMiterLimit(int printerContext,Fix * pmiterlimit)2827 int GetMiterLimit(int printerContext, Fix *pmiterlimit)
2828 {
2829         GraphicsState *gs;
2830 
2831         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2832 
2833         gs = GetGraphicsState(printerContext);
2834         if (gs == NULL) {
2835                 return(ERROR);
2836         }
2837 
2838         *pmiterlimit = gs->miterlimit;
2839 
2840         return(OK);
2841 }
2842 
2843 
SetPaintMode(int printerContext,PaintMode paintmode)2844 int SetPaintMode(int printerContext, PaintMode paintmode)
2845 {
2846         GraphicsState *gs;
2847         char obuf[128];
2848 
2849         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2850 
2851         gs = GetGraphicsState(printerContext);
2852         if (gs == NULL) {
2853                 return(ERROR);
2854         }
2855 
2856         gs->paintMode = paintmode;
2857 
2858         if (paintmode == paintModeOpaque) {
2859                 (void)sprintf(obuf, "TR0");
2860         }
2861         else {
2862                 (void)sprintf(obuf, "TR1");
2863         }
2864         DebugPrint("pdapi: %s,%d comm=[%s]\n", __FUNCTION__, __LINE__, obuf);
2865         return CheckWrite(printerContext, obuf, strlen(obuf));
2866 }
2867 
2868 
GetPaintMode(int printerContext,PaintMode * ppaintmode)2869 int GetPaintMode(int printerContext, PaintMode *ppaintmode)
2870 {
2871         GraphicsState *gs;
2872 
2873         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
2874 
2875         gs = GetGraphicsState(printerContext);
2876         if (gs == NULL) {
2877                 return(ERROR);
2878         }
2879 
2880         *ppaintmode = gs->paintMode;
2881 
2882         return(OK);
2883 }
2884 
2885 
SetStrokeColor(int printerContext,Brush * brush)2886 int SetStrokeColor(int printerContext, Brush *brush)
2887 {
2888 
2889         DebugPrint("pdapi: %s,%d printerContext=%d brush.color[1]=%X brush.color[2]=%X brush.color[3]=%X\n", __FUNCTION__, __LINE__, printerContext, brush->color[1], brush->color[2], brush->color[3]);
2890 
2891         GraphicsState *gs;
2892 
2893         gs = GetGraphicsState(printerContext);
2894         if (gs == NULL) {
2895                 return(ERROR);
2896         }
2897 
2898         // ľ����Brush��Ʊ�����ϡ�̵�뤹��
2899         if (IsSameBrush(&(gs->strokeBrush), brush)) {
2900                 return(OK);
2901         }
2902 
2903         // ��Brush�����Ƥ�GraphicsState�ǻ���Brush�ΰ�˥��ԡ�����
2904         if (CopyBrush(&(gs->strokeBrush), brush)) {
2905                 return(ERROR);
2906         }
2907 
2908         /* ���ޥ�ɤ����� */
2909         {
2910                 char obuf[64];
2911 
2912                 // �ڥ��顼����
2913                 (void)sprintf(obuf, "PC%d,%d,%d,%d",            // PC�͸�ľ��
2914                                           HP_COLOR_ID_STROKE,
2915                                           (unsigned char)brush->color[2],
2916                                           (unsigned char)brush->color[1],
2917                                           (unsigned char)brush->color[0]);
2918                 if (CheckWrite(printerContext, obuf, strlen(obuf)) != OK) {
2919                         return(ERROR);
2920                 }
2921         }
2922 
2923         if (brush->pbrush != NULL) {
2924                 if (SetBrushData(printerContext, brush, HP_COLOR_ID_STROKE) != OK) {
2925                         errorno = FATALERROR;
2926                         return(ERROR);
2927                 }
2928         }
2929 
2930         return (OK);
2931 }
2932 
2933 
SetFillColor(int printerContext,Brush * brush)2934 int SetFillColor(int printerContext, Brush *brush)
2935 {
2936 
2937         DebugPrint("pdapi: %s,%d printerContext=%d brush.color[1]=%X brush.color[2]=%X brush.color[3]=%X\n", __FUNCTION__, __LINE__, printerContext, brush->color[1], brush->color[2], brush->color[3]);
2938 
2939         GraphicsState *gs;
2940 
2941         gs = GetGraphicsState(printerContext);
2942         if (gs == NULL) {
2943                 return(ERROR);
2944         }
2945 
2946         // ľ����Brush��Ʊ�����ϡ�̵�뤹��
2947         if (IsSameBrush(&(gs->fillBrush), brush)) {
2948                 return(OK);
2949         }
2950 
2951         /* ��Brush�����Ƥ�GraphicsState�ǻ���Brush�˥��ԡ����� */
2952         if (CopyBrush(&(gs->fillBrush), brush)) {
2953                 return(ERROR);
2954         }
2955 
2956         /* ���ޥ�ɤ����� */
2957         {
2958 
2959                 char obuf[64];
2960 
2961                 // �ڥ��顼����
2962                 (void)sprintf(obuf, "PC%d,%d,%d,%d",            // PC�͸�ľ��
2963                                       HP_COLOR_ID_FILL,
2964                                           (unsigned char)brush->color[2],
2965                                           (unsigned char)brush->color[1],
2966                                           (unsigned char)brush->color[0]);
2967                 if (CheckWrite(printerContext, obuf, strlen(obuf)) != OK) {
2968                         return(ERROR);
2969                 }
2970         }
2971 
2972         if (brush->pbrush != NULL) {
2973                 if (SetBrushData(printerContext, brush, HP_COLOR_ID_FILL) != OK) {
2974                         errorno = FATALERROR;
2975                         return(ERROR);
2976                 }
2977         }
2978 
2979         return (OK);
2980 }
2981 
2982 
SetBgColor(int printerContext,Brush * brush)2983 int SetBgColor(int printerContext, Brush *brush)
2984 {
2985         DebugPrint("pdapi: %s,%d printerContext=%d brush.color[1]=%X brush.color[2]=%X brush.color[3]=%X\n", __FUNCTION__, __LINE__, printerContext, brush->color[1], brush->color[2], brush->color[3]);
2986 
2987         GraphicsState *gs;
2988 
2989         gs = GetGraphicsState(printerContext);
2990         if (gs == NULL) {
2991                 return(ERROR);
2992         }
2993 
2994         // ľ����Brush��Ʊ�����ϡ�̵�뤹��
2995         if (IsSameBrush(&(gs->bgBrush), brush)) {
2996                 return(OK);
2997         }
2998 
2999 
3000         CopyBrush(&(gs->bgBrush), brush);
3001 
3002         return(OK);
3003 }
3004 
3005 
3006 
3007 /* ----------------------------------------------------------------
3008  *
3009  * Path Operations
3010  *
3011  * ---------------------------------------------------------------- */
3012 
3013 /* �ѥ�����Ͽ�ֹ� */
3014 typedef enum HPPathId_e {
3015         HP_PATH_ID_PRINT = 0,
3016         HP_PATH_ID_CLIP = 1
3017 } HPPathId;
3018 
3019 /* �ѥ���������� */
3020 typedef enum HPPathType {
3021         HP_PATH_TYPE_STROKE = 0,
3022         HP_PATH_TYPE_FILL = 1,
3023         HP_PATH_TYPE_STROKEFILL = 2,
3024         HP_PATH_TYPE_CLIP = 3
3025 } HPPathType;
3026 
3027 static int FlashPath(int printerContext, unsigned char id, HPPathType type);
3028 static int CommitRectanglePath(int printerContext, Point point0, Point point1, Fix xellipse, Fix yellipse);
3029 
3030 
3031 /* ----------------------------------------------------------------
3032  *
3033  *      FlashPath
3034  *
3035  * Name
3036  *      FlashPath - �����ȥѥ����ۤ����޷������褹��
3037  *
3038  * Arguments
3039  *      printerContext - OpenPrinter()������줿�ץ������ƥ����Ȥ�
3040  *                                      ���ꤹ�롣
3041  *      id - �ѥ���Ͽ�ֹ�
3042  *           (Note) �������ѥ�������Ǥ�ID=0�Τߤ���Ѥ��Ƥ��뤬������
3043  *           ���Ϥ�ID����Ĥ������ɤ��Τ���Ƚ�Ǥ��Ĥ��ʤ��١������ǽ
3044  *           �ˤ��Ƥ���
3045  *      type - �������
3046  *
3047  * Description
3048  *      �����ȥѥ����ۤ����޷������褷�ޤ���������GraphicsState
3049  *      (current path�ޤ�)���ݻ�����ޤ���
3050  *
3051  *
3052  * Return Value
3053  *      ����˽�λ�����OK ���֤���롣���顼�����ä�����-1 ���֤��졢
3054  *      errorno �˥��顼�����ɤ���Ǽ����롣
3055  *
3056  * ---------------------------------------------------------------- */
FlashPath(int printerContext,unsigned char id,HPPathType type)3057 static int FlashPath(int printerContext, unsigned char id, HPPathType type)
3058 {
3059         GraphicsState *gs;
3060         char obuf[64] = "";
3061         ItemList *node;
3062         int param;
3063         int result;
3064 
3065         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
3066 
3067         gs = GetGraphicsState(printerContext);
3068         if (gs == NULL) {
3069                 /* GraphicsState��̵�����⤷����Printer Context�������Ǥ��� */
3070                 return (ERROR);
3071         }
3072 
3073         /* ���ֳ�ǧ */
3074         if (gs->pathActive == TRUE) {
3075                 /* �ѥ����������Ǥ���(EndPath���ƤФ�Ƥ��ʤ�) */
3076                 errorno = BADREQUEST;
3077                 return (ERROR);
3078         } else if (gs->pathList == NULL) {
3079                 /* �ѥ��ꥹ�Ȥ�¸�ߤ��ʤ� */
3080                 return (OK);
3081         }
3082 
3083         switch (type) {
3084                 case HP_PATH_TYPE_STROKE:
3085                 case HP_PATH_TYPE_STROKEFILL:
3086                         /* �ѥ����襳�ޥ�� */
3087                         if (!gs->strokeBrush.pbrush) {
3088                                 (void)sprintf(obuf, "SP%dEP", HP_COLOR_ID_STROKE);
3089                         }
3090                         else {
3091                                 (void)sprintf(obuf, "SP%dSV22,%dEP", HP_COLOR_ID_STROKE, HP_COLOR_ID_STROKE);
3092                         }
3093                         if (type == HP_PATH_TYPE_STROKE) {
3094                                 break;
3095                         }
3096                         /* if HP_PATH_TYPE_STROKEFILL fall through!! */
3097 
3098                 case HP_PATH_TYPE_FILL:
3099                         if (gs->fillMode == fillModeEvenOdd) {
3100                                 /* �ѥ����襳�ޥ�� */
3101                                 if (!gs->fillBrush.pbrush) {
3102                                         (void)sprintf(obuf+strlen(obuf), "SP%dFP", HP_COLOR_ID_FILL);
3103                                 }
3104                                 else {
3105                                         (void)sprintf(obuf+strlen(obuf), "SP%dFT22,%dFP",
3106                                                                 HP_COLOR_ID_FILL, HP_COLOR_ID_FILL);
3107                                 }
3108                         } else if (gs->fillMode == fillModeWinding) {
3109                                 /* �ѥ����襳�ޥ�� */
3110                                 if (!gs->fillBrush.pbrush) {
3111                                         (void)sprintf(obuf+strlen(obuf), "SP%dFP1;", HP_COLOR_ID_FILL);
3112                                 }
3113                                 else {
3114                                         (void)sprintf(obuf+strlen(obuf), "SP%dFT22,%dFP1;",
3115                                                                 HP_COLOR_ID_FILL, HP_COLOR_ID_FILL);
3116                                 }
3117                         } else {
3118                                 /* ���ݡ��Ȥ��Ƥ��ʤ�path mode�������줿 */
3119                                 errorno = NOTSUPPORTED;
3120                                 return (ERROR);
3121                         }
3122                         break;
3123 
3124                 case HP_PATH_TYPE_CLIP:
3125                         if (gs->fillMode == fillModeEvenOdd) {
3126                                 param = 0;
3127                                 (void)sprintf(obuf, " ");
3128                         } else if (gs->fillMode == fillModeWinding) {
3129                                 param = 0;
3130                                 (void)sprintf(obuf, " ");
3131                         } else {
3132                                 /* ���ݡ��Ȥ��Ƥ��ʤ�path mode�������줿 */
3133                                 errorno = NOTSUPPORTED;
3134                                 return (ERROR);
3135                         }
3136                         break;
3137 
3138                 default:
3139                         /* ���ݡ��Ȥ��Ƥ��ʤ�path type�������줿 */
3140                         errorno = NOTSUPPORTED;
3141                         return (ERROR);
3142         }
3143 
3144         /* �ꥹ�ȤκǸ����˥��ޥ�ɤ��ɲ� */
3145         /* ���λ������Ĥ����Ƥ��ʤ��ѥ��ϡ����ۤ�����Ĥ����� */
3146         gs->pathEndPoint = AddList(gs->pathList, obuf, strlen(obuf));
3147         if (gs->pathEndPoint == NULL) {
3148                 return (ERROR);
3149         }
3150 
3151         /* �ѥ���FD�ؽ��Ф� */
3152         node = gs->pathList;
3153         while (node != NULL) {
3154                 result = CheckWrite(printerContext, node->item, node->length);
3155                 if (result != OK) {
3156                         /* �����߼��� */
3157                         return (ERROR);
3158                 }
3159                 node = node->next;
3160         }
3161 
3162         return (OK);
3163 }
3164 
3165 
3166 /* ----------------------------------------------------------------
3167  *
3168  *      CommitRectanglePath
3169  *
3170  * Name
3171  *      CommitRectanglePath - ����ѥ���ѥ��ꥹ����Ͽ����
3172  *
3173  * Arguments
3174  *      printerContext - OpenPrinter()������줿�ץ������ƥ����Ȥ���ꤹ�롣
3175  *      point0 - ������
3176  *      point1 - �г���
3177  *      xellipse - �ʱߤο�ʿ������Ĺ��
3178  *      yellipse - �ʱߤο�ľ������Ĺ��
3179  *
3180  * Description
3181  *      Rectangle��ѥ����ɲä��롣
3182  *      Corner��xellipse�����yellipse��ɽ��������ʱ߸̤ˤ�ä���³����롣
3183  *
3184  * Return Value
3185  *      ����˽�λ�����OK ���֤���롣���顼�����ä�����-1 ���֤��졢
3186  *      errorno �˥��顼�����ɤ���Ǽ����롣
3187  *
3188  * ---------------------------------------------------------------- */
CommitRectanglePath(int printerContext,Point point0,Point point1,Fix xellipse,Fix yellipse)3189 static int CommitRectanglePath(int printerContext, Point point0, Point point1, Fix xellipse, Fix yellipse)
3190 {
3191         GraphicsState *gs;
3192         char obuf[64];
3193 
3194         gs = GetGraphicsState(printerContext);
3195         if (gs == NULL) {
3196                 /* GraphicsState��̵�����⤷����Printer Context�������Ǥ��� */
3197                 return (ERROR);
3198         }
3199 
3200         (void)sprintf(obuf, "PU%d,%d",
3201                       (int)ApplyCtmX_Integer((point0.x), (point0.y), gs->ctm),
3202                       (int)ApplyCtmY_Integer((point0.x), (point0.y), gs->ctm));
3203 
3204         if (CheckWrite(printerContext, obuf, strlen(obuf)) != OK) {
3205                 return(ERROR);
3206         }
3207 
3208         /* ������襳�ޥ�� */
3209         (void)sprintf(obuf, "PD%d,%d,%d,%d,%d,%d,%d,%d",
3210                       (int)ApplyCtmX_Integer((point0.x), (point1.y), gs->ctm),
3211                       (int)ApplyCtmY_Integer((point0.x), (point1.y), gs->ctm),
3212                       (int)ApplyCtmX_Integer((point1.x), (point1.y), gs->ctm),
3213                       (int)ApplyCtmY_Integer((point1.x), (point1.y), gs->ctm),
3214                       (int)ApplyCtmX_Integer((point1.x), (point0.y), gs->ctm),
3215                       (int)ApplyCtmY_Integer((point1.x), (point0.y), gs->ctm),
3216                       (int)ApplyCtmX_Integer((point0.x), (point0.y), gs->ctm),
3217                       (int)ApplyCtmY_Integer((point0.x), (point0.y), gs->ctm));
3218 
3219         /* �ѥ����ɲä��� */
3220         gs->pathEndPoint = AddList(gs->pathList, obuf, strlen(obuf));
3221         if (gs->pathEndPoint == NULL) {
3222                 return (ERROR);
3223         }
3224         return(OK);
3225 }
3226 
3227 
NewPath(int printerContext)3228 int NewPath(int printerContext)
3229 {
3230         GraphicsState *gs;
3231         char obuf[64];
3232 
3233         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
3234 
3235         gs = GetGraphicsState(printerContext);
3236         if (gs == NULL) {
3237                 /* GraphicsState��̵�����⤷����Printer Context�������Ǥ��� */
3238                 return (ERROR);
3239         }
3240 
3241         /* �Ť��ѥ����ĤäƤ���к�������������ѥ����Ϥ��롣path��
3242            �ϥ��ޥ�ɤϡ��ѥ�����Ф�ľ���˥ѥ�᡼�����åȤ���ɬ
3243            �פ�����Τǡ������Ǥ϶��ˤ��Ƥ��� */
3244         if (gs->pathList != NULL) {
3245                 DeleteListAll(gs->pathList);
3246         }
3247         gs->pathList = NewList("", 0);
3248         if (gs->pathList == NULL) {
3249                 errorno = FATALERROR;
3250                 return (ERROR);
3251         }
3252 
3253         /* �ѥ���������Ǥ���������ե饰���å� */
3254         gs->pathActive = TRUE;
3255 
3256         /* ������ꥳ�ޥ�� */
3257         (void)sprintf(obuf, "PM0");
3258 
3259         /* �ꥹ�ȤκǸ����˥��ޥ�ɤ��ɲ� */
3260         gs->pathEndPoint = AddList(gs->pathList, obuf, strlen(obuf));
3261         if (gs->pathEndPoint == NULL) {
3262                 return (ERROR);
3263         }
3264 
3265         return (OK);
3266 }
3267 
3268 
EndPath(int printerContext)3269 int EndPath(int printerContext)
3270 {
3271         GraphicsState *gs;
3272         char obuf[64];
3273 
3274         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
3275 
3276         gs = GetGraphicsState(printerContext);
3277         if (gs == NULL) {
3278                 /* GraphicsState��̵�����⤷����Printer Context�������Ǥ��� */
3279                 return (ERROR);
3280         }
3281 
3282         if (gs->pathActive != TRUE) {
3283                 /* NewPath���ƤФ�Ƥ��ʤ��Τˡ�EndPath���ƤФ줿 */
3284                 errorno = BADREQUEST;
3285                 return (ERROR);
3286         }
3287 
3288         /* �ѥ���Ͽ��λ���ޥ�� */
3289         (void)sprintf(obuf, "PM2");
3290 
3291         /* �ꥹ�ȤκǸ����˥��ޥ�ɤ��ɲ� */
3292         gs->pathEndPoint = AddList(gs->pathList, obuf, strlen(obuf));
3293         if (gs->pathEndPoint == NULL) {
3294                 return (ERROR);
3295         }
3296 
3297         /* �ѥ����꤬��λ���Ƥ���������ե饰���å� */
3298         gs->pathActive = FALSE;
3299         return (OK);
3300 }
3301 
3302 
StrokePath(int printerContext)3303 int StrokePath(int printerContext)
3304 {
3305         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
3306 
3307         return FlashPath(printerContext, HP_PATH_ID_PRINT, HP_PATH_TYPE_STROKE);
3308 }
3309 
3310 
FillPath(int printerContext)3311 int FillPath(int printerContext)
3312 {
3313         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
3314 
3315         return FlashPath(printerContext, HP_PATH_ID_PRINT, HP_PATH_TYPE_FILL);
3316 }
3317 
3318 
StrokeFillPath(int printerContext)3319 int StrokeFillPath(int printerContext)
3320 {
3321         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
3322 
3323         return FlashPath(printerContext, HP_PATH_ID_PRINT, HP_PATH_TYPE_STROKEFILL);
3324 }
3325 
3326 
SetClipPath(int printerContext,ClipRule clipRule)3327 int SetClipPath(int printerContext, ClipRule clipRule)
3328 {
3329         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
3330 
3331         return(OK);
3332 }
3333 
3334 
3335 #ifndef OLD_API
3336 /* Ver 0.2 pre���ɲ� */
ResetClipPath(int printerContext)3337 int ResetClipPath( int printerContext)
3338 {
3339         int             result;
3340         result = 0;
3341 
3342         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
3343 
3344         return(result);
3345 }
3346 #endif /* OLD_API */
3347 
3348 
SetCurrentPoint(int printerContext,Fix x,Fix y)3349 int SetCurrentPoint(int printerContext, Fix x, Fix y)
3350 {
3351         GraphicsState *gs;
3352         char obuf[64];
3353 
3354         DebugPrint("pdapi: %s,%d printerContext=%d, x=%d, y=%d\n", __FUNCTION__, __LINE__, printerContext, Fix2i(x), Fix2i(y));
3355 
3356         gs = GetGraphicsState(printerContext);
3357         if (gs == NULL) {
3358                 /* GraphicsState��̵�����⤷����Printer Context�������Ǥ��� */
3359                 return (ERROR);
3360         }
3361 
3362         if ((gs->pathActive == FALSE) ||
3363             ((gs->pathActive == TRUE) && (gs->pathList->next == gs->pathEndPoint))) {
3364                 /* �����ȥݥ���Ȼ��ꥳ�ޥ�� */
3365                 (void)sprintf(obuf, "PU%d,%d",
3366                               (int)ApplyCtmX_Integer(x, y, gs->ctm),
3367                               (int)ApplyCtmY_Integer(x, y, gs->ctm));
3368 
3369                 if (CheckWrite(printerContext, obuf, strlen(obuf)) != OK) {
3370                         return(ERROR);
3371                 }
3372         } else {
3373                 /* �����ȥݥ���Ȼ��ꥳ�ޥ�� */
3374                 (void)sprintf(obuf, "PM1PU%d,%d",
3375                               (int)ApplyCtmX_Integer(x, y, gs->ctm),
3376                               (int)ApplyCtmY_Integer(x, y, gs->ctm));
3377 
3378                 /* �ꥹ�ȤκǸ����˥��ޥ�ɤ��ɲ� */
3379                 gs->pathEndPoint = AddList(gs->pathList, obuf, strlen(obuf));
3380                 if (gs->pathEndPoint == NULL) {
3381                         return (ERROR);
3382                 }
3383         }
3384         return (OK);
3385 }
3386 
3387 
LinePath(int printerContext,int flag,int npoints,Point * points)3388 int LinePath(int printerContext, int flag, int npoints, Point *points)
3389 {
3390         GraphicsState *gs;
3391         char obuf[2048];
3392         int i;
3393         int max = npoints - 1;
3394 
3395         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
3396 
3397         if (npoints < 1) {
3398                 /* ĺ���������� */
3399                 return (ERROR);
3400         }
3401 
3402         gs = GetGraphicsState(printerContext);
3403         if (gs == NULL) {
3404                 /* GraphicsState��̵�����⤷����Printer Context�������Ǥ��� */
3405                 return (ERROR);
3406         }
3407 
3408         if (flag == PathClose) {
3409                 (void)sprintf(obuf, "PD");
3410 
3411                 /* �ꥹ�ȤκǸ����˥��ޥ�ɤ��ɲ� */
3412                 gs->pathEndPoint = AddList(gs->pathList, obuf, strlen(obuf));
3413                 if (gs->pathEndPoint == NULL) {
3414                         return (ERROR);
3415                 }
3416         } else {
3417                 (void)sprintf(obuf, "PD");
3418 
3419                 for (i = 0; i < max; i++) {
3420                         (void)sprintf(obuf+strlen(obuf), "%d,%d,",
3421                                 (int)ApplyCtmX_Integer((points[i].x), (points[i].y), gs->ctm), /* x */
3422                                 (int)ApplyCtmY_Integer((points[i].x), (points[i].y), gs->ctm)); /* y */
3423                 }
3424                 (void)sprintf(obuf+strlen(obuf), "%d,%dPU",
3425                         (int)ApplyCtmX_Integer((points[max].x), (points[max].y), gs->ctm), /* x */
3426                         (int)ApplyCtmY_Integer((points[max].x), (points[max].y), gs->ctm)); /* y */
3427 
3428                 /* �ꥹ�ȤκǸ����˥��ޥ�ɤ��ɲ� */
3429                 gs->pathEndPoint = AddList(gs->pathList, obuf, strlen(obuf));
3430                 if (gs->pathEndPoint == NULL) {
3431                         return (ERROR);
3432                 }
3433         }
3434         return (OK);
3435 }
3436 
3437 
PolygonPath(int printerContext,int npolygons,int * nvertexes,Point * points)3438 int PolygonPath(int printerContext, int npolygons, int *nvertexes, Point *points)
3439 {
3440         GraphicsState *gs;
3441         int i;
3442         char obuf[2048];
3443 
3444         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
3445 
3446         gs = GetGraphicsState(printerContext);
3447         if (gs == NULL) {
3448                 /* GraphicsState��̵�����⤷����Printer Context�������Ǥ��� */
3449                 return (ERROR);
3450         }
3451 
3452         for (i = 0; i < npolygons; i++)
3453         {
3454                 int index = ((i == 0) ? 0 : nvertexes[i-1]);
3455                 int p;
3456                 (void)sprintf(obuf, "PU%d,%dPD",
3457                         (int)ApplyCtmX_Integer((points[index+0].x), (points[index+0].y), gs->ctm), /* x */
3458                         (int)ApplyCtmY_Integer((points[index+0].x), (points[index+0].y), gs->ctm)); /* y */
3459 
3460                 for (p = 1; p < nvertexes[i]; p++)
3461                 {
3462                         (void)sprintf(obuf+strlen(obuf), "%d,%d,",
3463                                 (int)ApplyCtmX_Integer((points[index+p].x), (points[index+p].y), gs->ctm), /* x */
3464                                 (int)ApplyCtmY_Integer((points[index+p].x), (points[index+p].y), gs->ctm)); /* y */
3465 
3466                 }
3467                 (void)sprintf(obuf+strlen(obuf), "%d,%d",
3468                         (int)ApplyCtmX_Integer((points[index+0].x), (points[index+0].y), gs->ctm), /* x */
3469                         (int)ApplyCtmY_Integer((points[index+0].x), (points[index+0].y), gs->ctm)); /* y */
3470 
3471         }
3472         (void)sprintf(obuf+strlen(obuf), "PU");
3473 
3474         /* �ꥹ�ȤκǸ����˥��ޥ�ɤ��ɲ� */
3475         gs->pathEndPoint = AddList(gs->pathList, obuf, strlen(obuf));
3476         if (gs->pathEndPoint == NULL) {
3477                 return (ERROR);
3478         }
3479 
3480         return(OK);
3481 }
3482 
3483 
RectanglePath(int printerContext,int nrectangles,Rectangle * rectangles)3484 int RectanglePath(int printerContext, int nrectangles, Rectangle *rectangles)
3485 {
3486         Fix fix0;
3487         int i;
3488 
3489         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
3490 
3491         if (nrectangles <= 0) {
3492                 /* ����������� */
3493                 errorno = PARAMERROR;
3494                 return (ERROR);
3495         }
3496 
3497         memset(&fix0, 0, sizeof(Fix));
3498         for (i = 0; i < nrectangles; i++) {
3499                 int result;
3500 
3501                 result = CommitRectanglePath(printerContext, rectangles[i].p0, rectangles[i].p1, fix0, fix0);
3502                 if (result != OK) {
3503                         return (ERROR);
3504                 }
3505         }
3506         return(OK);
3507 }
3508 
3509 
RoundRectanglePath(int printerContext,int nrectangles,RoundRectangle * rectangles)3510 int RoundRectanglePath(int printerContext, int nrectangles, RoundRectangle *rectangles)
3511 {
3512         int i;
3513 
3514         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
3515 
3516         if (nrectangles <= 0) {
3517                 /* ����������� */
3518                 errorno = PARAMERROR;
3519                 return (ERROR);
3520         }
3521 
3522         for (i = 0; i < nrectangles; i++) {
3523                 int result;
3524 
3525                 result = CommitRectanglePath(printerContext, rectangles[i].p0, rectangles[i].p1,
3526                                              rectangles[i].xellipse, rectangles[i].yellipse);
3527                 if (result != OK) {
3528                         return (ERROR);
3529                 }
3530         }
3531         return(OK);
3532 }
3533 
3534 
3535 #ifdef OLD_API
BezierPath(int printerContext,int * npoints,Point * points)3536 int BezierPath(int printerContext, int *npoints, Point *points)
3537 #else
3538 int BezierPath(int printerContext, int npoints, Point *points)
3539 #endif /* OLD_API */
3540 {
3541         GraphicsState *gs;
3542         char obuf[4096];
3543         int offset;
3544 #ifdef OLD_API
3545         int count;
3546         int i;
3547 #else
3548         int max = npoints - 1;
3549 #endif /* OLD_API */
3550         int j;
3551 
3552         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
3553 
3554         /* ��������Ф�(�Ĥ��Ǥ˥ѥ�᡼����ǧ) */
3555 #ifdef OLD_API
3556         for (count = 0; npoints[count] != 0; count++) {
3557 /*              if (((npoints[count]) % 3) != 0) { */
3558 /*                      /\* �������������ĺ������3���ܿ��Ǥʤ� *\/ */
3559 /*                      DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__); */
3560 /*                      return (ERROR); */
3561 /*              } */
3562         }
3563 #else
3564         if ((npoints % 3) != 0) {
3565                 /* �������������ĺ������3���ܿ��Ǥʤ� */
3566                 errorno = PARAMERROR;
3567                 return (ERROR);
3568         }
3569 #endif /* OLD_API */
3570 
3571         gs = GetGraphicsState(printerContext);
3572         if (gs == NULL) {
3573                 /* GraphicsState��̵�����⤷����Printer Context�������Ǥ��� */
3574                 return (ERROR);
3575         }
3576 
3577         offset = 0;
3578 #ifdef OLD_API
3579         for (i = 0; npoints[i] != 0; i++) {
3580                 offset ++;
3581 #endif /* OLD_API */
3582                 /* Bezier�����ɲå��ޥ��(suffix) */
3583                 (void)sprintf(obuf, "PDBZ");
3584 
3585 #ifdef OLD_API
3586                 for (j = 1; j < npoints[i]-1; j++) {
3587 #else
3588                 for (j = 0; j < max; j++) {
3589 #endif /* OLD_API */
3590                         (void)sprintf(obuf+strlen(obuf), "%d,%d,",
3591                                 (int)ApplyCtmX_Integer((points[offset].x), (points[offset].y), gs->ctm), /* x */
3592                                 (int)ApplyCtmY_Integer((points[offset].x), (points[offset].y), gs->ctm)); /* y */
3593                         offset ++;
3594                 }
3595                 (void)sprintf(obuf+strlen(obuf), "%d,%dPU",
3596                         (int)ApplyCtmX_Integer((points[offset].x), (points[offset].y), gs->ctm), /* x */
3597                         (int)ApplyCtmY_Integer((points[offset].x), (points[offset].y), gs->ctm)); /* y */
3598 
3599                 /* �ꥹ�ȤκǸ����˥��ޥ�ɤ��ɲ� */
3600                 gs->pathEndPoint = AddList(gs->pathList, obuf, strlen(obuf));
3601                 if (gs->pathEndPoint == NULL) {
3602                         return (ERROR);
3603                 }
3604 
3605 #ifdef OLD_API
3606                 }
3607 #endif /* OLD_API */
3608 
3609         return(OK);
3610 
3611 }
3612 
3613 
3614 int ArchPath(int printerContext, int kind, int dir, Fix bbx0, Fix bby0, Fix bbx1, Fix bby1, Fix x0, Fix y0, Fix x1, Fix y1)
3615 {
3616         int             result;
3617         result = 0;
3618 
3619         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
3620 
3621         return(result);
3622 }
3623 
3624 
3625 
3626 /* ----------------------------------------------------------------
3627  *
3628  * Raw Data Operations
3629  *
3630  * ---------------------------------------------------------------- */
3631 static int StartRaws(int printerContext, int sourceWidth, int sourceHeight, int colorDepth, int destinationWidth, int destinationHeight);
3632 static int WriteRaws(int printerContext, int ndata, void *rawsData);
3633 static int EndRaws(int printerContext);
3634 
3635 static int StartRaws(int printerContext, int sourceWidth,
3636                     int sourceHeight, int colorDepth,
3637                     int destinationWidth, int destinationHeight)
3638 {
3639         GraphicsState *gs;
3640         char obuf[64];
3641         unsigned long
3642         int result;
3643         DeviceInfo *dev;
3644 
3645 	gs = GetGraphicsState(printerContext);
3646         if (gs == NULL) {
3647                 /* GraphicsState��̵�����⤷����Printer Context������
3648                    �Ǥ��� */
3649                 return (ERROR);
3650         }
3651 
3652         dev = GetDeviceInfo(printerContext);
3653         if (dev == NULL) {
3654                 return(ERROR);
3655         }
3656 
3657         /* PCL�⡼�ɰܹ� */
3658         (void)sprintf(obuf, PCL_ESC "%%1A" PCL_ESC "*p0P");
3659         result = CheckWrite(printerContext, obuf, strlen(obuf));
3660         if (result != OK) return (ERROR);
3661 
3662         if (colorDepth == 1) {
3663                 result = CheckWrite(printerContext, PCL_ESC "*v6W\00\01\01\00\00\00", 11);
3664                 if (result != OK) return (ERROR);
3665 
3666                 if ((gs->fillBrush.color[2] & 255) == 255
3667                         && (gs->fillBrush.color[1] & 255) == 255
3668                         && (gs->fillBrush.color[0] & 255) == 255) {
3669                         (void)sprintf(obuf,
3670                                       PCL_ESC "*v%da%db%dc1I",
3671                                       254, 254, 254);
3672                 } else {
3673                         (void)sprintf(obuf,
3674                                       PCL_ESC "*v%da%db%dc1I",
3675                                       (unsigned char)gs->fillBrush.color[2],
3676                                       (unsigned char)gs->fillBrush.color[1],
3677                                       (unsigned char)gs->fillBrush.color[0]);
3678                 }
3679                 result = CheckWrite(printerContext, obuf, strlen(obuf));
3680                 if (result != OK) return (ERROR);
3681         } else if (colorDepth == 4) {
3682                 /* (TBD) */
3683         } else if (colorDepth == 8) {
3684                 /* (TBD) */
3685         } else if (colorDepth == 24) {
3686                 result = CheckWrite(printerContext, PCL_ESC "*v6W\00\03\00\10\10\10", 11);
3687                 if (result != OK) return (ERROR);
3688         } else {
3689                 /* ���ݡ��Ȥ��ʤ�depth���Ϥ��줿 */
3690                 return (ERROR);
3691         }
3692 
3693         (void)sprintf(obuf,
3694                       PCL_ESC "*r%ds%dT"
3695                       PCL_ESC "*r1A",
3696                       destinationWidth,         /* ���������� */
3697                       destinationHeight);       /* �������ι⤵ */
3698 
3699         result =  CheckWrite(printerContext, obuf, strlen(obuf));
3700         if (result != OK) {
3701                 return (ERROR);
3702         }
3703 
3704         gs->imageWidth = sourceWidth;
3705         gs->imageHeight = sourceHeight;
3706         gs->imageDepth = colorDepth;
3707         gs->imageDestWidth = destinationWidth;
3708         gs->imageDestHeight = destinationHeight;
3709 
3710         return (OK);
3711 }
3712 
3713 static int WriteRaws(int printerContext, int ndata, void *rawsData)
3714 {
3715         GraphicsState *gs;
3716         char obuf[64];
3717         char *writeData;
3718         int i;
3719         int bytes_pre_pixel;
3720         unsigned int width_bytes;
3721         unsigned int prt_width_bytes;
3722         int result;
3723         double mag;
3724 
3725         if (ndata == 0) {
3726                 /* ��������̵�� */
3727                 return (OK);
3728         }
3729 
3730         gs = GetGraphicsState(printerContext);
3731         if (gs == NULL) {
3732                 /* GraphicsState��̵�����⤷����Printer Context������
3733                    �Ǥ��� */
3734                 return (ERROR);
3735         }
3736 
3737         /* �饹����ΥХ��ȿ� */
3738         width_bytes = ndata / gs->imageHeight;
3739 
3740         if (gs->imageDestWidth != gs->imageWidth) {
3741 
3742                 /* 1pixel�դ�ΥХ��ȿ� */
3743                 if (gs->imageDepth < 24) {
3744                         bytes_pre_pixel = 1;
3745                 } else {
3746                         bytes_pre_pixel = 3;
3747                 }
3748 
3749                 /* ����/�̾���Υ饹����ΥХ��ȿ� */
3750                 if (gs->imageDepth == 1) {
3751                         prt_width_bytes = (gs->imageDestWidth + 7) >> 3;
3752                 } else {
3753                         prt_width_bytes = gs->imageDestWidth * bytes_pre_pixel;
3754                 }
3755 
3756                 writeData = (char *)malloc(prt_width_bytes * gs->imageHeight);
3757                 if (writeData == NULL) {
3758                         errorno = FATALERROR;
3759                         return (ERROR);
3760                 }
3761 
3762                 mag = (double)gs->imageDestWidth / (double)gs->imageWidth;
3763 
3764                 if (gs->imageDepth == 1) {
3765                         memset(writeData, 0x0, prt_width_bytes * gs->imageHeight);
3766                         for (i = 0; i < gs->imageHeight; i++) {
3767                                 int j;
3768                                 unsigned char *pDest = writeData + (prt_width_bytes * i);
3769                                 unsigned char *pSrc = rawsData + (width_bytes * i);
3770                                 for (j = 0; j < gs->imageDestWidth; j++) {
3771                                         int index = (int)(j / mag);
3772                                         unsigned char bit = (*(pSrc + index / 8) >> (7 - (index % 8))) & 0x1;
3773                                         *(pDest + j / 8) |= bit << (7 - (j % 8));
3774                                 }
3775                         }
3776                 }
3777                 else {
3778                         memset(writeData, 0xff, prt_width_bytes * gs->imageHeight);
3779                         for (i = 0; i < gs->imageHeight; i++) {
3780                                 int j;
3781                                 char *pDest = writeData + (prt_width_bytes * i);
3782                                 char *pSrc = rawsData + (width_bytes * i);
3783                                 for (j = 0; j < gs->imageDestWidth; j++) {
3784                                         char *p = pSrc + (int)(j / mag) * bytes_pre_pixel;
3785                                         *pDest++ = *p++;
3786                                         *pDest++ = *p++;
3787                                         *pDest++ = *p;
3788                                 }
3789                         }
3790                 }
3791         }
3792         else {
3793                 writeData = rawsData;
3794                 prt_width_bytes = width_bytes;
3795         }
3796 
3797         DebugPrint("pdapi: %s,%d ndata=%d gs->imageHeight=%d prt_width_bytes=%d width_bytes=%d\n",
3798                    __FUNCTION__, __LINE__, ndata, gs->imageHeight, prt_width_bytes, width_bytes);
3799 
3800         /* �饹��ž�� */
3801         mag = (double)gs->imageDestHeight / (double)gs->imageHeight;
3802         for (i = 0; i < gs->imageDestHeight; i++) {
3803                 (void)sprintf(obuf, PCL_ESC "*b%dW", prt_width_bytes);
3804                 result = CheckWrite(printerContext, obuf, strlen(obuf));
3805                 if (result != OK) {
3806                         break;
3807                 }
3808 
3809                 result = CheckWrite(printerContext,
3810                                         writeData + (prt_width_bytes * (int)(i / mag)), prt_width_bytes);
3811                 if (result != OK) {
3812                         break;
3813                 }
3814         }
3815         if (gs->imageDestWidth != gs->imageWidth) {
3816                 free(writeData);
3817         }
3818         return (result);
3819 }
3820 
3821 static int EndRaws(int printerContext)
3822 {
3823         char obuf[64];
3824 
3825         /* GL2�⡼�ɰܹ� */
3826         (void)sprintf(obuf, PCL_ESC "*rC" PCL_ESC "*p1P" PCL_ESC "%%0B");
3827         return CheckWrite(printerContext, obuf, strlen(obuf));
3828 }
3829 
3830 
3831 
3832 /* ----------------------------------------------------------------
3833  *
3834  * Text Operations
3835  *
3836  * ---------------------------------------------------------------- */
3837 
3838 int DrawBitmapText(int printerContext, int width, int height, int pitch, void *fontdata)
3839 {
3840         GraphicsState *gs;
3841         char obuf[64];
3842         Fix x;
3843         Fix y;
3844         int i;
3845 
3846         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
3847 
3848         gs = GetGraphicsState(printerContext);
3849         if (gs == NULL) {
3850                 return (ERROR);
3851         }
3852 
3853         i2Fix(0, x);
3854         i2Fix(-height, y);
3855         /* Move current point from bottom left to top left. */
3856         (void)sprintf(obuf, "PRPD%d,%dPA",
3857                                 (int)ApplyCtmX_Integer(x, y, gs->ctm), /* x */
3858                                 (int)ApplyCtmY_Integer(x, y, gs->ctm)); /* y */
3859         if (OK != CheckWrite(printerContext, obuf, strlen(obuf))) {
3860                 return (ERROR);
3861         }
3862 
3863         gs->useBgBrush = TRUE;
3864         if (OK != StartRaster(printerContext, width)) {
3865                 gs->useBgBrush = FALSE;
3866                 return (ERROR);
3867         }
3868         gs->useBgBrush = FALSE;
3869 
3870         pitch >>= 3;
3871         for (i = 0; i < height; i++)
3872         {
3873                 if (OK != TransferRasterData(printerContext, pitch, fontdata + pitch * i)) {
3874                         return (ERROR);
3875                 }
3876 
3877         }
3878 
3879         if (OK != EndRaster(printerContext)) {
3880                 return (ERROR);
3881         }
3882 
3883         return(OK);
3884 }
3885 
3886 
3887 
3888 /* ----------------------------------------------------------------
3889  *
3890  * Bitmap Image Operations
3891  *
3892  * ---------------------------------------------------------------- */
3893 
3894 int DrawImage(int printerContext, int sourceWidth, int sourceHeight, int colorDepth, ImageFormat imageFormat, Rectangle destinationSize, int count, void *imageData)
3895 {
3896         int             result;
3897         result = 0;
3898 
3899         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
3900 
3901         result = StartDrawImage(printerContext, sourceWidth, sourceHeight, colorDepth, imageFormat, destinationSize);
3902         if (result != OK) return (ERROR);
3903 
3904         result = TransferDrawImage(printerContext, count, imageData);
3905         if (result != OK) return (ERROR);
3906 
3907         result = EndDrawImage(printerContext);
3908         if (result != OK) return (ERROR);
3909 
3910         return(result);
3911 }
3912 
3913 
3914 int StartDrawImage(int printerContext, int sourceWidth, int sourceHeight, int colorDepth, ImageFormat imageFormat, Rectangle destinationSize)
3915 {
3916         GraphicsState *gs;
3917         int x, y;
3918 
3919         DebugPrint("pdapi: %s,%d: width=%d, height=%d, imageFormat=%d, imageDepth=%d\n", __FUNCTION__, __LINE__, sourceWidth, sourceHeight, imageFormat, colorDepth);
3920 
3921 
3922         gs = GetGraphicsState(printerContext);
3923         if (gs == NULL) {
3924                 /* GraphicsState��̵�����⤷����Printer Context������
3925                    �Ǥ��� */
3926                 return (ERROR);
3927         }
3928 
3929         gs->imageFormat = imageFormat;
3930         gs->imageDepth = colorDepth;
3931 
3932         x = (int)ApplyCtmX_Integer(destinationSize.p0.x, destinationSize.p0.y, gs->ctm)
3933                 - (int)ApplyCtmX_Integer(destinationSize.p1.x, destinationSize.p1.y, gs->ctm);
3934         x = (int)fabs((double)x);
3935         y = (int)ApplyCtmY_Integer(destinationSize.p0.x, destinationSize.p0.y, gs->ctm)
3936                 - (int)ApplyCtmY_Integer(destinationSize.p1.x, destinationSize.p1.y, gs->ctm);
3937         y = (int)fabs((double)y);
3938 
3939         /* ���᡼�����賫�� */
3940         gs->imageActive = TRUE;
3941 
3942         if (imageFormat == iformatRaw) {
3943                 return StartRaws(printerContext, sourceWidth, sourceHeight, colorDepth, x, y);
3944 
3945         }
3946 
3947         /* ̤���ݡ��� */
3948         errorno = NOTSUPPORTED;
3949         return (ERROR);
3950 }
3951 
3952 
3953 int TransferDrawImage(int printerContext, int count, void *imageData)
3954 {
3955         GraphicsState *gs;
3956 
3957         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
3958 
3959         gs = GetGraphicsState(printerContext);
3960         if (gs == NULL) {
3961                 /* GraphicsState��̵�����⤷����Printer Context������
3962                    �Ǥ��� */
3963                 return (ERROR);
3964         }
3965 
3966         if (gs->imageFormat == iformatRaw) {
3967                 return WriteRaws(printerContext, count, imageData);
3968         }
3969 
3970         return(OK);
3971 }
3972 
3973 
3974 int EndDrawImage(int printerContext)
3975 {
3976         GraphicsState *gs;
3977 
3978         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
3979 
3980         gs = GetGraphicsState(printerContext);
3981         if (gs == NULL) {
3982                 /* GraphicsState��̵�����⤷����Printer Context������
3983                    �Ǥ��� */
3984                 return (ERROR);
3985         }
3986 
3987         /* ���᡼�����轪λ */
3988         gs->imageActive = FALSE;
3989 
3990         return EndRaws(printerContext);
3991 }
3992 
3993 
3994 
3995 /* ----------------------------------------------------------------
3996  *
3997  * Scan Line Operations
3998  *
3999  * ---------------------------------------------------------------- */
4000 
4001 int StartScanline(int printerContext, int yposition)
4002 {
4003         int             result;
4004         result = 0;
4005 
4006         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
4007 
4008         return(result);
4009 }
4010 
4011 
4012 int Scanline(int printerContext, int nscanpairs, int *scanpairs)
4013 {
4014         int             result;
4015         result = 0;
4016 
4017         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
4018 
4019         return(result);
4020 }
4021 
4022 
4023 int EndScanline(int printerContext)
4024 {
4025         int             result;
4026         result = 0;
4027 
4028         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
4029 
4030         return(result);
4031 }
4032 
4033 
4034 
4035 /* ----------------------------------------------------------------
4036  *
4037  * Raster Image Operations
4038  *
4039  *
4040  * ---------------------------------------------------------------- */
4041 
4042 int StartRaster(int printerContext, int rasterWidth)
4043 {
4044         int             result;
4045         GraphicsState *gs;
4046         char obuf[64];
4047         result = 0;
4048         DeviceInfo *dev;
4049 
4050         DebugPrint("pdapi: %s,%d rasterWidth=%d\n", __FUNCTION__, __LINE__, rasterWidth);
4051 
4052         gs = GetGraphicsState(printerContext);
4053         if (gs == NULL) {
4054                 /* GraphicsState��̵�����⤷����Printer Context������
4055                    �Ǥ��� */
4056                 return (ERROR);
4057         }
4058 
4059         dev = GetDeviceInfo(printerContext);
4060         if (dev == NULL) {
4061                 return(ERROR);
4062         }
4063 
4064         /* PCL�⡼�ɰܹ� */
4065         (void)sprintf(obuf, PCL_ESC "%%1A" PCL_ESC "*p0P");
4066         result = CheckWrite(printerContext, obuf, strlen(obuf));
4067         if (result != OK) return (ERROR);
4068 
4069         result = CheckWrite(printerContext, PCL_ESC "*v6W\00\03\00\10\10\10", 11);
4070         if (result != OK) return (ERROR);
4071 
4072         if (gs->useBgBrush == TRUE) {
4073                 (void)sprintf(obuf,
4074                       PCL_ESC "*v%da%db%dc0I",
4075                       (unsigned char)gs->bgBrush.color[2],
4076                       (unsigned char)gs->bgBrush.color[1],
4077                       (unsigned char)gs->bgBrush.color[0]);
4078                 result = CheckWrite(printerContext, obuf, strlen(obuf));
4079                 if (result != OK) return (ERROR);
4080         }
4081 
4082         (void)sprintf(obuf,
4083                       PCL_ESC "*v%da%db%dc1I"
4084                       PCL_ESC "*r%ds1A",
4085                       (unsigned char)gs->fillBrush.color[2],
4086                       (unsigned char)gs->fillBrush.color[1],
4087                       (unsigned char)gs->fillBrush.color[0],
4088                       rasterWidth);             /* ���������� */
4089         result = CheckWrite(printerContext, obuf, strlen(obuf));
4090         if (result != OK) return (ERROR);
4091 
4092         return(result);
4093 }
4094 
4095 
4096 int TransferRasterData(int printerContext, int count, unsigned char *data)
4097 {
4098         int             result;
4099         char obuf[64];
4100         result = 0;
4101 
4102         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
4103 
4104         if (count == 0) {
4105                 /* ��������̵�� */
4106                 return (OK);
4107         }
4108 
4109         /* �饹��ž�� */
4110         (void)sprintf(obuf, PCL_ESC "*b%dW",
4111                       count);
4112 
4113         result = CheckWrite(printerContext, obuf, strlen(obuf));
4114         if (result != OK) {
4115                 /* �����߼��� */
4116                 return (ERROR);
4117         }
4118         result = CheckWrite(printerContext, data, count);
4119 
4120         return(result);
4121 }
4122 
4123 
4124 int SkipRaster(int printerContext, int count)
4125 {
4126         char            obuf[64];
4127         int             result;
4128         result = 0;
4129 
4130         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
4131 
4132         (void)sprintf(obuf, PCL_ESC "*b%dY",
4133                       count);
4134 
4135         result = CheckWrite(printerContext, obuf, strlen(obuf));
4136         if (result != OK) {
4137                 /* �����߼��� */
4138                 return (ERROR);
4139         }
4140 
4141         return(result);
4142 }
4143 
4144 
4145 int EndRaster(int printerContext)
4146 {
4147         char obuf[64];
4148 
4149         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
4150 
4151         /* GL2�⡼�ɰܹ� */
4152         (void)sprintf(obuf,
4153                       PCL_ESC "*rC"
4154                       PCL_ESC "*v255a255b255c0I"
4155                       PCL_ESC "*p1P"
4156                       PCL_ESC "%%0B");
4157 
4158         return CheckWrite(printerContext, obuf, strlen(obuf));
4159 }
4160 
4161 
4162 
4163 /* ----------------------------------------------------------------
4164  *
4165  * Stream Data Operations
4166  *
4167  * ---------------------------------------------------------------- */
4168 
4169 int StartStream(int printerContext)
4170 {
4171         int             result;
4172         result = 0;
4173 
4174         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
4175 
4176         return(result);
4177 }
4178 
4179 
4180 int TransferStreamData(int printerContext, int count, void *data)
4181 {
4182         int             result;
4183         result = 0;
4184 
4185         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
4186 
4187         return(result);
4188 }
4189 
4190 
4191 int EndStream(int printerContext)
4192 {
4193         int             result;
4194         result = 0;
4195 
4196         DebugPrint("pdapi: %s,%d \n", __FUNCTION__, __LINE__);
4197 
4198         return(result);
4199 }
4200 
4201 /* end of HPPageColor.c */
4202