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

« back to all changes in this revision

Viewing changes to base/gdevlbp8.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: gdevlbp8.c 8250 2007-09-25 13:31:24Z giles $*/
 
14
/* Canon LBP-8II and LIPS III driver */
 
15
#include "gdevprn.h"
 
16
 
 
17
/* 
 
18
  Modifications:
 
19
    2.2.97  Lauri Paatero
 
20
            Changed CSI command into ESC [. DCS commands may still need to be changed
 
21
            (to ESC P).
 
22
    4.9.96  Lauri Paatero
 
23
            Corrected LBP-8II margins again. Real problem was that (0,0) is NOT 
 
24
                in upper left corner.
 
25
            Now using relative addressing for vertical addressing. This avoids
 
26
problems
 
27
                when printing to paper with wrong size.
 
28
    18.6.96 Lauri Paatero, lauri.paatero@paatero.pp.fi
 
29
            Corrected LBP-8II margins.
 
30
            Added logic to recognize (and optimize away) long strings of 00's in data.
 
31
            For LBP-8II removed use of 8-bit CSI (this does not work if 8-bit character
 
32
                set has been configured in LBP-8II. (Perhaps this should also be done
 
33
                for LBP-8III?)
 
34
  Original versions:
 
35
    LBP8 driver: Tom Quinn (trq@prg.oxford.ac.uk)
 
36
    LIPS III driver: Kenji Okamoto (okamoto@okamoto.cias.osakafu-u.ac.jp)
 
37
*/
 
38
 
 
39
 
 
40
#define X_DPI 300
 
41
#define Y_DPI 300
 
42
#define LINE_SIZE ((X_DPI * 85 / 10 + 7) / 8)   /* bytes per line */
 
43
 
 
44
/* The device descriptors */
 
45
static dev_proc_print_page(lbp8_print_page);
 
46
#ifdef NOCONTRIB
 
47
static dev_proc_print_page(lips3_print_page);
 
48
#endif
 
49
 
 
50
const gx_device_printer far_data gs_lbp8_device =
 
51
  prn_device(prn_std_procs, "lbp8",
 
52
        DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
 
53
        X_DPI, Y_DPI,
 
54
        0.16, 0.2, 0.32, 0.21,          /* margins: left, bottom, right, top */
 
55
        1, lbp8_print_page);
 
56
 
 
57
#ifdef NOCONTRIB
 
58
const gx_device_printer far_data gs_lips3_device =
 
59
  prn_device(prn_std_procs, "lips3",
 
60
        82,                             /* width_10ths, 8.3" */
 
61
        117,                            /* height_10ths, 11.7" */
 
62
        X_DPI, Y_DPI,
 
63
        0.16, 0.27, 0.23, 0.27,         /* margins */
 
64
        1, lips3_print_page);
 
65
#endif
 
66
 
 
67
/* ------ Internal routines ------ */
 
68
 
 
69
#define ESC (char)0x1b
 
70
#define CSI '\233'
 
71
#define DCS '\220'
 
72
#define ST '\234'
 
73
 
 
74
static const char lbp8_init[] = {
 
75
  ESC, ';', ESC, 'c', ESC, ';', /* reset, ISO */
 
76
  ESC, '[', '2', '&', 'z',      /* fullpaint mode */
 
77
  ESC, '[', '1', '4', 'p',      /* select page type (A4) */
 
78
  ESC, '[', '1', '1', 'h',      /* set mode */
 
79
  ESC, '[', '7', ' ', 'I',      /* select unit size (300dpi)*/
 
80
  ESC, '[', '6', '3', 'k',      /* Move 63 dots up (to top of printable area) */ 
 
81
};
 
82
 
 
83
static const char *lbp8_end = NULL;
 
84
 
 
85
#ifdef NOCONTRIB
 
86
static const char lips3_init[] = {
 
87
  ESC, '<', /* soft reset */
 
88
  DCS, '0', 'J', ST, /* JOB END */
 
89
  DCS, '3', '1', ';', '3', '0', '0', ';', '2', 'J', ST, /* 300dpi, LIPS3 JOB START */
 
90
  ESC, '<',  /* soft reset */
 
91
  DCS, '2', 'y', 'P', 'r', 'i', 'n', 't', 'i', 'n', 'g', '(', 'g', 's', ')', ST,  /* Printing (gs) display */
 
92
  ESC, '[', '?', '1', 'l',  /* auto cr-lf disable */
 
93
  ESC, '[', '?', '2', 'h', /* auto ff disable */
 
94
  ESC, '[', '1', '1', 'h', /* set mode */
 
95
  ESC, '[', '7', ' ', 'I', /* select unit size (300dpi)*/
 
96
  ESC, '[', 'f' /* move to home position */
 
97
};
 
