Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
/* Copyright (C) 1999 Aladdin Enterprises.  All rights reserved.
2
 
3
  This software is provided AS-IS with no warranty, either express or
4
  implied.
5
 
6
  This software is distributed under license and may not be copied,
7
  modified or distributed except as expressly authorized under the terms
8
  of the license contained in the file LICENSE in this distribution.
9
 
10
  For more information about licensing, please refer to
11
  http://www.ghostscript.com/licensing/. For information on
12
  commercial licensing, go to http://www.artifex.com/licensing/ or
13
  contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14
  San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15
*/
16
 
17
/* $Id: gdevcslw.c,v 1.5 2004/08/10 13:02:36 stefan Exp $ */
18
/* CoStar LabelWriter II, II Plus driver for Ghostscript */
19
/* Contributed by Mike McCauley mikem@open.com.au        */
20
 
21
#include "gdevprn.h"
22
 
23
/* We round up the LINE_SIZE to a multiple of a ulong for faster scanning. */
24
typedef ulong word;
25
#define W sizeof(word)
26
 
27
/* Printer types */
28
#define LW	0
29
 
30
/* The device descriptors */
31
 
32
private dev_proc_print_page(coslw_print_page);
33
 
34
const gx_device_printer gs_coslw2p_device =
35
prn_device(prn_std_procs, "coslw2p",
36
	   200, 400,    /* 2 inches wide */
37
	   128, 128,    /* 5 dots per mm */
38
	   0, 0, 0, 0,
39
	   1, coslw_print_page);
40
 
41
const gx_device_printer gs_coslwxl_device =
42
prn_device(prn_std_procs, "coslwxl",
43
	   200, 400,    /* 2 inches wide */
44
	   204, 204,    /* 8 dots per mm */
45
	   0, 0, 0, 0,
46
	   1, coslw_print_page);
47
 
48
/* ------ Internal routines ------ */
49
 
50
/* Send the page to the printer. */
51
private int
52
coslw_print_page(gx_device_printer * pdev, FILE * prn_stream)
53
{
54
    int line_size = gdev_mem_bytes_per_scan_line((gx_device *) pdev);
55
    int line_size_words = (line_size + W - 1) / W;
56
    uint storage_size_words = line_size_words * 8;	/* data, out_row, out_row_alt, prev_row */
57
    word *storage = (ulong *) gs_malloc(pdev->memory, storage_size_words, W,
58
					"coslw_print_page");
59
 
60
    word *data_words;
61
#define data ((byte *)data_words)
62
 
63
    byte *out_data;
64
    int num_rows = dev_print_scan_lines(pdev);
65
    int bytes_per_line = 0;
66
    int out_count;
67
    int code = 0;
68
 
69
    if (storage == 0)		/* can't allocate working area */
70
	return_error(gs_error_VMerror);
71
    data_words = storage;
72
 
73
    /* Clear temp storage */
74
    memset(data, 0, storage_size_words * W);
75
 
76
    /* Initialize printer. */
77
    if (pdev->PageCount == 0) {
78
    }
79
 
80
    /* Put out per-page initialization. */
81
 
82
    /* End raster graphics, position cursor at top. */
83
 
84
    /* Send each scan line in turn */
85
    {
86
	int lnum;
87
	int num_blank_lines = 0;
88
	word rmask = ~(word) 0 << (-pdev->width & (W * 8 - 1));
89
 
90
	/* Transfer raster graphics. */
91
	for (lnum = 0; lnum < num_rows; lnum++) {
92
	    register word *end_data =
93
	    data_words + line_size_words;
94
 
95
	    code = gdev_prn_copy_scan_lines(pdev, lnum,
96
					    (byte *) data, line_size);
97
	    if (code < 0)
98
		break;
99
	    /* Mask off 1-bits beyond the line width. */
100
	    end_data[-1] &= rmask;
101
	    /* Remove trailing 0s. */
102
	    while (end_data > data_words && end_data[-1] == 0)
103
		end_data--;
104
	    if (end_data == data_words) {	/* Blank line */
105
		num_blank_lines++;
106
		continue;
107
	    }
108
 
109
	    /* We've reached a non-blank line. */
110
	    /* Put out a spacing command if necessary. */
111
	    while (num_blank_lines > 0)
112
	    {
113
		int this_blank = 255;
114
		if (num_blank_lines < this_blank)
115
		    this_blank = num_blank_lines;
116
		fprintf(prn_stream, "\033f\001%c", this_blank);
117
		num_blank_lines -= this_blank;
118
	    }
119
 
120
	    /* Perhaps add compression here later? */
121
	    out_data = data;
122
	    out_count = (byte *) end_data - data;
123
 
124
	    /* For 2 inch model, max width is 56 bytes */
125
	    if (out_count > 56)
126
		out_count = 56;  
127
	    /* Possible change the bytes per line */
128
	    if (bytes_per_line != out_count)
129
	    {
130
		fprintf(prn_stream, "\033D%c", out_count);
131
		bytes_per_line = out_count;
132
	    }
133
 
134
	    /* Transfer the data */
135
	    fputs("\026", prn_stream);
136
	    fwrite(out_data, sizeof(byte), out_count, prn_stream);
137
	}
138
    }
139
 
140
    /* eject page */
141
    fputs("\033E", prn_stream);
142
 
143
    /* free temporary storage */
144
    gs_free(pdev->memory, (char *)storage, storage_size_words, W, "coslw_print_page");
145
 
146
    return code;
147
}