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

« back to all changes in this revision

Viewing changes to psi/zmatrix.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
 
 
14
/* $Id: zmatrix.c 9300 2008-12-21 07:46:52Z alexcher $ */
 
15
/* Matrix operators */
 
16
#include "ghost.h"
 
17
#include "oper.h"
 
18
#include "igstate.h"
 
19
#include "gsmatrix.h"
 
20
#include "gscoord.h"
 
21
#include "store.h"
 
22
 
 
23
/* Forward references */
 
24
static int common_transform(i_ctx_t *,
 
25
                int (*)(gs_state *, floatp, floatp, gs_point *),
 
26
                int (*)(floatp, floatp, const gs_matrix *, gs_point *));
 
27
 
 
28
/* - initmatrix - */
 
29
static int
 
30
zinitmatrix(i_ctx_t *i_ctx_p)
 
31
{
 
32
    return gs_initmatrix(igs);
 
33
}
 
34
 
 
35
/* <matrix> defaultmatrix <matrix> */
 
36
static int
 
37
zdefaultmatrix(i_ctx_t *i_ctx_p)
 
38
{
 
39
    os_ptr op = osp;
 
40
    gs_matrix mat;
 
41
 
 
42
    gs_defaultmatrix(igs, &mat);
 
43
    return write_matrix(op, &mat);
 
44
}
 
45
 
 
46
/* - .currentmatrix <xx> <xy> <yx> <yy> <tx> <ty> */
 
47
static int
 
48
zcurrentmatrix(i_ctx_t *i_ctx_p)
 
49
{
 
50
    os_ptr op = osp;
 
51
    gs_matrix mat;
 
52
    int code = gs_currentmatrix(igs, &mat);
 
53
 
 
54
    if (code < 0)
 
55
        return code;
 
56
    push(6);
 
57
    code = make_floats(op - 5, &mat.xx, 6);
 
58
    if (code < 0)
 
59
        pop(6);
 
60
    return code;
 
61
}
 
62
 
 
63
/* <xx> <xy> <yx> <yy> <tx> <ty> .setmatrix - */
 
64
static int
 
65
zsetmatrix(i_ctx_t *i_ctx_p)
 
66
{
 
67
    os_ptr op = osp;
 
68
    gs_matrix mat;
 
69
    int code = float_params(op, 6, &mat.xx);
 
70
 
 
71
    if (code < 0)
 
72
        return code;
 
73
    if ((code = gs_setmatrix(igs, &mat)) < 0)
 
74
        return code;
 
75
    pop(6);
 
76
    return 0;
 
77
}
 
78
 
 
79
/* <matrix|null> .setdefaultmatrix - */
 
80
static int
 
81
zsetdefaultmatrix(i_ctx_t *i_ctx_p)
 
82
{
 
83
    os_ptr op = osp;
 
84
    int code;
 
85
 
 
86
    if (r_has_type(op, t_null))
 
87
        code = gs_setdefaultmatrix(igs, NULL);
 
88
    else {
 
89
        gs_matrix mat;
 
90
 
 
91
        code = read_matrix(imemory, op, &mat);
 
92
        if (code < 0)
 
93
            return code;
 
94
        code = gs_setdefaultmatrix(igs, &mat);
 
95
    }
 
96
    if (code < 0)
 
97
        return code;
 
98
    pop(1);
 
99
    return 0;
 
100
}
 
101
 
 
102
/* <tx> <ty> translate - */
 
103
/* <tx> <ty> <matrix> translate <matrix> */
 
104
static int
 
105
ztranslate(i_ctx_t *i_ctx_p)
 
106
{
 
107
    os_ptr op = osp;
 
108
    int code;
 
109
    double trans[2];
 
110
 
 
111
    if ((code = num_params(op, 2, trans)) >= 0) {
 
112
        code = gs_translate(igs, trans[0], trans[1]);
 
113
        if (code < 0)
 
114
            return code;
 
115
    } else {                    /* matrix operand */
 
116
        gs_matrix mat;
 
117
 
 
118
        /* The num_params failure might be a stack underflow. */
 
119
        check_op(2);
 
120
        if ((code = num_params(op - 1, 2, trans)) < 0 ||
 
121
            (code = gs_make_translation(trans[0], trans[1], &mat)) < 0 ||
 
122
            (code = write_matrix(op, &mat)) < 0
 
123
            ) {                 /* Might be a stack underflow. */
 
124
            check_op(3);
 
125
            return code;
 
126
        }
 
127
        op[-2] = *op;
 
128
    }
 
129
    pop(2);
 
130
    return code;
 
131
}
 