98
 
 
99
static const char lips3_end[] = {
 
100
  DCS, '0', 'J', ST  /* JOB END */
 
101
};
 
102
#endif
 
103
 
 
104
/* Send the page to the printer.  */
 
105
static int
 
106
can_print_page(gx_device_printer *pdev, FILE *prn_stream,
 
107
  const char *init, int init_size, const char *end, int end_size)
 
108
{       
 
109
        char data[LINE_SIZE*2];
 
110
        char *out_data;
 
111
        int last_line_nro = 0;
 
112
 
 
113
        fwrite(init, init_size, 1, prn_stream);         /* initialize */
 
114
 
 
115
        /* Send each scan line in turn */
 
116
        {       
 
117
            int lnum;
 
118
            int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
 
119
            byte rmask = (byte)(0xff << (-pdev->width & 7));
 
120
 
 
121
            for ( lnum = 0; lnum < pdev->height; lnum++ ) {
 
122
                char *end_data = data + LINE_SIZE;
 
123
                gdev_prn_copy_scan_lines(pdev, lnum,
 
124
                                         (byte *)data, line_size);
 
125
                /* Mask off 1-bits beyond the line width. */
 
126
                end_data[-1] &= rmask;
 
127
                /* Remove trailing 0s. */
 
128
                while ( end_data > data && end_data[-1] == 0 )
 
129
                        end_data--;
 
130
                if ( end_data != data ) {
 
131
                    int num_cols = 0;
 
132
                    int out_count;
 
133
                    int zero_count;
 
134
                    out_data = data;
 
135
 
 
136
                    /* move down */
 
137
                    fprintf(prn_stream, "%c[%de", 
 
138
                            ESC, lnum-last_line_nro );
 
139
                    last_line_nro = lnum;
 
140
 
 
141
                    while (out_data < end_data) {
 
142
                        /* Remove leading 0s*/
 
143
                        while(out_data < end_data && *out_data == 0) {  
 
144
                            num_cols += 8;
 
145
                            out_data++;
 
146
                        }
 
147
 
 
148
                        out_count = end_data - out_data;
 
149
                        zero_count = 0;
 
150
                        
 
151
                        /* if there is a lot data, find if there is sequence of zeros */
 
152
                        if (out_count>22) {
 
153
 
 
154
                                out_count = 1;
 
155
 
 
156
                                while(out_data+out_count+zero_count < end_data) {
 
157
                                        if (out_data[zero_count+out_count] != 0) {
 
158
                                                out_count += 1+zero_count;
 
159
                                                zero_count = 0;
 
160
                                        }
 
161
                                        else {
 
162
                                                zero_count++;
 
163
                                                if (zero_count>20)
 
164
                                                        break;
 
165
                                        }
 
166
                                }
 
167
 
 
168
                        }
 
169
        
 
170
                        if (out_count==0)
 
171
                                break;
 
172
 
 
173
                        /* move down and across*/
 
174
                        fprintf(prn_stream, "%c[%d`", 
 
175
                                ESC, num_cols );
 
176
                        /* transfer raster graphic command */
 
177
                        fprintf(prn_stream, "%c[%d;%d;300;.r",
 
178
                                ESC, out_count, out_count);
 
179
 
 
180
                        /* send the row */
 
181
                        fwrite(out_data, sizeof(char),
 
182
                               out_count, prn_stream);
 
183
 
 
184
                        out_data += out_count+zero_count;
 
185
                        num_cols += 8*(out_count+zero_count);
 
186
                    }
 
187
                }
 
188
            }
 
189
        }
 
190
 
 
191
        /* eject page */
 
192
        fprintf(prn_stream, "%c=", ESC);
 
193
 
 
194
        /* terminate */
 
195
        if (end != NULL)
 
196
            fwrite(end, end_size, 1, prn_stream);
 
197
 
 
198
        return 0;
 
199
}
 
200
 
 
201
/* Print an LBP-8 page. */
 
202
static int
 
203
lbp8_print_page(gx_device_printer *pdev, FILE *prn_stream)
 
204
{       return can_print_page(pdev, prn_stream, lbp8_init, sizeof(lbp8_init),
 
205
                              lbp8_end, sizeof(lbp8_end));
 
206
}
 
207
 
 
208
#ifdef NOCONTRIB
 
209
/* Print a LIPS III page. */
 
210
static int
 
211
lips3_print_page(gx_device_printer *pdev, FILE *prn_stream)
 
212
{       return can_print_page(pdev, prn_stream, lips3_init, sizeof(lips3_init),
 
213
                              lips3_end, sizeof(lips3_end));
 
214
}
 
215
#endif