~ubuntu-branches/ubuntu/hardy/ghostscript/hardy

« back to all changes in this revision

Viewing changes to src/gdevbbox.c

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2007-11-22 12:17:43 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20071122121743-cd70s3ypq0r243mp
Tags: 8.61.dfsg.1-0ubtuntu1
* New upstream release
  o Final 8.61 release
* debian/patches/09_ijs_krgb_support.dpatch: Adapted to upstream changes.
* debian/rules: Updated CUPS-related variables for "make install" calls.
* debian/rules: Remove /usr/include/ghostscript from the ghostscript
  package, they go into lings-dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
   or contact Artifex Software, Inc.,  7 Mt. Lassen Drive - Suite A-134,
11
11
   San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
12
12
*/
13
 
/*$Id: gdevbbox.c 8022 2007-06-05 22:23:38Z giles $ */
 
13
/*$Id: gdevbbox.c 8250 2007-09-25 13:31:24Z giles $ */
14
14
/* Device for tracking bounding box */
15
15
#include "math_.h"
16
16
#include "memory_.h"
31
31
public_st_device_bbox();
32
32
 
33
33
/* Device procedures */
34
 
private dev_proc_open_device(bbox_open_device);
35
 
private dev_proc_close_device(bbox_close_device);
36
 
private dev_proc_output_page(bbox_output_page);
37
 
private dev_proc_fill_rectangle(bbox_fill_rectangle);
38
 
private dev_proc_copy_mono(bbox_copy_mono);
39
 
private dev_proc_copy_color(bbox_copy_color);
40
 
private dev_proc_get_params(bbox_get_params);
41
 
private dev_proc_put_params(bbox_put_params);
42
 
private dev_proc_copy_alpha(bbox_copy_alpha);
43
 
private dev_proc_fill_path(bbox_fill_path);
44
 
private dev_proc_stroke_path(bbox_stroke_path);
45
 
private dev_proc_fill_mask(bbox_fill_mask);
46
 
private dev_proc_fill_trapezoid(bbox_fill_trapezoid);
47
 
private dev_proc_fill_parallelogram(bbox_fill_parallelogram);
48
 
private dev_proc_fill_triangle(bbox_fill_triangle);
49
 
private dev_proc_draw_thin_line(bbox_draw_thin_line);
50
 
private dev_proc_strip_tile_rectangle(bbox_strip_tile_rectangle);
51
 
private dev_proc_strip_copy_rop(bbox_strip_copy_rop);
52
 
private dev_proc_begin_typed_image(bbox_begin_typed_image);
53
 
private dev_proc_create_compositor(bbox_create_compositor);
54
 
private dev_proc_text_begin(bbox_text_begin);
 
34
static dev_proc_open_device(bbox_open_device);
 
35
static dev_proc_close_device(bbox_close_device);
 
36
static dev_proc_output_page(bbox_output_page);
 
37
static dev_proc_fill_rectangle(bbox_fill_rectangle);
 
38
static dev_proc_copy_mono(bbox_copy_mono);
 
39
static dev_proc_copy_color(bbox_copy_color);
 
40
static dev_proc_get_params(bbox_get_params);
 
41
static dev_proc_put_params(bbox_put_params);
 
42
static dev_proc_copy_alpha(bbox_copy_alpha);
 
43
static dev_proc_fill_path(bbox_fill_path);
 
44
static dev_proc_stroke_path(bbox_stroke_path);
 
45
static dev_proc_fill_mask(bbox_fill_mask);
 
46
static dev_proc_fill_trapezoid(bbox_fill_trapezoid);
 
47
static dev_proc_fill_parallelogram(bbox_fill_parallelogram);
 
48
static dev_proc_fill_triangle(bbox_fill_triangle);
 
49
static dev_proc_draw_thin_line(bbox_draw_thin_line);
 
50
static dev_proc_strip_tile_rectangle(bbox_strip_tile_rectangle);
 
51
static dev_proc_strip_copy_rop(bbox_strip_copy_rop);
 
52
static dev_proc_begin_typed_image(bbox_begin_typed_image);
 
53
static dev_proc_create_compositor(bbox_create_compositor);
 
54
static dev_proc_text_begin(bbox_text_begin);
55
55
 
56
56
/* The device prototype */
57
57
/*
58
 
 * Normally this would be private, but if the device is going to be used
 
58
 * Normally this would be static, but if the device is going to be used
59
59
 * stand-alone, it has to be public.
60
60
 */
61
 
/*private */ const
 
