~ubuntu-branches/ubuntu/jaunty/ghostscript/jaunty-updates

« back to all changes in this revision

Viewing changes to base/gdevl31s.c

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2009-01-20 16:40:45 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090120164045-lnfhi0n30o5lwhwa
Tags: 8.64.dfsg.1~svn9377-0ubuntu1
* New upstream release (SVN rev 9377)
   o Fixes many bugs concerning PDF rendering, to make the PDF printing
     workflow correctly working.
   o Fixes long-standing bugs in many drivers, like input paper tray and
     duplex options not working for the built-in PCL 4, 5, 5c, 5e, and
     6/XL drivers, PDF input not working for bjc600, bjc800, and cups
     output devices, several options not working and uninitialized
     memory with cups output device.
   o Merged nearly all patches of the Ubuntu and Debian packages upstream.
   o Fixes LP: #317810, LP: #314439, LP: #314018.
* debian/patches/03_libpaper_support.dpatch,
  debian/patches/11_gs-cjk_font_glyph_handling_fix.dpatch,
  debian/patches/12_gs-cjk_vertical_writing_metrics_fix.dpatch,
  debian/patches/13_gs-cjk_cjkps_examples.dpatch,
  debian/patches/20_bbox_segv_fix.dpatch,
  debian/patches/21_brother_7x0_gdi_fix.dpatch,
  debian/patches/22_epsn_margin_workaround.dpatch,
  debian/patches/24_gs_man_fix.dpatch,
  debian/patches/25_toolbin_insecure_tmp_usage_fix.dpatch,
  debian/patches/26_assorted_script_fixes.dpatch,
  debian/patches/29_gs_css_fix.dpatch,
  debian/patches/30_ps2pdf_man_improvement.dpatch,
  debian/patches/31_fix-gc-sigbus.dpatch,
  debian/patches/34_ftbfs-on-hurd-fix.dpatch,
  debian/patches/35_disable_libcairo.dpatch,
  debian/patches/38_pxl-duplex.dpatch,
  debian/patches/39_pxl-resolution.dpatch,
  debian/patches/42_gs-init-ps-delaybind-fix.dpatch,
  debian/patches/45_bjc600-bjc800-pdf-input.dpatch,
  debian/patches/48_cups-output-device-pdf-duplex-uninitialized-memory-fix.dpatch,
  debian/patches/50_lips4-floating-point-exception.dpatch,
  debian/patches/52_cups-device-logging.dpatch,
  debian/patches/55_pcl-input-slot-fix.dpatch,
  debian/patches/57_pxl-input-slot-fix.dpatch,
  debian/patches/60_pxl-cups-driver-pdf.dpatch,
  debian/patches/62_onebitcmyk-pdf.dpatch,
  debian/patches/65_too-big-temp-files-1.dpatch,
  debian/patches/67_too-big-temp-files-2.dpatch,
  debian/patches/70_take-into-account-data-in-stream-buffer-before-refill.dpatch:
  Removed, applied upstream.
* debian/patches/01_docdir_fix_for_debian.dpatch,
  debian/patches/02_gs_man_fix_debian.dpatch,
  debian/patches/01_docdir-fix-for-debian.dpatch,
  debian/patches/02_docdir-fix-for-debian.dpatch: Renamed patches to
  make merging with Debian easier.
* debian/patches/32_improve-handling-of-media-size-changes-from-gv.dpatch, 
  debian/patches/33_bad-params-to-xinitimage-on-large-bitmaps.dpatch:
  regenerated for new source directory structure.
* debian/rules: Corrected paths to remove cidfmap (it is in Resource/Init/
  in GS 8.64) and to install headers (source paths are psi/ and base/ now).
* debian/rules: Remove all fontmaps, as DeFoMa replaces them.
* debian/local/pdftoraster/pdftoraster.c,
  debian/local/pdftoraster/pdftoraster.convs, debian/rules: Removed
  added pdftoraster filter and use the one which comes with Ghostscript.
* debian/ghostscript.links: s/8.63/8.64/

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2001-2006 Artifex Software, Inc.
 
2
   All Rights Reserved.
 
3
  
 
4
   This software is provided AS-IS with no warranty, either express or
 
5
   implied.
 
6
 
 
7
   This software is distributed under license and may not be copied, modified
 