132
 
 
133
/* <sx> <sy> scale - */
 
134
/* <sx> <sy> <matrix> scale <matrix> */
 
135
static int
 
136
zscale(i_ctx_t *i_ctx_p)
 
137
{
 
138
    os_ptr op = osp;
 
139
    int code;
 
140
    double scale[2];
 
141
 
 
142
    if ((code = num_params(op, 2, scale)) >= 0) {
 
143
        code = gs_scale(igs, scale[0], scale[1]);
 
144
        if (code < 0)
 
145
            return code;
 
146
    } else {                    /* matrix operand */
 
147
        gs_matrix mat;
 
148
 
 
149
        /* The num_params failure might be a stack underflow. */
 
150
        check_op(2);
 
151
        if ((code = num_params(op - 1, 2, scale)) < 0 ||
 
152
            (code = gs_make_scaling(scale[0], scale[1], &mat)) < 0 ||
 
153
            (code = write_matrix(op, &mat)) < 0
 
154
            ) {                 /* Might be a stack underflow. */
 
155
            check_op(3);
 
156
            return code;
 
157
        }
 
158
        op[-2] = *op;
 
159
    }
 
160
    pop(2);
 
161
    return code;
 
162
}
 
163
 
 
164
/* <angle> rotate - */
 
165
/* <angle> <matrix> rotate <matrix> */
 
166
static int
 
167
zrotate(i_ctx_t *i_ctx_p)
 
168
{
 
169
    os_ptr op = osp;
 
170
    int code;
 
171
    double ang;
 
172
 
 
173
    if ((code = real_param(op, &ang)) >= 0) {
 
174
        code = gs_rotate(igs, ang);
 
175
        if (code < 0)
 
176
            return code;
 
177
    } else {                    /* matrix operand */
 
178
        gs_matrix mat;
 
179
 
 
180
        /* The num_params failure might be a stack underflow. */
 
181
        check_op(1);
 
182
        if ((code = num_params(op - 1, 1, &ang)) < 0 ||
 
183
            (code = gs_make_rotation(ang, &mat)) < 0 ||
 
184
            (code = write_matrix(op, &mat)) < 0
 
185
            ) {                 /* Might be a stack underflow. */
 
186
            check_op(2);
 
187
            return code;
 
188
        }
 
189
        op[-1] = *op;
 
190
    }
 
191
    pop(1);
 
192
    return code;
 
193
}
 
194
 
 
195
/* <matrix> concat - */
 
196
static int
 
197
zconcat(i_ctx_t *i_ctx_p)
 
198
{
 
199
    os_ptr op = osp;
 
200
    gs_matrix mat;
 
201
    int code = read_matrix(imemory, op, &mat);
 
202
 
 
203
    if (code < 0)
 
204
        return code;
 
205
    code = gs_concat(igs, &mat);
 
206
    if (code < 0)
 
207
        return code;
 
208
    pop(1);
 
209
    return 0;
 
210
}
 
211
 
 
212
/* <matrix1> <matrix2> <matrix> concatmatrix <matrix> */
 
213
static int
 
214
zconcatmatrix(i_ctx_t *i_ctx_p)
 
215
{
 
216
    os_ptr op = osp;
 
217
    gs_matrix m1, m2, mp;
 
218
    int code;
 
219
 
 
220
    if ((code = read_matrix(imemory, op - 2, &m1)) < 0 ||
 
221
        (code = read_matrix(imemory, op - 1, &m2)) < 0 ||
 
222
        (code = gs_matrix_multiply(&m1, &m2, &mp)) < 0 ||
 
223
        (code = write_matrix(op, &mp)) < 0
 
224
        )
 
225
        return code;
 
226
    op[-2] = *op;
 
227
    pop(2);
 
228
    return code;
 
229
}
 
