1 #ifndef MUPDF_FITZ_BUFFER_H
2 #define MUPDF_FITZ_BUFFER_H
4 #include "mupdf/fitz/system.h"
5 #include "mupdf/fitz/context.h"
8 fz_buffer is a wrapper around a dynamically allocated array of bytes.
10 Buffers have a capacity (the number of bytes storage immediately
11 available) and a current size.
13 typedef struct fz_buffer_s fz_buffer;
16 fz_keep_buffer: Increment the reference count for a buffer.
18 buf: The buffer to increment the reference count for.
20 Returns a pointer to the buffer. Does not throw exceptions.
22 fz_buffer *fz_keep_buffer(fz_context *ctx, fz_buffer *buf);
25 fz_drop_buffer: Decrement the reference count for a buffer.
27 buf: The buffer to decrement the reference count for.
29 void fz_drop_buffer(fz_context *ctx, fz_buffer *buf);
32 fz_buffer_storage: Retrieve information on the storage currently used
35 data: Pointer to place to retrieve data pointer.
37 Returns length of stream.
39 int fz_buffer_storage(fz_context *ctx, fz_buffer *buf, unsigned char **data);
50 fz_new_buffer: Create a new buffer.
52 capacity: Initial capacity.
54 Returns pointer to new buffer. Throws exception on allocation
57 fz_buffer *fz_new_buffer(fz_context *ctx, int capacity);
60 fz_new_buffer_from_data: Create a new buffer with existing data.
62 data: Pointer to existing data.
63 size: Size of existing data.
65 Takes ownership of data. Does not make a copy. Calls fz_free on the
66 data when the buffer is deallocated. Do not use 'data' after passing
69 Returns pointer to new buffer. Throws exception on allocation
72 fz_buffer *fz_new_buffer_from_data(fz_context *ctx, unsigned char *data, int size);
75 fz_resize_buffer: Ensure that a buffer has a given capacity,
76 truncating data if required.
78 buf: The buffer to alter.
80 capacity: The desired capacity for the buffer. If the current size
81 of the buffer contents is smaller than capacity, it is truncated.
84 void fz_resize_buffer(fz_context *ctx, fz_buffer *buf, int capacity);
87 fz_grow_buffer: Make some space within a buffer (i.e. ensure that
90 buf: The buffer to grow.
92 May throw exception on failure to allocate.
94 void fz_grow_buffer(fz_context *ctx, fz_buffer *buf);
97 fz_trim_buffer: Trim wasted capacity from a buffer.
99 buf: The buffer to trim.
101 void fz_trim_buffer(fz_context *ctx, fz_buffer *buf);
104 fz_buffer_cat: Concatenate buffers
106 buf: first to concatenate and the holder of the result
107 extra: second to concatenate
109 May throw exception on failure to allocate.
111 void fz_buffer_cat(fz_context *ctx, fz_buffer *buf, fz_buffer *extra);
113 void fz_write_buffer(fz_context *ctx, fz_buffer *buf, const void *data, int len);
115 void fz_write_buffer_byte(fz_context *ctx, fz_buffer *buf, int val);
117 void fz_write_buffer_rune(fz_context *ctx, fz_buffer *buf, int val);
119 void fz_write_buffer_bits(fz_context *ctx, fz_buffer *buf, int val, int bits);
121 void fz_write_buffer_pad(fz_context *ctx, fz_buffer *buf);
124 fz_buffer_printf: print formatted to a buffer. The buffer will grow
127 int fz_buffer_printf(fz_context *ctx, fz_buffer *buffer, const char *fmt, ...);
128 int fz_buffer_vprintf(fz_context *ctx, fz_buffer *buffer, const char *fmt, va_list args);
131 fz_buffer_printf: print a string formatted as a pdf string to a buffer.
132 The buffer will grow.
135 fz_buffer_cat_pdf_string(fz_context *ctx, fz_buffer *buffer, const char *text);