8
   or distributed except as expressly authorized under the terms of that
 
9
   license.  Refer to licensing information at http://www.artifex.com/
 
10
   or contact Artifex Software, Inc.,  7 Mt. Lassen Drive - Suite A-134,
 
11
   San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
 
12
*/
 
13
/* $Id: gdevl31s.c 8250 2007-09-25 13:31:24Z giles $ */
 
14
/*
 
15
 * H-P LaserJet 3100 driver
 
16
 *
 
17
 * This is a driver for use with the H-P LaserJet 3100 Software.
 
18
 * It requires installed H-P LaserJet 3100 Software to print.
 
19
 * It can be used with smbclient to print from an UNIX box
 
20
 * to a LaserJet 3100 printer attached to a MS-Windows box.
 
21
 *
 
22
 * Written by Ulrich Schmid, uschmid@mail.hh.provi.de.
 
23
 */
 
24
 
 
25
#include "gdevprn.h"
 
26
#include "gdevmeds.h"
 
27
 
 
28
#define XCORRECTION 0.11
 
29
#define YCORRECTION 0.12
 
30
 
 
31
/* order matters!             0       1        2        3       4      5     6       7           8 */
 
32
const char *media[10]   =  {"a4", "letter", "legal", "com10", "c5",  "dl", "b5", "monarch", "executive", 0};
 
33
const int height[2][10] = {{3447,     3240,    4140,    5587, 2644,  5083, 2975,      4387,        3090, 0},
 
34
                           {6894,     6480,    8280,   11167, 5288, 10159, 5950,      8767,        6180, 0}};
 
35
const int width[2]      = {2528,
 
36
                           5056};
 
37
#define LARGEST_MEDIUM 2 /* legal */
 
38
 
 
39
/* These codes correspond to sequences of pixels with the same color.
 
40
 * After the code for a sequence < 64 pixels the color changes.
 
41
 * After the code for a sequence with 64 pixels the previous color continues. */ 
 
42
static struct {
 
43
        uint bits;
 
44
        uint length; /* number of valid bits */
 
45
} code[2][65] =
 
46
/* White */
 
47
{{{0x0ac,  8}, {0x038,  6}, {0x00e,  4}, {0x001,  4}, {0x00d,  4}, {0x003,  4}, {0x007,  4}, {0x00f,  4},
 
48
  {0x019,  5}, {0x005,  5}, {0x01c,  5}, {0x002,  5}, {0x004,  6}, {0x030,  6}, {0x00b,  6}, {0x02b,  6},
 
49
  {0x015,  6}, {0x035,  6}, {0x072,  7}, {0x018,  7}, {0x008,  7}, {0x074,  7}, {0x060,  7}, {0x010,  7},
 
50
  {0x00a,  7}, {0x06a,  7}, {0x064,  7}, {0x012,  7}, {0x00c,  7}, {0x040,  8}, {0x0c0,  8}, {0x058,  8},
 
51
  {0x0d8,  8}, {0x048,  8}, {0x0c8,  8}, {0x028,  8}, {0x0a8,  8}, {0x068,  8}, {0x0e8,  8}, {0x014,  8},
 
52
  {0x094,  8}, {0x054,  8}, {0x0d4,  8}, {0x034,  8}, {0x0b4,  8}, {0x020,  8}, {0x0a0,  8}, {0x050,  8},
 
53
  {0x0d0,  8}, {0x04a,  8}, {0x0ca,  8}, {0x02a,  8}, {0x0aa,  8}, {0x024,  8}, {0x0a4,  8}, {0x01a,  8},
 
54
  {0x09a,  8}, {0x05a,  8}, {0x0da,  8}, {0x052,  8}, {0x0d2,  8}, {0x04c,  8}, {0x0cc,  8}, {0x02c,  8},
 
55
  {0x01b,  5}},
 
56
/* Black */
 
57
 {{0x3b0, 10}, {0x002,  3}, {0x003,  2}, {0x001,  2}, {0x006,  3}, {0x00c,  4}, {0x004,  4}, {0x018,  5},
 
58
  {0x028,  6}, {0x008,  6}, {0x010,  7}, {0x050,  7}, {0x070,  7}, {0x020,  8}, {0x0e0,  8}, {0x030,  9},
 
59
  {0x3a0, 10}, {0x060, 10}, {0x040, 10}, {0x730, 11}, {0x0b0, 11}, {0x1b0, 11}, {0x760, 11}, {0x0a0, 11},
 
60
  {0x740, 11}, {0x0c0, 11}, {0x530, 12}, {0xd30, 12}, {0x330, 12}, {0xb30, 12}, {0x160, 12}, {0x960, 12},
 
61
  {0x560, 12}, {0xd60, 12}, {0x4b0, 12}, {0xcb0, 12}, {0x2b0, 12}, {0xab0, 12}, {0x6b0, 12}, {0xeb0, 12},
 
62
  {0x360, 12}, {0xb60, 12}, {0x5b0, 12}, {0xdb0, 12}, {0x2a0, 12}, {0xaa0, 12}, {0x6a0, 12}, {0xea0, 12},
 
63
  {0x260, 12}, {0xa60, 12}, {0x4a0, 12}, {0xca0, 12}, {0x240, 12}, {0xec0, 12}, {0x1c0, 12}, {0xe40, 12},
 
64
  {0x140, 12}, {0x1a0, 12}, {0x9a0, 12}, {0xd40, 12}, {0x340, 12}, {0x5a0, 12}, {0x660, 12}, {0xe60, 12},
 
65
  {0x3c0, 10}}}; 
 