230
 
 
231
/* <x> <y> transform <xt> <yt> */
 
232
/* <x> <y> <matrix> transform <xt> <yt> */
 
233
static int
 
234
ztransform(i_ctx_t *i_ctx_p)
 
235
{
 
236
    return common_transform(i_ctx_p, gs_transform, gs_point_transform);
 
237
}
 
238
 
 
239
/* <dx> <dy> dtransform <dxt> <dyt> */
 
240
/* <dx> <dy> <matrix> dtransform <dxt> <dyt> */
 
241
static int
 
242
zdtransform(i_ctx_t *i_ctx_p)
 
243
{
 
244
    return common_transform(i_ctx_p, gs_dtransform, gs_distance_transform);
 
245
}
 
246
 
 
247
/* <xt> <yt> itransform <x> <y> */
 
248
/* <xt> <yt> <matrix> itransform <x> <y> */
 
249
static int
 
250
zitransform(i_ctx_t *i_ctx_p)
 
251
{
 
252
    return common_transform(i_ctx_p, gs_itransform, gs_point_transform_inverse);
 
253
}
 
254
 
 
255
/* <dxt> <dyt> idtransform <dx> <dy> */
 
256
/* <dxt> <dyt> <matrix> idtransform <dx> <dy> */
 
257
static int
 
258
zidtransform(i_ctx_t *i_ctx_p)
 
259
{
 
260
    return common_transform(i_ctx_p, gs_idtransform, gs_distance_transform_inverse);
 
261
}
 
262
 
 
263
/* Common logic for [i][d]transform */
 
264
static int
 
265
common_transform(i_ctx_t *i_ctx_p,
 
266
        int (*ptproc)(gs_state *, floatp, floatp, gs_point *),
 
267
        int (*matproc)(floatp, floatp, const gs_matrix *, gs_point *))
 
268
{
 
269
    os_ptr op = osp;
 
270
    double opxy[2];
 
271
    gs_point pt;
 
272
    int code;
 
273
 
 
274
    /* Optimize for the non-matrix case */
 
275
    switch (r_type(op)) {
 
276
        case t_real:
 
277
            opxy[1] = op->value.realval;
 
278
            break;
 
279
        case t_integer:
 
280
            opxy[1] = op->value.intval;
 
281
            break;
 
282
        case t_array:           /* might be a matrix */
 
283
        case t_shortarray:
 
284
        case t_mixedarray: {
 
285
            gs_matrix mat;
 
286
            gs_matrix *pmat = &mat;
 
287
 
 
288
            if ((code = read_matrix(imemory, op, pmat)) < 0 ||
 
289
                (code = num_params(op - 1, 2, opxy)) < 0 ||
 
290
                (code = (*matproc) (opxy[0], opxy[1], pmat, &pt)) < 0
 
291
                ) {             /* Might be a stack underflow. */
 
292
                check_op(3);
 
293
                return code;
 
294
            }
 
295
            op--;
 
296
            pop(1);
 
297
            goto out;
 
298
        }
 
299
        default:
 
300
            return_op_typecheck(op);
 
301
    }
 
302
    switch (r_type(op - 1)) {
 
303
        case t_real:
 
304
            opxy[0] = (op - 1)->value.realval;
 
305
            break;
 
306
        case t_integer:
 
307
            opxy[0] = (op - 1)->value.intval;
 
308
            break;
 
309
        default:
 
310
            return_op_typecheck(op - 1);
 
311
    }
 
312
    if ((code = (*ptproc) (igs, opxy[0], opxy[1], &pt)) < 0)
 
313
        return code;
 
314
out:
 
315
    make_real(op - 1, pt.x);
 
316
    make_real(op, pt.y);
 
317
    return 0;
 
318
}
 
319
 
 
320
/* <matrix> <inv_matrix> invertmatrix <inv_matrix> */
 
321
static int
 
322
zinvertmatrix(i_ctx_t *i_ctx_p)
 
