1 /* cairo - a vector graphics library with display and print output
3 * Copyright © 2006 Red Hat, Inc
5 * This library is free software; you can redistribute it and/or
6 * modify it either under the terms of the GNU Lesser General Public
7 * License version 2.1 as published by the Free Software Foundation
8 * (the "LGPL") or, at your option, under the terms of the Mozilla
9 * Public License Version 1.1 (the "MPL"). If you do not alter this
10 * notice, a recipient may use your version of this file under either
11 * the MPL or the LGPL.
13 * You should have received a copy of the LGPL along with this library
14 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 * You should have received a copy of the MPL along with this library
17 * in the file COPYING-MPL-1.1
19 * The contents of this file are subject to the Mozilla Public License
20 * Version 1.1 (the "License"); you may not use this file except in
21 * compliance with the License. You may obtain a copy of the License at
22 * http://www.mozilla.org/MPL/
24 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
25 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
26 * the specific language governing rights and limitations.
28 * The Original Code is the cairo graphics library.
30 * The Initial Developer of the Original Code is Red Hat, Inc.
33 * Kristian Høgsberg <krh@redhat.com>
36 #ifndef CAIRO_OUTPUT_STREAM_PRIVATE_H
37 #define CAIRO_OUTPUT_STREAM_PRIVATE_H
39 #include "cairo-compiler-private.h"
40 #include "cairo-types-private.h"
46 typedef cairo_status_t
47 (*cairo_output_stream_write_func_t
) (cairo_output_stream_t
*output_stream
,
48 const unsigned char *data
,
51 typedef cairo_status_t
52 (*cairo_output_stream_flush_func_t
) (cairo_output_stream_t
*output_stream
);
54 typedef cairo_status_t
55 (*cairo_output_stream_close_func_t
) (cairo_output_stream_t
*output_stream
);
57 struct _cairo_output_stream
{
58 cairo_output_stream_write_func_t write_func
;
59 cairo_output_stream_flush_func_t flush_func
;
60 cairo_output_stream_close_func_t close_func
;
61 unsigned long position
;
62 cairo_status_t status
;
66 extern const cairo_private cairo_output_stream_t _cairo_output_stream_nil
;
69 _cairo_output_stream_init (cairo_output_stream_t
*stream
,
70 cairo_output_stream_write_func_t write_func
,
71 cairo_output_stream_flush_func_t flush_func
,
72 cairo_output_stream_close_func_t close_func
);
74 cairo_private cairo_status_t
75 _cairo_output_stream_fini (cairo_output_stream_t
*stream
);
78 /* We already have the following declared in cairo.h:
80 typedef cairo_status_t (*cairo_write_func_t) (void *closure,
81 const unsigned char *data,
84 typedef cairo_status_t (*cairo_close_func_t
) (void *closure
);
87 /* This function never returns %NULL. If an error occurs (NO_MEMORY)
88 * while trying to create the output stream this function returns a
89 * valid pointer to a nil output stream.
91 * Note that even with a nil surface, the close_func callback will be
92 * called by a call to _cairo_output_stream_close or
93 * _cairo_output_stream_destroy.
95 cairo_private cairo_output_stream_t
*
96 _cairo_output_stream_create (cairo_write_func_t write_func
,
97 cairo_close_func_t close_func
,
100 cairo_private cairo_output_stream_t
*
101 _cairo_output_stream_create_in_error (cairo_status_t status
);
103 /* Tries to flush any buffer maintained by the stream or its delegates. */
104 cairo_private cairo_status_t
105 _cairo_output_stream_flush (cairo_output_stream_t
*stream
);
107 /* Returns the final status value associated with this object, just
108 * before its last gasp. This final status value will capture any
109 * status failure returned by the stream's close_func as well. */
110 cairo_private cairo_status_t
111 _cairo_output_stream_close (cairo_output_stream_t
*stream
);
113 /* Returns the final status value associated with this object, just
114 * before its last gasp. This final status value will capture any
115 * status failure returned by the stream's close_func as well. */
116 cairo_private cairo_status_t
117 _cairo_output_stream_destroy (cairo_output_stream_t
*stream
);
120 _cairo_output_stream_write (cairo_output_stream_t
*stream
,
121 const void *data
, size_t length
);
124 _cairo_output_stream_write_hex_string (cairo_output_stream_t
*stream
,
125 const unsigned char *data
,
129 _cairo_output_stream_vprintf (cairo_output_stream_t
*stream
,
131 va_list ap
) CAIRO_PRINTF_FORMAT ( 2, 0);
134 _cairo_output_stream_printf (cairo_output_stream_t
*stream
,
136 ...) CAIRO_PRINTF_FORMAT (2, 3);
139 _cairo_output_stream_get_position (cairo_output_stream_t
*stream
);
141 cairo_private cairo_status_t
142 _cairo_output_stream_get_status (cairo_output_stream_t
*stream
);
144 /* This function never returns %NULL. If an error occurs (NO_MEMORY or
145 * WRITE_ERROR) while trying to create the output stream this function
146 * returns a valid pointer to a nil output stream.
148 * Note: Even if a nil surface is returned, the caller should still
149 * call _cairo_output_stream_destroy (or _cairo_output_stream_close at
150 * least) in order to ensure that everything is properly cleaned up.
152 cairo_private cairo_output_stream_t
*
153 _cairo_output_stream_create_for_filename (const char *filename
);
155 /* This function never returns %NULL. If an error occurs (NO_MEMORY or
156 * WRITE_ERROR) while trying to create the output stream this function
157 * returns a valid pointer to a nil output stream.
159 * The caller still "owns" file and is responsible for calling fclose
160 * on it when finished. The stream will not do this itself.
162 cairo_private cairo_output_stream_t
*
163 _cairo_output_stream_create_for_file (FILE *file
);
165 cairo_private cairo_output_stream_t
*
166 _cairo_memory_stream_create (void);
169 _cairo_memory_stream_copy (cairo_output_stream_t
*base
,
170 cairo_output_stream_t
*dest
);
173 _cairo_memory_stream_length (cairo_output_stream_t
*stream
);
175 cairo_private cairo_status_t
176 _cairo_memory_stream_destroy (cairo_output_stream_t
*abstract_stream
,
177 unsigned char **data_out
,
178 unsigned int *length_out
);
180 cairo_private cairo_output_stream_t
*
181 _cairo_null_stream_create (void);
183 /* cairo-base85-stream.c */
184 cairo_private cairo_output_stream_t
*
185 _cairo_base85_stream_create (cairo_output_stream_t
*output
);
187 /* cairo-deflate-stream.c */
188 cairo_private cairo_output_stream_t
*
189 _cairo_deflate_stream_create (cairo_output_stream_t
*output
);
192 #endif /* CAIRO_OUTPUT_STREAM_PRIVATE_H */