diff options
Diffstat (limited to 'pdf')
-rw-r--r-- | pdf/mupdf-internal.h | 97 | ||||
-rw-r--r-- | pdf/mupdf.h | 95 | ||||
-rw-r--r-- | pdf/pdf_xref.c | 5 |
3 files changed, 101 insertions, 96 deletions
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) |