~ubuntu-branches/ubuntu/raring/hplip/raring

« back to all changes in this revision

Viewing changes to prnt/hpijs/hpcups.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2009-12-14 20:08:44 UTC
  • mfrom: (2.1.118 lucid)
  • Revision ID: james.westby@ubuntu.com-20091214200844-z8qhqwgppbu3t7ze
Tags: 3.9.10-4
KBSD patch from KiBi (Closes: #560796)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************\
2
 
    hpcups.cpp : HP cups filter
3
 
 
4
 
    Copyright (c) 2009, Hewlett-Packard Co.
5
 
    All rights reserved.
6
 
 
7
 
    Redistribution and use in source and binary forms, with or without
8
 
    modification, are permitted provided that the following conditions
9
 
    are met:
10
 
    1. Redistributions of source code must retain the above copyright
11
 
       notice, this list of conditions and the following disclaimer.
12
 
    2. Redistributions in binary form must reproduce the above copyright
13
 
       notice, this list of conditions and the following disclaimer in the
14
 
       documentation and/or other materials provided with the distribution.
15
 
    3. Neither the name of the Hewlett-Packard nor the names of its
16
 
       contributors may be used to endorse or promote products derived
17
 
       from this software without specific prior written permission.
18
 
 
19
 
    THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20
 
    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21
 
    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22
 
    IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23
 
    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24
 
    NOT LIMITED TO, PATENT INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR
25
 
    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26
 
    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27
 
    STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
28
 
    IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
 
    POSSIBILITY OF SUCH DAMAGE.
30
 
\*****************************************************************************/
31
 
 
32
 
#include <sys/stat.h>
33
 
#include <stdio.h>
34
 
#include <stdlib.h>
35
 
#include <stdarg.h>
36
 
#include <syslog.h>
37
 
#include <string.h>
38
 
#include <unistd.h>
39
 
#include <fcntl.h>
40
 
#include "header.h"
41
 
#include "ijs.h"
42
 
#include "ijs_server.h"
43
 
#include "hpimage.h"
44
 
 
45
 
/*
46
 
typedef struct
47
 
{
48
 
    int    width;
49
 
    int    height;
50
 
    char   cs[32];
51
 
} IjsPageHeader;
52
 
*/
53
 
 
54
 
#include "services.h"
55
 
 
56
 
#include <cups/cups.h>
57
 
#include <cups/raster.h>
58
 
#include "hpcups.h"
59
 
 
60
 
void SendDbusMessage (const char *dev, const char *printer, int code, 
61
 
                      const char *username, const int jobid, const char *title);
62
 
 
63
 
#ifdef HAVE_LIBHPIP
64
 
extern  int hpijsFaxServer (int argc, char **argv);
65
 
#endif
66
 
 
67
 
HPCups::HPCups ()
68
 
{
69
 
    m_pSys      = NULL;
70
 
    m_fd        = 0;
71
 
    m_iLogLevel = 0;
72
 
}
73
 
 
74
 
HPCups::~HPCups ()
75
 
{
76
 
    if (m_fd)
77
 
    {
78
 
        close (m_fd);
79
 
    }
80
 
    if (m_pSys)
81
 
    {
82
 
        if (m_pSys->pJob)
83
 
        {
84
 
            delete m_pSys->pJob;
85
 
        }
86
 
        if (m_pSys->pPC)
87
 
        {
88
 
            delete m_pSys->pPC;
89
 
        }
90
 
        delete m_pSys;
91
 
    }
92
 
}
93
 
 
94
 
void HPCups::setLogLevel ()
95
 
{
96
 
    FILE    *fp;
97
 
    char    str[258];
98
 
    char    *p;
99
 
    fp = fopen ("/etc/cups/cupsd.conf", "r");
100
 
    if (fp == NULL)
101
 
        return;
102
 
    while (!feof (fp))
103
 
    {
104
 
        if (!fgets (str, 256, fp))
105
 
        {
106
 
            break;
107
 
        }
108
 
        if ((p = strstr (str, "hpLogLevel")))
109
 
        {
110
 
            p += strlen ("hpLogLevel") + 1;
111
 
            m_iLogLevel = atoi (p);
112
 
            break;
113
 
        }
114
 
    }
115
 
    fclose (fp);
116
 
}
117
 
 
118
 
int HPCups::initPrintJob ()
119
 
{
120
 
//    MediaSize       msMedia = sizeUSLetter;
121
 
    COLORMODE       colormode;
122
 
    if (m_iLogLevel & ADDITIONAL_LOG)
123
 
    {
124
 
        printcupsHeader ();
125
 
    }
126
 
 
127
 
    if (m_cupsHeader.ImagingBoundingBox[0] == 0)
128
 
    {
129
 
        m_pSys->FullBleed = 1;
130
 
    }
131
 
    /*
132
 
    m_pSys->ph.width  = m_cupsHeader.cupsWidth;
133
 
    m_pSys->ph.height = m_cupsHeader.cupsHeight;
134
 
    */
135
 
 
136
 
/*
137
 
 *  cupsRowStep represents colormode
138
 
 *  cupsRowCount represents pen type
139
 
 *  cupsOutputType represents quality mode
140
 
 */
141
 
 
142
 
    m_pSys->pPC->SetPenSet ((PEN_TYPE) (m_cupsHeader.cupsRowCount - 1));
143
 
    switch (m_cupsHeader.cupsRowStep)
144
 
    {
145
 
        case 1:
146
 
            colormode = GREY_K;
147
 
            break;
148
 
        case 2:
149
 
            colormode = GREY_CMY;
150
 
        default:
151
 
            colormode = COLOR;
152
 
            break;
153
 
    }
154
 
    m_pSys->pPC->SelectPrintMode ((QUALITY_MODE) m_cupsHeader.cupsCompression,
155
 
                                  (MEDIATYPE) m_cupsHeader.cupsMediaType,
156
 
                                  colormode);
157
 
    m_pSys->pPC->SetMediaSource ((MediaSource) m_cupsHeader.MediaPosition);
158
 
    if (m_cupsHeader.Duplex)
159
 
    {
160
 
        if (m_cupsHeader.Tumble)
161
 
            m_pSys->pPC->SelectDuplexPrinting (DUPLEXMODE_TABLET);
162
 
        else
163
 
            m_pSys->pPC->SelectDuplexPrinting (DUPLEXMODE_BOOK);
164
 
    }
165
 
    else
166
 
    {
167
 
        m_pSys->pPC->SelectDuplexPrinting (DUPLEXMODE_NONE);
168
 
    }
169
 
    float    fWidth  = (float) m_cupsHeader.PageSize[0] / (float) 72.0;
170
 
    float    fHeight = (float) m_cupsHeader.PageSize[1] / (float) 72.0;
171
 
    m_pSys->MapPaperSize (fWidth, fHeight);
172
 
 
173
 
    m_pSys->pPC->SetPixelsPerRow (m_cupsHeader.cupsWidth, m_cupsHeader.cupsWidth);
174
 
 
175
 
//  Now set all the printer hints
176
 
    if (m_cupsHeader.cupsInteger[0])
177
 
    {
178
 
        // Papersize as PCL id
179
 
    }
180
 
 
181
 
    PRINTER_HINT    eHint;
182
 
    int             iValue;
183
 
    for (int i = 1; i < 6; i++)
184
 
    {
185
 
        eHint = (PRINTER_HINT) i;
186
 
        iValue = m_cupsHeader.cupsInteger[i];
187
 
        if (iValue)
188
 
        {
189
 
            m_pSys->pPC->SetPrinterHint (eHint, iValue);
190
 
        }
191
 
    }
192
 
 
193
 
    // Turn off bi-di support.
194
 
    m_pSys->ResetIOMode (FALSE, FALSE);
195
 
 
196
 
    // Create a new Job object
197
 
    m_pSys->pJob = new Job (m_pSys->pPC);
198
 
    if (m_pSys->pJob->constructor_error != NO_ERROR)
199
 
    {
200
 
        BUG ("ERROR: Unable to create Job object, error = %d\n",
201
 
                m_pSys->pJob->constructor_error);
202
 
        return 1;
203
 
    }
204
 
    return 0;
205
 
}
206
 
 
207
 
int HPCups::ProcessJob (int argc, char **argv)
208
 
{
209
 
    int              iStatus = 0;
210
 
    cups_raster_t    *cups_raster;
211
 
 
212
 
    setLogLevel ();
213
 
 
214
 
//  Check commandline.
215
 
 
216
 
    if (argc < 6 || argc > 7)
217
 
    {
218
 
        BUG ("ERROR: %s job-id user title copies options [file]\n", *argv);
219
 
        return JOB_CANCELED;
220
 
    }
221
 
 
222
 
    if (initServices (argv[1]) != 0)
223
 
    {
224
 
        return 1;
225
 
    }
226
 
    if (initContext (argv) != 0)
227
 
    {
228
 
        return 1;
229
 
    }
230
 
 
231
 
//  Open input stream if it is not stdin
232
 
    if (argc == 7)
233
 
    {
234
 
        m_fd = open (argv[6], O_RDONLY);
235
 
        if (m_fd == -1)
236
 
        {
237
 
            BUG ("ERROR: Unable to open raster file %s\n", argv[6]);
238
 
            return 1;
239
 
        }
240
 
    }
241
 
 
242
 
    cups_raster = cupsRasterOpen (m_fd, CUPS_RASTER_READ);
243
 
    if (cups_raster == NULL)
244
 
    {
245
 
        BUG ("cupsRasterOpen failed, fd = %d\n", m_fd);
246
 
        return 1;
247
 
    }
248
 
 
249
 
    iStatus = processRasterData (cups_raster);
250
 
    cupsRasterClose (cups_raster);
251
 
 
252
 
    return iStatus;
253
 
}
254
 
 
255
 
int HPCups::initServices (char *szJobId)
256
 
{
257
 
    m_pSys = new UXServices ();
258
 
    if (m_pSys->constructor_error != NO_ERROR)
259
 
    {
260
 
        BUG ("Services object failed, error = %d\n", m_pSys->constructor_error);
261
 
        return 1;
262
 
    }
263
 
    m_pSys->OutputPath = STDOUT_FILENO;
264
 
    m_pSys->m_iLogLevel = m_iLogLevel;
265
 
 
266
 
//  Does the user wish to send printer ready data to a disk file
267
 
    if (m_iLogLevel & SAVE_PCL_FILE)
268
 
    {
269
 
        char    szFileName[32];
270
 
        sprintf (szFileName, "/tmp/hpcups_%s.out", szJobId);
271
 
        m_pSys->outfp = fopen (szFileName, "w");
272
 
        if (m_pSys->outfp)
273
 
        {
274
 
            chmod (szFileName, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
275
 
        }
276
 
    }
277
 
 
278
 
    return 0;
279
 
}
280
 
 
281
 
int HPCups::initContext (char **argv)
282
 
{
283
 
    DRIVER_ERROR     err = NO_ERROR;
284
 
    ppd_file_t       *ppd;
285
 
    ppd_attr_t       *attr;
286
 
 
287
 
    m_pSys->pPC = new PrintContext (m_pSys, 0, 0);
288
 
 
289
 
/*
290
 
 *  If bi-di fails, we still want to continue, so ignore this error.
291
 
 *  The failure can also be because of missing plugin. If this printer
292
 
 *  requires the plugin, it will be handled later, but if it is optional
293
 
 *  then we want to continue.
294
 
 */
295
 
 
296
 
    if (m_pSys->pPC->constructor_error > 0 &&
297
 
        m_pSys->pPC->constructor_error != PLUGIN_LIBRARY_MISSING &&
298
 
        m_pSys->DisplayStatus != DISPLAY_PRINTING_CANCELED)
299
 
    {
300
 
        BUG("PrintContext creation failed, error = %d", m_pSys->pPC->constructor_error);
301
 
        return 1;
302
 
    }
303
 
 
304
 
/*
305
 
 *  Check for any warnings, but ignore printmode mismatch warning.
306
 
 *  This will happen on monochrome printers. We will select the proper
307
 
 *  printmode later.
308
 
 */
309
 
 
310
 
    if (m_pSys->pPC->constructor_error < 0 &&
311
 
        m_pSys->pPC->constructor_error != WARN_MODE_MISMATCH)
312
 
    {
313
 
        BUG ("WARNING: %s\n", m_pSys->GetDriverMessage (m_pSys->pPC->constructor_error));
314
 
        switch (m_pSys->pPC->constructor_error)
315
 
        {
316
 
            case WARN_LOW_INK_BOTH_PENS:
317
 
            case WARN_LOW_INK_BLACK:
318
 
            case WARN_LOW_INK_COLOR:
319
 
            case WARN_LOW_INK_PHOTO:
320
 
            case WARN_LOW_INK_GREY:
321
 
            case WARN_LOW_INK_BLACK_PHOTO:
322
 
            case WARN_LOW_INK_COLOR_PHOTO:
323
 
            case WARN_LOW_INK_GREY_PHOTO:
324
 
            case WARN_LOW_INK_COLOR_GREY:
325
 
            case WARN_LOW_INK_COLOR_GREY_PHOTO:
326
 
            case WARN_LOW_INK_COLOR_BLACK_PHOTO:
327
 
            case WARN_LOW_INK_CYAN:
328
 
            case WARN_LOW_INK_MAGENTA:
329
 
            case WARN_LOW_INK_YELLOW:
330
 
            case WARN_LOW_INK_MULTIPLE_PENS:
331
 
            {
332
 
               BUG ("STATE: marker-supply-low-warning\n");
333
 
               break;
334
 
            }
335
 
            default:
336
 
               BUG ("STATE: -marker-supply-low-warning");
337
 
        }
338
 
    }
339
 
 
340
 
//  Select the device class
341
 
    ppd = ppdOpenFile (getenv ("PPD"));
342
 
    if (ppd == NULL)
343
 
    {
344
 
        BUG ("ERROR: Unable to open ppd file %s\n", getenv ("PPD"));
345
 
        return 1;
346
 
    }
347
 
    if ((attr = ppdFindAttr (ppd, "cupsModelName", NULL)) == NULL ||
348
 
        (attr && attr->value == NULL))
349
 
    {
350
 
        BUG ("ERROR: Required cupsModelName is missing in ppd file\n");
351
 
        ppdClose (ppd);
352
 
        return 1;
353
 
    }
354
 
    err = m_pSys->pPC->SelectDevice (attr->value);
355
 
    if (err == PLUGIN_LIBRARY_MISSING)
356
 
    {
357
 
        // call dbus here
358
 
        SendDbusMessage (getenv ("DEVICE_URI"), getenv ("PRINTER"),
359
 
                         EVENT_PRINT_FAILED_MISSING_PLUGIN,
360
 
                         argv[2], atoi (argv[1]), argv[3]);
361
 
        BUG ("ERROR: unable to set device = %s, err = %d\n", attr->value, err);
362
 
        return 1;
363
 
    }
364
 
    return 0;
365
 
}
366
 
 
367
 
int HPCups::processRasterData (cups_raster_t *cups_raster)
368
 
{
369
 
    DRIVER_ERROR           err = NO_ERROR;
370
 
    int                    iStatus = 0;
371
 
//    int                    iWidthBytes;
372
 
    FILE                   *kfp = NULL;
373
 
    FILE                   *cfp = NULL;
374
 
    int                    iPageNum = 0;
375
 
    BYTE                   *black_raster;
376
 
    BYTE                   *color_raster;
377
 
    BYTE                   *pKRGBRaster;
378
 
    BYTE                   *kRaster = NULL;
379
 
    BYTE                   *rgbRaster = NULL;
380
 
    HPImage                bitmap;
381
 
    while (cupsRasterReadHeader2 (cups_raster, &m_cupsHeader))
382
 
    {
383
 
        iPageNum++;
384
 
        if (iPageNum == 1)
385
 
        {
386
 
            pKRGBRaster = new BYTE[m_cupsHeader.cupsBytesPerLine];
387
 
            iStatus = initPrintJob ();
388
 
            if (iStatus != 0)
389
 
            {
390
 
                break;
391
 
            }
392
 
            if (m_cupsHeader.cupsColorSpace == CUPS_CSPACE_RGBW)
393
 
            {
394
 
                kRaster   = new BYTE[m_cupsHeader.cupsWidth];
395
 
                rgbRaster = new BYTE[m_cupsHeader.cupsWidth * 3];
396
 
                if (kRaster == NULL || rgbRaster == NULL)
397
 
                {
398
 
                    BUG ("Memory allocation error\n");
399
 
                    iStatus = 1;
400
 
                    break;
401
 
                }
402
 
                memset (kRaster, 0, m_cupsHeader.cupsWidth);
403
 
                memset (rgbRaster, 0xFF, m_cupsHeader.cupsWidth * 3);
404
 
            }
405
 
            else if (m_cupsHeader.cupsColorSpace == CUPS_CSPACE_K)
406
 
            {
407
 
                kRaster = pKRGBRaster;
408
 
                rgbRaster = NULL;
409
 
            }
410
 
        }
411
 
        if (m_cupsHeader.cupsColorSpace == CUPS_CSPACE_K)
412
 
        {
413
 
            kRaster = pKRGBRaster;
414
 
            rgbRaster = NULL;
415
 
        }
416
 
        else if (m_cupsHeader.cupsColorSpace != CUPS_CSPACE_RGBW)
417
 
        {
418
 
            rgbRaster = pKRGBRaster;
419
 
        }
420
 
        if (m_iLogLevel & SAVE_INPUT_RASTERS)
421
 
        {
422
 
            char    szFileName[32];
423
 
            sprintf (szFileName, "/tmp/hpcupsc_%d.bmp", iPageNum);
424
 
            if (m_cupsHeader.cupsColorSpace == CUPS_CSPACE_RGBW ||
425
 
                m_cupsHeader.cupsColorSpace == CUPS_CSPACE_RGB)
426
 
            {
427
 
                cfp = fopen (szFileName, "w");
428
 
                chmod (szFileName, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
429
 
            }
430
 
            if (m_cupsHeader.cupsColorSpace == CUPS_CSPACE_RGBW ||
431
 
                m_cupsHeader.cupsColorSpace == CUPS_CSPACE_K)
432
 
            {
433
 
                szFileName[11] = 'k';
434
 
                kfp = fopen (szFileName, "w");
435
 
                chmod (szFileName, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
436
 
            }
437
 
            bitmap.WriteBMPHeader (cfp, m_cupsHeader.cupsWidth, m_cupsHeader.cupsHeight, COLOR_RASTER);
438
 
            bitmap.WriteBMPHeader (kfp, m_cupsHeader.cupsWidth, m_cupsHeader.cupsHeight, BLACK_RASTER);
439
 
        }
440
 
        m_pSys->SendPreviousPage ();
441
 
        for (int y = 0; y < (int) m_cupsHeader.cupsHeight; y++)
442
 
        {
443
 
            cupsRasterReadPixels (cups_raster, pKRGBRaster, m_cupsHeader.cupsBytesPerLine);
444
 
            color_raster = rgbRaster;
445
 
            black_raster = kRaster;
446
 
            if (isBlankRaster (pKRGBRaster, (int) m_cupsHeader.cupsBytesPerLine))
447
 
            {
448
 
                color_raster = NULL;
449
 
                black_raster = NULL;
450
 
            }
451
 
            doKSeparation (pKRGBRaster, black_raster, color_raster);
452
 
            err = m_pSys->pJob->SendRasters (black_raster, color_raster);
453
 
            if (err != NO_ERROR)
454
 
            {
455
 
                iStatus = 1;
456
 
                break;
457
 
            }
458
 
            bitmap.WriteBMPRaster (cfp, color_raster, m_cupsHeader.cupsWidth, COLOR_RASTER);
459
 
            bitmap.WriteBMPRaster (kfp, black_raster, m_cupsHeader.cupsWidth/8, BLACK_RASTER);
460
 
        }
461
 
        iStatus = (int) m_pSys->pJob->NewPage ();
462
 
        if (iStatus != 0)
463
 
        {
464
 
            break;
465
 
        }
466
 
    }
467
 
    if (pKRGBRaster)
468
 
    {
469
 
        delete [] pKRGBRaster;
470
 
    }
471
 
    if (kRaster && m_cupsHeader.cupsColorSpace != CUPS_CSPACE_K)
472
 
    {
473
 
        delete [] kRaster;
474
 
    }
475
 
    if (m_cupsHeader.cupsColorSpace == CUPS_CSPACE_RGBW)
476
 
    {
477
 
        delete [] rgbRaster;
478
 
    }
479
 
    if (cfp)
480
 
    {
481
 
        fclose (cfp);
482
 
    }
483
 
    if (kfp)
484
 
    {
485
 
        fclose (kfp);
486
 
    }
487
 
    return iStatus;
488
 
}
489
 
 
490
 
void HPCups::doKSeparation (BYTE *pKRGBRaster, BYTE *black_raster, BYTE *color_raster)
491
 
{
492
 
    
493
 
static BYTE pixel_value[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
494
 
 
495
 
    if (black_raster == NULL || m_cupsHeader.cupsColorSpace != CUPS_CSPACE_RGBW)
496
 
    {
497
 
        return;
498
 
    }
499
 
 
500
 
    int    k = 0;
501
 
    BYTE   *pIn = pKRGBRaster;
502
 
    BYTE   kVal = 0;
503
 
    BYTE   b;
504
 
    BYTE   *rgb   = color_raster;
505
 
    BYTE   *black = black_raster;
506
 
    memset (black_raster, 0, m_cupsHeader.cupsWidth);
507
 
 
508
 
    for (unsigned int i = 0; i < m_cupsHeader.cupsWidth; i++)
509
 
    {
510
 
        rgb[0] = *pIn++;
511
 
        rgb[1] = *pIn++;
512
 
        rgb[2] = *pIn++;
513
 
        b = *pIn++;
514
 
 
515
 
        if (b != 0 && b != 0xFF)
516
 
        {
517
 
            rgb[0] -= (255 - b);
518
 
            rgb[1] -= (255 - b);
519
 
            rgb[2] -= (255 - b);
520
 
        }
521
 
        else
522
 
        {
523
 
            kVal |= (b == 0) ? pixel_value[k] : 0;
524
 
        }
525
 
        rgb += 3;
526
 
        if (k == 7)
527
 
        {
528
 
            *black++ = kVal;
529
 
            kVal = 0;
530
 
            k = 0;
531
 
        }
532
 
        else
533
 
        {
534
 
            k++;
535
 
        }
536
 
    }  // end of for loop
537
 
    *black = kVal;
538
 
}
539
 
 
540
 
BOOL HPCups::isBlankRaster (BYTE *pRaster, int iNumBytes)
541
 
{
542
 
    if (pRaster == NULL)
543
 
    {
544
 
        return TRUE;
545
 
    }
546
 
    if (*pRaster == 0xFF &&
547
 
        !(memcmp (pRaster + 1, pRaster, iNumBytes - 1)))
548
 
    {
549
 
        return TRUE;
550
 
    }
551
 
    return FALSE;
552
 
}
553
 
 
554
 
void HPCups::printcupsHeader ()
555
 
{
556
 
    BUG("DEBUG: startPage...\n");
557
 
    BUG("DEBUG: MediaClass = \"%s\"\n", m_cupsHeader.MediaClass);
558
 
    BUG("DEBUG: MediaColor = \"%s\"\n", m_cupsHeader.MediaColor);
559
 
    BUG("DEBUG: MediaType = \"%s\"\n", m_cupsHeader.MediaType);
560
 
    BUG("DEBUG: OutputType = \"%s\"\n", m_cupsHeader.OutputType);
561
 
    BUG("DEBUG: AdvanceDistance = %d\n", m_cupsHeader.AdvanceDistance);
562
 
    BUG("DEBUG: AdvanceMedia = %d\n", m_cupsHeader.AdvanceMedia);
563
 
    BUG("DEBUG: Collate = %d\n", m_cupsHeader.Collate);
564
 
    BUG("DEBUG: CutMedia = %d\n", m_cupsHeader.CutMedia);
565
 
    BUG("DEBUG: Duplex = %d\n", m_cupsHeader.Duplex);
566
 
    BUG("DEBUG: HWResolution = [ %d %d ]\n", m_cupsHeader.HWResolution[0], m_cupsHeader.HWResolution[1]);
567
 
    BUG("DEBUG: ImagingBoundingBox = [ %d %d %d %d ]\n",
568
 
               m_cupsHeader.ImagingBoundingBox[0], m_cupsHeader.ImagingBoundingBox[1],
569
 
               m_cupsHeader.ImagingBoundingBox[2], m_cupsHeader.ImagingBoundingBox[3]);
570
 
    BUG("DEBUG: InsertSheet = %d\n", m_cupsHeader.InsertSheet);
571
 
    BUG("DEBUG: Jog = %d\n", m_cupsHeader.Jog);
572
 
    BUG("DEBUG: LeadingEdge = %d\n", m_cupsHeader.LeadingEdge);
573
 
    BUG("DEBUG: Margins = [ %d %d ]\n", m_cupsHeader.Margins[0], m_cupsHeader.Margins[1]);
574
 
    BUG("DEBUG: ManualFeed = %d\n", m_cupsHeader.ManualFeed);
575
 
    BUG("DEBUG: MediaPosition = %d\n", m_cupsHeader.MediaPosition);
576
 
    BUG("DEBUG: MediaWeight = %d\n", m_cupsHeader.MediaWeight);
577
 
    BUG("DEBUG: MirrorPrint = %d\n", m_cupsHeader.MirrorPrint);
578
 
    BUG("DEBUG: NegativePrint = %d\n", m_cupsHeader.NegativePrint);
579
 
    BUG("DEBUG: NumCopies = %d\n", m_cupsHeader.NumCopies);
580
 
    BUG("DEBUG: Orientation = %d\n", m_cupsHeader.Orientation);
581
 
    BUG("DEBUG: OutputFaceUp = %d\n", m_cupsHeader.OutputFaceUp);
582
 
    BUG("DEBUG: PageSize = [ %d %d ]\n", m_cupsHeader.PageSize[0], m_cupsHeader.PageSize[1]);
583
 
    BUG("DEBUG: Separations = %d\n", m_cupsHeader.Separations);
584
 
    BUG("DEBUG: TraySwitch = %d\n", m_cupsHeader.TraySwitch);
585
 
    BUG("DEBUG: Tumble = %d\n", m_cupsHeader.Tumble);
586
 
    BUG("DEBUG: cupsWidth = %d\n", m_cupsHeader.cupsWidth);
587
 
    BUG("DEBUG: cupsHeight = %d\n", m_cupsHeader.cupsHeight);
588
 
    BUG("DEBUG: cupsMediaType = %d\n", m_cupsHeader.cupsMediaType);
589
 
    BUG("DEBUG: cupsRowStep = %d\n", m_cupsHeader.cupsRowStep);
590
 
    BUG("DEBUG: cupsBitsPerColor = %d\n", m_cupsHeader.cupsBitsPerColor);
591
 
    BUG("DEBUG: cupsBitsPerPixel = %d\n", m_cupsHeader.cupsBitsPerPixel);
592
 
    BUG("DEBUG: cupsBytesPerLine = %d\n", m_cupsHeader.cupsBytesPerLine);
593
 
    BUG("DEBUG: cupsColorOrder = %d\n", m_cupsHeader.cupsColorOrder);
594
 
    BUG("DEBUG: cupsColorSpace = %d\n", m_cupsHeader.cupsColorSpace);
595
 
    BUG("DEBUG: cupsCompression = %d\n", m_cupsHeader.cupsCompression);
596
 
    BUG("DEBUG: cupsPageSizeName = %s\n", m_cupsHeader.cupsPageSizeName);
597
 
    BUG("DEBUG: cupsInteger0 = %d\n", m_cupsHeader.cupsInteger[0]); // Page Size
598
 
    BUG("DEBUG: cupsInteger1 = %d\n", m_cupsHeader.cupsInteger[1]); // Speedmech
599
 
    BUG("DEBUG: cupsInteger2 = %d\n", m_cupsHeader.cupsInteger[2]); // Dry time
600
 
    BUG("DEBUG: cupsInteger3 = %d\n", m_cupsHeader.cupsInteger[3]); // Filesize
601
 
    BUG("DEBUG: cupsInteger4 = %d\n", m_cupsHeader.cupsInteger[4]); // Redeye
602
 
    BUG("DEBUG: cupsInteger5 = %d\n", m_cupsHeader.cupsInteger[5]); // Photofix
603
 
}
604
 
 
605
 
void HPCups::CancelJob ()
606
 
{
607
 
    BYTE byResetLIDIL[] =  {0x24, 0x00, 0x10, 0x00, 0x06, 0x00, 0x00, 0x00,
608
 
                            0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x24};
609
 
    PRINTER_TYPE    pt;
610
 
    DWORD   size = 4096;
611
 
    BYTE    buffer[4098];
612
 
    memset (buffer, 0, size);
613
 
    pt = m_pSys->pPC->SelectedDevice();
614
 
    switch(pt)
615
 
    {
616
 
        case ePScript:
617
 
            break;
618
 
        case eDJ3320:
619
 
        case eDJ3600:
620
 
        case eDJ4100:
621
 
        {
622
 
            memcpy (buffer + 4080, byResetLIDIL, 16);
623
 
            m_pSys->ToDevice ((const BYTE *) buffer, &size);
624
 
            break;
625
 
        }
626
 
        case eQuickConnect:
627
 
            break;
628
 
        default:
629
 
        {
630
 
            memcpy (buffer + 4087, "\x1B%-12345X", 9);
631
 
            m_pSys->ToDevice ((const BYTE *) buffer, &size);
632
 
        }
633
 
    }
634
 
 
635
 
    m_pSys->OutputPath = -1;    // so no more output is sent to the printer
636
 
    if (m_pSys->pJob != NULL)
637
 
        delete m_pSys->pJob;
638
 
    if (m_pSys->pPC != NULL)
639
 
        delete m_pSys->pPC;
640
 
    delete m_pSys;
641
 
    exit (0);
642
 
}
643
 
 
644
 
static HPCups    hpCups;
645
 
void CancelPrintJob (int sig)
646
 
{
647
 
    hpCups.CancelJob ();
648
 
    exit (0);
649
 
}
650
 
 
651
 
int main (int argc, char **argv)
652
 
{
653
 
    int iRet = hpCups.ProcessJob (argc, argv);
654
 
    BUG("hpcups: returning status %d from main", iRet);
655
 
    return iRet;
656
 
}
657