66
 
 
67
/* Define the default, maximum resolutions. */
 
68
#ifndef X_DPI
 
69
#  define X_DPI 600
 
70
#endif
 
71
#ifndef Y_DPI
 
72
#  define Y_DPI 600
 
73
#endif
 
74
 
 
75
/* The device descriptors */
 
76
static dev_proc_print_page_copies(lj3100sw_print_page_copies);
 
77
static dev_proc_close_device(lj3100sw_close);
 
78
 
 
79
static gx_device_procs prn_lj3100sw_procs = 
 
80
    prn_params_procs(gdev_prn_open, gdev_prn_output_page, lj3100sw_close,
 
81
             gdev_prn_get_params, gdev_prn_put_params);
 
82
 
 
83
/* workaround to emulate the missing prn_device_margins_copies macro */
 
84
#define gx_default_print_page_copies lj3100sw_print_page_copies
 
85
gx_device_printer far_data gs_lj3100sw_device =
 
86
    prn_device_margins/*_copies*/(prn_lj3100sw_procs, "lj3100sw",
 
87
             DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
 
88
             X_DPI, Y_DPI,
 
89
             XCORRECTION, YCORRECTION,
 
90
             0.25, 0.2, 0.25, 0.2,
 
91
             1, 0 /* lj3100sw_print_page_copies */);
 
92
#undef gx_default_print_page_copies
 
93
 
 
94
#define ppdev ((gx_device_printer *)pdev)
 
95
 
 
96
#define BUFFERSIZE 0x1000
 
97
 
 
98
static void
 
99
lj3100sw_output_section_header(FILE *prn_stream, int type, int arg1, int arg2)
 
100
{
 
101
        fputc(type      & 0xff, prn_stream);
 
102
        fputc(type >> 8 & 0xff, prn_stream);
 
103
        fputc(arg1      & 0xff, prn_stream);
 
104
        fputc(arg1 >> 8 & 0xff, prn_stream);
 
105
        fputc(arg2      & 0xff, prn_stream);
 
106
        fputc(arg2 >> 8 & 0xff, prn_stream);
 
107
}
 
108
 
 
109
static void
 
110
lj3100sw_flush_buffer(FILE *prn_stream, char *buffer, char **pptr)
 
111
{
 
112
        int size = *pptr - buffer;
 
113
        if (size) {
 
114
                lj3100sw_output_section_header(prn_stream, 0, size, 0);
 
115
                fwrite(buffer, 1, size, prn_stream);
 
116
                *pptr = buffer;
 
117
        }
 
118
}
 
119
 
 
120
static void
 
121
lj3100sw_output_data_byte(FILE *prn_stream, char *buffer, char **pptr, int val)
 
122
{
 
123
        if (*pptr >= buffer + BUFFERSIZE)
 
124
                lj3100sw_flush_buffer(prn_stream, buffer, pptr);
 
125
        *(*pptr)++ = val;
 
126
}
 
