1
/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */
2
/* cairo - a vector graphics library with display and print output
3
 *
4
 * Copyright (c) 2008  M Joonas Pihlaja
5
 *
6
 * Permission is hereby granted, free of charge, to any person
7
 * obtaining a copy of this software and associated documentation
8
 * files (the "Software"), to deal in the Software without
9
 * restriction, including without limitation the rights to use,
10
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
11
 * copies of the Software, and to permit persons to whom the
12
 * Software is furnished to do so, subject to the following
13
 * conditions:
14
 *
15
 * The above copyright notice and this permission notice shall be
16
 * included in all copies or substantial portions of the Software.
17
 *
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25
 * OTHER DEALINGS IN THE SOFTWARE.
26
 */
27
#include "cairoint.h"
28

            
29
#include "cairo-composite-rectangles-private.h"
30
#include "cairo-clip-private.h"
31
#include "cairo-error-private.h"
32
#include "cairo-fixed-private.h"
33
#include "cairo-types-private.h"
34

            
35
static void
36
_cairo_nil_destroy (void *abstract)
37
{
38
    (void) abstract;
39
}
40

            
41
static cairo_status_t
42
_cairo_nil_scan_converter_generate (void *abstract_converter,
43
				    cairo_span_renderer_t *renderer)
44
{
45
    (void) abstract_converter;
46
    (void) renderer;
47
    return _cairo_scan_converter_status (abstract_converter);
48
}
49

            
50
cairo_status_t
51
_cairo_scan_converter_status (void *abstract_converter)
52
{
53
    cairo_scan_converter_t *converter = abstract_converter;
54
    return converter->status;
55
}
56

            
57
cairo_status_t
58
_cairo_scan_converter_set_error (void *abstract_converter,
59
				 cairo_status_t error)
60
{
61
    cairo_scan_converter_t *converter = abstract_converter;
62
    if (error == CAIRO_STATUS_SUCCESS)
63
	ASSERT_NOT_REACHED;
64
    if (converter->status == CAIRO_STATUS_SUCCESS) {
65
	converter->generate = _cairo_nil_scan_converter_generate;
66
	converter->status = error;
67
    }
68
    return converter->status;
69
}
70

            
71
static void
72
_cairo_nil_scan_converter_init (cairo_scan_converter_t *converter,
73
				cairo_status_t status)
74
{
75
    converter->destroy = _cairo_nil_destroy;
76
    converter->status = CAIRO_STATUS_SUCCESS;
77
    status = _cairo_scan_converter_set_error (converter, status);
78
}
79

            
80
cairo_scan_converter_t *
81
_cairo_scan_converter_create_in_error (cairo_status_t status)
82
{
83
#define RETURN_NIL {\
84
	    static cairo_scan_converter_t nil;\
85
	    _cairo_nil_scan_converter_init (&nil, status);\
86
	    return &nil;\
87
	}
