summaryrefslogtreecommitdiff
path: root/psi/zpaint.c
blob: 6213f6c1e589ad90ca9620d8a27f46b4e0396b2a (plain)
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
/* Copyright (C) 2001-2023 Artifex Software, Inc.
   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 the license contained in the file LICENSE in this distribution.

   Refer to licensing information at http://www.artifex.com or contact
   Artifex Software, Inc.,  39 Mesa Street, Suite 108A, San Francisco,
   CA 94129, USA, for further information.
*/


/* Painting operators */
#include "ghost.h"
#include "oper.h"
#include "gspaint.h"
#include "igstate.h"
#include "store.h"
#include "estack.h"

/* - fill - */
static int
zfill(i_ctx_t *i_ctx_p)
{
    return gs_fill(igs);
}

/* - eofill - */
static int
zeofill(i_ctx_t *i_ctx_p)
{
    return gs_eofill(igs);
}

/* - stroke - */
static int
zstroke(i_ctx_t *i_ctx_p)
{
    return gs_stroke(igs);
}

static int
fillstroke_cont(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    int restart, code;

    check_type(*op, t_integer);
    restart = (int)op->value.intval;
    code = gs_fillstroke(igs, &restart);
    if (code == gs_error_Remap_Color) {
        op->value.intval = restart;
        return code;
    }
    pop(1);
    return code;
}

static int
zfillstroke(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    push(1);
    make_int(op, 0);		/* 0 implies we are at fill color, need to swap first */
    push_op_estack(fillstroke_cont);
    return o_push_estack;
}

static int
eofillstroke_cont(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    int restart, code;

    check_type(*op, t_integer);
    restart = (int)op->value.intval;
    code = gs_eofillstroke(igs, &restart);
    if (code == gs_error_Remap_Color) {
        op->value.intval = restart;
        return code;
    }
    pop(1);
    return code;
}

static int
zeofillstroke(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    push(1);
    make_int(op, 0);
    push_op_estack(eofillstroke_cont);
    return o_push_estack;
}

/* ------ Non-standard operators ------ */

/* - .fillpage - */
static int
zfillpage(i_ctx_t *i_ctx_p)
{
    return gs_fillpage(igs);
}

/* <width> <height> <data> .imagepath - */
static int
zimagepath(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    int code;

    check_type(op[-2], t_integer);
    check_type(op[-1], t_integer);
    check_read_type(*op, t_string);
    if (r_size(op) < ((op[-2].value.intval + 7) >> 3) * op[-1].value.intval)
        return_error(gs_error_rangecheck);
    code = gs_imagepath(igs,
                        (int)op[-2].value.intval, (int)op[-1].value.intval,
                        op->value.const_bytes);
    if (code >= 0)
        pop(3);
    return code;
}

/* ------ Initialization procedure ------ */

const op_def zpaint_op_defs[] =
{
    {"0eofill", zeofill},
    {"0fill", zfill},
    {"0stroke", zstroke},
                /* Non-standard operators */
    {"0.fillpage", zfillpage},
    {"3.imagepath", zimagepath},
    {"0.eofillstroke", zeofillstroke},
    {"0.fillstroke", zfillstroke},
    {"0%eofillstroke_cont", eofillstroke_cont },
    {"0%fillstroke_cont", fillstroke_cont },
    op_def_end(0)
};