61
/*static*/ const
62
62
/*
63
63
 * The bbox device sets the resolution to some value R (currently 4000), and
64
64
 * the page size in device pixels to slightly smaller than the largest
200
200
#define BBOX_IN_RECT(bdev, pbox)\
201
201
    bdev->box_procs.in_rect(bdev->box_proc_data, pbox)
202
202
 
203
 
private const gx_device_bbox_procs_t box_procs_default = {
 
203
static const gx_device_bbox_procs_t box_procs_default = {
204
204
    bbox_default_init_box, bbox_default_get_box, bbox_default_add_rect,
205
205
    bbox_default_in_rect
206
206
};
211
211
     /* ---------------- Open/close/page ---------------- */
212
212
 
213
213
/* Copy device parameters back from the target. */
214
 
private void
 
214
static void
215
215
bbox_copy_params(gx_device_bbox * bdev, bool remap_colors)
216
216
{
217
217
    gx_device *tdev = bdev->target;
229
229
#define GX_DC_IS_TRANSPARENT(pdevc, bdev)\
230
230
  (gx_dc_pure_color(pdevc) == (bdev)->transparent && gx_dc_is_pure(pdevc))
231
231
 
232
 
private int
 
232
static int
233
233
bbox_close_device(gx_device * dev)
234
234
{
235
235
    gx_device_bbox *const bdev = (gx_device_bbox *) dev;
331
331
    }
332
332
}
333
333
 
334
 
private int
 
334
static int
335
335
bbox_open_device(gx_device * dev)
336
336
{
337
337
    gx_device_bbox *const bdev = (gx_device_bbox *) dev;
354
354
    }
355
355
}
356
356
 
357
 
private int
 
357
static int
358
358
bbox_output_page(gx_device * dev, int num_copies, int flush)
359
359
{
360
360
    gx_device_bbox *const bdev = (gx_device_bbox *) dev;
377
377
 
378
378
/* ---------------- Low-level drawing ---------------- */
379
379
 
380
 
private int
 
380
static int
381
381
bbox_fill_rectangle(gx_device * dev, int x, int y, int w, int h,
382
382
                    gx_color_index color)
383
383
{
398
398
    return code;
399
399
}
400
400
 
401
 
private int
 
401
static int
402
402
bbox_copy_mono(gx_device * dev, const byte * data,
403
403
            int dx, int raster, gx_bitmap_id id, int x, int y, int w, int h,
404
404
               gx_color_index zero, gx_color_index one)
418
418
    return code;
419
419
}
420
420
 
421
 
private int
 
421
static int
422
422
bbox_copy_color(gx_device * dev, const byte * data,
423
423
            int dx, int raster, gx_bitmap_id id, int x, int y, int w, int h)
424
424
{
434
434
    return code;
435
435
}
436
436
 
437
 
private int
 
437
static int
438
438
bbox_copy_alpha(gx_device * dev, const byte * data, int data_x,
439
439
                int raster, gx_bitmap_id id, int x, int y, int w, int h,
440
440
                gx_color_index color, int depth)
451
451
    return code;
452
452
}
453
453
 
454
 
private int
 
454
static int
455
455
bbox_strip_tile_rectangle(gx_device * dev, const gx_strip_bitmap * tiles,
456
456
   int x, int y, int w, int h, gx_color_index color0, gx_color_index color1,
457
457
                          int px, int py)
472
472
    return code;
473
473
}
474
474
 
475
 
private int
 