88
    switch (status) {
89
    case CAIRO_STATUS_SUCCESS:
90
    case CAIRO_STATUS_LAST_STATUS:
91
	ASSERT_NOT_REACHED;
92
	break;
93
    case CAIRO_STATUS_INVALID_RESTORE: RETURN_NIL;
94
    case CAIRO_STATUS_INVALID_POP_GROUP: RETURN_NIL;
95
    case CAIRO_STATUS_NO_CURRENT_POINT: RETURN_NIL;
96
    case CAIRO_STATUS_INVALID_MATRIX: RETURN_NIL;
97
    case CAIRO_STATUS_INVALID_STATUS: RETURN_NIL;
98
    case CAIRO_STATUS_NULL_POINTER: RETURN_NIL;
99
    case CAIRO_STATUS_INVALID_STRING: RETURN_NIL;
100
    case CAIRO_STATUS_INVALID_PATH_DATA: RETURN_NIL;
101
    case CAIRO_STATUS_READ_ERROR: RETURN_NIL;
102
    case CAIRO_STATUS_WRITE_ERROR: RETURN_NIL;
103
    case CAIRO_STATUS_SURFACE_FINISHED: RETURN_NIL;
104
    case CAIRO_STATUS_SURFACE_TYPE_MISMATCH: RETURN_NIL;
105
    case CAIRO_STATUS_PATTERN_TYPE_MISMATCH: RETURN_NIL;
106
    case CAIRO_STATUS_INVALID_CONTENT: RETURN_NIL;
107
    case CAIRO_STATUS_INVALID_FORMAT: RETURN_NIL;
108
    case CAIRO_STATUS_INVALID_VISUAL: RETURN_NIL;
109
    case CAIRO_STATUS_FILE_NOT_FOUND: RETURN_NIL;
110
    case CAIRO_STATUS_INVALID_DASH: RETURN_NIL;
111
    case CAIRO_STATUS_INVALID_DSC_COMMENT: RETURN_NIL;
112
    case CAIRO_STATUS_INVALID_INDEX: RETURN_NIL;
113
    case CAIRO_STATUS_CLIP_NOT_REPRESENTABLE: RETURN_NIL;
114
    case CAIRO_STATUS_TEMP_FILE_ERROR: RETURN_NIL;
115
    case CAIRO_STATUS_INVALID_STRIDE: RETURN_NIL;
116
    case CAIRO_STATUS_FONT_TYPE_MISMATCH: RETURN_NIL;
117
    case CAIRO_STATUS_USER_FONT_IMMUTABLE: RETURN_NIL;
118
    case CAIRO_STATUS_USER_FONT_ERROR: RETURN_NIL;
119
    case CAIRO_STATUS_NEGATIVE_COUNT: RETURN_NIL;
120
    case CAIRO_STATUS_INVALID_CLUSTERS: RETURN_NIL;
121
    case CAIRO_STATUS_INVALID_SLANT: RETURN_NIL;
122
    case CAIRO_STATUS_INVALID_WEIGHT: RETURN_NIL;
123
    case CAIRO_STATUS_NO_MEMORY: RETURN_NIL;
124
    case CAIRO_STATUS_INVALID_SIZE: RETURN_NIL;
125
    case CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED: RETURN_NIL;
126
    case CAIRO_STATUS_DEVICE_TYPE_MISMATCH: RETURN_NIL;
127
    case CAIRO_STATUS_DEVICE_ERROR: RETURN_NIL;
128
    case CAIRO_STATUS_INVALID_MESH_CONSTRUCTION: RETURN_NIL;
129
    case CAIRO_STATUS_DEVICE_FINISHED: RETURN_NIL;
130
    case CAIRO_STATUS_JBIG2_GLOBAL_MISSING:
131
    case CAIRO_STATUS_PNG_ERROR:
132
    case CAIRO_STATUS_FREETYPE_ERROR:
133
    case CAIRO_STATUS_WIN32_GDI_ERROR:
134
    case CAIRO_STATUS_TAG_ERROR:
135
    case CAIRO_STATUS_DWRITE_ERROR:
136
    case CAIRO_STATUS_SVG_FONT_ERROR:
137
    default:
138
	break;
139
    }
140
    status = CAIRO_STATUS_NO_MEMORY;
141
    RETURN_NIL;
142
#undef RETURN_NIL
143
}
144

            
145
static cairo_status_t
146
_cairo_nil_span_renderer_render_rows (
147
    void				*abstract_renderer,
148
    int					 y,
149
    int					 height,
150
    const cairo_half_open_span_t	*coverages,
151
    unsigned				 num_coverages)
152
{
153
    (void) y;
154
    (void) height;
155
    (void) coverages;
156
    (void) num_coverages;
157
    return _cairo_span_renderer_status (abstract_renderer);
158
}
159

            
160
static cairo_status_t
161
_cairo_nil_span_renderer_finish (void *abstract_renderer)
162
{
163
    return _cairo_span_renderer_status (abstract_renderer);
164
}
165

            
166
cairo_status_t
167
_cairo_span_renderer_status (void *abstract_renderer)
168
{
169
    cairo_span_renderer_t *renderer = abstract_renderer;
170
    return renderer->status;
171
}
172

            
173
cairo_status_t
174
_cairo_span_renderer_set_error (
175
    void *abstract_renderer,
176
    cairo_status_t error)
177
{
178
    cairo_span_renderer_t *renderer = abstract_renderer;
179
    if (error == CAIRO_STATUS_SUCCESS) {
180
	ASSERT_NOT_REACHED;
181
    }
182
    if (renderer->status == CAIRO_STATUS_SUCCESS) {
183
	renderer->render_rows = _cairo_nil_span_renderer_render_rows;
184
	renderer->finish = _cairo_nil_span_renderer_finish;
185
	renderer->status = error;
186
    }
187
    return renderer->status;
188
}
189

            
190
static void
191
_cairo_nil_span_renderer_init (cairo_span_renderer_t *renderer,
192
			       cairo_status_t status)
193
{
194
    renderer->destroy = _cairo_nil_destroy;
195
    renderer->status = CAIRO_STATUS_SUCCESS;
196
    status = _cairo_span_renderer_set_error (renderer, status);
197
}
198

            
199
cairo_span_renderer_t *
200
_cairo_span_renderer_create_in_error (cairo_status_t status)
201
{
202
#define RETURN_NIL {\
203
	    static cairo_span_renderer_t nil;\
204
	    _cairo_nil_span_renderer_init (&nil, status);\
205
	    return &nil;\
206
	}