127
 
 
128
static void
 
129
lj3100sw_output_repeated_data_bytes(FILE *prn_stream, char *buffer, char **pptr, int val, int num)
 
130
{
 
131
        int size;
 
132
        while (num) {
 
133
                if (*pptr >= buffer + BUFFERSIZE)
 
134
                        lj3100sw_flush_buffer(prn_stream, buffer, pptr);
 
135
                size = min(num, buffer + BUFFERSIZE - *pptr);
 
136
                memset(*pptr, val, size);
 
137
                *pptr += size;
 
138
                num -= size;
 
139
        }
 
140
}
 
141
 
 
142
static void
 
143
lj3100sw_output_newline(FILE *prn_stream, char *buffer, char **pptr)
 
144
{
 
145
        lj3100sw_output_data_byte(prn_stream, buffer, pptr, 0);
 
146
        lj3100sw_output_data_byte(prn_stream, buffer, pptr, 0);
 
147
        lj3100sw_output_data_byte(prn_stream, buffer, pptr, 0x80);
 
148
}
 
149
 
 
150
static void
 
151
lj3100sw_output_empty_line(FILE *prn_stream, char *buffer, char **pptr, bool high_resolution)
 
152
{
 
153
        if (high_resolution) {
 
154
                lj3100sw_output_data_byte(prn_stream, buffer, pptr, 0x80);
 
155
                lj3100sw_output_data_byte(prn_stream, buffer, pptr, 0x0f);
 
156
                lj3100sw_output_data_byte(prn_stream, buffer, pptr, 0x78);
 
157
                lj3100sw_output_data_byte(prn_stream, buffer, pptr, 0xac);
 
158
        } else {
 
159
                lj3100sw_output_data_byte(prn_stream, buffer, pptr, 0x80);
 
160
                lj3100sw_output_data_byte(prn_stream, buffer, pptr, 0x87);
 
161
                lj3100sw_output_data_byte(prn_stream, buffer, pptr, 0x0d);
 
162
        }
 
163
}
 
164
 
 
165
static int
 
166
lj3100sw_print_page_copies(gx_device_printer *pdev, FILE *prn_stream, int num_copies /* ignored */)
 
