From 2bd952f3fa8241aad0626f39343cffa9855c2d8c Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Mon, 12 Mar 2012 15:57:28 +0000 Subject: More API work. Details of buffers hidden in fitz-internal.h. Public API now just lets us keep/drop and get storage details for a buffer. fz_debug_outline{,_xml} lose the 'level' param in their public API. fz_matrix_max_expansion hidden, as it's only used internally. Document fz_setjmp/fz_longjmp and Apple specific hackery. --- fitz/doc_outline.c | 22 ++++++++++++---- fitz/fitz-internal.h | 47 ++++++++++++++++++++++++++++++++++ fitz/fitz.h | 72 ++++++++++++++++++---------------------------------- fitz/stm_buffer.c | 8 ++++++ 4 files changed, 97 insertions(+), 52 deletions(-) (limited to 'fitz') diff --git a/fitz/doc_outline.c b/fitz/doc_outline.c index a00c56f1..4847b919 100644 --- a/fitz/doc_outline.c +++ b/fitz/doc_outline.c @@ -14,8 +14,8 @@ fz_free_outline(fz_context *ctx, fz_outline *outline) } } -void -fz_debug_outline_xml(fz_context *ctx, fz_outline *outline, int level) +static void +do_debug_outline_xml(fz_outline *outline, int level) { while (outline) { @@ -23,7 +23,7 @@ fz_debug_outline_xml(fz_context *ctx, fz_outline *outline, int level) if (outline->down) { printf(">\n"); - fz_debug_outline_xml(ctx, outline->down, level + 1); + do_debug_outline_xml(outline->down, level + 1); printf("\n"); } else @@ -35,7 +35,13 @@ fz_debug_outline_xml(fz_context *ctx, fz_outline *outline, int level) } void -fz_debug_outline(fz_context *ctx, fz_outline *outline, int level) +fz_debug_outline_xml(fz_context *ctx, fz_outline *outline) +{ + do_debug_outline_xml(outline, 0); +} + +static void +do_debug_outline(fz_outline *outline, int level) { int i; while (outline) @@ -44,7 +50,13 @@ fz_debug_outline(fz_context *ctx, fz_outline *outline, int level) putchar('\t'); printf("%s\t%d\n", outline->title, outline->dest.kind == FZ_LINK_GOTO ? outline->dest.ld.gotor.page + 1 : 0); if (outline->down) - fz_debug_outline(ctx, outline->down, level + 1); + do_debug_outline(outline->down, level + 1); outline = outline->next; } } + +void +fz_debug_outline(fz_context *ctx, fz_outline *outline) +{ + do_debug_outline(outline, 0); +} diff --git a/fitz/fitz-internal.h b/fitz/fitz-internal.h index 5c4e9514..f9604443 100644 --- a/fitz/fitz-internal.h +++ b/fitz/fitz-internal.h @@ -125,6 +125,7 @@ static inline int fz_mul255(int a, int b) #define FZ_BLEND(SRC, DST, AMOUNT) ((((SRC)-(DST))*(AMOUNT) + ((DST)<<8))>>8) void fz_gridfit_matrix(fz_matrix *m); +float fz_matrix_max_expansion(fz_matrix m); /* * Basic crypto functions. @@ -376,6 +377,52 @@ void fz_empty_store(fz_context *ctx); */ int fz_store_scavenge(fz_context *ctx, unsigned int size, int *phase); +struct fz_buffer_s +{ + int refs; + unsigned char *data; + int cap, len; +}; + +/* + fz_new_buffer: Create a new buffer. + + capacity: Initial capacity. + + Returns pointer to new buffer. Throws exception on allocation + failure. +*/ +fz_buffer *fz_new_buffer(fz_context *ctx, int capacity); + +/* + fz_resize_buffer: Ensure that a buffer has a given capacity, + truncating data if required. + + buf: The buffer to alter. + + capacity: The desired capacity for the buffer. If the current size + of the buffer contents is smaller than capacity, it is truncated. + +*/ +void fz_resize_buffer(fz_context *ctx, fz_buffer *buf, int capacity); + +/* + fz_grow_buffer: Make some space within a buffer (i.e. ensure that + capacity > size). + + buf: The buffer to grow. + + May throw exception on failure to allocate. +*/ +void fz_grow_buffer(fz_context *ctx, fz_buffer *buf); + +/* + fz_trim_buffer: Trim wasted capacity from a buffer. + + buf: The buffer to trim. +*/ +void fz_trim_buffer(fz_context *ctx, fz_buffer *buf); + struct fz_stream_s { fz_context *ctx; diff --git a/fitz/fitz.h b/fitz/fitz.h index fedf6ea4..4592f315 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -22,6 +22,12 @@ #include "memento.h" +/* + Some versions of setjmp/longjmp (notably MacOSX and ios) store/restore + signal handlers too. We don't alter signal handlers within mupdf, so + there is no need for us to store/restore - hence we use the + non-restoring variants. This makes a large speed difference. +*/ #ifdef __APPLE__ #define fz_setjmp _setjmp #define fz_longjmp _longjmp @@ -781,7 +787,6 @@ int fz_is_rectilinear(fz_matrix m); fz_matrix_expansion: Calculate average scaling factor of matrix. */ float fz_matrix_expansion(fz_matrix m); /* sumatrapdf */ -float fz_matrix_max_expansion(fz_matrix m); /* fz_round_rect: Convert a rect into a bounding box. @@ -902,23 +907,6 @@ fz_bbox fz_transform_bbox(fz_matrix matrix, fz_bbox bbox); */ typedef struct fz_buffer_s fz_buffer; -struct fz_buffer_s -{ - int refs; - unsigned char *data; - int cap, len; -}; - -/* - fz_new_buffer: Create a new buffer. - - capacity: Initial capacity. - - Returns pointer to new buffer. Throws exception on allocation - failure. -*/ -fz_buffer *fz_new_buffer(fz_context *ctx, int capacity); - /* fz_keep_buffer: Increment the reference count for a buffer. @@ -936,33 +924,14 @@ fz_buffer *fz_keep_buffer(fz_context *ctx, fz_buffer *buf); void fz_drop_buffer(fz_context *ctx, fz_buffer *buf); /* - fz_resize_buffer: Ensure that a buffer has a given capacity, - truncating data if required. - - buf: The buffer to alter. + fz_buffer_storage: Retrieve information on the storage currently used + by a buffer. - capacity: The desired capacity for the buffer. If the current size - of the buffer contents is smaller than capacity, it is truncated. + data: Pointer to place to retrieve data pointer. + Returns length of stream. */ -void fz_resize_buffer(fz_context *ctx, fz_buffer *buf, int capacity); - -/* - fz_grow_buffer: Make some space within a buffer (i.e. ensure that - capacity > size). - - buf: The buffer to grow. - - May throw exception on failure to allocate. -*/ -void fz_grow_buffer(fz_context *ctx, fz_buffer *buf); - -/* - fz_trim_buffer: Trim wasted capacity from a buffer. - - buf: The buffer to trim. -*/ -void fz_trim_buffer(fz_context *ctx, fz_buffer *buf); +int fz_buffer_storage(fz_context *ctx, fz_buffer *buf, unsigned char **data); /* fz_stream is a buffered reader capable of seeking in both @@ -1782,8 +1751,16 @@ struct fz_outline_s fz_outline *down; }; -void fz_debug_outline_xml(fz_context *ctx, fz_outline *outline, int level); -void fz_debug_outline(fz_context *ctx, fz_outline *outline, int level); +/* + fz_debug_outline_xml: Dump the given outlines to stdout as (pseudo) + XML. +*/ +void fz_debug_outline_xml(fz_context *ctx, fz_outline *outline); + +/* + fz_debug_outline: Dump the given outlines to stdout as text. +*/ +void fz_debug_outline(fz_context *ctx, fz_outline *outline); /* fz_free_outline: Free hierarchical outline. @@ -1794,10 +1771,11 @@ void fz_debug_outline(fz_context *ctx, fz_outline *outline, int level); */ void fz_free_outline(fz_context *ctx, fz_outline *outline); -/* Document interface */ - +/* + Document interface +*/ typedef struct fz_document_s fz_document; -typedef struct fz_page_s fz_page; /* doesn't have a definition -- always cast to *_page */ +typedef struct fz_page_s fz_page; /* fz_open_document: Open a PDF, XPS or CBZ document. diff --git a/fitz/stm_buffer.c b/fitz/stm_buffer.c index b5728d57..4be0165a 100644 --- a/fitz/stm_buffer.c +++ b/fitz/stm_buffer.c @@ -70,3 +70,11 @@ fz_trim_buffer(fz_context *ctx, fz_buffer *buf) if (buf->cap > buf->len+1) fz_resize_buffer(ctx, buf, buf->len); } + +int +fz_buffer_storage(fz_context *ctx, fz_buffer *buf, unsigned char **datap) +{ + if (datap) + *datap = (buf ? buf->data : NULL); + return (buf ? buf->len : 0); +} -- cgit v1.2.3