diff options
author | Robin Watts <robin.watts@artifex.com> | 2012-02-26 11:15:16 -0800 |
---|---|---|
committer | Robin Watts <robin@ghostscript.com> | 2012-02-26 19:36:30 +0000 |
commit | bbfe635555dce16858403706e2031dd3bfa1a9f1 (patch) | |
tree | 6e414005f04f233a83dbeec5607c0665a6d498bc /pdf/mupdf.h | |
parent | ca578b08dc1243dc6cbb3235272d52d9e2336925 (diff) | |
download | mupdf-bbfe635555dce16858403706e2031dd3bfa1a9f1.tar.xz |
Move fz_obj to be pdf_obj.
Currently, we are in the slightly strange position of having
the PDF specific object types as part of fitz. Here we pull
them out into the pdf layer instead. This has been made possible
by the recent changes to make the store no longer be tied to
having fz_obj's as keys.
Most of this work is a simple huge rename; to help customers who
may have code that use such functions we have provided a sed
script to do the renaming; scripts/rename2.sed.
Various other small tweaks are required; the store used to have
some debugging code that still required knowledge of fz_obj
types - we extract that into a nicer 'type' based function
pointer. Also, the type 3 font handling used to have an fz_obj
pointer for type 3 resources, and therefore needed to know how
to free this; this has become a void * with a function to free
it.
Diffstat (limited to 'pdf/mupdf.h')
-rw-r--r-- | pdf/mupdf.h | 179 |
1 files changed, 129 insertions, 50 deletions
diff --git a/pdf/mupdf.h b/pdf/mupdf.h index 93682083..5d775044 100644 --- a/pdf/mupdf.h +++ b/pdf/mupdf.h @@ -6,6 +6,85 @@ #endif /* + * Dynamic objects. + * The same type of objects as found in PDF and PostScript. + * Used by the filters and the mupdf parser. + */ + +typedef struct pdf_obj_s pdf_obj; + +pdf_obj *pdf_new_null(fz_context *ctx); +pdf_obj *pdf_new_bool(fz_context *ctx, int b); +pdf_obj *pdf_new_int(fz_context *ctx, int i); +pdf_obj *pdf_new_real(fz_context *ctx, float f); +pdf_obj *fz_new_name(fz_context *ctx, char *str); +pdf_obj *pdf_new_string(fz_context *ctx, char *str, int len); +pdf_obj *pdf_new_indirect(fz_context *ctx, int num, int gen, void *doc); + +pdf_obj *pdf_new_array(fz_context *ctx, int initialcap); +pdf_obj *pdf_new_dict(fz_context *ctx, int initialcap); +pdf_obj *pdf_copy_array(fz_context *ctx, pdf_obj *array); +pdf_obj *pdf_copy_dict(fz_context *ctx, pdf_obj *dict); + +pdf_obj *pdf_keep_obj(pdf_obj *obj); +void pdf_drop_obj(pdf_obj *obj); + +/* type queries */ +int pdf_is_null(pdf_obj *obj); +int pdf_is_bool(pdf_obj *obj); +int pdf_is_int(pdf_obj *obj); +int pdf_is_real(pdf_obj *obj); +int pdf_is_name(pdf_obj *obj); +int pdf_is_string(pdf_obj *obj); +int pdf_is_array(pdf_obj *obj); +int pdf_is_dict(pdf_obj *obj); +int pdf_is_indirect(pdf_obj *obj); + +int pdf_objcmp(pdf_obj *a, pdf_obj *b); + +/* dict marking and unmarking functions - to avoid infinite recursions */ +int pdf_dict_marked(pdf_obj *obj); +int pdf_dict_mark(pdf_obj *obj); +void pdf_dict_unmark(pdf_obj *obj); + +/* safe, silent failure, no error reporting on type mismatches */ +int pdf_to_bool(pdf_obj *obj); +int pdf_to_int(pdf_obj *obj); +float pdf_to_real(pdf_obj *obj); +char *pdf_to_name(pdf_obj *obj); +char *pdf_to_str_buf(pdf_obj *obj); +pdf_obj *pdf_to_dict(pdf_obj *obj); +int pdf_to_str_len(pdf_obj *obj); +int pdf_to_num(pdf_obj *obj); +int pdf_to_gen(pdf_obj *obj); + +int pdf_array_len(pdf_obj *array); +pdf_obj *pdf_array_get(pdf_obj *array, int i); +void pdf_array_put(pdf_obj *array, int i, pdf_obj *obj); +void pdf_array_push(pdf_obj *array, pdf_obj *obj); +void pdf_array_insert(pdf_obj *array, pdf_obj *obj); +int pdf_array_contains(pdf_obj *array, pdf_obj *obj); + +int pdf_dict_len(pdf_obj *dict); +pdf_obj *pdf_dict_get_key(pdf_obj *dict, int idx); +pdf_obj *pdf_dict_get_val(pdf_obj *dict, int idx); +pdf_obj *pdf_dict_get(pdf_obj *dict, pdf_obj *key); +pdf_obj *pdf_dict_gets(pdf_obj *dict, char *key); +pdf_obj *pdf_dict_getsa(pdf_obj *dict, char *key, char *abbrev); +void fz_dict_put(pdf_obj *dict, pdf_obj *key, pdf_obj *val); +void pdf_dict_puts(pdf_obj *dict, char *key, pdf_obj *val); +void pdf_dict_del(pdf_obj *dict, pdf_obj *key); +void pdf_dict_dels(pdf_obj *dict, char *key); +void pdf_sort_dict(pdf_obj *dict); + +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); + +void pdf_set_str_len(pdf_obj *obj, int newlen); /* private */ +void *pdf_get_indirect_document(pdf_obj *obj); /* private */ + +/* * PDF Images */ @@ -132,16 +211,16 @@ struct pdf_lexbuf_large_s int pdf_lex(fz_stream *f, pdf_lexbuf *lexbuf); -fz_obj *pdf_parse_array(pdf_document *doc, fz_stream *f, pdf_lexbuf *buf); -fz_obj *pdf_parse_dict(pdf_document *doc, fz_stream *f, pdf_lexbuf *buf); -fz_obj *pdf_parse_stm_obj(pdf_document *doc, fz_stream *f, pdf_lexbuf *buf); -fz_obj *pdf_parse_ind_obj(pdf_document *doc, fz_stream *f, pdf_lexbuf *buf, int *num, int *gen, int *stm_ofs); +pdf_obj *pdf_parse_array(pdf_document *doc, fz_stream *f, pdf_lexbuf *buf); +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_rect pdf_to_rect(fz_context *ctx, fz_obj *array); -fz_matrix pdf_to_matrix(fz_context *ctx, fz_obj *array); -char *pdf_to_utf8(fz_context *ctx, fz_obj *src); -unsigned short *pdf_to_ucs2(fz_context *ctx, fz_obj *src); -fz_obj *pdf_to_utf8_name(fz_context *ctx, fz_obj *src); +fz_rect pdf_to_rect(fz_context *ctx, pdf_obj *array); +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); /* @@ -158,7 +237,7 @@ struct pdf_xref_entry_s int ofs; /* file offset / objstm object number */ int gen; /* generation / objstm index */ int stm_ofs; /* on-disk stream */ - fz_obj *obj; /* stored/cached object */ + pdf_obj *obj; /* stored/cached object */ int type; /* 0=unset (f)ree i(n)use (o)bjstm */ }; @@ -173,7 +252,7 @@ struct pdf_ocg_descriptor_s { int len; pdf_ocg_entry *ocgs; - fz_obj *intent; + pdf_obj *intent; }; struct pdf_document_s @@ -187,7 +266,7 @@ struct pdf_document_s int startxref; int file_size; pdf_crypt *crypt; - fz_obj *trailer; + pdf_obj *trailer; pdf_ocg_descriptor *ocg; int len; @@ -195,26 +274,26 @@ struct pdf_document_s int page_len; int page_cap; - fz_obj **page_objs; - fz_obj **page_refs; + pdf_obj **page_objs; + pdf_obj **page_refs; pdf_lexbuf_large lexbuf; }; -fz_obj *pdf_resolve_indirect(fz_obj *ref); +pdf_obj *pdf_resolve_indirect(pdf_obj *ref); void pdf_cache_object(pdf_document *doc, int num, int gen); -fz_obj *pdf_load_object(pdf_document *doc, int num, int gen); -void pdf_update_object(pdf_document *doc, int num, int gen, fz_obj *newobj); +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); int pdf_is_stream(pdf_document *doc, int num, int gen); -fz_stream *pdf_open_inline_stream(pdf_document *doc, fz_obj *stmobj, int length, fz_stream *chain, pdf_image_params *params); +fz_stream *pdf_open_inline_stream(pdf_document *doc, pdf_obj *stmobj, int length, fz_stream *chain, pdf_image_params *params); fz_buffer *pdf_load_raw_stream(pdf_document *doc, int num, int gen); fz_buffer *pdf_load_stream(pdf_document *doc, int num, int gen); fz_buffer *pdf_load_image_stream(pdf_document *doc, int num, int gen, pdf_image_params *params); fz_stream *pdf_open_raw_stream(pdf_document *doc, int num, int gen); fz_stream *pdf_open_image_stream(pdf_document *doc, int num, int gen, pdf_image_params *params); fz_stream *pdf_open_stream(pdf_document *doc, int num, int gen); -fz_stream *pdf_open_stream_with_offset(pdf_document *doc, int num, int gen, fz_obj *dict, int stm_ofs); +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); /* @@ -280,10 +359,10 @@ enum PDF_DEFAULT_PERM_FLAGS = 0xfffc }; -pdf_crypt *pdf_new_crypt(fz_context *ctx, fz_obj *enc, fz_obj *id); +pdf_crypt *pdf_new_crypt(fz_context *ctx, pdf_obj *enc, pdf_obj *id); void pdf_free_crypt(fz_context *ctx, pdf_crypt *crypt); -void pdf_crypt_obj(fz_context *ctx, pdf_crypt *crypt, fz_obj *obj, int num, int gen); +void pdf_crypt_obj(fz_context *ctx, pdf_crypt *crypt, pdf_obj *obj, int num, int gen); 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); @@ -304,20 +383,20 @@ void pdf_debug_crypt(pdf_crypt *crypt); typedef struct pdf_function_s pdf_function; -pdf_function *pdf_load_function(pdf_document *doc, fz_obj *ref); +pdf_function *pdf_load_function(pdf_document *doc, pdf_obj *ref); void pdf_eval_function(fz_context *ctx, pdf_function *func, float *in, int inlen, float *out, int outlen); pdf_function *pdf_keep_function(fz_context *ctx, pdf_function *func); void pdf_drop_function(fz_context *ctx, pdf_function *func); unsigned int pdf_function_size(pdf_function *func); -fz_colorspace *pdf_load_colorspace(pdf_document *doc, fz_obj *obj); +fz_colorspace *pdf_load_colorspace(pdf_document *doc, pdf_obj *obj); fz_pixmap *pdf_expand_indexed_pixmap(fz_context *ctx, fz_pixmap *src); -fz_shade *pdf_load_shading(pdf_document *doc, fz_obj *obj); +fz_shade *pdf_load_shading(pdf_document *doc, pdf_obj *obj); -fz_image *pdf_load_inline_image(pdf_document *doc, fz_obj *rdb, fz_obj *dict, fz_stream *file); -fz_image *pdf_load_image(pdf_document *doc, fz_obj *obj); -int pdf_is_jpx_image(fz_context *ctx, fz_obj *dict); +fz_image *pdf_load_inline_image(pdf_document *doc, pdf_obj *rdb, pdf_obj *dict, fz_stream *file); +fz_image *pdf_load_image(pdf_document *doc, pdf_obj *obj); +int pdf_is_jpx_image(fz_context *ctx, pdf_obj *dict); /* * Pattern @@ -333,11 +412,11 @@ struct pdf_pattern_s float ystep; fz_matrix matrix; fz_rect bbox; - fz_obj *resources; + pdf_obj *resources; fz_buffer *contents; }; -pdf_pattern *pdf_load_pattern(pdf_document *doc, fz_obj *obj); +pdf_pattern *pdf_load_pattern(pdf_document *doc, pdf_obj *obj); pdf_pattern *pdf_keep_pattern(fz_context *ctx, pdf_pattern *pat); void pdf_drop_pattern(fz_context *ctx, pdf_pattern *pat); @@ -356,12 +435,12 @@ struct pdf_xobject_s int knockout; int transparency; fz_colorspace *colorspace; - fz_obj *resources; + pdf_obj *resources; fz_buffer *contents; - fz_obj *me; + pdf_obj *me; }; -pdf_xobject *pdf_load_xobject(pdf_document *doc, fz_obj *obj); +pdf_xobject *pdf_load_xobject(pdf_document *doc, pdf_obj *obj); pdf_xobject *pdf_keep_xobject(fz_context *ctx, pdf_xobject *xobj); void pdf_drop_xobject(fz_context *ctx, pdf_xobject *xobj); @@ -434,7 +513,7 @@ pdf_cmap *pdf_new_identity_cmap(fz_context *ctx, int wmode, int bytes); pdf_cmap *pdf_load_cmap(fz_context *ctx, fz_stream *file); pdf_cmap *pdf_load_system_cmap(fz_context *ctx, char *name); pdf_cmap *pdf_load_builtin_cmap(fz_context *ctx, char *name); -pdf_cmap *pdf_load_embedded_cmap(pdf_document *doc, fz_obj *ref); +pdf_cmap *pdf_load_embedded_cmap(pdf_document *doc, pdf_obj *ref); /* * Font @@ -536,7 +615,7 @@ void pdf_end_vmtx(fz_context *ctx, pdf_font_desc *font); pdf_hmtx pdf_get_hmtx(fz_context *ctx, pdf_font_desc *font, int cid); pdf_vmtx pdf_get_vmtx(fz_context *ctx, pdf_font_desc *font, int cid); -void pdf_load_to_unicode(pdf_document *doc, pdf_font_desc *font, char **strings, char *collection, fz_obj *cmapstm); +void pdf_load_to_unicode(pdf_document *doc, pdf_font_desc *font, char **strings, char *collection, pdf_obj *cmapstm); int pdf_font_cid_to_gid(fz_context *ctx, pdf_font_desc *fontdesc, int cid); @@ -544,8 +623,8 @@ unsigned char *pdf_find_builtin_font(char *name, unsigned int *len); unsigned char *pdf_find_substitute_font(int mono, int serif, int bold, int italic, unsigned int *len); unsigned char *pdf_find_substitute_cjk_font(int ros, int serif, unsigned int *len); -pdf_font_desc *pdf_load_type3_font(pdf_document *doc, fz_obj *rdb, fz_obj *obj); -pdf_font_desc *pdf_load_font(pdf_document *doc, fz_obj *rdb, fz_obj *obj); +pdf_font_desc *pdf_load_type3_font(pdf_document *doc, pdf_obj *rdb, pdf_obj *obj); +pdf_font_desc *pdf_load_font(pdf_document *doc, pdf_obj *rdb, pdf_obj *obj); pdf_font_desc *pdf_new_font_desc(fz_context *ctx); pdf_font_desc *pdf_keep_font(fz_context *ctx, pdf_font_desc *fontdesc); @@ -561,24 +640,24 @@ typedef struct pdf_annot_s pdf_annot; struct pdf_annot_s { - fz_obj *obj; + pdf_obj *obj; fz_rect rect; pdf_xobject *ap; fz_matrix matrix; pdf_annot *next; }; -fz_link_dest pdf_parse_link_dest(pdf_document *doc, fz_obj *dest); -fz_link_dest pdf_parse_action(pdf_document *doc, fz_obj *action); -fz_obj *pdf_lookup_dest(pdf_document *doc, fz_obj *needle); -fz_obj *pdf_lookup_name(pdf_document *doc, char *which, fz_obj *needle); -fz_obj *pdf_load_name_tree(pdf_document *doc, char *which); +fz_link_dest pdf_parse_link_dest(pdf_document *doc, pdf_obj *dest); +fz_link_dest pdf_parse_action(pdf_document *doc, pdf_obj *action); +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 *, fz_obj *annots, fz_matrix page_ctm); +fz_link *pdf_load_link_annots(pdf_document *, pdf_obj *annots, fz_matrix page_ctm); -pdf_annot *pdf_load_annots(pdf_document *, fz_obj *annots); +pdf_annot *pdf_load_annots(pdf_document *, pdf_obj *annots); void pdf_free_annot(fz_context *ctx, pdf_annot *link); /* @@ -593,13 +672,13 @@ struct pdf_page_s fz_rect mediabox; int rotate; int transparency; - fz_obj *resources; + pdf_obj *resources; fz_buffer *contents; fz_link *links; pdf_annot *annots; }; -int pdf_find_page_number(pdf_document *doc, fz_obj *pageobj); +int pdf_find_page_number(pdf_document *doc, pdf_obj *pageobj); int pdf_count_pages(pdf_document *doc); /* @@ -652,14 +731,14 @@ void pdf_free_page(pdf_document *doc, pdf_page *page); 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, fz_obj *resources, fz_buffer *contents, fz_device *dev, fz_matrix ctm, void *gstate); +void pdf_run_glyph(pdf_document *doc, pdf_obj *resources, fz_buffer *contents, fz_device *dev, fz_matrix ctm, void *gstate); /* * PDF interface to store */ -void pdf_store_item(fz_context *ctx, fz_obj *key, void *val, unsigned int itemsize); -void *pdf_find_item(fz_context *ctx, fz_store_free_fn *free, fz_obj *key); -void pdf_remove_item(fz_context *ctx, fz_store_free_fn *free, fz_obj *key); +void pdf_store_item(fz_context *ctx, pdf_obj *key, void *val, unsigned int itemsize); +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 |