#ifndef MUPDF_FITZ_BUFFER_H1#define MUPDF_FITZ_BUFFER_H23#include "mupdf/fitz/system.h"4#include "mupdf/fitz/context.h"56/*7fz_buffer is a wrapper around a dynamically allocated array of bytes.89Buffers have a capacity (the number of bytes storage immediately10available) and a current size.11*/12typedef struct fz_buffer_s fz_buffer;1314/*15fz_keep_buffer: Increment the reference count for a buffer.1617buf: The buffer to increment the reference count for.1819Returns a pointer to the buffer. Does not throw exceptions.20*/21fz_buffer *fz_keep_buffer(fz_context *ctx, fz_buffer *buf);2223/*24fz_drop_buffer: Decrement the reference count for a buffer.2526buf: The buffer to decrement the reference count for.27*/28void fz_drop_buffer(fz_context *ctx, fz_buffer *buf);2930/*31fz_buffer_storage: Retrieve information on the storage currently used32by a buffer.3334data: Pointer to place to retrieve data pointer.3536Returns length of stream.37*/38int fz_buffer_storage(fz_context *ctx, fz_buffer *buf, unsigned char **data);3940struct fz_buffer_s41{42int refs;43unsigned char *data;44int cap, len;45int unused_bits;46};4748/*49fz_new_buffer: Create a new buffer.5051capacity: Initial capacity.5253Returns pointer to new buffer. Throws exception on allocation54failure.55*/56fz_buffer *fz_new_buffer(fz_context *ctx, int capacity);5758/*59fz_new_buffer_from_data: Create a new buffer with existing data.6061data: Pointer to existing data.62size: Size of existing data.6364Takes ownership of data. Does not make a copy. Calls fz_free on the65data when the buffer is deallocated. Do not use 'data' after passing66to this function.6768Returns pointer to new buffer. Throws exception on allocation69failure.70*/71fz_buffer *fz_new_buffer_from_data(fz_context *ctx, unsigned char *data, int size);7273/*74fz_resize_buffer: Ensure that a buffer has a given capacity,75truncating data if required.7677buf: The buffer to alter.7879capacity: The desired capacity for the buffer. If the current size80of the buffer contents is smaller than capacity, it is truncated.8182*/83void fz_resize_buffer(fz_context *ctx, fz_buffer *buf, int capacity);8485/*86fz_grow_buffer: Make some space within a buffer (i.e. ensure that87capacity > size).8889buf: The buffer to grow.9091May throw exception on failure to allocate.92*/93void fz_grow_buffer(fz_context *ctx, fz_buffer *buf);9495/*96fz_trim_buffer: Trim wasted capacity from a buffer.9798buf: The buffer to trim.99*/100void fz_trim_buffer(fz_context *ctx, fz_buffer *buf);101102/*103fz_buffer_cat: Concatenate buffers104105buf: first to concatenate and the holder of the result106extra: second to concatenate107108May throw exception on failure to allocate.109*/110void fz_buffer_cat(fz_context *ctx, fz_buffer *buf, fz_buffer *extra);111112void fz_write_buffer(fz_context *ctx, fz_buffer *buf, const void *data, int len);113114void fz_write_buffer_byte(fz_context *ctx, fz_buffer *buf, int val);115116void fz_write_buffer_rune(fz_context *ctx, fz_buffer *buf, int val);117118void fz_write_buffer_bits(fz_context *ctx, fz_buffer *buf, int val, int bits);119120void fz_write_buffer_pad(fz_context *ctx, fz_buffer *buf);121122/*123fz_buffer_printf: print formatted to a buffer. The buffer will grow124as required.125*/126int fz_buffer_printf(fz_context *ctx, fz_buffer *buffer, const char *fmt, ...);127int fz_buffer_vprintf(fz_context *ctx, fz_buffer *buffer, const char *fmt, va_list args);128129/*130fz_buffer_printf: print a string formatted as a pdf string to a buffer.131The buffer will grow.132*/133void134fz_buffer_cat_pdf_string(fz_context *ctx, fz_buffer *buffer, const char *text);135136#endif137138139