1 /* cairo - a vector graphics library with display and print output 2 * 3 * Copyright © 2006 Red Hat, Inc 4 * 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. 12 * 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., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA 16 * You should have received a copy of the MPL along with this library 17 * in the file COPYING-MPL-1.1 18 * 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/ 23 * 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. 27 * 28 * The Original Code is the cairo graphics library. 29 * 30 * The Initial Developer of the Original Code is Red Hat, Inc. 31 * 32 * Author(s): 33 * Kristian Høgsberg <krh@redhat.com> 34 */ 35 36 #ifndef CAIRO_OUTPUT_STREAM_PRIVATE_H 37 #define CAIRO_OUTPUT_STREAM_PRIVATE_H 38 39 #include "cairo-compiler-private.h" 40 #include "cairo-types-private.h" 41 42 #include <stdlib.h> 43 #include <stdio.h> 44 #include <stdarg.h> 45 46 typedef cairo_status_t 47 (*cairo_output_stream_write_func_t) (cairo_output_stream_t *output_stream, 48 const unsigned char *data, 49 unsigned int length); 50 51 typedef cairo_status_t 52 (*cairo_output_stream_flush_func_t) (cairo_output_stream_t *output_stream); 53 54 typedef cairo_status_t 55 (*cairo_output_stream_close_func_t) (cairo_output_stream_t *output_stream); 56 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; 63 cairo_bool_t closed; 64 }; 65 66 extern const cairo_private cairo_output_stream_t _cairo_output_stream_nil; 67 68 cairo_private void 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); 73 74 cairo_private cairo_status_t 75 _cairo_output_stream_fini (cairo_output_stream_t *stream); 76 77 78 /* We already have the following declared in cairo.h: 79 80 typedef cairo_status_t (*cairo_write_func_t) (void *closure, 81 const unsigned char *data, 82 unsigned int length); 83 */ 84 typedef cairo_status_t (*cairo_close_func_t) (void *closure); 85 86 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. 90 * 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. 94 */ 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, 98 void *closure); 99 100 cairo_private cairo_output_stream_t * 101 _cairo_output_stream_create_in_error (cairo_status_t status); 102 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); 106 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); 112 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); 118 119 cairo_private void 120 _cairo_output_stream_write (cairo_output_stream_t *stream, 121 const void *data, size_t length); 122 123 cairo_private void 124 _cairo_output_stream_write_hex_string (cairo_output_stream_t *stream, 125 const unsigned char *data, 126 size_t length); 127 128 cairo_private void 129 _cairo_output_stream_vprintf (cairo_output_stream_t *stream, 130 const char *fmt, 131 va_list ap) CAIRO_PRINTF_FORMAT ( 2, 0); 132 133 cairo_private void 134 _cairo_output_stream_printf (cairo_output_stream_t *stream, 135 const char *fmt, 136 ...) CAIRO_PRINTF_FORMAT (2, 3); 137 138 /* Print matrix element values with rounding of insignificant digits. */ 139 cairo_private void 140 _cairo_output_stream_print_matrix (cairo_output_stream_t *stream, 141 const cairo_matrix_t *matrix); 142 143 cairo_private long 144 _cairo_output_stream_get_position (cairo_output_stream_t *stream); 145 146 cairo_private cairo_status_t 147 _cairo_output_stream_get_status (cairo_output_stream_t *stream); 148 149 /* This function never returns %NULL. If an error occurs (NO_MEMORY or 150 * WRITE_ERROR) while trying to create the output stream this function 151 * returns a valid pointer to a nil output stream. 152 * 153 * Note: Even if a nil surface is returned, the caller should still 154 * call _cairo_output_stream_destroy (or _cairo_output_stream_close at 155 * least) in order to ensure that everything is properly cleaned up. 156 */ 157 cairo_private cairo_output_stream_t * 158 _cairo_output_stream_create_for_filename (const char *filename); 159 160 /* This function never returns %NULL. If an error occurs (NO_MEMORY or 161 * WRITE_ERROR) while trying to create the output stream this function 162 * returns a valid pointer to a nil output stream. 163 * 164 * The caller still "owns" file and is responsible for calling fclose 165 * on it when finished. The stream will not do this itself. 166 */ 167 cairo_private cairo_output_stream_t * 168 _cairo_output_stream_create_for_file (FILE *file); 169 170 cairo_private cairo_output_stream_t * 171 _cairo_memory_stream_create (void); 172 173 cairo_private void 174 _cairo_memory_stream_copy (cairo_output_stream_t *base, 175 cairo_output_stream_t *dest); 176 177 cairo_private int 178 _cairo_memory_stream_length (cairo_output_stream_t *stream); 179 180 cairo_private cairo_status_t 181 _cairo_memory_stream_destroy (cairo_output_stream_t *abstract_stream, 182 unsigned char **data_out, 183 unsigned long *length_out); 184 185 cairo_private cairo_output_stream_t * 186 _cairo_null_stream_create (void); 187 188 /* cairo-base85-stream.c */ 189 cairo_private cairo_output_stream_t * 190 _cairo_base85_stream_create (cairo_output_stream_t *output); 191 192 /* cairo-base64-stream.c */ 193 cairo_private cairo_output_stream_t * 194 _cairo_base64_stream_create (cairo_output_stream_t *output); 195 196 /* cairo-deflate-stream.c */ 197 cairo_private cairo_output_stream_t * 198 _cairo_deflate_stream_create (cairo_output_stream_t *output); 199 200 201 #endif /* CAIRO_OUTPUT_STREAM_PRIVATE_H */ 202