]> rtime.felk.cvut.cz Git - hornmich/skoda-qr-demo.git/blob - QRScanner/mobile/jni/include/mupdf/fitz/buffer.h
Add MuPDF native source codes
[hornmich/skoda-qr-demo.git] / QRScanner / mobile / jni / include / mupdf / fitz / buffer.h
1 #ifndef MUPDF_FITZ_BUFFER_H
2 #define MUPDF_FITZ_BUFFER_H
3
4 #include "mupdf/fitz/system.h"
5 #include "mupdf/fitz/context.h"
6
7 /*
8         fz_buffer is a wrapper around a dynamically allocated array of bytes.
9
10         Buffers have a capacity (the number of bytes storage immediately
11         available) and a current size.
12 */
13 typedef struct fz_buffer_s fz_buffer;
14
15 /*
16         fz_keep_buffer: Increment the reference count for a buffer.
17
18         buf: The buffer to increment the reference count for.
19
20         Returns a pointer to the buffer. Does not throw exceptions.
21 */
22 fz_buffer *fz_keep_buffer(fz_context *ctx, fz_buffer *buf);
23
24 /*
25         fz_drop_buffer: Decrement the reference count for a buffer.
26
27         buf: The buffer to decrement the reference count for.
28 */
29 void fz_drop_buffer(fz_context *ctx, fz_buffer *buf);
30
31 /*
32         fz_buffer_storage: Retrieve information on the storage currently used
33         by a buffer.
34
35         data: Pointer to place to retrieve data pointer.
36
37         Returns length of stream.
38 */
39 int fz_buffer_storage(fz_context *ctx, fz_buffer *buf, unsigned char **data);
40
41 struct fz_buffer_s
42 {
43         int refs;
44         unsigned char *data;
45         int cap, len;
46         int unused_bits;
47 };
48
49 /*
50         fz_new_buffer: Create a new buffer.
51
52         capacity: Initial capacity.
53
54         Returns pointer to new buffer. Throws exception on allocation
55         failure.
56 */
57 fz_buffer *fz_new_buffer(fz_context *ctx, int capacity);
58
59 /*
60         fz_new_buffer_from_data: Create a new buffer with existing data.
61
62         data: Pointer to existing data.
63         size: Size of existing data.
64
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
67         to this function.
68
69         Returns pointer to new buffer. Throws exception on allocation
70         failure.
71 */
72 fz_buffer *fz_new_buffer_from_data(fz_context *ctx, unsigned char *data, int size);
73
74 /*
75         fz_resize_buffer: Ensure that a buffer has a given capacity,
76         truncating data if required.
77
78         buf: The buffer to alter.
79
80         capacity: The desired capacity for the buffer. If the current size
81         of the buffer contents is smaller than capacity, it is truncated.
82
83 */
84 void fz_resize_buffer(fz_context *ctx, fz_buffer *buf, int capacity);
85
86 /*
87         fz_grow_buffer: Make some space within a buffer (i.e. ensure that
88         capacity > size).
89
90         buf: The buffer to grow.
91
92         May throw exception on failure to allocate.
93 */
94 void fz_grow_buffer(fz_context *ctx, fz_buffer *buf);
95
96 /*
97         fz_trim_buffer: Trim wasted capacity from a buffer.
98
99         buf: The buffer to trim.
100 */
101 void fz_trim_buffer(fz_context *ctx, fz_buffer *buf);
102
103 /*
104         fz_buffer_cat: Concatenate buffers
105
106         buf: first to concatenate and the holder of the result
107         extra: second to concatenate
108
109         May throw exception on failure to allocate.
110 */
111 void fz_buffer_cat(fz_context *ctx, fz_buffer *buf, fz_buffer *extra);
112
113 void fz_write_buffer(fz_context *ctx, fz_buffer *buf, const void *data, int len);
114
115 void fz_write_buffer_byte(fz_context *ctx, fz_buffer *buf, int val);
116
117 void fz_write_buffer_rune(fz_context *ctx, fz_buffer *buf, int val);
118
119 void fz_write_buffer_bits(fz_context *ctx, fz_buffer *buf, int val, int bits);
120
121 void fz_write_buffer_pad(fz_context *ctx, fz_buffer *buf);
122
123 /*
124         fz_buffer_printf: print formatted to a buffer. The buffer will grow
125         as required.
126 */
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);
129
130 /*
131         fz_buffer_printf: print a string formatted as a pdf string to a buffer.
132         The buffer will grow.
133 */
134 void
135 fz_buffer_cat_pdf_string(fz_context *ctx, fz_buffer *buffer, const char *text);
136
137 #endif