summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/mudraw.c1
-rw-r--r--apps/mupdfextract.c5
-rw-r--r--apps/mupdfshow.c3
-rw-r--r--apps/pdfapp.c3
-rw-r--r--apps/pdfapp.h7
-rw-r--r--apps/win_main.c2
-rw-r--r--apps/x11_image.c8
-rw-r--r--apps/x11_main.c44
-rw-r--r--cbz/mucbz.h8
-rw-r--r--fitz/base_string.c7
-rw-r--r--fitz/fitz-internal.h97
-rw-r--r--fitz/fitz.h92
-rw-r--r--pdf/mupdf-internal.h97
-rw-r--r--pdf/mupdf.h95
-rw-r--r--pdf/pdf_xref.c5
15 files changed, 234 insertions, 240 deletions
diff --git a/apps/mudraw.c b/apps/mudraw.c
index 46da1949..8b3aebf5 100644
--- a/apps/mudraw.c
+++ b/apps/mudraw.c
@@ -3,7 +3,6 @@
*/
#include "fitz.h"
-#include "mupdf.h"
#ifdef _MSC_VER
#include <winsock2.h>
diff --git a/apps/mupdfextract.c b/apps/mupdfextract.c
index 069f7233..1f53541b 100644
--- a/apps/mupdfextract.c
+++ b/apps/mupdfextract.c
@@ -2,8 +2,7 @@
* pdfextract -- the ultimate way to extract images and fonts from pdfs
*/
-#include "fitz.h"
-#include "mupdf-internal.h"
+#include "mupdf.h"
static pdf_document *doc = NULL;
static fz_context *ctx = NULL;
@@ -180,7 +179,7 @@ int main(int argc, char **argv)
if (fz_optind == argc)
{
- for (o = 0; o < doc->len; o++)
+ for (o = 0; o < pdf_count_objects(doc); o++)
showobject(o);
}
else
diff --git a/apps/mupdfshow.c b/apps/mupdfshow.c
index 475dc5a9..94aa90d6 100644
--- a/apps/mupdfshow.c
+++ b/apps/mupdfshow.c
@@ -2,7 +2,6 @@
* pdfshow -- the ultimate pdf debugging tool
*/
-#include "fitz.h"
#include "mupdf-internal.h"
static pdf_document *doc = NULL;
@@ -145,7 +144,7 @@ static void showgrep(char *filename)
pdf_obj *obj;
int i;
- for (i = 0; i < doc->len; i++)
+ for (i = 0; i < pdf_count_objects(doc); i++)
{
if (doc->table[i].type == 'n' || doc->table[i].type == 'o')
{
diff --git a/apps/pdfapp.c b/apps/pdfapp.c
index 68b4b945..4f093508 100644
--- a/apps/pdfapp.c
+++ b/apps/pdfapp.c
@@ -1,8 +1,7 @@
-#include "fitz.h"
+#include "pdfapp.h"
#include "mupdf.h"
#include "muxps.h"
#include "mucbz.h"
-#include "pdfapp.h"
#include <ctype.h> /* for tolower() */
diff --git a/apps/pdfapp.h b/apps/pdfapp.h
index bb067bb4..0c1b6ac4 100644
--- a/apps/pdfapp.h
+++ b/apps/pdfapp.h
@@ -1,3 +1,8 @@
+#ifndef PDFAPP_H
+#define PDFAPP_H
+
+#include "fitz.h"
+
/*
* Utility object for handling a pdf application / view
* Takes care of PDF loading and displaying and navigation,
@@ -106,3 +111,5 @@ void pdfapp_onresize(pdfapp_t *app, int w, int h);
void pdfapp_invert(pdfapp_t *app, fz_bbox rect);
void pdfapp_inverthit(pdfapp_t *app);
+
+#endif
diff --git a/apps/win_main.c b/apps/win_main.c
index 1052ccdd..6cb1f7e1 100644
--- a/apps/win_main.c
+++ b/apps/win_main.c
@@ -1,5 +1,5 @@
#include "fitz.h"
-#include "mupdf.h"
+#include "mupdf-internal.h"
#include "muxps.h"
#include "mucbz.h"
#include "pdfapp.h"
diff --git a/apps/x11_image.c b/apps/x11_image.c
index 35b32c7e..06764313 100644
--- a/apps/x11_image.c
+++ b/apps/x11_image.c
@@ -22,6 +22,12 @@
extern int ffs(int);
+static int is_big_endian(void)
+{
+ static const int one = 1;
+ return *(char*)&one == 0;
+}
+
typedef void (*ximage_convert_func_t)
(
const unsigned char *src,
@@ -212,7 +218,7 @@ select_mode(void)
unsigned long rs, gs, bs;
byteorder = ImageByteOrder(info.display);
- if (fz_is_big_endian())
+ if (is_big_endian())
byterev = byteorder != MSBFirst;
else
byterev = byteorder != LSBFirst;
diff --git a/apps/x11_main.c b/apps/x11_main.c
index 281618ef..091f0ec6 100644
--- a/apps/x11_main.c
+++ b/apps/x11_main.c
@@ -1,7 +1,3 @@
-#include "fitz.h"
-#include "mupdf.h"
-#include "muxps.h"
-#include "mucbz.h"
#include "pdfapp.h"
#include <X11/Xlib.h>
@@ -253,6 +249,9 @@ void winhelp(pdfapp_t *app)
void winresize(pdfapp_t *app, int w, int h)
{
+ fz_bbox bb = fz_bound_pixmap(gapp.image);
+ int image_w = bb.x1 - bb.x0;
+ int image_h = bb.y1 - bb.y0;
XWindowChanges values;
int mask, width, height;
@@ -287,7 +286,7 @@ void winresize(pdfapp_t *app, int w, int h)
}
XSetForeground(xdpy, xgc, WhitePixel(xdpy, xscr));
- XFillRectangle(xdpy, xwin, xgc, 0, 0, gapp.image->w, gapp.image->h);
+ XFillRectangle(xdpy, xwin, xgc, 0, 0, image_w, image_h);
XFlush(xdpy);
if (width != reqw || height != reqh)
@@ -338,10 +337,15 @@ static void winblitsearch(pdfapp_t *app)
static void winblit(pdfapp_t *app)
{
+ fz_bbox bb = fz_bound_pixmap(gapp.image);
+ int image_w = bb.x1 - bb.x0;
+ int image_h = bb.y1 - bb.y0;
+ int image_n = fz_pixmap_components(gapp.ctx, gapp.image);
+ unsigned char *image_samples = fz_pixmap_pixels(gapp.ctx, gapp.image);
int x0 = gapp.panx;
int y0 = gapp.pany;
- int x1 = gapp.panx + gapp.image->w;
- int y1 = gapp.pany + gapp.image->h;
+ int x1 = gapp.panx + image_w;
+ int y1 = gapp.pany + image_h;
XSetForeground(xdpy, xgc, xbgcolor.pixel);
fillrect(0, 0, x0, gapp.winh);
@@ -350,8 +354,8 @@ static void winblit(pdfapp_t *app)
fillrect(0, y1, gapp.winw, gapp.winh - y1);
XSetForeground(xdpy, xgc, xshcolor.pixel);
- fillrect(x0+2, y1, gapp.image->w, 2);
- fillrect(x1, y0+2, 2, gapp.image->h);
+ fillrect(x0+2, y1, image_w, 2);
+ fillrect(x1, y0+2, 2, image_h);
if (gapp.iscopying || justcopied)
{
@@ -361,21 +365,21 @@ static void winblit(pdfapp_t *app)
pdfapp_inverthit(&gapp);
- if (gapp.image->n == 4)
+ if (image_n == 4)
ximage_blit(xwin, xgc,
x0, y0,
- gapp.image->samples,
+ image_samples,
0, 0,
- gapp.image->w,
- gapp.image->h,
- gapp.image->w * gapp.image->n);
- else if (gapp.image->n == 2)
+ image_w,
+ image_h,
+ image_w * image_n);
+ else if (image_n == 2)
{
- int i = gapp.image->w*gapp.image->h;
+ int i = image_w*image_h;
unsigned char *color = malloc(i*4);
if (color)
{
- unsigned char *s = gapp.image->samples;
+ unsigned char *s = image_samples;
unsigned char *d = color;
for (; i > 0 ; i--)
{
@@ -387,9 +391,9 @@ static void winblit(pdfapp_t *app)
x0, y0,
color,
0, 0,
- gapp.image->w,
- gapp.image->h,
- gapp.image->w * 4);
+ image_w,
+ image_h,
+ image_w * 4);
free(color);
}
}
diff --git a/cbz/mucbz.h b/cbz/mucbz.h
index cdda3472..080423bf 100644
--- a/cbz/mucbz.h
+++ b/cbz/mucbz.h
@@ -1,9 +1,7 @@
-#ifndef _MUCBZ_H_
-#define _MUCBZ_H_
+#ifndef MUCBZ_H
+#define MUCBZ_H
-#ifndef _FITZ_H_
-#error "fitz.h must be included before mucbz.h"
-#endif
+#include "fitz.h"
typedef struct cbz_document_s cbz_document;
typedef struct cbz_page_s cbz_page;
diff --git a/fitz/base_string.c b/fitz/base_string.c
index 6fdfef62..8ab09438 100644
--- a/fitz/base_string.c
+++ b/fitz/base_string.c
@@ -1,12 +1,5 @@
#include "fitz-internal.h"
-int
-fz_is_big_endian(void)
-{
- static const int one = 1;
- return *(char*)&one == 0;
-}
-
char *
fz_strsep(char **stringp, const char *delim)
{
diff --git a/fitz/fitz-internal.h b/fitz/fitz-internal.h
index 4ede601d..f9175c65 100644
--- a/fitz/fitz-internal.h
+++ b/fitz/fitz-internal.h
@@ -1,5 +1,5 @@
-#ifndef _FITZ_INTERNAL_H_
-#define _FITZ_INTERNAL_H_
+#ifndef FITZ_INTERNAL_H
+#define FITZ_INTERNAL_H
#include "fitz.h"
@@ -57,11 +57,6 @@ fz_unlock(fz_context *ctx, int lock)
/* Range checking atof */
float fz_atof(const char *s);
-/* utf-8 encoding and decoding */
-int chartorune(int *rune, char *str);
-int runetochar(char *str, int *rune);
-int runelen(int c);
-
/*
* Generic hash-table with fixed-length keys.
*/
@@ -109,11 +104,6 @@ static inline int fz_mul255(int a, int b)
* AMOUNT (in the 0...256 range). */
#define FZ_BLEND(SRC, DST, AMOUNT) ((((SRC)-(DST))*(AMOUNT) + ((DST)<<8))>>8)
-
-float fz_matrix_expansion(fz_matrix m);
-float fz_matrix_max_expansion(fz_matrix m);
-
-
void fz_gridfit_matrix(fz_matrix *m);
/*
@@ -190,19 +180,6 @@ void aes_crypt_cbc( fz_aes *ctx, int mode, int length,
const unsigned char *input,
unsigned char *output );
-struct fz_buffer_s
-{
- int refs;
- unsigned char *data;
- int cap, len;
-};
-
-fz_buffer *fz_new_buffer(fz_context *ctx, int size);
-
-void fz_resize_buffer(fz_context *ctx, fz_buffer *buf, int size);
-void fz_grow_buffer(fz_context *ctx, fz_buffer *buf);
-void fz_trim_buffer(fz_context *ctx, fz_buffer *buf);
-
/*
Resource store
@@ -397,46 +374,13 @@ struct fz_stream_s
unsigned char buf[4096];
};
-/*
- fz_open_file: Open the named file and wrap it in a stream.
-
- filename: Path to a file as it would be given to open(2).
-*/
-fz_stream *fz_open_file(fz_context *ctx, const char *filename);
-
-/*
- fz_open_file_w: Open the named file and wrap it in a stream.
-
- This function is only available when compiling for Win32.
-
- filename: Wide character path to the file as it would be given
- to _wopen().
-*/
-fz_stream *fz_open_file_w(fz_context *ctx, const wchar_t *filename);
-
-
-/*
- fz_open_buffer: XXX
-*/
-fz_stream *fz_open_buffer(fz_context *ctx, fz_buffer *buf);
-
-/*
- fz_open_memory: XXX
-*/
-fz_stream *fz_open_memory(fz_context *ctx, unsigned char *data, int len);
-
void fz_lock_stream(fz_stream *stm);
fz_stream *fz_new_stream(fz_context *ctx, void*, int(*)(fz_stream*, unsigned char*, int), void(*)(fz_context *, void *));
fz_stream *fz_keep_stream(fz_stream *stm);
void fz_fill_buffer(fz_stream *stm);
-int fz_tell(fz_stream *stm);
-void fz_seek(fz_stream *stm, int offset, int whence);
-
-int fz_read(fz_stream *stm, unsigned char *buf, int len);
void fz_read_line(fz_stream *stm, char *buf, int max);
-fz_buffer *fz_read_all(fz_stream *stm, int initial);
static inline int fz_read_byte(fz_stream *stm)
{
@@ -583,27 +527,6 @@ struct fz_pixmap_s
int free_samples;
};
-
-fz_pixmap *fz_new_pixmap_with_data(fz_context *ctx, fz_colorspace *colorspace, int w, int h, unsigned char *samples);
-
-/*
- fz_new_pixmap_with_rect_and_data: Create a pixmap using the
- provided buffer for pixel data.
-
- While fz_new_pixmap_with_rect allocates its own buffer for
- pixel data, fz_new_pixmap_with_rect_and_data lets the caller
- allocate and provide a buffer to be used. Otherwise the two
- functions are identical.
-
- samples: An array of pixel samples. The created pixmap will
- keep a pointer to the array so it must not be modified or
- freed until the created pixmap is dropped and freed by
- fz_drop_pixmap.
-*/
-fz_pixmap *fz_new_pixmap_with_rect_and_data(fz_context *ctx,
-fz_colorspace *colorspace, fz_bbox bbox, unsigned char *samples);
-fz_pixmap *fz_new_pixmap(fz_context *ctx, fz_colorspace *, int w, int h);
-
void fz_free_pixmap_imp(fz_context *ctx, fz_storable *pix);
void fz_clear_pixmap_rect_with_value(fz_context *ctx, fz_pixmap *pix, int value, fz_bbox r);
@@ -628,18 +551,6 @@ fz_pixmap *fz_load_jpeg(fz_context *doc, unsigned char *data, int size);
fz_pixmap *fz_load_png(fz_context *doc, unsigned char *data, int size);
fz_pixmap *fz_load_tiff(fz_context *doc, unsigned char *data, int size);
-struct fz_bitmap_s
-{
- int refs;
- int w, h, stride, n;
- unsigned char *samples;
-};
-
-fz_bitmap *fz_new_bitmap(fz_context *ctx, int w, int h, int n);
-fz_bitmap *fz_keep_bitmap(fz_context *ctx, fz_bitmap *bit);
-void fz_clear_bitmap(fz_context *ctx, fz_bitmap *bit);
-
-
struct fz_halftone_s
{
int refs;
@@ -650,7 +561,6 @@ struct fz_halftone_s
fz_halftone *fz_new_halftone(fz_context *ctx, int num_comps);
fz_halftone *fz_keep_halftone(fz_context *ctx, fz_halftone *half);
-
struct fz_colorspace_s
{
fz_storable storable;
@@ -669,9 +579,6 @@ void fz_drop_colorspace(fz_context *ctx, fz_colorspace *colorspace);
void fz_free_colorspace_imp(fz_context *ctx, fz_storable *colorspace);
void fz_convert_color(fz_context *ctx, fz_colorspace *srcs, float *srcv, fz_colorspace *dsts, float *dstv);
-void fz_convert_pixmap(fz_context *ctx, fz_pixmap *src, fz_pixmap *dst);
-
-fz_colorspace *fz_find_device_colorspace(char *name);
/*
* Fonts come in two variants:
diff --git a/fitz/fitz.h b/fitz/fitz.h
index 732f2fc7..4de15e0e 100644
--- a/fitz/fitz.h
+++ b/fitz/fitz.h
@@ -1,5 +1,5 @@
-#ifndef _FITZ_H_
-#define _FITZ_H_
+#ifndef FITZ_H
+#define FITZ_H
/*
Include the standard libc headers.
@@ -351,8 +351,10 @@ char *fz_strsep(char **stringp, const char *delim);
int fz_strlcpy(char *dst, const char *src, int n);
int fz_strlcat(char *dst, const char *src, int n);
-/* runtime (hah!) test for endian-ness */
-int fz_is_big_endian(void);
+/* utf-8 encoding and decoding */
+int chartorune(int *rune, char *str);
+int runetochar(char *str, int *rune);
+int runelen(int c);
/* getopt */
extern int fz_getopt(int nargc, char * const *nargv, const char *ostr);
@@ -590,6 +592,12 @@ fz_matrix fz_invert_matrix(fz_matrix matrix);
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.
Coordinates in a bounding box are integers, so rounding of the
@@ -701,14 +709,25 @@ fz_rect fz_transform_rect(fz_matrix transform, fz_rect rect);
fz_bbox fz_transform_bbox(fz_matrix matrix, fz_bbox bbox);
/*
- fz_buffer is a XXX
+ fz_buffer is a wrapper around a dynamically allocated array of bytes
*/
typedef struct fz_buffer_s fz_buffer;
-fz_buffer *fz_keep_buffer(fz_context *ctx, fz_buffer *buf);
+struct fz_buffer_s
+{
+ int refs;
+ unsigned char *data;
+ int cap, len;
+};
+fz_buffer *fz_new_buffer(fz_context *ctx, int size);
+fz_buffer *fz_keep_buffer(fz_context *ctx, fz_buffer *buf);
void fz_drop_buffer(fz_context *ctx, fz_buffer *buf);
+void fz_resize_buffer(fz_context *ctx, fz_buffer *buf, int size);
+void fz_grow_buffer(fz_context *ctx, fz_buffer *buf);
+void fz_trim_buffer(fz_context *ctx, fz_buffer *buf);
+
/*
fz_stream is a buffered reader capable of seeking in both
directions.
@@ -721,6 +740,23 @@ void fz_drop_buffer(fz_context *ctx, fz_buffer *buf);
typedef struct fz_stream_s fz_stream;
/*
+ fz_open_file: Open the named file and wrap it in a stream.
+
+ filename: Path to a file as it would be given to open(2).
+*/
+fz_stream *fz_open_file(fz_context *ctx, const char *filename);
+
+/*
+ fz_open_file_w: Open the named file and wrap it in a stream.
+
+ This function is only available when compiling for Win32.
+
+ filename: Wide character path to the file as it would be given
+ to _wopen().
+*/
+fz_stream *fz_open_file_w(fz_context *ctx, const wchar_t *filename);
+
+/*
fz_open_fd: Wrap an open file descriptor in a stream.
file: An open file descriptor supporting bidirectional
@@ -732,6 +768,16 @@ typedef struct fz_stream_s fz_stream;
fz_stream *fz_open_fd(fz_context *ctx, int file);
/*
+ fz_open_memory: XXX
+*/
+fz_stream *fz_open_memory(fz_context *ctx, unsigned char *data, int len);
+
+/*
+ fz_open_buffer: XXX
+*/
+fz_stream *fz_open_buffer(fz_context *ctx, fz_buffer *buf);
+
+/*
fz_close: Close an open stream.
Drops a reference for the stream. Once no references remain
@@ -742,6 +788,11 @@ fz_stream *fz_open_fd(fz_context *ctx, int file);
*/
void fz_close(fz_stream *stm);
+int fz_tell(fz_stream *stm);
+void fz_seek(fz_stream *stm, int offset, int whence);
+int fz_read(fz_stream *stm, unsigned char *buf, int len);
+fz_buffer *fz_read_all(fz_stream *stm, int initial);
+
/*
Bitmaps have 1 bit per component. Only used for creating halftoned
versions of contone buffers, and saving out. Samples are stored msb
@@ -749,6 +800,16 @@ void fz_close(fz_stream *stm);
*/
typedef struct fz_bitmap_s fz_bitmap;
+struct fz_bitmap_s
+{
+ int refs;
+ int w, h, stride, n;
+ unsigned char *samples;
+};
+
+fz_bitmap *fz_new_bitmap(fz_context *ctx, int w, int h, int n);
+fz_bitmap *fz_keep_bitmap(fz_context *ctx, fz_bitmap *bit);
+void fz_clear_bitmap(fz_context *ctx, fz_bitmap *bit);
void fz_drop_bitmap(fz_context *ctx, fz_bitmap *bit);
/*
@@ -763,6 +824,8 @@ typedef struct fz_colorspace_s fz_colorspace;
fz_bbox fz_bound_pixmap(fz_pixmap *pix);
+fz_pixmap *fz_new_pixmap(fz_context *ctx, fz_colorspace *, int w, int h);
+
/*
fz_new_pixmap_with_rect: Create a pixmap of a given size,
location and pixel format.
@@ -779,6 +842,17 @@ fz_bbox fz_bound_pixmap(fz_pixmap *pix);
*/
fz_pixmap *fz_new_pixmap_with_rect(fz_context *ctx, fz_colorspace *colorspace, fz_bbox bbox);
+fz_pixmap *fz_new_pixmap_with_data(fz_context *ctx, fz_colorspace *colorspace, int w, int h, unsigned char *samples);
+
+/*
+ fz_keep_pixmap: Take a reference to a pixmap.
+
+ pix: The pixmap to increment the reference for.
+
+ Returns pix. Does not throw exceptions.
+*/
+fz_pixmap *fz_new_pixmap_with_rect_and_data(fz_context *ctx, fz_colorspace *colorspace, fz_bbox bbox, unsigned char *samples);
+
/*
fz_keep_pixmap: Take a reference to a pixmap.
@@ -899,6 +973,10 @@ fz_bitmap *fz_halftone_pixmap(fz_context *ctx, fz_pixmap *pix, fz_halftone *ht);
Colorspace resources.
*/
+void fz_convert_pixmap(fz_context *ctx, fz_pixmap *src, fz_pixmap *dst);
+
+fz_colorspace *fz_find_device_colorspace(char *name);
+
/*
fz_device_gray: XXX
*/
@@ -1418,4 +1496,4 @@ void fz_run_page(fz_document *doc, fz_page *page, fz_device *dev, fz_matrix tran
*/
void fz_free_page(fz_document *doc, fz_page *page);
-#endif /* _FITZ_H_ */
+#endif
diff --git a/pdf/mupdf-internal.h b/pdf/mupdf-internal.h
index 35f76904..faec16b5 100644
--- a/pdf/mupdf-internal.h
+++ b/pdf/mupdf-internal.h
@@ -1,11 +1,11 @@
-#ifndef _MUPDF_INTERNAL_H_
-#define _MUPDF_INTERNAL_H_
+#ifndef MUPDF_INTERNAL_H
+#define MUPDF_INTERNAL_H
#include "mupdf.h"
#include "fitz-internal.h"
-void pdf_set_str_len(pdf_obj *obj, int newlen); /* private */
-void *pdf_get_indirect_document(pdf_obj *obj); /* private */
+void pdf_set_str_len(pdf_obj *obj, int newlen);
+void *pdf_get_indirect_document(pdf_obj *obj);
/*
* PDF Images
@@ -133,16 +133,21 @@ pdf_obj *pdf_parse_dict(pdf_document *doc, fz_stream *f, pdf_lexbuf *buf);
pdf_obj *pdf_parse_stm_obj(pdf_document *doc, fz_stream *f, pdf_lexbuf *buf);
pdf_obj *pdf_parse_ind_obj(pdf_document *doc, fz_stream *f, pdf_lexbuf *buf, int *num, int *gen, int *stm_ofs);
-fz_matrix pdf_to_matrix(fz_context *ctx, pdf_obj *array);
-char *pdf_to_utf8(fz_context *ctx, pdf_obj *src);
-unsigned short *pdf_to_ucs2(fz_context *ctx, pdf_obj *src);
-pdf_obj *pdf_to_utf8_name(fz_context *ctx, pdf_obj *src);
-char *pdf_from_ucs2(fz_context *ctx, unsigned short *str);
-
/*
* xref and object / stream api
*/
+typedef struct pdf_xref_entry_s pdf_xref_entry;
+
+struct pdf_xref_entry_s
+{
+ int ofs; /* file offset / objstm object number */
+ int gen; /* generation / objstm index */
+ int stm_ofs; /* on-disk stream */
+ pdf_obj *obj; /* stored/cached object */
+ int type; /* 0=unset (f)ree i(n)use (o)bjstm */
+};
+
typedef struct pdf_crypt_s pdf_crypt;
typedef struct pdf_ocg_descriptor_s pdf_ocg_descriptor;
typedef struct pdf_ocg_entry_s pdf_ocg_entry;
@@ -194,8 +199,6 @@ fz_stream *pdf_open_image_stream(pdf_document *doc, int num, int gen, pdf_image_
fz_stream *pdf_open_stream_with_offset(pdf_document *doc, int num, int gen, pdf_obj *dict, int stm_ofs);
fz_stream *pdf_open_image_decomp_stream(fz_context *ctx, fz_buffer *, pdf_image_params *params, int *factor);
-
-/* private */
void pdf_repair_xref(pdf_document *doc, pdf_lexbuf *buf);
void pdf_repair_obj_stms(pdf_document *doc);
void pdf_debug_xref(pdf_document *);
@@ -205,19 +208,6 @@ void pdf_resize_xref(pdf_document *doc, int newcap);
* Encryption
*/
-enum
-{
- PDF_PERM_PRINT = 1 << 2,
- PDF_PERM_CHANGE = 1 << 3,
- PDF_PERM_COPY = 1 << 4,
- PDF_PERM_NOTES = 1 << 5,
- PDF_PERM_FILL_FORM = 1 << 8,
- PDF_PERM_ACCESSIBILITY = 1 << 9,
- PDF_PERM_ASSEMBLE = 1 << 10,
- PDF_PERM_HIGH_RES_PRINT = 1 << 11,
- PDF_DEFAULT_PERM_FLAGS = 0xfffc
-};
-
pdf_crypt *pdf_new_crypt(fz_context *ctx, pdf_obj *enc, pdf_obj *id);
void pdf_free_crypt(fz_context *ctx, pdf_crypt *crypt);
@@ -225,8 +215,6 @@ void pdf_crypt_obj(fz_context *ctx, pdf_crypt *crypt, pdf_obj *obj, int num, int
fz_stream *pdf_open_crypt(fz_stream *chain, pdf_crypt *crypt, int num, int gen);
fz_stream *pdf_open_crypt_with_filter(fz_stream *chain, pdf_crypt *crypt, char *name, int num, int gen);
-int pdf_has_permission(pdf_document *doc, int p);
-
int pdf_get_crypt_revision(pdf_document *doc);
char *pdf_get_crypt_method(pdf_document *doc);
int pdf_get_crypt_length(pdf_document *doc);
@@ -509,8 +497,6 @@ pdf_obj *pdf_lookup_dest(pdf_document *doc, pdf_obj *needle);
pdf_obj *pdf_lookup_name(pdf_document *doc, char *which, pdf_obj *needle);
pdf_obj *pdf_load_name_tree(pdf_document *doc, char *which);
-fz_outline *pdf_load_outline(pdf_document *doc);
-
fz_link *pdf_load_link_annots(pdf_document *, pdf_obj *annots, fz_matrix page_ctm);
pdf_annot *pdf_load_annots(pdf_document *, pdf_obj *annots);
@@ -520,8 +506,6 @@ void pdf_free_annot(fz_context *ctx, pdf_annot *link);
* Page tree, pages and related objects
*/
-typedef struct pdf_page_s pdf_page;
-
struct pdf_page_s
{
fz_matrix ctm; /* calculated from mediabox and rotate */
@@ -534,59 +518,10 @@ struct pdf_page_s
pdf_annot *annots;
};
-int pdf_find_page_number(pdf_document *doc, pdf_obj *pageobj);
-int pdf_count_pages(pdf_document *doc);
-
-/*
- pdf_load_page: Load a page and its resources.
-
- Locates the page in the PDF document and loads the page and its
- resources. After pdf_load_page is it possible to retrieve the size
- of the page using pdf_bound_page, or to render the page using
- pdf_run_page_*.
-
- number: page number, where 0 is the first page of the document.
-*/
-pdf_page *pdf_load_page(pdf_document *doc, int number);
-
-fz_link *pdf_load_links(pdf_document *doc, pdf_page *page);
-
-/*
- pdf_bound_page: Determine the size of a page.
-
- Determine the page size in user space units, taking page rotation
- into account. The page size is taken to be the crop box if it
- exists (visible area after cropping), otherwise the media box will
- be used (possibly including printing marks).
-
- Does not throw exceptions.
-*/
-fz_rect pdf_bound_page(pdf_document *doc, pdf_page *page);
-
-/*
- pdf_free_page: Frees a page and its resources.
-
- Does not throw exceptions.
-*/
-void pdf_free_page(pdf_document *doc, pdf_page *page);
-
/*
* Content stream parsing
*/
-/*
- pdf_run_page: Interpret a loaded page and render it on a device.
-
- page: A page loaded by pdf_load_page.
-
- dev: Device used for rendering, obtained from fz_new_*_device.
-
- ctm: A transformation matrix applied to the objects on the page,
- e.g. to scale or rotate the page contents as desired.
-*/
-void pdf_run_page(pdf_document *doc, pdf_page *page, fz_device *dev, fz_matrix ctm, fz_cookie *cookie);
-
-void pdf_run_page_with_usage(pdf_document *doc, pdf_page *page, fz_device *dev, fz_matrix ctm, char *event, fz_cookie *cookie);
void pdf_run_glyph(pdf_document *doc, pdf_obj *resources, fz_buffer *contents, fz_device *dev, fz_matrix ctm, void *gstate);
/*
@@ -597,4 +532,4 @@ void pdf_store_item(fz_context *ctx, pdf_obj *key, void *val, unsigned int items
void *pdf_find_item(fz_context *ctx, fz_store_free_fn *free, pdf_obj *key);
void pdf_remove_item(fz_context *ctx, fz_store_free_fn *free, pdf_obj *key);
-#endif /* _MUPDF_INTERNAL_H_ */
+#endif
diff --git a/pdf/mupdf.h b/pdf/mupdf.h
index 0e5df0d9..7566bc36 100644
--- a/pdf/mupdf.h
+++ b/pdf/mupdf.h
@@ -1,5 +1,5 @@
-#ifndef _MUPDF_H_
-#define _MUPDF_H_
+#ifndef MUPDF_H
+#define MUPDF_H
#include "fitz.h"
@@ -82,19 +82,15 @@ int pdf_fprint_obj(FILE *fp, pdf_obj *obj, int tight);
void pdf_debug_obj(pdf_obj *obj);
void pdf_debug_ref(pdf_obj *obj);
-fz_rect pdf_to_rect(fz_context *ctx, pdf_obj *array);
-
-typedef struct pdf_xref_entry_s pdf_xref_entry;
+char *pdf_to_utf8(fz_context *ctx, pdf_obj *src);
+unsigned short *pdf_to_ucs2(fz_context *ctx, pdf_obj *src); /* sumatrapdf */
+pdf_obj *pdf_to_utf8_name(fz_context *ctx, pdf_obj *src);
+char *pdf_from_ucs2(fz_context *ctx, unsigned short *str);
-struct pdf_xref_entry_s
-{
- int ofs; /* file offset / objstm object number */
- int gen; /* generation / objstm index */
- int stm_ofs; /* on-disk stream */
- pdf_obj *obj; /* stored/cached object */
- int type; /* 0=unset (f)ree i(n)use (o)bjstm */
-};
+fz_rect pdf_to_rect(fz_context *ctx, pdf_obj *array);
+fz_matrix pdf_to_matrix(fz_context *ctx, pdf_obj *array);
+int pdf_count_objects(pdf_document *doc);
pdf_obj *pdf_resolve_indirect(pdf_obj *ref);
pdf_obj *pdf_load_object(pdf_document *doc, int num, int gen);
void pdf_update_object(pdf_document *doc, int num, int gen, pdf_obj *newobj);
@@ -104,6 +100,10 @@ fz_buffer *pdf_load_stream(pdf_document *doc, int num, int gen);
fz_stream *pdf_open_raw_stream(pdf_document *doc, int num, int gen);
fz_stream *pdf_open_stream(pdf_document *doc, int num, int gen);
+fz_image *pdf_load_image(pdf_document *doc, pdf_obj *obj);
+
+fz_outline *pdf_load_outline(pdf_document *doc);
+
/*
pdf_open_document: Open a PDF document.
@@ -147,6 +147,71 @@ void pdf_close_document(pdf_document *doc);
int pdf_needs_password(pdf_document *doc);
int pdf_authenticate_password(pdf_document *doc, char *pw);
-fz_image *pdf_load_image(pdf_document *doc, pdf_obj *obj);
+enum
+{
+ PDF_PERM_PRINT = 1 << 2,
+ PDF_PERM_CHANGE = 1 << 3,
+ PDF_PERM_COPY = 1 << 4,
+ PDF_PERM_NOTES = 1 << 5,
+ PDF_PERM_FILL_FORM = 1 << 8,
+ PDF_PERM_ACCESSIBILITY = 1 << 9,
+ PDF_PERM_ASSEMBLE = 1 << 10,
+ PDF_PERM_HIGH_RES_PRINT = 1 << 11,
+ PDF_DEFAULT_PERM_FLAGS = 0xfffc
+};
+
+int pdf_has_permission(pdf_document *doc, int p);
+
+typedef struct pdf_page_s pdf_page;
+
+int pdf_find_page_number(pdf_document *doc, pdf_obj *pageobj);
+int pdf_count_pages(pdf_document *doc);
+
+/*
+ pdf_load_page: Load a page and its resources.
+
+ Locates the page in the PDF document and loads the page and its
+ resources. After pdf_load_page is it possible to retrieve the size
+ of the page using pdf_bound_page, or to render the page using
+ pdf_run_page_*.
+
+ number: page number, where 0 is the first page of the document.
+*/
+pdf_page *pdf_load_page(pdf_document *doc, int number);
+
+fz_link *pdf_load_links(pdf_document *doc, pdf_page *page);
+
+/*
+ pdf_bound_page: Determine the size of a page.
+
+ Determine the page size in user space units, taking page rotation
+ into account. The page size is taken to be the crop box if it
+ exists (visible area after cropping), otherwise the media box will
+ be used (possibly including printing marks).
+
+ Does not throw exceptions.
+*/
+fz_rect pdf_bound_page(pdf_document *doc, pdf_page *page);
+
+/*
+ pdf_free_page: Frees a page and its resources.
+
+ Does not throw exceptions.
+*/
+void pdf_free_page(pdf_document *doc, pdf_page *page);
+
+/*
+ pdf_run_page: Interpret a loaded page and render it on a device.
+
+ page: A page loaded by pdf_load_page.
+
+ dev: Device used for rendering, obtained from fz_new_*_device.
+
+ ctm: A transformation matrix applied to the objects on the page,
+ e.g. to scale or rotate the page contents as desired.
+*/
+void pdf_run_page(pdf_document *doc, pdf_page *page, fz_device *dev, fz_matrix ctm, fz_cookie *cookie);
+
+void pdf_run_page_with_usage(pdf_document *doc, pdf_page *page, fz_device *dev, fz_matrix ctm, char *event, fz_cookie *cookie);
-#endif /* _MUPDF_H_ */
+#endif
diff --git a/pdf/pdf_xref.c b/pdf/pdf_xref.c
index 1952c9bf..9e60955c 100644
--- a/pdf/pdf_xref.c
+++ b/pdf/pdf_xref.c
@@ -1074,6 +1074,11 @@ pdf_resolve_indirect(pdf_obj *ref)
return ref;
}
+int pdf_count_objects(pdf_document *doc)
+{
+ return doc->len;
+}
+
/* Replace numbered object -- for use by pdfclean and similar tools */
void
pdf_update_object(pdf_document *xref, int num, int gen, pdf_obj *newobj)