323
{
 
324
    os_ptr op = osp;
 
325
    gs_matrix m;
 
326
    int code;
 
327
 
 
328
    if ((code = read_matrix(imemory, op - 1, &m)) < 0 ||
 
329
        (code = gs_matrix_invert(&m, &m)) < 0 ||
 
330
        (code = write_matrix(op, &m)) < 0
 
331
        )
 
332
        return code;
 
333
    op[-1] = *op;
 
334
    pop(1);
 
335
    return code;
 
336
}
 
337
 
 
338
/* <bbox> <matrix> .bbox_transform <x0> <y0> <x1> <y1> */
 
339
/* Calculate bonding box of a box transformed by a matrix. */
 
340
static int
 
341
zbbox_transform(i_ctx_t *i_ctx_p)
 
342
{
 
343
    os_ptr op = osp;
 
344
    gs_matrix m;
 
345
    float bbox[4];
 
346
    gs_point aa, az, za, zz;
 
347
    floatp temp;
 
348
    int code;
 
349
 
 
350
    if ((code = read_matrix(imemory, op, &m)) < 0)
 
351
        return code;
 
352
    
 
353
    if (!r_is_array(op - 1))
 
354
        return_op_typecheck(op - 1);
 
355
    check_read(op[-1]);
 
356
    if (r_size(op - 1) != 4)
 
357
        return_error(e_rangecheck);
 
358
    if ((code = process_float_array(imemory, op - 1, 4, bbox) < 0))
 
359
        return code;
 
360
 
 
361
    gs_point_transform(bbox[0], bbox[1], &m, &aa);
 
362
    gs_point_transform(bbox[0], bbox[3], &m, &az);
 
363
    gs_point_transform(bbox[2], bbox[1], &m, &za);
 
364
    gs_point_transform(bbox[2], bbox[3], &m, &zz);
 
365
 
 
366
    if ( aa.x > az.x)
 
367
        temp = aa.x, aa.x = az.x, az.x = temp;
 
368
    if ( za.x > zz.x)
 
369
        temp = za.x, za.x = zz.x, zz.x = temp;
 
370
    if ( za.x < aa.x)
 
371
        aa.x = za.x;  /* min */
 
372
    if ( az.x > zz.x)
 
373
        zz.x = az.x;  /* max */
 
374
 
 
375
    if ( aa.y > az.y)
 
376
        temp = aa.y, aa.y = az.y, az.y = temp;
 
377
    if ( za.y > zz.y)
 
378
        temp = za.y, za.y = zz.y, zz.y = temp;
 
379
    if ( za.y < aa.y)
 
380
        aa.y = za.y;  /* min */
 
381
    if ( az.y > zz.y)
 
382
        zz.y = az.y;  /* max */
 
383
 
 
384
    push(2);
 
385
    make_real(op - 3, (float)aa.x);
 
386
    make_real(op - 2, (float)aa.y);
 
387
    make_real(op - 1, (float)zz.x);
 
388
    make_real(op    , (float)zz.y);
 
389
    return 0;
 
390
}
 
391
 
 
392
/* ------ Initialization procedure ------ */
 
393
 
 
394
const op_def zmatrix_op_defs[] =
 
395
{
 
396
    {"1concat", zconcat},
 
397
    {"2dtransform", zdtransform},
 
398
    {"3concatmatrix", zconcatmatrix},
 
399
    {"0.currentmatrix", zcurrentmatrix},
 
400
    {"1defaultmatrix", zdefaultmatrix},
 
401
    {"2idtransform", zidtransform},
 
402
    {"0initmatrix", zinitmatrix},
 
403
    {"2invertmatrix", zinvertmatrix},
 
404
    {"2itransform", zitransform},
 
405
    {"1rotate", zrotate},
 
406
    {"2scale", zscale},
 
407
    {"6.setmatrix", zsetmatrix},
 
408
    {"1.setdefaultmatrix", zsetdefaultmatrix},
 
409
    {"2transform", ztransform},
 
410
    {"2translate", ztranslate},
 
411
    op_def_end(0)
 
412
};
 
413
 
 
414
const op_def zmatrix2_op_defs[] =
 
415
{
 
416
    {"2.bbox_transform", zbbox_transform},
 
417
    op_def_end(0)
 
418
};