summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2012-03-12 15:57:28 +0000
committerRobin Watts <robin.watts@artifex.com>2012-03-12 15:57:28 +0000
commit2bd952f3fa8241aad0626f39343cffa9855c2d8c (patch)
tree002167e3d4bf0301fd53be96a3324fd9ed48936d
parente49c70808fba2d0d2a691d1568d766bfeee863f0 (diff)
downloadmupdf-2bd952f3fa8241aad0626f39343cffa9855c2d8c.tar.xz
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.
-rw-r--r--apps/mudraw.c4
-rw-r--r--apps/mupdfextract.c8
-rw-r--r--fitz/doc_outline.c22
-rw-r--r--fitz/fitz-internal.h47
-rw-r--r--fitz/fitz.h72
-rw-r--r--fitz/stm_buffer.c8
6 files changed, 104 insertions, 57 deletions
diff --git a/apps/mudraw.c b/apps/mudraw.c
index cf60bbcf..2ca925c6 100644
--- a/apps/mudraw.c
+++ b/apps/mudraw.c
@@ -349,9 +349,9 @@ static void drawoutline(fz_context *ctx, fz_document *doc)
{
fz_outline *outline = fz_load_outline(doc);
if (showoutline > 1)
- fz_debug_outline_xml(ctx, outline, 0);
+ fz_debug_outline_xml(ctx, outline);
else
- fz_debug_outline(ctx, outline, 0);
+ fz_debug_outline(ctx, outline);
fz_free_outline(ctx, outline);
}
diff --git a/apps/mupdfextract.c b/apps/mupdfextract.c
index 1f53541b..398ff6d9 100644
--- a/apps/mupdfextract.c
+++ b/apps/mupdfextract.c
@@ -60,7 +60,8 @@ static void savefont(pdf_obj *dict, int num)
char *ext = "";
FILE *f;
char *fontname = "font";
- int n;
+ int n, len;
+ char *data;
obj = pdf_dict_gets(dict, "FontName");
if (obj)
@@ -113,8 +114,9 @@ static void savefont(pdf_obj *dict, int num)
if (!f)
fz_throw(ctx, "Error creating font file");
- n = fwrite(buf->data, 1, buf->len, f);
- if (n < buf->len)
+ len = fz_buffer_storage(ctx, buf, &data);
+ n = fwrite(data, 1, len, f);
+ if (n < len)
fz_throw(ctx, "Error writing font file");
if (fclose(f) < 0)
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("</outline>\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);
+}