1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
|
/* Copyright (C) 2001-2006 artofcode LLC.
All Rights Reserved.
This software is provided AS-IS with no warranty, either express or
implied.
This software is distributed under license and may not be copied, modified
or distributed except as expressly authorized under the terms of that
license. Refer to licensing information at http://www.artifex.com/
or contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information.
*/
/*$Id: gdevtxtw.c 7795 2007-03-23 13:56:11Z tim $ */
/* Device for ASCII or Unicode text extraction */
/* FIXME: not all .h files are listed as dependencies */
#include "memory_.h"
#include "gp.h" /* for gp_file_name_sizeof */
#include "gx.h"
#include "gserrors.h"
#include "gsparam.h"
#include "gsutil.h"
#include "gxdevice.h"
#include "gsdevice.h" /* requires gsmatrix.h */
typedef struct gx_device_txtwrite_s {
gx_device_common;
void *example_data;
char fname[gp_file_name_sizeof]; /* OutputFile */
FILE *file;
} gx_device_txtwrite_t;
/* GC descriptor */
gs_private_st_suffix_add1_final(st_device_txtwrite, gx_device_txtwrite_t,
"gx_device_txtwrite", device_txtwrite_enum_ptrs, device_txtwrite_reloc_ptrs,
gx_device_finalize, st_device_forward, example_data);
/* Device procedures */
static dev_proc_open_device(txtwrite_open_device);
static dev_proc_close_device(txtwrite_close_device);
static dev_proc_output_page(txtwrite_output_page);
static dev_proc_fill_rectangle(txtwrite_fill_rectangle);
static dev_proc_get_params(txtwrite_get_params);
static dev_proc_put_params(txtwrite_put_params);
static dev_proc_copy_alpha(txtwrite_copy_alpha);
static dev_proc_copy_mono(txtwrite_copy_mono);
static dev_proc_copy_color(txtwrite_copy_color);
static dev_proc_fill_path(txtwrite_fill_path);
static dev_proc_stroke_path(txtwrite_stroke_path);
static dev_proc_fill_mask(txtwrite_fill_mask);
static dev_proc_fill_trapezoid(txtwrite_fill_trapezoid);
static dev_proc_fill_parallelogram(txtwrite_fill_parallelogram);
static dev_proc_fill_triangle(txtwrite_fill_triangle);
static dev_proc_draw_thin_line(txtwrite_draw_thin_line);
static dev_proc_strip_tile_rectangle(txtwrite_strip_tile_rectangle);
static dev_proc_strip_copy_rop(txtwrite_strip_copy_rop);
static dev_proc_begin_typed_image(txtwrite_begin_typed_image);
static dev_proc_text_begin(txtwrite_text_begin);
/* The device prototype */
#define X_DPI 720
#define Y_DPI 720
const gx_device_txtwrite_t gs_txtwrite_device =
{
/* Define the device as 8-bit gray scale to avoid computing halftones. */
std_device_dci_body(gx_device_txtwrite_t, 0, "txtwrite",
DEFAULT_WIDTH_10THS * X_DPI / 10,
DEFAULT_HEIGHT_10THS * Y_DPI / 10,
X_DPI, Y_DPI,
1, 8, 255, 0, 256, 1),
{txtwrite_open_device,
gx_upright_get_initial_matrix,
gx_default_sync_output,
txtwrite_output_page,
gx_default_close_device,
gx_default_gray_map_rgb_color,
gx_default_gray_map_color_rgb,
txtwrite_fill_rectangle,
gx_default_tile_rectangle,
txtwrite_copy_mono,
txtwrite_copy_color,
gx_default_draw_line,
gx_default_get_bits,
txtwrite_get_params,
txtwrite_put_params,
gx_default_map_cmyk_color,
gx_default_get_xfont_procs,
gx_default_get_xfont_device,
gx_default_map_rgb_alpha_color,
gx_page_device_get_page_device,
NULL, /* get_alpha_bits */
txtwrite_copy_alpha,
NULL, /* get_band */
NULL, /* copy_rop */
txtwrite_fill_path,
txtwrite_stroke_path,
txtwrite_fill_mask,
txtwrite_fill_trapezoid,
txtwrite_fill_parallelogram,
txtwrite_fill_triangle,
txtwrite_draw_thin_line,
gx_default_begin_image,
NULL, /* image_data */
NULL, /* end_image */
txtwrite_strip_tile_rectangle,
txtwrite_strip_copy_rop,
NULL, /* get_clipping_box */
txtwrite_begin_typed_image,
NULL, /* get_bits_rectangle */
gx_default_map_color_rgb_alpha,
gx_null_create_compositor,
NULL, /* get_hardware_params */
txtwrite_text_begin,
NULL, /* finish_copydevice */
NULL, /* begin_transparency_group */
NULL, /* end_transparency_group */
NULL, /* begin_transparency_mask */
NULL, /* end_transparency_mask */
NULL, /* discard_transparency_layer */
NULL, /* get_color_mapping_procs */
NULL, /* get_color_comp_index */
NULL, /* encode_color */
NULL /* decode_color */
},
0, /* example_data */
{ 0 }, /* OutputFile */
0 /* FILE *file */
};
/* ---------------- Open/close/page ---------------- */
static int
txtwrite_open_device(gx_device * dev)
{
int code;
gx_device_txtwrite_t *const tdev = (gx_device_txtwrite_t *) dev;
gx_device_fill_in_procs(dev);
if (tdev->fname[0] == 0)
return_error(gs_error_undefinedfilename);
code = gx_device_open_output_file(dev, tdev->fname,
true, false, &tdev->file); /* binary, sequential */
if (code < 0)
return code;
return 0;
}
static int
txtwrite_close_device(gx_device * dev)
{
return 0;
}
static int
txtwrite_output_page(gx_device * dev, int num_copies, int flush)
{
gx_device_txtwrite_t *const tdev = (gx_device_txtwrite_t *) dev;
fprintf(tdev->file, "Hello world\n");
return gx_default_output_page(dev, num_copies, flush);
}
/* ---------------- Low-level drawing ---------------- */
static int
txtwrite_fill_rectangle(gx_device * dev, int x, int y, int w, int h,
gx_color_index color)
{
return 0;
}
static int
txtwrite_copy_alpha(gx_device * dev, const byte * data, int data_x,
int raster, gx_bitmap_id id, int x, int y, int w, int h,
gx_color_index color, int depth)
{
return 0;
}
static int
txtwrite_copy_mono(gx_device * dev, const byte * data, int dx, int raster,
gx_bitmap_id id, int x, int y, int w, int h,
gx_color_index zero, gx_color_index one)
{
return 0;
}
static int
txtwrite_copy_color(gx_device * dev, const byte * data,
int data_x, int raster, gx_bitmap_id id,
int x, int y, int width, int height)
{
return 0;
}
static int
txtwrite_strip_tile_rectangle(gx_device * dev, const gx_strip_bitmap * tiles,
int x, int y, int w, int h, gx_color_index color0, gx_color_index color1,
int px, int py)
{
return 0;
}
static int
txtwrite_strip_copy_rop(gx_device * dev,
const byte * sdata, int sourcex, uint sraster,
gx_bitmap_id id,
const gx_color_index * scolors,
const gx_strip_bitmap * textures,
const gx_color_index * tcolors,
int x, int y, int w, int h,
int phase_x, int phase_y, gs_logical_operation_t lop)
{
return 0;
}
/* ---------------- Parameters ---------------- */
static int
txtwrite_get_params(gx_device * dev, gs_param_list * plist)
{
int code;
gs_param_string ofns;
gx_device_txtwrite_t *const tdev = (gx_device_txtwrite_t *) dev;
code = gx_default_get_params(dev, plist);
if (code < 0)
return code;
ofns.data = (const byte *)tdev->fname,
ofns.size = strlen(tdev->fname),
ofns.persistent = false;
code = param_write_string(plist, "OutputFile", &ofns);
return code;
}
/* We implement put_params to ensure that we keep the important */
/* device parameters up to date, and to prevent an /undefined error */
static int
txtwrite_put_params(gx_device * dev, gs_param_list * plist)
{
gx_device_txtwrite_t *tdev = (gx_device_txtwrite_t *) dev;
int ecode = 0;
int code;
const char *param_name;
gs_param_string ofs;
switch (code = param_read_string(plist, (param_name = "OutputFile"), &ofs)) {
case 0:
if (dev->LockSafetyParams &&
bytes_compare(ofs.data, ofs.size,
(const byte *)tdev->fname, strlen(tdev->fname))) {
ecode = gs_note_error(gs_error_invalidaccess);
goto ofe;
}
if (ofs.size >= gp_file_name_sizeof)
ecode = gs_error_limitcheck;
else
break;
goto ofe;
default:
ecode = code;
ofe:param_signal_error(plist, param_name, ecode);
case 1:
ofs.data = 0;
break;
}
if (ecode < 0)
return ecode;
code = gx_default_put_params(dev, plist);
if (code < 0)
return code;
if (ofs.data != 0) { /* Close the file if it's open. */
if (tdev->file != 0) {
fclose(tdev->file);
tdev->file = 0;
}
memcpy(tdev->fname, ofs.data, ofs.size);
tdev->fname[ofs.size] = 0;
tdev->file = fopen(tdev->fname, "wb");
if (tdev->file == 0)
return_error(gs_error_ioerror);
}
return 0;
}
/* ---------------- Polygon drawing ---------------- */
static int
txtwrite_fill_trapezoid(gx_device * dev,
const gs_fixed_edge * left, const gs_fixed_edge * right,
fixed ybot, fixed ytop, bool swap_axes,
const gx_device_color * pdevc, gs_logical_operation_t lop)
{
return 0;
}
static int
txtwrite_fill_parallelogram(gx_device * dev,
fixed px, fixed py, fixed ax, fixed ay,
fixed bx, fixed by, const gx_device_color * pdevc,
gs_logical_operation_t lop)
{
return 0;
}
static int
txtwrite_fill_triangle(gx_device * dev,
fixed px, fixed py, fixed ax, fixed ay, fixed bx, fixed by,
const gx_device_color * pdevc, gs_logical_operation_t lop)
{
return 0;
}
static int
txtwrite_draw_thin_line(gx_device * dev,
fixed fx0, fixed fy0, fixed fx1, fixed fy1,
const gx_device_color * pdevc, gs_logical_operation_t lop,
fixed adjustx, fixed adjusty)
{
return 0;
}
/* ---------------- High-level drawing ---------------- */
static int
txtwrite_fill_path(gx_device * dev, const gs_imager_state * pis, gx_path * ppath,
const gx_fill_params * params, const gx_device_color * pdevc,
const gx_clip_path * pcpath)
{
return 0;
}
static int
txtwrite_stroke_path(gx_device * dev, const gs_imager_state * pis, gx_path * ppath,
const gx_stroke_params * params,
const gx_drawing_color * pdevc, const gx_clip_path * pcpath)
{
return 0;
}
static int
txtwrite_fill_mask(gx_device * dev,
const byte * data, int dx, int raster, gx_bitmap_id id,
int x, int y, int w, int h,
const gx_drawing_color * pdcolor, int depth,
gs_logical_operation_t lop, const gx_clip_path * pcpath)
{
return 0;
}
static int
txtwrite_begin_typed_image(gx_device * dev,
const gs_imager_state * pis, const gs_matrix * pmat,
const gs_image_common_t * pic, const gs_int_rect * prect,
const gx_drawing_color * pdcolor,
const gx_clip_path * pcpath,
gs_memory_t * memory, gx_image_enum_common_t ** pinfo)
{
return 0;
}
/* ------ Text imaging ------ */
static int
txtwrite_text_begin(gx_device * dev, gs_imager_state * pis,
const gs_text_params_t * text, gs_font * font,
gx_path * path, const gx_device_color * pdcolor,
const gx_clip_path * pcpath,
gs_memory_t * memory, gs_text_enum_t ** ppenum)
{
int code = gx_default_text_begin(dev, pis, text, font, path, pdcolor,
pcpath, memory, ppenum);
return code;
}
|