207
    switch (status) {
208
    case CAIRO_STATUS_SUCCESS:
209
    case CAIRO_STATUS_LAST_STATUS:
210
	ASSERT_NOT_REACHED;
211
	break;
212
    case CAIRO_STATUS_INVALID_RESTORE: RETURN_NIL;
213
    case CAIRO_STATUS_INVALID_POP_GROUP: RETURN_NIL;
214
    case CAIRO_STATUS_NO_CURRENT_POINT: RETURN_NIL;
215
    case CAIRO_STATUS_INVALID_MATRIX: RETURN_NIL;
216
    case CAIRO_STATUS_INVALID_STATUS: RETURN_NIL;
217
    case CAIRO_STATUS_NULL_POINTER: RETURN_NIL;
218
    case CAIRO_STATUS_INVALID_STRING: RETURN_NIL;
219
    case CAIRO_STATUS_INVALID_PATH_DATA: RETURN_NIL;
220
    case CAIRO_STATUS_READ_ERROR: RETURN_NIL;
221
    case CAIRO_STATUS_WRITE_ERROR: RETURN_NIL;
222
    case CAIRO_STATUS_SURFACE_FINISHED: RETURN_NIL;
223
    case CAIRO_STATUS_SURFACE_TYPE_MISMATCH: RETURN_NIL;
224
    case CAIRO_STATUS_PATTERN_TYPE_MISMATCH: RETURN_NIL;
225
    case CAIRO_STATUS_INVALID_CONTENT: RETURN_NIL;
226
    case CAIRO_STATUS_INVALID_FORMAT: RETURN_NIL;
227
    case CAIRO_STATUS_INVALID_VISUAL: RETURN_NIL;
228
    case CAIRO_STATUS_FILE_NOT_FOUND: RETURN_NIL;
229
    case CAIRO_STATUS_INVALID_DASH: RETURN_NIL;
230
    case CAIRO_STATUS_INVALID_DSC_COMMENT: RETURN_NIL;
231
    case CAIRO_STATUS_INVALID_INDEX: RETURN_NIL;
232
    case CAIRO_STATUS_CLIP_NOT_REPRESENTABLE: RETURN_NIL;
233
    case CAIRO_STATUS_TEMP_FILE_ERROR: RETURN_NIL;
234
    case CAIRO_STATUS_INVALID_STRIDE: RETURN_NIL;
235
    case CAIRO_STATUS_FONT_TYPE_MISMATCH: RETURN_NIL;
236
    case CAIRO_STATUS_USER_FONT_IMMUTABLE: RETURN_NIL;
237
    case CAIRO_STATUS_USER_FONT_ERROR: RETURN_NIL;
238
    case CAIRO_STATUS_NEGATIVE_COUNT: RETURN_NIL;
239
    case CAIRO_STATUS_INVALID_CLUSTERS: RETURN_NIL;
240
    case CAIRO_STATUS_INVALID_SLANT: RETURN_NIL;
241
    case CAIRO_STATUS_INVALID_WEIGHT: RETURN_NIL;
242
    case CAIRO_STATUS_NO_MEMORY: RETURN_NIL;
243
    case CAIRO_STATUS_INVALID_SIZE: RETURN_NIL;
244
    case CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED: RETURN_NIL;
245
    case CAIRO_STATUS_DEVICE_TYPE_MISMATCH: RETURN_NIL;
246
    case CAIRO_STATUS_DEVICE_ERROR: RETURN_NIL;
247
    case CAIRO_STATUS_INVALID_MESH_CONSTRUCTION: RETURN_NIL;
248
    case CAIRO_STATUS_DEVICE_FINISHED: RETURN_NIL;
249
    case CAIRO_STATUS_JBIG2_GLOBAL_MISSING: RETURN_NIL;
250
    case CAIRO_STATUS_PNG_ERROR: RETURN_NIL;
251
    case CAIRO_STATUS_FREETYPE_ERROR: RETURN_NIL;
252
    case CAIRO_STATUS_WIN32_GDI_ERROR: RETURN_NIL;
253
    case CAIRO_STATUS_TAG_ERROR: RETURN_NIL;
254
    case CAIRO_STATUS_DWRITE_ERROR: RETURN_NIL;
255
    case CAIRO_STATUS_SVG_FONT_ERROR: RETURN_NIL;
256
    default:
257
	break;
258
    }
259
    status = CAIRO_STATUS_NO_MEMORY;
260
    RETURN_NIL;
261
#undef RETURN_NIL
262
}