475
static int
476
476
bbox_strip_copy_rop(gx_device * dev,
477
477
                    const byte * sdata, int sourcex, uint sraster,
478
478
                    gx_bitmap_id id,
498
498
/* ---------------- Parameters ---------------- */
499
499
 
500
500
/* We implement get_params to provide a way to read out the bounding box. */
501
 
private int
 
501
static int
502
502
bbox_get_params(gx_device * dev, gs_param_list * plist)
503
503
{
504
504
    gx_device_bbox *const bdev = (gx_device_bbox *) dev;
532
532
/* We implement put_params to ensure that we keep the important */
533
533
/* device parameters up to date, and to prevent an /undefined error */
534
534
/* from PageBoundingBox. */
535
 
private int
 
535
static int
536
536
bbox_put_params(gx_device * dev, gs_param_list * plist)
537
537
{
538
538
    gx_device_bbox *const bdev = (gx_device_bbox *) dev;
584
584
 
585
585
/* ---------------- Polygon drawing ---------------- */
586
586
 
587
 
private fixed
 
587
static fixed
588
588
edge_x_at_y(const gs_fixed_edge * edge, fixed y)
589
589
{
590
590
    return fixed_mult_quo(edge->end.x - edge->start.x,
591
591
                          y - edge->start.y,
592
592
                          edge->end.y - edge->start.y) + edge->start.x;
593
593
}
594
 
private int
 
594
static int
595
595
bbox_fill_trapezoid(gx_device * dev,
596
596
                    const gs_fixed_edge * left, const gs_fixed_edge * right,
597
597
                    fixed ybot, fixed ytop, bool swap_axes,
630
630
    return code;
631
631
}
632
632
 
633
 
private int
 
633
static int
634
634
bbox_fill_parallelogram(gx_device * dev,
635
635
                        fixed px, fixed py, fixed ax, fixed ay,
636
636
                        fixed bx, fixed by, const gx_device_color * pdevc,
668
668
    return code;
669
669
}
670
670
 
671
 
private int
 
671
static int
672
672
bbox_fill_triangle(gx_device * dev,
673
673
                   fixed px, fixed py, fixed ax, fixed ay, fixed bx, fixed by,
674
674
                   const gx_device_color * pdevc, gs_logical_operation_t lop)
705
705
    return code;
706
706
}
707
707
 
708
 
private int
 
708
static int
709
709
bbox_draw_thin_line(gx_device * dev,
710
710
                    fixed fx0, fixed fy0, fixed fx1, fixed fy1,
711
711
                    const gx_device_color * pdevc, gs_logical_operation_t lop)
743
743
((pbox)->p.x -= (adj).x, (pbox)->p.y -= (adj).y,\
744
744
 (pbox)->q.x += (adj).x, (pbox)->q.y += (adj).y)
745
745
 
746
 
private int
 
746
static int
747
747
bbox_fill_path(gx_device * dev, const gs_imager_state * pis, gx_path * ppath,
748
748
               const gx_fill_params * params, const gx_device_color * pdevc,
749
749
               const gx_clip_path * pcpath)
803
803
        return fill_path(tdev, pis, ppath, params, pdevc, pcpath);
804
804
}
805
805
 
806
 
private int
 
806
static int
807
807
bbox_stroke_path(gx_device * dev, const gs_imager_state * pis, gx_path * ppath,
808
808
                 const gx_stroke_params * params,
809
809
                 const gx_drawing_color * pdevc, const gx_clip_path * pcpath)
865
865
    return code;
866
866
}
867
867
 
868
 
private int
 
868
static int
869
869
bbox_fill_mask(gx_device * dev,
870
870
               const byte * data, int dx, int raster, gx_bitmap_id id,
871
871
               int x, int y, int w, int h,
916
916
  "bbox_image_enum", bbox_image_enum_enum_ptrs, bbox_image_enum_reloc_ptrs,
917
917
  st_gx_image_enum_common, pcpath, target_info);
918
918
 
919
 
private image_enum_proc_plane_data(bbox_image_plane_data);
920
 
private image_enum_proc_end_image(bbox_image_end_image);
921
 
private image_enum_proc_flush(bbox_image_flush);
922
 
private image_enum_proc_planes_wanted(bbox_image_planes_wanted);
923
 
private const gx_image_enum_procs_t bbox_image_enum_procs = {
 
919
static image_enum_proc_plane_data(bbox_image_plane_data);
 
920
static image_enum_proc_end_image(bbox_image_end_image);
 
921
static image_enum_proc_flush(bbox_image_flush);
 
922
static image_enum_proc_planes_wanted(bbox_image_planes_wanted);
 
923
static const gx_image_enum_procs_t bbox_image_enum_procs = {
924
924
    bbox_image_plane_data, bbox_image_end_image,
925
925
    bbox_image_flush, bbox_image_planes_wanted
926
926
};
927
927
 
928
 
private int
 
928
static int
929
929
bbox_image_begin(const gs_imager_state * pis, const gs_matrix * pmat,
930
930
                 const gs_image_common_t * pic, const gs_int_rect * prect,
931
931
                 const gx_clip_path * pcpath, gs_memory_t * memory,
968
968
    return 0;
969
969
}
970
970
 
971
 
private void
 
971
static void
972
972
bbox_image_copy_target_info(bbox_image_enum * pbe)
973
973
{
974
974
    const gx_image_enum_common_t *target_info = pbe->target_info;
980
980
           pbe->num_planes * sizeof(pbe->plane_widths[0]));
981
981
}
982
982
 
983
 
private int
 
983
static int
984
984
bbox_begin_typed_image(gx_device * dev,
985
985
                       const gs_imager_state * pis, const gs_matrix * pmat,
986
986
                   const gs_image_common_t * pic, const gs_int_rect * prect,
1036
1036
    return 0;
1037
1037
}
1038
1038
 
