summaryrefslogtreecommitdiff
path: root/gs/src/gdevpx.c
diff options
context:
space:
mode:
Diffstat (limited to 'gs/src/gdevpx.c')
-rw-r--r--gs/src/gdevpx.c986
1 files changed, 518 insertions, 468 deletions
diff --git a/gs/src/gdevpx.c b/gs/src/gdevpx.c
index 03c7e567d..c3dd6a9f8 100644
--- a/gs/src/gdevpx.c
+++ b/gs/src/gdevpx.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1998 Aladdin Enterprises. All rights reserved.
+/* Copyright (C) 1997, 1998, 1999 Aladdin Enterprises. All rights reserved.
This file is part of Aladdin Ghostscript.
@@ -46,11 +46,11 @@
#endif
/* Structure definition */
-#define num_points 100 /* must be >= 3 and <= 255 */
+#define NUM_POINTS 40 /* must be >= 3 and <= 255 */
typedef enum {
- points_none,
- points_lines,
- points_curves
+ POINTS_NONE,
+ POINTS_LINES,
+ POINTS_CURVES
} point_type_t;
typedef struct gx_device_pclxl_s {
gx_device_vector_common;
@@ -67,18 +67,18 @@ typedef struct gx_device_pclxl_s {
gs_int_point current; /* current point as of start of data */
point_type_t type;
int count;
- gs_int_point data[num_points];
+ gs_int_point data[NUM_POINTS];
} points;
struct ch_ { /* cache for downloaded characters */
-#define max_cached_chars 400
-#define max_char_data 500000
-#define max_char_size 5000
-#define char_hash_factor 247
- ushort table[max_cached_chars * 3 / 2];
+#define MAX_CACHED_CHARS 400
+#define MAX_CHAR_DATA 500000
+#define MAX_CHAR_SIZE 5000
+#define CHAR_HASH_FACTOR 247
+ ushort table[MAX_CACHED_CHARS * 3 / 2];
struct cd_ {
gs_id id; /* key */
uint size;
- } data[max_cached_chars];
+ } data[MAX_CACHED_CHARS];
int next_in; /* next data element to fill in */
int next_out; /* next data element to discard */
int count; /* of occupied data elements */
@@ -88,7 +88,8 @@ typedef struct gx_device_pclxl_s {
} gx_device_pclxl;
gs_public_st_suffix_add0_final(st_device_pclxl, gx_device_pclxl,
- "gx_device_pclxl", device_pclxl_enum_ptrs, device_pclxl_reloc_ptrs,
+ "gx_device_pclxl",
+ device_pclxl_enum_ptrs, device_pclxl_reloc_ptrs,
gx_device_finalize, st_device_vector);
#define pclxl_device_body(dname, depth)\
@@ -113,52 +114,51 @@ private dev_proc_begin_image(pclxl_begin_image);
private dev_proc_strip_copy_rop(pclxl_strip_copy_rop);
#define pclxl_device_procs(map_rgb_color, map_color_rgb)\
- { pclxl_open_device,\
- NULL, /* get_initial_matrix */\
- NULL, /* sync_output */\
- pclxl_output_page,\
- pclxl_close_device,\
- map_rgb_color, /* differs */\
- map_color_rgb, /* differs */\
- gdev_vector_fill_rectangle,\
- NULL, /* tile_rectangle */\
- pclxl_copy_mono,\
- pclxl_copy_color,\
- NULL, /* draw_line */\
- NULL, /* get_bits */\
- gdev_vector_get_params,\
- gdev_vector_put_params,\
- NULL, /* map_cmyk_color */\
- NULL, /* get_xfont_procs */\
- NULL, /* get_xfont_device */\
- NULL, /* map_rgb_alpha_color */\
- gx_page_device_get_page_device,\
- NULL, /* get_alpha_bits */\
- NULL, /* copy_alpha */\
- NULL, /* get_band */\
- NULL, /* copy_rop */\
- gdev_vector_fill_path,\
- gdev_vector_stroke_path,\
- pclxl_fill_mask,\
- gdev_vector_fill_trapezoid,\
- gdev_vector_fill_parallelogram,\
- gdev_vector_fill_triangle,\
- NULL /****** WRONG ******/, /* draw_thin_line */\
- pclxl_begin_image,\
- NULL, /* image_data */\
- NULL, /* end_image */\
- NULL, /* strip_tile_rectangle */\
- pclxl_strip_copy_rop\
- }
+{\
+ pclxl_open_device,\
+ NULL, /* get_initial_matrix */\
+ NULL, /* sync_output */\
+ pclxl_output_page,\
+ pclxl_close_device,\
+ map_rgb_color, /* differs */\
+ map_color_rgb, /* differs */\
+ gdev_vector_fill_rectangle,\
+ NULL, /* tile_rectangle */\
+ pclxl_copy_mono,\
+ pclxl_copy_color,\
+ NULL, /* draw_line */\
+ NULL, /* get_bits */\
+ gdev_vector_get_params,\
+ gdev_vector_put_params,\
+ NULL, /* map_cmyk_color */\
+ NULL, /* get_xfont_procs */\
+ NULL, /* get_xfont_device */\
+ NULL, /* map_rgb_alpha_color */\
+ gx_page_device_get_page_device,\
+ NULL, /* get_alpha_bits */\
+ NULL, /* copy_alpha */\
+ NULL, /* get_band */\
+ NULL, /* copy_rop */\
+ gdev_vector_fill_path,\
+ gdev_vector_stroke_path,\
+ pclxl_fill_mask,\
+ gdev_vector_fill_trapezoid,\
+ gdev_vector_fill_parallelogram,\
+ gdev_vector_fill_triangle,\
+ NULL /****** WRONG ******/, /* draw_thin_line */\
+ pclxl_begin_image,\
+ NULL, /* image_data */\
+ NULL, /* end_image */\
+ NULL, /* strip_tile_rectangle */\
+ pclxl_strip_copy_rop\
+}
-const gx_device_pclxl gs_pxlmono_device =
-{
+const gx_device_pclxl gs_pxlmono_device = {
pclxl_device_body("pxlmono", 8),
pclxl_device_procs(gx_default_gray_map_rgb_color, gx_default_gray_map_color_rgb)
};
-const gx_device_pclxl gs_pxlcolor_device =
-{
+const gx_device_pclxl gs_pxlcolor_device = {
pclxl_device_body("pxlcolor", 24),
pclxl_device_procs(gx_default_rgb_map_rgb_color, gx_default_rgb_map_color_rgb)
};
@@ -166,7 +166,7 @@ const gx_device_pclxl gs_pxlcolor_device =
/* ---------------- Output utilities ---------------- */
/* Write a sequence of bytes. */
-#define put_lit(s, bytes) px_put_bytes(s, bytes, sizeof(bytes))
+#define PX_PUT_LIT(s, bytes) px_put_bytes(s, bytes, sizeof(bytes))
private void
px_put_bytes(stream * s, const byte * data, uint count)
{
@@ -177,89 +177,105 @@ px_put_bytes(stream * s, const byte * data, uint count)
/* Utilities for writing data values. */
/* H-P printers only support little-endian data, so that's what we emit. */
-#define da(a) pxt_attr_ubyte, (a)
+#define DA(a) pxt_attr_ubyte, (a)
private void
-put_a(stream * s, px_attribute_t a)
+px_put_a(stream * s, px_attribute_t a)
{
sputc(s, pxt_attr_ubyte);
sputc(s, a);
}
-#define dub(b) pxt_ubyte, (byte)(b)
private void
-put_ub(stream * s, byte b)
+px_put_ac(stream *s, px_attribute_t a, px_tag_t op)
+{
+ px_put_a(s, a);
+ sputc(s, op);
+}
+
+#define DUB(b) pxt_ubyte, (byte)(b)
+private void
+px_put_ub(stream * s, byte b)
{
sputc(s, pxt_ubyte);
sputc(s, b);
}
-#define put_uba(s, b, a)\
- (put_ub(s, b), put_a(s, a))
-#define ds(i) (byte)(i), (byte)((i) >> 8)
private void
-put_s(stream * s, uint i)
+px_put_uba(stream *s, byte b, px_attribute_t a)
+{
+ px_put_ub(s, b);
+ px_put_a(s, a);
+}
+
+#define DS(i) (byte)(i), (byte)((i) >> 8)
+private void
+px_put_s(stream * s, uint i)
{
sputc(s, (byte) i);
sputc(s, (byte) (i >> 8));
}
-#define dus(i) pxt_uint16, ds(i)
+#define DUS(i) pxt_uint16, DS(i)
private void
-put_us(stream * s, uint i)
+px_put_us(stream * s, uint i)
{
sputc(s, pxt_uint16);
- put_s(s, i);
+ px_put_s(s, i);
+}
+private void
+px_put_usa(stream *s, uint i, px_attribute_t a)
+{
+ px_put_us(s, i);
+ px_put_a(s, a);
}
-#define put_usa(s, i, a)\
- (put_us(s, i), put_a(s, a))
private void
-put_u(stream * s, uint i)
+px_put_u(stream * s, uint i)
{
if (i <= 255)
- put_ub(s, i);
+ px_put_ub(s, i);
else
- put_us(s, i);
+ px_put_us(s, i);
}
-#define dusp(ix,iy) pxt_uint16_xy, ds(ix), ds(iy)
+
private void
-put_usp(stream * s, uint ix, uint iy)
+px_put_usp(stream * s, uint ix, uint iy)
{
- sputc(s, pxt_uint16_xy);
- put_s(s, ix);
- put_s(s, iy);
+ spputc(s, pxt_uint16_xy);
+ px_put_s(s, ix);
+ px_put_s(s, iy);
}
private void
-put_usq_fixed(stream * s, fixed x0, fixed y0, fixed x1, fixed y1)
+px_put_usq_fixed(stream * s, fixed x0, fixed y0, fixed x1, fixed y1)
{
- sputc(s, pxt_uint16_box);
- put_s(s, fixed2int(x0));
- put_s(s, fixed2int(y0));
- put_s(s, fixed2int(x1));
- put_s(s, fixed2int(y1));
+ spputc(s, pxt_uint16_box);
+ px_put_s(s, fixed2int(x0));
+ px_put_s(s, fixed2int(y0));
+ px_put_s(s, fixed2int(x1));
+ px_put_s(s, fixed2int(y1));
}
-#define dss(i) pxt_sint16, ds(i)
+
#if 0 /* NOT CURRENTLY USED */
private void
-put_ss(stream * s, int i)
+px_put_ss(stream * s, int i)
{
sputc(s, pxt_sint16);
- put_s(s, (uint) i);
+ px_put_s(s, (uint) i);
}
#endif
-#define dssp(ix,iy) pxt_sint16_xy, ds(ix), ds(iy)
private void
-put_ssp(stream * s, int ix, int iy)
+px_put_ssp(stream * s, int ix, int iy)
{
sputc(s, pxt_sint16_xy);
- put_s(s, (uint) ix);
- put_s(s, (uint) iy);
+ px_put_s(s, (uint) ix);
+ px_put_s(s, (uint) iy);
}
-#define dl(l) ds(l), ds((l) >> 16)
+
private void
-put_l(stream * s, ulong l)
+px_put_l(stream * s, ulong l)
{
- put_s(s, (uint) l);
- put_s(s, (uint) (l >> 16));
+ px_put_s(s, (uint) l);
+ px_put_s(s, (uint) (l >> 16));
}
+
private void
-put_r(stream * s, floatp r)
+px_put_r(stream * s, floatp r)
{ /* Convert to single-precision IEEE float. */
int exp;
long mantissa = (long)(frexp(r, &exp) * 0x1000000);
@@ -275,37 +291,37 @@ put_r(stream * s, floatp r)
spputc(s, (exp + 127) >> 1);
}
private void
-put_rl(stream * s, floatp r)
+px_put_rl(stream * s, floatp r)
{
- sputc(s, pxt_real32);
- put_r(s, r);
+ spputc(s, pxt_real32);
+ px_put_r(s, r);
}
+
private void
-put_data_length(stream * s, uint num_bytes)
+px_put_data_length(stream * s, uint num_bytes)
{
if (num_bytes > 255) {
spputc(s, pxt_dataLength);
- put_l(s, (ulong) num_bytes);
+ px_put_l(s, (ulong) num_bytes);
} else {
spputc(s, pxt_dataLengthByte);
spputc(s, (byte) num_bytes);
}
}
-#define put_ac(s, a, op)\
-BEGIN static const byte ac_[] = { da(a), op }; put_lit(s, ac_); END
-#define return_put_ac(s, a, op)\
-BEGIN put_ac(s, a, op); return 0; END
-
/* ---------------- Other utilities ---------------- */
-#define vxdev ((gx_device_vector *)xdev)
+inline private stream *
+pclxl_stream(gx_device_pclxl *xdev)
+{
+ return gdev_vector_stream((gx_device_vector *)xdev);
+}
/* Initialize for a page. */
private void
pclxl_page_init(gx_device_pclxl * xdev)
{
- gdev_vector_init(vxdev);
+ gdev_vector_init((gx_device_vector *)xdev);
xdev->in_page = false;
xdev->fill_rule = gx_path_type_winding_number;
xdev->clip_rule = gx_path_type_winding_number;
@@ -315,17 +331,17 @@ pclxl_page_init(gx_device_pclxl * xdev)
}
/* Test whether a RGB color is actually a gray shade. */
-#define rgb_is_gray(ci) ((ci) >> 8 == ((ci) & 0xffff))
+#define RGB_IS_GRAY(ci) ((ci) >> 8 == ((ci) & 0xffff))
/* Set the color space and (optionally) palette. */
private void
pclxl_set_color_space(gx_device_pclxl * xdev, pxeColorSpace_t color_space)
{
if (xdev->color_space != color_space) {
- stream *s = gdev_vector_stream(vxdev);
+ stream *s = pclxl_stream(xdev);
- put_ub(s, color_space);
- put_ac(s, pxaColorSpace, pxtSetColorSpace);
+ px_put_ub(s, color_space);
+ px_put_ac(s, pxaColorSpace, pxtSetColorSpace);
xdev->color_space = color_space;
}
}
@@ -337,19 +353,18 @@ pclxl_set_color_palette(gx_device_pclxl * xdev, pxeColorSpace_t color_space,
xdev->palette.size != palette_size ||
memcmp(xdev->palette.data, palette, palette_size)
) {
- stream *s = gdev_vector_stream(vxdev);
- static const byte csp_[] =
- {
- da(pxaColorSpace),
- dub(e8Bit), da(pxaPaletteDepth),
+ stream *s = pclxl_stream(xdev);
+ static const byte csp_[] = {
+ DA(pxaColorSpace),
+ DUB(e8Bit), DA(pxaPaletteDepth),
pxt_ubyte_array
};
- put_ub(s, color_space);
- put_lit(s, csp_);
- put_u(s, palette_size);
+ px_put_ub(s, color_space);
+ PX_PUT_LIT(s, csp_);
+ px_put_u(s, palette_size);
px_put_bytes(s, palette, palette_size);
- put_ac(s, pxaPaletteData, pxtSetColorSpace);
+ px_put_ac(s, pxaPaletteData, pxtSetColorSpace);
xdev->color_space = color_space;
xdev->palette.size = palette_size;
memcpy(xdev->palette.data, palette, palette_size);
@@ -361,25 +376,25 @@ private int
pclxl_set_color(gx_device_pclxl * xdev, const gx_drawing_color * pdc,
px_attribute_t null_source, px_tag_t op)
{
- stream *s = gdev_vector_stream(vxdev);
+ stream *s = pclxl_stream(xdev);
if (gx_dc_is_pure(pdc)) {
gx_color_index color = gx_dc_pure_color(pdc);
- if (xdev->color_info.num_components == 1 || rgb_is_gray(color)) {
+ if (xdev->color_info.num_components == 1 || RGB_IS_GRAY(color)) {
pclxl_set_color_space(xdev, eGray);
- put_uba(s, (byte) color, pxaGrayLevel);
+ px_put_uba(s, (byte) color, pxaGrayLevel);
} else {
pclxl_set_color_space(xdev, eRGB);
spputc(s, pxt_ubyte_array);
- put_ub(s, 3);
+ px_put_ub(s, 3);
spputc(s, (byte) (color >> 16));
spputc(s, (byte) (color >> 8));
spputc(s, (byte) color);
- put_a(s, pxaRGBColor);
+ px_put_a(s, pxaRGBColor);
}
} else if (gx_dc_is_null(pdc))
- put_uba(s, 0, null_source);
+ px_put_uba(s, 0, null_source);
else
return_error(gs_error_rangecheck);
spputc(s, op);
@@ -406,35 +421,33 @@ pclxl_can_handle_color_space(const gs_color_space * pcs)
private void
pclxl_set_paints(gx_device_pclxl * xdev, gx_path_type_t type)
{
- stream *s = gdev_vector_stream(vxdev);
+ stream *s = pclxl_stream(xdev);
gx_path_type_t rule = type & gx_path_type_rule;
if (!(type & gx_path_type_fill) &&
!gx_dc_is_null(&xdev->fill_color)
) {
- static const byte nac_[] =
- {
- dub(0), da(pxaNullBrush), pxtSetBrushSource
+ static const byte nac_[] = {
+ DUB(0), DA(pxaNullBrush), pxtSetBrushSource
};
- put_lit(s, nac_);
+ PX_PUT_LIT(s, nac_);
color_set_null(&xdev->fill_color);
if (rule != xdev->fill_rule) {
- put_ub(s, (rule == gx_path_type_even_odd ? eEvenOdd :
+ px_put_ub(s, (rule == gx_path_type_even_odd ? eEvenOdd :
eNonZeroWinding));
- put_ac(s, pxaFillMode, pxtSetFillMode);
+ px_put_ac(s, pxaFillMode, pxtSetFillMode);
xdev->fill_rule = rule;
}
}
if (!(type & gx_path_type_stroke) &&
!gx_dc_is_null(&xdev->stroke_color)
) {
- static const byte nac_[] =
- {
- dub(0), da(pxaNullPen), pxtSetPenSource
+ static const byte nac_[] = {
+ DUB(0), DA(pxaNullPen), pxtSetPenSource
};
- put_lit(s, nac_);
+ PX_PUT_LIT(s, nac_);
color_set_null(&xdev->stroke_color);
}
}
@@ -443,20 +456,21 @@ pclxl_set_paints(gx_device_pclxl * xdev, gx_path_type_t type)
private int
pclxl_set_cursor(gx_device_pclxl * xdev, int x, int y)
{
- stream *s = gdev_vector_stream(vxdev);
+ stream *s = pclxl_stream(xdev);
- put_ssp(s, x, y);
- return_put_ac(s, pxaPoint, pxtSetCursor);
+ px_put_ssp(s, x, y);
+ px_put_ac(s, pxaPoint, pxtSetCursor);
+ return 0;
}
/* ------ Paths ------ */
/* Flush any buffered path points. */
private void
-put_np(stream * s, int count, pxeDataType_t dtype)
+px_put_np(stream * s, int count, pxeDataType_t dtype)
{
- put_uba(s, count, pxaNumberOfPoints);
- put_uba(s, dtype, pxaPointType);
+ px_put_uba(s, count, pxaNumberOfPoints);
+ px_put_uba(s, dtype, pxaPointType);
}
private int
pclxl_flush_points(gx_device_pclxl * xdev)
@@ -464,13 +478,13 @@ pclxl_flush_points(gx_device_pclxl * xdev)
int count = xdev->points.count;
if (count) {
- stream *s = gdev_vector_stream(vxdev);
+ stream *s = pclxl_stream(xdev);
px_tag_t op;
int x = xdev->points.current.x, y = xdev->points.current.y;
int uor = 0, sor = 0;
pxeDataType_t data_type;
int i, di;
- byte diffs[num_points * 2];
+ byte diffs[NUM_POINTS * 2];
/*
* Writing N lines using a point list requires 11 + 4*N or 11 +
@@ -484,15 +498,15 @@ pclxl_flush_points(gx_device_pclxl * xdev)
* coordinates).
*/
switch (xdev->points.type) {
- case points_none:
+ case POINTS_NONE:
return 0;
- case points_lines:
+ case POINTS_LINES:
op = pxtLinePath;
if (count < 3) {
for (i = 0; i < count; ++i) {
- put_ssp(s, xdev->points.data[i].x,
+ px_put_ssp(s, xdev->points.data[i].x,
xdev->points.data[i].y);
- put_a(s, pxaEndPoint);
+ px_put_a(s, pxaEndPoint);
spputc(s, op);
}
goto zap;
@@ -516,12 +530,12 @@ pclxl_flush_points(gx_device_pclxl * xdev)
break;
op = pxtLineRelPath;
/* Use byte values. */
- useb:put_np(s, count, data_type);
+ useb:px_put_np(s, count, data_type);
spputc(s, op);
- put_data_length(s, count * 2); /* 2 bytes per point */
+ px_put_data_length(s, count * 2); /* 2 bytes per point */
px_put_bytes(s, diffs, count * 2);
goto zap;
- case points_curves:
+ case POINTS_CURVES:
op = pxtBezierPath;
/* See if we can use byte values. */
for (i = di = 0; i < count; i += 3, di += 6) {
@@ -555,14 +569,14 @@ pclxl_flush_points(gx_device_pclxl * xdev)
default: /* can't happen */
return_error(gs_error_unknownerror);
}
- put_np(s, count, eSInt16);
+ px_put_np(s, count, eSInt16);
spputc(s, op);
- put_data_length(s, count * 4); /* 2 UInt16s per point */
+ px_put_data_length(s, count * 4); /* 2 UInt16s per point */
for (i = 0; i < count; ++i) {
- put_s(s, xdev->points.data[i].x);
- put_s(s, xdev->points.data[i].y);
+ px_put_s(s, xdev->points.data[i].x);
+ px_put_s(s, xdev->points.data[i].y);
}
- zap:xdev->points.type = points_none;
+ zap:xdev->points.type = POINTS_NONE;
xdev->points.count = 0;
}
return 0;
@@ -572,8 +586,7 @@ pclxl_flush_points(gx_device_pclxl * xdev)
private image_enum_proc_plane_data(pclxl_image_plane_data);
private image_enum_proc_end_image(pclxl_image_end_image);
-private const gx_image_enum_procs_t pclxl_image_enum_procs =
-{
+private const gx_image_enum_procs_t pclxl_image_enum_procs = {
pclxl_image_plane_data, pclxl_image_end_image
};
@@ -582,12 +595,12 @@ private void
pclxl_write_begin_image(gx_device_pclxl * xdev, uint width, uint height,
uint dest_width, uint dest_height)
{
- stream *s = gdev_vector_stream(vxdev);
+ stream *s = pclxl_stream(xdev);
- put_usa(s, width, pxaSourceWidth);
- put_usa(s, height, pxaSourceHeight);
- put_usp(s, dest_width, dest_height);
- put_ac(s, pxaDestinationSize, pxtBeginImage);
+ px_put_usa(s, width, pxaSourceWidth);
+ px_put_usa(s, height, pxaSourceHeight);
+ px_put_usp(s, dest_width, dest_height);
+ px_put_ac(s, pxaDestinationSize, pxtBeginImage);
}
/* Write rows of an image. */
@@ -596,21 +609,21 @@ private void
pclxl_write_image_data(gx_device_pclxl * xdev, const byte * data, int data_bit,
uint raster, uint width_bits, int y, int height)
{
- stream *s = gdev_vector_stream(vxdev);
+ stream *s = pclxl_stream(xdev);
uint width_bytes = (width_bits + 7) >> 3;
- bool compress = width_bytes >= 8;
- uint num_bytes = round_up(width_bytes, 4) * height;
+ uint num_bytes = ROUND_UP(width_bytes, 4) * height;
+ bool compress = num_bytes >= 8;
int i;
- put_usa(s, y, pxaStartLine);
- put_usa(s, height, pxaBlockHeight);
+ px_put_usa(s, y, pxaStartLine);
+ px_put_usa(s, height, pxaBlockHeight);
if (compress) {
stream_RLE_state rlstate;
stream_cursor_write w;
stream_cursor_read r;
/*
- * H-P printers required that all the data for an operator be
+ * H-P printers require that all the data for an operator be
* contained in a single data block. Thus, we must allocate
* a temporary buffer for the compressed data. Currently we
* don't go to the trouble of breaking the data up into scan
@@ -656,9 +669,9 @@ pclxl_write_image_data(gx_device_pclxl * xdev, const byte * data, int data_bit,
{
uint count = w.ptr + 1 - buf;
- put_ub(s, eRLECompression);
- put_ac(s, pxaCompressMode, pxtReadImage);
- put_data_length(s, count);
+ px_put_ub(s, eRLECompression);
+ px_put_ac(s, pxaCompressMode, pxtReadImage);
+ px_put_data_length(s, count);
px_put_bytes(s, buf, count);
}
return;
@@ -666,9 +679,9 @@ pclxl_write_image_data(gx_device_pclxl * xdev, const byte * data, int data_bit,
nc:;
}
/* Write the data uncompressed. */
- put_ub(s, eNoCompression);
- put_ac(s, pxaCompressMode, pxtReadImage);
- put_data_length(s, num_bytes);
+ px_put_ub(s, eNoCompression);
+ px_put_ac(s, pxaCompressMode, pxtReadImage);
+ px_put_data_length(s, num_bytes);
for (i = 0; i < height; ++i) {
px_put_bytes(s, data + i * raster, width_bytes);
px_put_bytes(s, (const byte *)"\000\000\000\000", -width_bytes & 3);
@@ -686,95 +699,92 @@ pclxl_write_end_image(gx_device_pclxl * xdev)
/* Write a string (single- or double-byte). */
private void
-put_string(stream * s, const byte * data, uint len, bool wide)
+px_put_string(stream * s, const byte * data, uint len, bool wide)
{
if (wide) {
spputc(s, pxt_uint16_array);
- put_u(s, len);
+ px_put_u(s, len);
px_put_bytes(s, data, len * 2);
} else {
spputc(s, pxt_ubyte_array);
- put_u(s, len);
+ px_put_u(s, len);
px_put_bytes(s, data, len);
}
}
/* Write a 16-bit big-endian value. */
private void
-put_us_be(stream * s, uint i)
+px_put_us_be(stream * s, uint i)
{
spputc(s, (byte) (i >> 8));
spputc(s, (byte) i);
}
-/* Define a bitmap font. The client must call put_string */
+/* Define a bitmap font. The client must call px_put_string */
/* with the font name immediately before calling this procedure. */
private void
pclxl_define_bitmap_font(gx_device_pclxl * xdev)
{
- stream *s = gdev_vector_stream(vxdev);
- static const byte bfh_[] =
- {
- da(pxaFontName), dub(0), da(pxaFontFormat),
+ stream *s = pclxl_stream(xdev);
+ static const byte bfh_[] = {
+ DA(pxaFontName), DUB(0), DA(pxaFontFormat),
pxtBeginFontHeader,
- dus(8 + 6 + 4 + 6), da(pxaFontHeaderLength),
+ DUS(8 + 6 + 4 + 6), DA(pxaFontHeaderLength),
pxtReadFontHeader,
pxt_dataLengthByte, 8 + 6 + 4 + 6,
0, 0, 0, 0,
- 254, 0, (max_cached_chars + 255) >> 8, 0,
+ 254, 0, (MAX_CACHED_CHARS + 255) >> 8, 0,
'B', 'R', 0, 0, 0, 4
};
- static const byte efh_[] =
- {
+ static const byte efh_[] = {
0xff, 0xff, 0, 0, 0, 0,
pxtEndFontHeader
};
- put_lit(s, bfh_);
- put_us_be(s, (uint) (xdev->HWResolution[0] + 0.5));
- put_us_be(s, (uint) (xdev->HWResolution[1] + 0.5));
- put_lit(s, efh_);
+ PX_PUT_LIT(s, bfh_);
+ px_put_us_be(s, (uint) (xdev->HWResolution[0] + 0.5));
+ px_put_us_be(s, (uint) (xdev->HWResolution[1] + 0.5));
+ PX_PUT_LIT(s, efh_);
}
-/* Set the font. The client must call put_string */
+/* Set the font. The client must call px_put_string */
/* with the font name immediately before calling this procedure. */
private void
pclxl_set_font(gx_device_pclxl * xdev)
{
- stream *s = gdev_vector_stream(vxdev);
- static const byte sf_[] =
- {
- da(pxaFontName), dub(1), da(pxaCharSize), dus(0), da(pxaSymbolSet),
+ stream *s = pclxl_stream(xdev);
+ static const byte sf_[] = {
+ DA(pxaFontName), DUB(1), DA(pxaCharSize), DUS(0), DA(pxaSymbolSet),
pxtSetFont
};
- put_lit(s, sf_);
+ PX_PUT_LIT(s, sf_);
}
-/* Define a character in a bitmap font. The client must call put_string */
+/* Define a character in a bitmap font. The client must call px_put_string */
/* with the font name immediately before calling this procedure. */
private void
pclxl_define_bitmap_char(gx_device_pclxl * xdev, uint ccode,
const byte * data, uint raster, uint width_bits, uint height)
{
- stream *s = gdev_vector_stream(vxdev);
+ stream *s = pclxl_stream(xdev);
uint width_bytes = (width_bits + 7) >> 3;
uint size = 10 + width_bytes * height;
uint i;
- put_ac(s, pxaFontName, pxtBeginChar);
- put_u(s, ccode);
- put_a(s, pxaCharCode);
+ px_put_ac(s, pxaFontName, pxtBeginChar);
+ px_put_u(s, ccode);
+ px_put_a(s, pxaCharCode);
if (size > 0xffff) {
spputc(s, pxt_uint32);
- put_l(s, (ulong) size);
+ px_put_l(s, (ulong) size);
} else
- put_us(s, size);
- put_ac(s, pxaCharDataSize, pxtReadChar);
- put_data_length(s, size);
+ px_put_us(s, size);
+ px_put_ac(s, pxaCharDataSize, pxtReadChar);
+ px_put_data_length(s, size);
px_put_bytes(s, (const byte *)"\000\000\000\000\000\000", 6);
- put_us_be(s, width_bits);
- put_us_be(s, height);
+ px_put_us_be(s, width_bits);
+ px_put_us_be(s, height);
for (i = 0; i < height; ++i)
px_put_bytes(s, data + i * raster, width_bytes);
spputc(s, pxtEndChar);
@@ -784,9 +794,9 @@ pclxl_define_bitmap_char(gx_device_pclxl * xdev, uint ccode,
private void
pclxl_write_font_name(gx_device_pclxl * xdev)
{
- stream *s = gdev_vector_stream(vxdev);
+ stream *s = pclxl_stream(xdev);
- put_string(s, (const byte *)"@", 1, false);
+ px_put_string(s, (const byte *)"@", 1, false);
}
/* Look up a bitmap id, return the index in the character table. */
@@ -797,7 +807,7 @@ pclxl_char_index(gx_device_pclxl * xdev, gs_id id)
int i, i_empty = -1;
uint ccode;
- for (i = (id * char_hash_factor) % countof(xdev->chars.table);;
+ for (i = (id * CHAR_HASH_FACTOR) % countof(xdev->chars.table);;
i = (i == 0 ? countof(xdev->chars.table) : i) - 1
) {
ccode = xdev->chars.table[i];
@@ -847,21 +857,21 @@ pclxl_copy_text_char(gx_device_pclxl * xdev, const byte * data,
uint size = width_bytes * h;
int index;
uint ccode;
- stream *s = gdev_vector_stream(vxdev);
+ stream *s = pclxl_stream(xdev);
- if (size > max_char_size)
+ if (size > MAX_CHAR_SIZE)
return -1;
index = pclxl_char_index(xdev, id);
if ((ccode = xdev->chars.table[index]) < 2) {
/* Enter the character in the table. */
- while (xdev->chars.used + size > max_char_data ||
- xdev->chars.count >= max_cached_chars - 2
+ while (xdev->chars.used + size > MAX_CHAR_DATA ||
+ xdev->chars.count >= MAX_CACHED_CHARS - 2
) {
ccode = xdev->chars.next_out;
index = pclxl_char_index(xdev, xdev->chars.data[ccode].id);
pclxl_remove_char(xdev, index);
xdev->chars.next_out =
- (ccode == max_cached_chars - 1 ? 2 : ccode + 1);
+ (ccode == MAX_CACHED_CHARS - 1 ? 2 : ccode + 1);
}
index = pclxl_char_index(xdev, id);
ccode = xdev->chars.next_in;
@@ -869,7 +879,7 @@ pclxl_copy_text_char(gx_device_pclxl * xdev, const byte * data,
xdev->chars.data[ccode].size = size;
xdev->chars.table[index] = ccode;
xdev->chars.next_in =
- (ccode == max_cached_chars - 1 ? 2 : ccode + 1);
+ (ccode == MAX_CACHED_CHARS - 1 ? 2 : ccode + 1);
if (!xdev->chars.count++) {
/* This is the very first character. */
pclxl_write_font_name(xdev);
@@ -888,44 +898,44 @@ pclxl_copy_text_char(gx_device_pclxl * xdev, const byte * data,
cc_bytes[0] = (byte) ccode;
cc_bytes[1] = ccode >> 8;
- put_string(s, cc_bytes, 1, cc_bytes[1] != 0);
+ px_put_string(s, cc_bytes, 1, cc_bytes[1] != 0);
}
- put_ac(s, pxaTextData, pxtText);
+ px_put_ac(s, pxaTextData, pxtText);
return 0;
}
/* ---------------- Vector implementation procedures ---------------- */
-#define xvdev ((gx_device_pclxl *)vdev)
-
private int
pclxl_beginpage(gx_device_vector * vdev)
-{ /*
- * We can't use gdev_vector_stream here, because this may be called
- * from there before in_page is set.
- */
+{
+ gx_device_pclxl *const xdev = (gx_device_pclxl *)vdev;
+ /*
+ * We can't use gdev_vector_stream here, because this may be called
+ * from there before in_page is set.
+ */
stream *s = vdev->strm;
{
- static const byte page_header_1[] =
- {
- dub(ePortraitOrientation), da(pxaOrientation),
+ static const byte page_header_1[] = {
+ DUB(ePortraitOrientation), DA(pxaOrientation),
};
- put_lit(s, page_header_1);
+ PX_PUT_LIT(s, page_header_1);
}
{
-#define msd(ms, res, w, h)\
+#define MSD(ms, res, w, h)\
{ ms, (w) * 1.0 / (res), (h) * 1.0 / res },
static const struct {
pxeMediaSize_t ms;
float width, height;
} media_sizes[] = {
- px_enumerate_media(msd) {
- pxeMediaSize_next
- }
+ px_enumerate_media(MSD)
+ { pxeMediaSize_next }
};
- float w = vdev->width / vdev->HWResolution[0], h = vdev->height / vdev->HWResolution[1];
+#undef MSD
+ float w = vdev->width / vdev->HWResolution[0],
+ h = vdev->height / vdev->HWResolution[1];
int i;
pxeMediaSize_t size;
@@ -940,15 +950,14 @@ pclxl_beginpage(gx_device_vector * vdev)
* According to the PCL XL documentation, MediaSize must always
* be specified, but MediaSource is optional.
*/
- put_uba(s, size, pxaMediaSize);
- if (size != xvdev->media_size) {
- static const byte page_header_2[] =
- {
- dub(eAutoSelect), da(pxaMediaSource)
+ px_put_uba(s, size, pxaMediaSize);
+ if (size != xdev->media_size) {
+ static const byte page_header_2[] = {
+ DUB(eAutoSelect), DA(pxaMediaSource)
};
- put_lit(s, page_header_2);
- xvdev->media_size = size;
+ PX_PUT_LIT(s, page_header_2);
+ xdev->media_size = size;
}
}
spputc(s, pxtBeginPage);
@@ -960,8 +969,9 @@ pclxl_setlinewidth(gx_device_vector * vdev, floatp width)
{
stream *s = gdev_vector_stream(vdev);
- put_us(s, (uint) width);
- return_put_ac(s, pxaPenWidth, pxtSetPenWidth);
+ px_put_us(s, (uint) width);
+ px_put_ac(s, pxaPenWidth, pxtSetPenWidth);
+ return 0;
}
private int
@@ -970,8 +980,9 @@ pclxl_setlinecap(gx_device_vector * vdev, gs_line_cap cap)
stream *s = gdev_vector_stream(vdev);
/* The PCL XL cap styles just happen to be identical to PostScript. */
- put_ub(s, (byte) cap);
- return_put_ac(s, pxaLineCapStyle, pxtSetLineCap);
+ px_put_ub(s, (byte) cap);
+ px_put_ac(s, pxaLineCapStyle, pxtSetLineCap);
+ return 0;
}
private int
@@ -980,23 +991,24 @@ pclxl_setlinejoin(gx_device_vector * vdev, gs_line_join join)
stream *s = gdev_vector_stream(vdev);
/* The PCL XL join styles just happen to be identical to PostScript. */
- put_ub(s, (byte) join);
- return_put_ac(s, pxaLineJoinStyle, pxtSetLineJoin);
+ px_put_ub(s, (byte) join);
+ px_put_ac(s, pxaLineJoinStyle, pxtSetLineJoin);
+ return 0;
}
private int
pclxl_setmiterlimit(gx_device_vector * vdev, floatp limit)
{
stream *s = gdev_vector_stream(vdev);
-
/*
* Amazingly enough, the PCL XL specification doesn't allow real
* numbers for the miter limit.
*/
int i_limit = (int)(limit + 0.5);
- put_u(s, max(i_limit, 1));
- return_put_ac(s, pxaMiterLength, pxtSetMiterLimit);
+ px_put_u(s, max(i_limit, 1));
+ px_put_ac(s, pxaMiterLength, pxtSetMiterLimit);
+ return 0;
}
private int
@@ -1006,23 +1018,28 @@ pclxl_setdash(gx_device_vector * vdev, const float *pattern, uint count,
stream *s = gdev_vector_stream(vdev);
if (count == 0) {
- static const byte nac_[] =
- {dub(0), da(pxaSolidLine)};
+ static const byte nac_[] = {
+ DUB(0), DA(pxaSolidLine)
+ };
- put_lit(s, nac_);
+ PX_PUT_LIT(s, nac_);
} else if (count > 255)
return_error(gs_error_limitcheck);
else {
uint i;
- spputc(s, pxt_real32_array);
- put_ub(s, count);
+ /*
+ * Astoundingly, PCL XL doesn't allow real numbers here.
+ * Do the best we can.
+ */
+ spputc(s, pxt_uint16_array);
+ px_put_ub(s, count);
for (i = 0; i < count; ++i)
- put_r(s, pattern[i]);
- put_a(s, pxaLineDashStyle);
+ px_put_s(s, (uint)pattern[i]);
+ px_put_a(s, pxaLineDashStyle);
if (offset != 0) {
- put_rl(s, offset);
- put_a(s, pxaDashOffset);
+ px_put_rl(s, offset);
+ px_put_a(s, pxaDashOffset);
}
}
spputc(s, pxtSetLineDash);
@@ -1036,16 +1053,16 @@ pclxl_setlogop(gx_device_vector * vdev, gs_logical_operation_t lop,
stream *s = gdev_vector_stream(vdev);
if (diff & lop_S_transparent) {
- put_ub(s, (lop & lop_S_transparent ? 1 : 0));
- put_ac(s, pxaTxMode, pxtSetSourceTxMode);
+ px_put_ub(s, (lop & lop_S_transparent ? 1 : 0));
+ px_put_ac(s, pxaTxMode, pxtSetSourceTxMode);
}
if (diff & lop_T_transparent) {
- put_ub(s, (lop & lop_T_transparent ? 1 : 0));
- put_ac(s, pxaTxMode, pxtSetPaintTxMode);
+ px_put_ub(s, (lop & lop_T_transparent ? 1 : 0));
+ px_put_ac(s, pxaTxMode, pxtSetPaintTxMode);
}
if (lop_rop(diff)) {
- put_ub(s, lop_rop(lop));
- put_ac(s, pxaROP3, pxtSetROP);
+ px_put_ub(s, lop_rop(lop));
+ px_put_ac(s, pxaROP3, pxtSetROP);
}
return 0;
}
@@ -1053,36 +1070,40 @@ pclxl_setlogop(gx_device_vector * vdev, gs_logical_operation_t lop,
private int
pclxl_setfillcolor(gx_device_vector * vdev, const gx_drawing_color * pdc)
{
- return pclxl_set_color(xvdev, pdc, pxaNullBrush, pxtSetBrushSource);
+ gx_device_pclxl *const xdev = (gx_device_pclxl *)vdev;
+
+ return pclxl_set_color(xdev, pdc, pxaNullBrush, pxtSetBrushSource);
}
private int
pclxl_setstrokecolor(gx_device_vector * vdev, const gx_drawing_color * pdc)
{
- return pclxl_set_color(xvdev, pdc, pxaNullPen, pxtSetPenSource);
+ gx_device_pclxl *const xdev = (gx_device_pclxl *)vdev;
+
+ return pclxl_set_color(xdev, pdc, pxaNullPen, pxtSetPenSource);
}
private int
pclxl_dorect(gx_device_vector * vdev, fixed x0, fixed y0, fixed x1,
fixed y1, gx_path_type_t type)
{
+ gx_device_pclxl *const xdev = (gx_device_pclxl *)vdev;
stream *s = gdev_vector_stream(vdev);
if (type & (gx_path_type_fill | gx_path_type_stroke)) {
- pclxl_set_paints(xvdev, type);
- put_usq_fixed(s, x0, y0, x1, y1);
- put_ac(s, pxaBoundingBox, pxtRectangle);
+ pclxl_set_paints(xdev, type);
+ px_put_usq_fixed(s, x0, y0, x1, y1);
+ px_put_ac(s, pxaBoundingBox, pxtRectangle);
}
if (type & gx_path_type_clip) {
- static const byte cr_[] =
- {
- da(pxaBoundingBox),
- dub(eInterior), da(pxaClipRegion),
+ static const byte cr_[] = {
+ DA(pxaBoundingBox),
+ DUB(eInterior), DA(pxaClipRegion),
pxtSetClipRectangle
};
- put_usq_fixed(s, x0, y0, x1, y1);
- put_lit(s, cr_);
+ px_put_usq_fixed(s, x0, y0, x1, y1);
+ PX_PUT_LIT(s, cr_);
}
return 0;
}
@@ -1090,11 +1111,12 @@ pclxl_dorect(gx_device_vector * vdev, fixed x0, fixed y0, fixed x1,
private int
pclxl_beginpath(gx_device_vector * vdev, gx_path_type_t type)
{
+ gx_device_pclxl *const xdev = (gx_device_pclxl *)vdev;
stream *s = gdev_vector_stream(vdev);
spputc(s, pxtNewPath);
- xvdev->points.type = points_none;
- xvdev->points.count = 0;
+ xdev->points.type = POINTS_NONE;
+ xdev->points.count = 0;
return 0;
}
@@ -1102,33 +1124,36 @@ private int
pclxl_moveto(gx_device_vector * vdev, floatp x0, floatp y0, floatp x, floatp y,
gx_path_type_t type)
{
- int code = pclxl_flush_points(xvdev);
+ gx_device_pclxl *const xdev = (gx_device_pclxl *)vdev;
+ int code = pclxl_flush_points(xdev);
if (code < 0)
return code;
- return pclxl_set_cursor(xvdev,
- xvdev->points.current.x = (int)x,
- xvdev->points.current.y = (int)y);
+ return pclxl_set_cursor(xdev,
+ xdev->points.current.x = (int)x,
+ xdev->points.current.y = (int)y);
}
private int
pclxl_lineto(gx_device_vector * vdev, floatp x0, floatp y0, floatp x, floatp y,
gx_path_type_t type)
{
- if (xvdev->points.type != points_lines ||
- xvdev->points.count >= num_points
+ gx_device_pclxl *const xdev = (gx_device_pclxl *)vdev;
+
+ if (xdev->points.type != POINTS_LINES ||
+ xdev->points.count >= NUM_POINTS
) {
- if (xvdev->points.type != points_none) {
- int code = pclxl_flush_points(xvdev);
+ if (xdev->points.type != POINTS_NONE) {
+ int code = pclxl_flush_points(xdev);
if (code < 0)
return code;
}
- xvdev->points.current.x = (int)x0;
- xvdev->points.current.y = (int)y0;
- xvdev->points.type = points_lines;
+ xdev->points.current.x = (int)x0;
+ xdev->points.current.y = (int)y0;
+ xdev->points.type = POINTS_LINES;
} {
- gs_int_point *ppt = &xvdev->points.data[xvdev->points.count++];
+ gs_int_point *ppt = &xdev->points.data[xdev->points.count++];
ppt->x = (int)x, ppt->y = (int)y;
}
@@ -1140,26 +1165,29 @@ pclxl_curveto(gx_device_vector * vdev, floatp x0, floatp y0,
floatp x1, floatp y1, floatp x2, floatp y2, floatp x3, floatp y3,
gx_path_type_t type)
{
- if (xvdev->points.type != points_curves ||
- xvdev->points.count >= num_points - 2
+ gx_device_pclxl *const xdev = (gx_device_pclxl *)vdev;
+
+ if (xdev->points.type != POINTS_CURVES ||
+ xdev->points.count >= NUM_POINTS - 2
) {
- if (xvdev->points.type != points_none) {
- int code = pclxl_flush_points(xvdev);
+ if (xdev->points.type != POINTS_NONE) {
+ int code = pclxl_flush_points(xdev);
if (code < 0)
return code;
}
- xvdev->points.current.x = (int)x0;
- xvdev->points.current.y = (int)y0;
- xvdev->points.type = points_curves;
- } {
- gs_int_point *ppt = &xvdev->points.data[xvdev->points.count];
+ xdev->points.current.x = (int)x0;
+ xdev->points.current.y = (int)y0;
+ xdev->points.type = POINTS_CURVES;
+ }
+ {
+ gs_int_point *ppt = &xdev->points.data[xdev->points.count];
ppt->x = (int)x1, ppt->y = (int)y1, ++ppt;
ppt->x = (int)x2, ppt->y = (int)y2, ++ppt;
ppt->x = (int)x3, ppt->y = (int)y3;
}
- xvdev->points.count += 3;
+ xdev->points.count += 3;
return 0;
}
@@ -1167,51 +1195,51 @@ private int
pclxl_closepath(gx_device_vector * vdev, floatp x, floatp y,
floatp x_start, floatp y_start, gx_path_type_t type)
{
+ gx_device_pclxl *const xdev = (gx_device_pclxl *)vdev;
stream *s = gdev_vector_stream(vdev);
- int code = pclxl_flush_points(xvdev);
+ int code = pclxl_flush_points(xdev);
if (code < 0)
return code;
spputc(s, pxtCloseSubPath);
- xvdev->points.current.x = (int)x_start;
- xvdev->points.current.y = (int)y_start;
+ xdev->points.current.x = (int)x_start;
+ xdev->points.current.y = (int)y_start;
return 0;
}
private int
pclxl_endpath(gx_device_vector * vdev, gx_path_type_t type)
{
+ gx_device_pclxl *const xdev = (gx_device_pclxl *)vdev;
stream *s = gdev_vector_stream(vdev);
- int code = pclxl_flush_points(xvdev);
+ int code = pclxl_flush_points(xdev);
gx_path_type_t rule = type & gx_path_type_rule;
if (code < 0)
return code;
if (type & (gx_path_type_fill | gx_path_type_stroke)) {
- pclxl_set_paints(xvdev, type);
+ pclxl_set_paints(xdev, type);
spputc(s, pxtPaintPath);
}
if (type & gx_path_type_clip) {
- static const byte scr_[] =
- {
- dub(eInterior), da(pxaClipRegion), pxtSetClipReplace
+ static const byte scr_[] = {
+ DUB(eInterior), DA(pxaClipRegion), pxtSetClipReplace
};
- if (rule != xvdev->clip_rule) {
- put_ub(s, (rule == gx_path_type_even_odd ? eEvenOdd :
+ if (rule != xdev->clip_rule) {
+ px_put_ub(s, (rule == gx_path_type_even_odd ? eEvenOdd :
eNonZeroWinding));
- put_ac(s, pxaClipMode, pxtSetClipMode);
- xvdev->clip_rule = rule;
+ px_put_ac(s, pxaClipMode, pxtSetClipMode);
+ xdev->clip_rule = rule;
}
- put_lit(s, scr_);
+ PX_PUT_LIT(s, scr_);
}
return 0;
}
/* Vector implementation procedures */
-private const gx_device_vector_procs pclxl_vector_procs =
-{
+private const gx_device_vector_procs pclxl_vector_procs = {
/* Page management */
pclxl_beginpage,
/* Imager state */
@@ -1238,27 +1266,25 @@ private const gx_device_vector_procs pclxl_vector_procs =
/* ---------------- Driver procedures ---------------- */
-#define vdev ((gx_device_vector *)dev)
-#define xdev ((gx_device_pclxl *)dev)
-
/* ------ Open/close/page ------ */
/* Open the device. */
private int
pclxl_open_device(gx_device * dev)
{
+ gx_device_vector *const vdev = (gx_device_vector *)dev;
+ gx_device_pclxl *const xdev = (gx_device_pclxl *)dev;
int code;
static const char *const file_header =
- "\033%-12345X@PJL ENTER LANGUAGE = PCLXL\n\
+ "\033%-12345X@PJL ENTER LANGUAGE = PCLXL\n\
) HP-PCL XL;1;1;Comment Copyright Aladdin Enterprises 1996\000\n";
- static const byte stream_header[] =
- {
- da(pxaUnitsPerMeasure),
- dub(0), da(pxaMeasure),
- dub(eBackChAndErrPage), da(pxaErrorReport),
+ static const byte stream_header[] = {
+ DA(pxaUnitsPerMeasure),
+ DUB(0), DA(pxaMeasure),
+ DUB(eBackChAndErrPage), DA(pxaErrorReport),
pxtBeginSession,
- dub(0), da(pxaSourceType),
- dub(eBinaryLowByteFirst), da(pxaDataOrg),
+ DUB(0), DA(pxaSourceType),
+ DUB(eBinaryLowByteFirst), DA(pxaDataOrg),
pxtOpenDataSource
};
@@ -1275,10 +1301,10 @@ pclxl_open_device(gx_device * dev)
/* We have to add 2 to the strlen because the next-to-last */
/* character is a null. */
px_put_bytes(s, (const byte *)file_header,
- strlen(file_header) + 2);
- put_usp(s, (uint) (dev->HWResolution[0] + 0.5),
- (uint) (dev->HWResolution[1] + 0.5));
- put_lit(s, stream_header);
+ strlen(file_header) + 2);
+ px_put_usp(s, (uint) (dev->HWResolution[0] + 0.5),
+ (uint) (dev->HWResolution[1] + 0.5));
+ PX_PUT_LIT(s, stream_header);
}
xdev->media_size = pxeMediaSize_next; /* no size selected */
memset(&xdev->chars, 0, sizeof(xdev->chars));
@@ -1291,15 +1317,17 @@ pclxl_open_device(gx_device * dev)
private int
pclxl_output_page(gx_device * dev, int num_copies, int flush)
{
- if (xdev->in_page) {
- stream *s = vdev->strm;
+ gx_device_pclxl *const xdev = (gx_device_pclxl *)dev;
+ stream *s;
- spputc(s, pxtEndPage);
- sflush(s);
- pclxl_page_init(xdev);
- return gx_finish_output_page(dev, num_copies, flush);
- }
- return 0;
+ /* Note that unlike close_device, end_page must not omit blank pages. */
+ if (!xdev->in_page)
+ pclxl_beginpage((gx_device_vector *)dev);
+ s = xdev->strm;
+ spputc(s, pxtEndPage);
+ sflush(s);
+ pclxl_page_init(xdev);
+ return gx_finish_output_page(dev, num_copies, flush);
}
/* Close the device. */
@@ -1308,13 +1336,13 @@ pclxl_output_page(gx_device * dev, int num_copies, int flush)
private int
pclxl_close_device(gx_device * dev)
{
- FILE *file = vdev->file;
+ gx_device_pclxl *const xdev = (gx_device_pclxl *)dev;
+ FILE *file = xdev->file;
if (xdev->in_page)
fputc(pxtEndPage, file);
{
- static const byte file_trailer[] =
- {
+ static const byte file_trailer[] = {
pxtCloseDataSource,
pxtEndSession,
033, '%', '-', '1', '2', '3', '4', '5', 'X'
@@ -1323,23 +1351,24 @@ pclxl_close_device(gx_device * dev)
/* The stream may no longer exist: see above. */
fwrite(file_trailer, 1, sizeof(file_trailer), file);
}
- gdev_vector_close_file(vdev);
+ gdev_vector_close_file((gx_device_vector *)dev);
return 0;
}
/* ------ One-for-one images ------ */
-private const byte eBit_values[] =
-{
+private const byte eBit_values[] = {
0, e1Bit, 0, 0, e4Bit, 0, 0, 0, e8Bit
};
/* Copy a monochrome bitmap. */
private int
-pclxl_copy_mono(gx_device * dev, const byte * data,
- int data_x, int raster, gx_bitmap_id id, int x, int y, int w, int h,
+pclxl_copy_mono(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 zero, gx_color_index one)
{
+ gx_device_vector *const vdev = (gx_device_vector *)dev;
+ gx_device_pclxl *const xdev = (gx_device_pclxl *)dev;
int code;
stream *s;
gx_color_index color0 = zero, color1 = one;
@@ -1359,7 +1388,7 @@ pclxl_copy_mono(gx_device * dev, const byte * data,
gx_drawing_color dcolor;
color_set_pure(&dcolor, one);
- pclxl_setfillcolor(vxdev, &dcolor);
+ pclxl_setfillcolor(vdev, &dcolor);
if (pclxl_copy_text_char(xdev, data, raster, id, w, h) >= 0)
return 0;
}
@@ -1379,7 +1408,7 @@ pclxl_copy_mono(gx_device * dev, const byte * data,
lop = rop3_S;
}
if (dev->color_info.num_components == 1 ||
- (rgb_is_gray(color0) && rgb_is_gray(color1))
+ (RGB_IS_GRAY(color0) && RGB_IS_GRAY(color1))
) {
palette[0] = (byte) color0;
palette[1] = (byte) color1;
@@ -1399,15 +1428,14 @@ pclxl_copy_mono(gx_device * dev, const byte * data,
if (code < 0)
return 0;
pclxl_set_color_palette(xdev, color_space, palette, palette_size);
- s = gdev_vector_stream(vxdev);
+ s = pclxl_stream(xdev);
{
- static const byte mi_[] =
- {
- dub(e1Bit), da(pxaColorDepth),
- dub(eIndexedPixel), da(pxaColorMapping)
+ static const byte mi_[] = {
+ DUB(e1Bit), DA(pxaColorDepth),
+ DUB(eIndexedPixel), DA(pxaColorMapping)
};
- put_lit(s, mi_);
+ PX_PUT_LIT(s, mi_);
}
pclxl_write_begin_image(xdev, w, h, w, h);
pclxl_write_image_data(xdev, data, data_x, raster, w, 0, h);
@@ -1421,6 +1449,8 @@ pclxl_copy_color(gx_device * dev,
const byte * base, int sourcex, int raster, gx_bitmap_id id,
int x, int y, int w, int h)
{
+ gx_device_vector *const vdev = (gx_device_vector *)dev;
+ gx_device_pclxl *const xdev = (gx_device_pclxl *)dev;
stream *s;
uint source_bit;
int code;
@@ -1435,16 +1465,16 @@ pclxl_copy_color(gx_device * dev,
x, y, w, h);
gdev_vector_update_log_op(vdev, rop3_S);
pclxl_set_cursor(xdev, x, y);
- s = gdev_vector_stream(vxdev);
+ s = pclxl_stream(xdev);
{
- static const byte ci_[] =
- {
- da(pxaColorDepth),
- dub(eDirectPixel), da(pxaColorMapping)
+ static const byte ci_[] = {
+ DA(pxaColorDepth),
+ DUB(eDirectPixel), DA(pxaColorMapping)
};
- put_ub(s, eBit_values[dev->color_info.depth / dev->color_info.num_components]);
- put_lit(s, ci_);
+ px_put_ub(s, eBit_values[dev->color_info.depth /
+ dev->color_info.num_components]);
+ PX_PUT_LIT(s, ci_);
}
pclxl_write_begin_image(xdev, w, h, w, h);
pclxl_write_image_data(xdev, base, source_bit, raster,
@@ -1461,6 +1491,8 @@ pclxl_fill_mask(gx_device * dev,
const gx_drawing_color * pdcolor, int depth,
gs_logical_operation_t lop, const gx_clip_path * pcpath)
{
+ gx_device_vector *const vdev = (gx_device_vector *)dev;
+ gx_device_pclxl *const xdev = (gx_device_pclxl *)dev;
int code;
stream *s;
@@ -1488,15 +1520,14 @@ pclxl_fill_mask(gx_device * dev,
if (code < 0)
return 0;
pclxl_set_color_palette(xdev, eGray, (const byte *)"\377\000", 2);
- s = gdev_vector_stream(vxdev);
+ s = pclxl_stream(xdev);
{
- static const byte mi_[] =
- {
- dub(e1Bit), da(pxaColorDepth),
- dub(eIndexedPixel), da(pxaColorMapping)
+ static const byte mi_[] = {
+ DUB(e1Bit), DA(pxaColorDepth),
+ DUB(eIndexedPixel), DA(pxaColorMapping)
};
- put_lit(s, mi_);
+ PX_PUT_LIT(s, mi_);
}
pclxl_write_begin_image(xdev, w, h, w, h);
pclxl_write_image_data(xdev, data, data_x, raster, w, 0, h);
@@ -1506,10 +1537,11 @@ pclxl_fill_mask(gx_device * dev,
/* Do a RasterOp. */
private int
-pclxl_strip_copy_rop(gx_device * dev,
- const byte * sdata, int sourcex, uint sraster, gx_bitmap_id id,
+pclxl_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,
+ const gx_strip_bitmap * textures,
+ const gx_color_index * tcolors,
int x, int y, int width, int height,
int phase_x, int phase_y, gs_logical_operation_t lop)
{ /* We can't do general RasterOps yet. */
@@ -1520,7 +1552,6 @@ pclxl_strip_copy_rop(gx_device * dev,
/* ------ High-level images ------ */
typedef gdev_vector_image_enum_t pclxl_image_enum_t;
-
#define st_pclxl_image_enum st_vector_image_enum
/* Start processing an image. */
@@ -1528,26 +1559,28 @@ private int
pclxl_begin_image(gx_device * dev,
const gs_imager_state * pis, const gs_image_t * pim,
gs_image_format_t format, const gs_int_rect * prect,
- const gx_drawing_color * pdcolor, const gx_clip_path * pcpath,
- gs_memory_t * mem, gx_image_enum_common_t ** pinfo)
+ const gx_drawing_color * pdcolor,
+ const gx_clip_path * pcpath, gs_memory_t * mem,
+ gx_image_enum_common_t ** pinfo)
{
+ gx_device_vector *const vdev = (gx_device_vector *)dev;
+ gx_device_pclxl *const xdev = (gx_device_pclxl *)dev;
const gs_color_space *pcs = pim->ColorSpace;
pclxl_image_enum_t *pie;
- int bits_per_pixel;
+ /*
+ * Following should divide by num_planes, but we only handle chunky
+ * images, i.e., num_planes = 1.
+ */
+ int bits_per_pixel =
+ (pim->ImageMask ? 1 :
+ pim->BitsPerComponent * gs_color_space_num_components(pcs));
gs_matrix mat;
int code;
- pie = gs_alloc_struct(mem, pclxl_image_enum_t, &st_pclxl_image_enum,
- "pclxl_begin_image");
- if (pie == 0)
- return_error(gs_error_VMerror);
- code = gdev_vector_begin_image(vdev, pis, pim, format, prect,
- pdcolor, pcpath, mem,
- &pclxl_image_enum_procs, pie);
- if (code < 0)
- return code;
- bits_per_pixel = pie->bits_per_pixel;
- *pinfo = (gx_image_enum_common_t *) pie;
+ /*
+ * Check whether we can handle this image. PCL XL 1.0 and 2.0 only
+ * handle orthogonal transformations.
+ */
gs_matrix_invert(&pim->ImageMatrix, &mat);
gs_matrix_multiply(&mat, &ctm_only(pis), &mat);
/* Currently we only handle portrait transformations. */
@@ -1559,70 +1592,89 @@ pclxl_begin_image(gx_device * dev,
bits_per_pixel != 8))) ||
format != gs_image_format_chunky ||
prect
- ) {
- int code = gx_default_begin_image(dev, pis, pim, format, prect,
- pdcolor, pcpath, mem,
- &pie->default_info);
-
- if (code < 0)
- gs_free_object(mem, pie, "pclxl_begin_image");
+ )
+ return gx_default_begin_image(dev, pis, pim, format, prect,
+ pdcolor, pcpath, mem, pinfo);
+ pie = gs_alloc_struct(mem, pclxl_image_enum_t, &st_pclxl_image_enum,
+ "pclxl_begin_image");
+ if (pie == 0)
+ return_error(gs_error_VMerror);
+ code = gdev_vector_begin_image(vdev, pis, pim, format, prect,
+ pdcolor, pcpath, mem,
+ &pclxl_image_enum_procs, pie);
+ if (code < 0)
return code;
- } {
- stream *s = gdev_vector_stream(vxdev);
+ *pinfo = (gx_image_enum_common_t *) pie;
+ pclxl_set_cursor(xdev, (int)((mat.tx + 0.5) / xdev->scale.x),
+ (int)((mat.ty + 0.5) / xdev->scale.y));
+ {
+ stream *s = pclxl_stream(xdev);
gs_logical_operation_t lop = pis->log_op;
- int code = gdev_vector_update_log_op
- (vdev, (pim->ImageMask || pim->CombineWithColor ? lop :
- rop3_know_T_0(lop)));
- int bpc = pim->BitsPerComponent;
- int num_components = pie->plane_depths[0] * pie->num_planes / bpc;
- int sample_max = (1 << bpc) - 1;
- byte palette[256 * 3];
- int i;
- if (code < 0)
- return code;
- pclxl_set_cursor(xdev, (int)((mat.tx + 0.5) / xdev->scale.x),
- (int)((mat.ty + 0.5) / xdev->scale.y));
- for (i = 0; i < 1 << bits_per_pixel; ++i) {
- gs_client_color cc;
- gx_device_color devc;
- int cv = i, j;
-
- for (j = num_components - 1; j >= 0; cv >>= bpc, --j)
- cc.paint.values[j] = pim->Decode[j * 2] +
- (cv & sample_max) *
- (pim->Decode[j * 2 + 1] - pim->Decode[j * 2]) /
- sample_max;
- (*pcs->type->remap_color)
- (&cc, pcs, &devc, pis, dev, gs_color_select_source);
- if (!gx_dc_is_pure(&devc))
- return_error(gs_error_Fatal);
- if (dev->color_info.num_components == 1)
- palette[i] = (byte) gx_dc_pure_color(&devc);
- else {
- gx_color_index ci = gx_dc_pure_color(&devc);
- byte *ppal = &palette[i * 3];
-
- ppal[0] = (byte) (ci >> 16);
- ppal[1] = (byte) (ci >> 8);
- ppal[2] = (byte) ci;
+ if (pim->ImageMask) {
+ code = gdev_vector_update_fill_color(vdev, pdcolor);
+ if (code < 0)
+ return 0;
+ code = gdev_vector_update_log_op
+ (vdev, lop | rop3_S | lop_S_transparent);
+ if (code < 0)
+ return 0;
+ pclxl_set_color_palette(xdev, eGray,
+ (pim->Decode[0] ?
+ (const byte *)"\377\000" :
+ (const byte *)"\000\377"),
+ 2);
+ } else {
+ int bpc = pim->BitsPerComponent;
+ int num_components = pie->plane_depths[0] * pie->num_planes / bpc;
+ int sample_max = (1 << bpc) - 1;
+ byte palette[256 * 3];
+ int i;
+
+ code = gdev_vector_update_log_op
+ (vdev, (pim->CombineWithColor ? lop : rop3_know_T_0(lop)));
+ if (code < 0)
+ return code;
+ for (i = 0; i < 1 << bits_per_pixel; ++i) {
+ gs_client_color cc;
+ gx_device_color devc;
+ int cv = i, j;
+
+ for (j = num_components - 1; j >= 0; cv >>= bpc, --j)
+ cc.paint.values[j] = pim->Decode[j * 2] +
+ (cv & sample_max) *
+ (pim->Decode[j * 2 + 1] - pim->Decode[j * 2]) /
+ sample_max;
+ (*pcs->type->remap_color)
+ (&cc, pcs, &devc, pis, dev, gs_color_select_source);
+ if (!gx_dc_is_pure(&devc))
+ return_error(gs_error_Fatal);
+ if (dev->color_info.num_components == 1)
+ palette[i] = (byte) gx_dc_pure_color(&devc);
+ else {
+ gx_color_index ci = gx_dc_pure_color(&devc);
+ byte *ppal = &palette[i * 3];
+
+ ppal[0] = (byte) (ci >> 16);
+ ppal[1] = (byte) (ci >> 8);
+ ppal[2] = (byte) ci;
+ }
}
+ if (dev->color_info.num_components == 1)
+ pclxl_set_color_palette(xdev, eGray, palette,
+ 1 << bits_per_pixel);
+ else
+ pclxl_set_color_palette(xdev, eRGB, palette,
+ 3 << bits_per_pixel);
}
- if (dev->color_info.num_components == 1)
- pclxl_set_color_palette(xdev, eGray, palette,
- 1 << bits_per_pixel);
- else
- pclxl_set_color_palette(xdev, eRGB, palette,
- 3 << bits_per_pixel);
{
- static const byte ii_[] =
- {
- da(pxaColorDepth),
- dub(eIndexedPixel), da(pxaColorMapping)
+ static const byte ii_[] = {
+ DA(pxaColorDepth),
+ DUB(eIndexedPixel), DA(pxaColorMapping)
};
- put_ub(s, eBit_values[bits_per_pixel]);
- put_lit(s, ii_);
+ px_put_ub(s, eBit_values[bits_per_pixel]);
+ PX_PUT_LIT(s, ii_);
}
pclxl_write_begin_image(xdev, pim->Width, pim->Height,
(uint) (pim->Width * mat.xx),
@@ -1633,13 +1685,14 @@ pclxl_begin_image(gx_device * dev,
/* Process the next piece of an image. */
private int
-pclxl_image_plane_data(gx_device * dev,
- gx_image_enum_common_t * info, const gx_image_plane_t * planes, int height)
+pclxl_image_plane_data(gx_image_enum_common_t * info,
+ const gx_image_plane_t * planes, int height,
+ int *rows_used)
{
+ gx_device *dev = info->dev;
+ gx_device_pclxl *const xdev = (gx_device_pclxl *)dev;
pclxl_image_enum_t *pie = (pclxl_image_enum_t *) info;
- if (pie->default_info)
- return gx_image_plane_data(pie->default_info, planes, height);
if (height > pie->height - pie->y)
height = pie->height - pie->y;
pclxl_write_image_data(xdev, planes[0].data,
@@ -1647,38 +1700,35 @@ pclxl_image_plane_data(gx_device * dev,
planes[0].raster,
pie->width * info->plane_depths[0],
pie->y, height);
+ *rows_used = height;
return (pie->y += height) >= pie->height;
}
/* Clean up by releasing the buffers. */
private int
-pclxl_image_end_image(gx_device * dev, gx_image_enum_common_t * info,
- bool draw_last)
+pclxl_image_end_image(gx_image_enum_common_t * info, bool draw_last)
{
+ gx_device *dev = info->dev;
+ gx_device_pclxl *const xdev = (gx_device_pclxl *)dev;
pclxl_image_enum_t *pie = (pclxl_image_enum_t *) info;
int code = 0;
- if (pie->default_info)
- code = gx_default_end_image(dev, pie->default_info, draw_last);
- else { /* Fill out to the full image height. */
-/****** WRONG -- REST OF IMAGE SHOULD BE TRANSPARENT ******/
- if (pie->height > pie->y) {
- uint bytes_per_row = (pie->bits_per_row + 7) >> 3;
- byte *row = gs_alloc_bytes(pie->memory, bytes_per_row,
- "pclxl_end_image(fill)");
-
- if (row == 0)
- return_error(gs_error_VMerror);
- memset(row, 0, bytes_per_row);
- for (; pie->y < pie->height; pie->y++)
- pclxl_write_image_data(xdev, row, 0, bytes_per_row,
- pie->bits_per_row, pie->y, 1);
- gs_free_object(pie->memory, row, "pclxl_end_image(fill)");
- }
- pclxl_write_end_image(xdev);
+ /* Fill out to the full image height. */
+ /****** WRONG -- REST OF IMAGE SHOULD BE TRANSPARENT ******/
+ if (pie->height > pie->y) {
+ uint bytes_per_row = (pie->bits_per_row + 7) >> 3;
+ byte *row = gs_alloc_bytes(pie->memory, bytes_per_row,
+ "pclxl_end_image(fill)");
+
+ if (row == 0)
+ return_error(gs_error_VMerror);
+ memset(row, 0, bytes_per_row);
+ for (; pie->y < pie->height; pie->y++)
+ pclxl_write_image_data(xdev, row, 0, bytes_per_row,
+ pie->bits_per_row, pie->y, 1);
+ gs_free_object(pie->memory, row, "pclxl_end_image(fill)");
}
+ pclxl_write_end_image(xdev);
gs_free_object(pie->memory, pie, "pclxl_end_image");
return code;
}
-
-#undef vdev