167
{
 
168
        int i, j;
 
169
        char buffer[BUFFERSIZE], *ptr = buffer;
 
170
        int medium_index = select_medium(pdev, media, LARGEST_MEDIUM);
 
171
        bool high_resolution = (pdev->x_pixels_per_inch > 300);
 
172
        int printer_height = height[high_resolution ? 1 : 0][medium_index];
 
173
        int printer_width  = width[high_resolution ? 1 : 0];
 
174
        int paper_height = pdev->height;
 
175
        int paper_width  = pdev->width;
 
176
        int line_size = gdev_prn_raster(pdev);
 
177
        gs_memory_t *mem = pdev->memory;
 
178
        byte *in = (byte *)gs_malloc(mem, line_size, 1, "lj3100sw_print_page");
 
179
        byte *data;
 
180
        if (in == 0)
 
181
                return_error(gs_error_VMerror);
 
182
        if (gdev_prn_file_is_new(pdev)) {
 
183
                lj3100sw_output_section_header(prn_stream, 1, 0, 0);
 
184
                lj3100sw_output_repeated_data_bytes(prn_stream, buffer, &ptr, 0x1b, 12);
 
185
                ptr += sprintf(ptr, "\r\nBD");
 
186
                lj3100sw_output_repeated_data_bytes(prn_stream, buffer, &ptr, 0, 5520);
 
187
                ptr += sprintf(ptr, "%s\r\n%s %d\r\n%s %d\r\n%s %d\r\n%s %d\r\n%s %d\r\n%s %d\r\n",
 
188
                               "NJ",
 
189
                               "PQ", -1,
 
190
                               "RE",  high_resolution ? 6 : 2,
 
191
                               "SL",  printer_width,
 
192
                               "LM",  0,
 
193
                               "PS",  medium_index,
 
194
                               "PC",  0);
 
195
                lj3100sw_flush_buffer(prn_stream, buffer, &ptr);
 
196
        }
 
197
 
 
198
        lj3100sw_output_section_header(prn_stream, 3, ppdev->NumCopies, 0);
 
199
        ptr += sprintf(ptr, "%s %d\r\n%s\r\n",
 
200
                       "CM", 1,
 
201
                       "PD");
 
202
        *ptr++ = 0;
 
203
        lj3100sw_output_newline(prn_stream, buffer, &ptr);
 
204
 
 
205
        for (i = 0; i < printer_height; i++) {
 
206
                if (i < paper_height) {
 
207
                        int color = 0; /* white */
 
208
                        int count = 0;
 
209
                        int bit_index = 0;
 
210
                        uint tmp = 0;
 
211
                        gdev_prn_get_bits(pdev, i, in, &data);
 
212
                        for (j = 0; j <= printer_width; j++) {
 
213
                                int xoffset = (printer_width - paper_width) / 2;
 
214
                                int newcolor = 0;
 
215
                                if (j >= xoffset && j <  xoffset + paper_width)
 
216
                                        newcolor = (data[(j - xoffset) / 8] >> (7 - (j - xoffset) % 8)) & 1;
 
217
                                if (j == printer_width)
 
218
                                        newcolor = !color; /* force output */
 
219
                                if (newcolor == color)
 
220
                                        count++;
 
221
                                else if (count == printer_width && color == 0) /* implies j == printer_width */
 
222
                                        lj3100sw_output_empty_line(prn_stream, buffer, &ptr, high_resolution);
 
223
                                else    /* print a sequence of pixels with a uniform color */
 
224
                                        while (newcolor != color) {
 
225
                                                int size = min(count, 64);
 
226
                                                tmp |= code[color][size].bits << bit_index;
 
227
                                                bit_index += code[color][size].length;
 
228
                                                while (bit_index >= 8)  {
 
229
                                                        lj3100sw_output_data_byte(prn_stream, buffer, &ptr, tmp & 0xff);
 
230
                                                        tmp >>= 8;
 
231
                                                        bit_index -= 8;
 
232
                                                }
 
233
                                                if (size == 64)
 
234
                                                        count -= 64;
 
235
                                                else {
 
236
                                                        color = newcolor;
 
237
                                                        count = 1;
 
238
                                                }
 
239
                                        }
 
240
                        }
 
241
                        if (bit_index)
 
242
                                lj3100sw_output_data_byte(prn_stream, buffer, &ptr, tmp & 0xff);
 
243
                }
 
244
                else
 
245
                        lj3100sw_output_empty_line(prn_stream, buffer, &ptr, high_resolution);
 
246
                lj3100sw_output_newline(prn_stream, buffer, &ptr);
 
247
        }
 
248
 
 
249
        for (i = 0; i < 3; i++ ) {
 
250
                lj3100sw_output_data_byte(prn_stream, buffer, &ptr, 0x00);
 
251
                lj3100sw_output_data_byte(prn_stream, buffer, &ptr, 0x08);
 
252
                lj3100sw_output_data_byte(prn_stream, buffer, &ptr, 0x80);
 
253
        }
 
254
        lj3100sw_output_repeated_data_bytes(prn_stream, buffer, &ptr, 0, 520);
 
255
        lj3100sw_flush_buffer(prn_stream, buffer, &ptr);
 
256
 
 
257
        lj3100sw_output_section_header(prn_stream, 4, 0, 0);
 
258
        for (i = 0; i < 4 * ppdev->NumCopies; i++)
 
259
                lj3100sw_output_section_header(prn_stream, 54, 0, 0);
 
260
 
 
261
        gs_free(mem, (char *)in, line_size, 1, "lj3100sw_print_page");
 
262
        return 0;
 
263
}
 
264
 
 
265
static int
 
266
lj3100sw_close(gx_device *pdev)
 
267
{
 
268
        int i;
 
269
        FILE *prn_stream = ((gx_device_printer *)pdev)->file;
 
270
 
 
271
        lj3100sw_output_section_header(prn_stream, 0, 4, 0);
 
272
        fputs("XX\r\n", prn_stream);
 
273
        for (i = 0; i < 4 * ppdev->NumCopies; i++)
 
274
                lj3100sw_output_section_header(prn_stream, 54, 0, 0);
 
275
        lj3100sw_output_section_header(prn_stream, 2, 0, 0);
 
276
 
 
277
        return gdev_prn_close(pdev);
 
278
}