1039
 
private int
 
1039
static int
1040
1040
bbox_image_plane_data(gx_image_enum_common_t * info,
1041
1041
                      const gx_image_plane_t * planes, int height,
1042
1042
                      int *rows_used)
1076
1076
        fixed x0 = float2fixed(corners[0].x), y0 = float2fixed(corners[0].y);
1077
1077
        fixed bx2 = float2fixed(corners[2].x) - x0, by2 = float2fixed(corners[2].y) - y0;
1078
1078
 
1079
 
        gx_make_clip_path_device(&cdev, pcpath);
1080
 
        cdev.target = dev;
1081
 
        (*dev_proc(&cdev, open_device)) ((gx_device *) & cdev);
 
1079
        gx_make_clip_device_on_stack(&cdev, pcpath, dev);
1082
1080
        set_nonclient_dev_color(&devc, bdev->black);  /* any non-white color will do */
1083
1081
        bdev->target = NULL;
1084
1082
        gx_default_fill_triangle((gx_device *) & cdev, x0, y0,
1097
1095
    return code;
1098
1096
}
1099
1097
 
1100
 
private int
 
1098
static int
1101
1099
bbox_image_end_image(gx_image_enum_common_t * info, bool draw_last)
1102
1100
{
1103
1101
    bbox_image_enum *pbe = (bbox_image_enum *) info;
1107
1105
    return code;
1108
1106
}
1109
1107
 
1110
 
private int
 
1108
static int
1111
1109
bbox_image_flush(gx_image_enum_common_t * info)
1112
1110
{
1113
1111
    bbox_image_enum *pbe = (bbox_image_enum *) info;
1116
1114
    return (target_info ? gx_image_flush(target_info) : 0);
1117
1115
}
1118
1116
 
1119
 
private bool
 
1117
static bool
1120
1118
bbox_image_planes_wanted(const gx_image_enum_common_t * info, byte *wanted)
1121
1119
{
1122
1120
    /* This is only used if target_info != 0. */
1127
1125
 
1128
1126
/* Compositing */
1129
1127
 
1130
 
private bool
 
1128
static bool
1131
1129
bbox_forward_init_box(void *pdata)
1132
1130
{
1133
1131
    gx_device_bbox *const bdev = (gx_device_bbox *)pdata;
1134
1132
 
1135
1133
    return BBOX_INIT_BOX(bdev);
1136
1134
}
1137
 
private void
 
1135
static void
1138
1136
bbox_forward_get_box(const void *pdata, gs_fixed_rect *pbox)
1139
1137
{
1140
1138
    const gx_device_bbox *const bdev = (const gx_device_bbox *)pdata;
1141
1139
 
1142
1140
    BBOX_GET_BOX(bdev, pbox);
1143
1141
}
1144
 
private void
 
1142
static void
1145
1143
bbox_forward_add_rect(void *pdata, fixed x0, fixed y0, fixed x1, fixed y1)
1146
1144
{
1147
1145
    gx_device_bbox *const bdev = (gx_device_bbox *)pdata;
1148
1146
 
1149
1147
    BBOX_ADD_RECT(bdev, x0, y0, x1, y1);
1150
1148
}
1151
 
private bool
 
1149
static bool
1152
1150
bbox_forward_in_rect(const void *pdata, const gs_fixed_rect *pbox)
1153
1151
{
1154
1152
    const gx_device_bbox *const bdev = (const gx_device_bbox *)pdata;
1155
1153
 
1156
1154
    return BBOX_IN_RECT(bdev, pbox);
1157
1155
}
1158
 
private const gx_device_bbox_procs_t box_procs_forward = {
 
1156
static const gx_device_bbox_procs_t box_procs_forward = {
1159
1157
    bbox_forward_init_box, bbox_forward_get_box, bbox_forward_add_rect,
1160
1158
    bbox_forward_in_rect
1161
1159
};
1162
1160
 
1163
 
private int
 
1161
static int
1164
1162
bbox_create_compositor(gx_device * dev,
1165
1163
                       gx_device ** pcdev, const gs_composite_t * pcte,
1166
1164
                       gs_imager_state * pis, gs_memory_t * memory)
1210
1208
 
1211
1209
/* ------ Text imaging ------ */
1212
1210
 
1213
 
private int
 
1211
static int
1214
1212
bbox_text_begin(gx_device * dev, gs_imager_state * pis,
1215
1213
                const gs_text_params_t * text, gs_font * font,
1216
1214
                gx_path * path, const gx_device_color * pdcolor,