diff options
Diffstat (limited to 'pdf')
-rw-r--r-- | pdf/base_object.c | 4 | ||||
-rw-r--r-- | pdf/mupdf-internal.h | 535 | ||||
-rw-r--r-- | pdf/mupdf.h | 559 | ||||
-rw-r--r-- | pdf/pdf_annot.c | 4 | ||||
-rw-r--r-- | pdf/pdf_cmap.c | 4 | ||||
-rw-r--r-- | pdf/pdf_cmap_load.c | 4 | ||||
-rw-r--r-- | pdf/pdf_cmap_parse.c | 4 | ||||
-rw-r--r-- | pdf/pdf_cmap_table.c | 4 | ||||
-rw-r--r-- | pdf/pdf_colorspace.c | 4 | ||||
-rw-r--r-- | pdf/pdf_crypt.c | 4 | ||||
-rw-r--r-- | pdf/pdf_encoding.c | 4 | ||||
-rw-r--r-- | pdf/pdf_font.c | 4 | ||||
-rw-r--r-- | pdf/pdf_fontfile.c | 4 | ||||
-rw-r--r-- | pdf/pdf_function.c | 4 | ||||
-rw-r--r-- | pdf/pdf_image.c | 4 | ||||
-rw-r--r-- | pdf/pdf_interpret.c | 4 | ||||
-rw-r--r-- | pdf/pdf_lex.c | 4 | ||||
-rw-r--r-- | pdf/pdf_metrics.c | 4 | ||||
-rw-r--r-- | pdf/pdf_nametree.c | 4 | ||||
-rw-r--r-- | pdf/pdf_outline.c | 4 | ||||
-rw-r--r-- | pdf/pdf_page.c | 4 | ||||
-rw-r--r-- | pdf/pdf_parse.c | 16 | ||||
-rw-r--r-- | pdf/pdf_pattern.c | 4 | ||||
-rw-r--r-- | pdf/pdf_repair.c | 4 | ||||
-rw-r--r-- | pdf/pdf_shade.c | 4 | ||||
-rw-r--r-- | pdf/pdf_store.c | 4 | ||||
-rw-r--r-- | pdf/pdf_stream.c | 4 | ||||
-rw-r--r-- | pdf/pdf_type3.c | 4 | ||||
-rw-r--r-- | pdf/pdf_unicode.c | 4 | ||||
-rw-r--r-- | pdf/pdf_xobject.c | 4 | ||||
-rw-r--r-- | pdf/pdf_xref.c | 9 |
31 files changed, 620 insertions, 607 deletions
diff --git a/pdf/base_object.c b/pdf/base_object.c index 94f1acfc..1dc07f1a 100644 --- a/pdf/base_object.c +++ b/pdf/base_object.c @@ -1,5 +1,5 @@ -#include "fitz.h" -#include "mupdf.h" +#include "fitz-internal.h" +#include "mupdf-internal.h" typedef enum pdf_objkind_e { diff --git a/pdf/mupdf-internal.h b/pdf/mupdf-internal.h new file mode 100644 index 00000000..faec16b5 --- /dev/null +++ b/pdf/mupdf-internal.h @@ -0,0 +1,535 @@ +#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); +void *pdf_get_indirect_document(pdf_obj *obj); + +/* + * PDF Images + */ + +typedef struct pdf_image_params_s pdf_image_params; + +struct pdf_image_params_s +{ + int type; + fz_colorspace *colorspace; + union + { + struct + { + int columns; + int rows; + int k; + int eol; + int eba; + int eob; + int bi1; + } + fax; + struct + { + int ct; + } + jpeg; + struct + { + int columns; + int colors; + int predictor; + int bpc; + } + flate; + struct + { + int columns; + int colors; + int predictor; + int bpc; + int ec; + } + lzw; + } + u; +}; + + +typedef struct pdf_image_s pdf_image; + +struct pdf_image_s +{ + fz_image base; + fz_pixmap *tile; + int n, bpc; + pdf_image_params params; + fz_buffer *buffer; + int colorkey[FZ_MAX_COLORS * 2]; + float decode[FZ_MAX_COLORS * 2]; + int imagemask; + int interpolate; + int usecolorkey; +}; + +enum +{ + PDF_IMAGE_RAW, + PDF_IMAGE_FAX, + PDF_IMAGE_JPEG, + PDF_IMAGE_RLD, + PDF_IMAGE_FLATE, + PDF_IMAGE_LZW, + PDF_IMAGE_JPX +}; + +/* + * tokenizer and low-level object parser + */ + +enum +{ + PDF_TOK_ERROR, PDF_TOK_EOF, + PDF_TOK_OPEN_ARRAY, PDF_TOK_CLOSE_ARRAY, + PDF_TOK_OPEN_DICT, PDF_TOK_CLOSE_DICT, + PDF_TOK_OPEN_BRACE, PDF_TOK_CLOSE_BRACE, + PDF_TOK_NAME, PDF_TOK_INT, PDF_TOK_REAL, PDF_TOK_STRING, PDF_TOK_KEYWORD, + PDF_TOK_R, PDF_TOK_TRUE, PDF_TOK_FALSE, PDF_TOK_NULL, + PDF_TOK_OBJ, PDF_TOK_ENDOBJ, + PDF_TOK_STREAM, PDF_TOK_ENDSTREAM, + PDF_TOK_XREF, PDF_TOK_TRAILER, PDF_TOK_STARTXREF, + PDF_NUM_TOKENS +}; + +enum +{ + PDF_LEXBUF_SMALL = 256, + PDF_LEXBUF_LARGE = 65536 +}; + +typedef struct pdf_lexbuf_s pdf_lexbuf; +typedef struct pdf_lexbuf_large_s pdf_lexbuf_large; + +struct pdf_lexbuf_s +{ + int size; + int len; + int i; + float f; + char scratch[PDF_LEXBUF_SMALL]; +}; + +struct pdf_lexbuf_large_s +{ + pdf_lexbuf base; + char scratch[PDF_LEXBUF_LARGE - PDF_LEXBUF_SMALL]; +}; + +int pdf_lex(fz_stream *f, pdf_lexbuf *lexbuf); + +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); + +/* + * 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; + +struct pdf_ocg_entry_s +{ + int num; + int gen; + int state; +}; + +struct pdf_ocg_descriptor_s +{ + int len; + pdf_ocg_entry *ocgs; + pdf_obj *intent; +}; + +struct pdf_document_s +{ + fz_document super; + + fz_context *ctx; + fz_stream *file; + + int version; + int startxref; + int file_size; + pdf_crypt *crypt; + pdf_obj *trailer; + pdf_ocg_descriptor *ocg; + + int len; + pdf_xref_entry *table; + + int page_len; + int page_cap; + pdf_obj **page_objs; + pdf_obj **page_refs; + + pdf_lexbuf_large lexbuf; +}; + +void pdf_cache_object(pdf_document *doc, int num, int gen); + +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_image_stream(pdf_document *doc, int num, int gen, pdf_image_params *params); +fz_stream *pdf_open_image_stream(pdf_document *doc, int num, int gen, pdf_image_params *params); +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); + +void pdf_repair_xref(pdf_document *doc, pdf_lexbuf *buf); +void pdf_repair_obj_stms(pdf_document *doc); +void pdf_debug_xref(pdf_document *); +void pdf_resize_xref(pdf_document *doc, int newcap); + +/* + * Encryption + */ + +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, 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); + +int pdf_get_crypt_revision(pdf_document *doc); +char *pdf_get_crypt_method(pdf_document *doc); +int pdf_get_crypt_length(pdf_document *doc); +unsigned char *pdf_get_crypt_key(pdf_document *doc); + +void pdf_debug_crypt(pdf_crypt *crypt); + +/* + * Functions, Colorspaces, Shadings and Images + */ + +typedef struct pdf_function_s pdf_function; + +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, pdf_obj *obj); +fz_pixmap *pdf_expand_indexed_pixmap(fz_context *ctx, fz_pixmap *src); + +fz_shade *pdf_load_shading(pdf_document *doc, pdf_obj *obj); + +fz_image *pdf_load_inline_image(pdf_document *doc, pdf_obj *rdb, pdf_obj *dict, fz_stream *file); +int pdf_is_jpx_image(fz_context *ctx, pdf_obj *dict); + +/* + * Pattern + */ + +typedef struct pdf_pattern_s pdf_pattern; + +struct pdf_pattern_s +{ + fz_storable storable; + int ismask; + float xstep; + float ystep; + fz_matrix matrix; + fz_rect bbox; + pdf_obj *resources; + fz_buffer *contents; +}; + +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); + +/* + * XObject + */ + +typedef struct pdf_xobject_s pdf_xobject; + +struct pdf_xobject_s +{ + fz_storable storable; + fz_matrix matrix; + fz_rect bbox; + int isolated; + int knockout; + int transparency; + fz_colorspace *colorspace; + pdf_obj *resources; + fz_buffer *contents; + pdf_obj *me; +}; + +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); + +/* + * CMap + */ + +typedef struct pdf_cmap_s pdf_cmap; +typedef struct pdf_range_s pdf_range; + +enum { PDF_CMAP_SINGLE, PDF_CMAP_RANGE, PDF_CMAP_TABLE, PDF_CMAP_MULTI }; + +struct pdf_range_s +{ + unsigned short low; + /* Next, we pack 2 fields into the same unsigned short. Top 14 bits + * are the extent, bottom 2 bits are flags: single, range, table, + * multi */ + unsigned short extent_flags; + unsigned short offset; /* range-delta or table-index */ +}; + +struct pdf_cmap_s +{ + fz_storable storable; + char cmap_name[32]; + + char usecmap_name[32]; + pdf_cmap *usecmap; + + int wmode; + + int codespace_len; + struct + { + unsigned short n; + unsigned short low; + unsigned short high; + } codespace[40]; + + int rlen, rcap; + pdf_range *ranges; + + int tlen, tcap; + unsigned short *table; +}; + +pdf_cmap *pdf_new_cmap(fz_context *ctx); +pdf_cmap *pdf_keep_cmap(fz_context *ctx, pdf_cmap *cmap); +void pdf_drop_cmap(fz_context *ctx, pdf_cmap *cmap); +void pdf_free_cmap_imp(fz_context *ctx, fz_storable *cmap); +unsigned int pdf_cmap_size(fz_context *ctx, pdf_cmap *cmap); + +void pdf_debug_cmap(fz_context *ctx, pdf_cmap *cmap); +int pdf_get_wmode(fz_context *ctx, pdf_cmap *cmap); +void pdf_set_wmode(fz_context *ctx, pdf_cmap *cmap, int wmode); +void pdf_set_usecmap(fz_context *ctx, pdf_cmap *cmap, pdf_cmap *usecmap); + +void pdf_add_codespace(fz_context *ctx, pdf_cmap *cmap, int low, int high, int n); +void pdf_map_range_to_table(fz_context *ctx, pdf_cmap *cmap, int low, int *map, int len); +void pdf_map_range_to_range(fz_context *ctx, pdf_cmap *cmap, int srclo, int srchi, int dstlo); +void pdf_map_one_to_many(fz_context *ctx, pdf_cmap *cmap, int one, int *many, int len); +void pdf_sort_cmap(fz_context *ctx, pdf_cmap *cmap); + +int pdf_lookup_cmap(pdf_cmap *cmap, int cpt); +int pdf_lookup_cmap_full(pdf_cmap *cmap, int cpt, int *out); +int pdf_decode_cmap(pdf_cmap *cmap, unsigned char *s, int *cpt); + +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, pdf_obj *ref); + +/* + * Font + */ + +enum +{ + PDF_FD_FIXED_PITCH = 1 << 0, + PDF_FD_SERIF = 1 << 1, + PDF_FD_SYMBOLIC = 1 << 2, + PDF_FD_SCRIPT = 1 << 3, + PDF_FD_NONSYMBOLIC = 1 << 5, + PDF_FD_ITALIC = 1 << 6, + PDF_FD_ALL_CAP = 1 << 16, + PDF_FD_SMALL_CAP = 1 << 17, + PDF_FD_FORCE_BOLD = 1 << 18 +}; + +enum { PDF_ROS_CNS, PDF_ROS_GB, PDF_ROS_JAPAN, PDF_ROS_KOREA }; + +void pdf_load_encoding(char **estrings, char *encoding); +int pdf_lookup_agl(char *name); +const char **pdf_lookup_agl_duplicates(int ucs); + +extern const unsigned short pdf_doc_encoding[256]; +extern const char * const pdf_mac_roman[256]; +extern const char * const pdf_mac_expert[256]; +extern const char * const pdf_win_ansi[256]; +extern const char * const pdf_standard[256]; + +typedef struct pdf_font_desc_s pdf_font_desc; +typedef struct pdf_hmtx_s pdf_hmtx; +typedef struct pdf_vmtx_s pdf_vmtx; + +struct pdf_hmtx_s +{ + unsigned short lo; + unsigned short hi; + int w; /* type3 fonts can be big! */ +}; + +struct pdf_vmtx_s +{ + unsigned short lo; + unsigned short hi; + short x; + short y; + short w; +}; + +struct pdf_font_desc_s +{ + fz_storable storable; + unsigned int size; + + fz_font *font; + + /* FontDescriptor */ + int flags; + float italic_angle; + float ascent; + float descent; + float cap_height; + float x_height; + float missing_width; + + /* Encoding (CMap) */ + pdf_cmap *encoding; + pdf_cmap *to_ttf_cmap; + int cid_to_gid_len; + unsigned short *cid_to_gid; + + /* ToUnicode */ + pdf_cmap *to_unicode; + int cid_to_ucs_len; + unsigned short *cid_to_ucs; + + /* Metrics (given in the PDF file) */ + int wmode; + + int hmtx_len, hmtx_cap; + pdf_hmtx dhmtx; + pdf_hmtx *hmtx; + + int vmtx_len, vmtx_cap; + pdf_vmtx dvmtx; + pdf_vmtx *vmtx; + + int is_embedded; +}; + +void pdf_set_font_wmode(fz_context *ctx, pdf_font_desc *font, int wmode); +void pdf_set_default_hmtx(fz_context *ctx, pdf_font_desc *font, int w); +void pdf_set_default_vmtx(fz_context *ctx, pdf_font_desc *font, int y, int w); +void pdf_add_hmtx(fz_context *ctx, pdf_font_desc *font, int lo, int hi, int w); +void pdf_add_vmtx(fz_context *ctx, pdf_font_desc *font, int lo, int hi, int x, int y, int w); +void pdf_end_hmtx(fz_context *ctx, pdf_font_desc *font); +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, pdf_obj *cmapstm); + +int pdf_font_cid_to_gid(fz_context *ctx, pdf_font_desc *fontdesc, int cid); + +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, 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); +void pdf_drop_font(fz_context *ctx, pdf_font_desc *font); + +void pdf_debug_font(fz_context *ctx, pdf_font_desc *fontdesc); + +/* + * Interactive features + */ + +typedef struct pdf_annot_s pdf_annot; + +struct pdf_annot_s +{ + 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, 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_link *pdf_load_link_annots(pdf_document *, pdf_obj *annots, fz_matrix page_ctm); + +pdf_annot *pdf_load_annots(pdf_document *, pdf_obj *annots); +void pdf_free_annot(fz_context *ctx, pdf_annot *link); + +/* + * Page tree, pages and related objects + */ + +struct pdf_page_s +{ + fz_matrix ctm; /* calculated from mediabox and rotate */ + fz_rect mediabox; + int rotate; + int transparency; + pdf_obj *resources; + fz_buffer *contents; + fz_link *links; + pdf_annot *annots; +}; + +/* + * Content stream parsing + */ + +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, 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 diff --git a/pdf/mupdf.h b/pdf/mupdf.h index 5d775044..7566bc36 100644 --- a/pdf/mupdf.h +++ b/pdf/mupdf.h @@ -1,9 +1,9 @@ -#ifndef _MUPDF_H_ -#define _MUPDF_H_ +#ifndef MUPDF_H +#define MUPDF_H -#ifndef _FITZ_H_ -#error "fitz.h must be included before mupdf.h" -#endif +#include "fitz.h" + +typedef struct pdf_document_s pdf_document; /* * Dynamic objects. @@ -39,6 +39,7 @@ 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_is_stream(pdf_document *doc, int num, int gen); int pdf_objcmp(pdf_obj *a, pdf_obj *b); @@ -81,220 +82,27 @@ 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 - */ - -typedef struct pdf_image_params_s pdf_image_params; - -struct pdf_image_params_s -{ - int type; - fz_colorspace *colorspace; - union - { - struct - { - int columns; - int rows; - int k; - int eol; - int eba; - int eob; - int bi1; - } - fax; - struct - { - int ct; - } - jpeg; - struct - { - int columns; - int colors; - int predictor; - int bpc; - } - flate; - struct - { - int columns; - int colors; - int predictor; - int bpc; - int ec; - } - lzw; - } - u; -}; - - -typedef struct pdf_image_s pdf_image; - -struct pdf_image_s -{ - fz_image base; - fz_pixmap *tile; - int n, bpc; - pdf_image_params params; - fz_buffer *buffer; - int colorkey[FZ_MAX_COLORS * 2]; - float decode[FZ_MAX_COLORS * 2]; - int imagemask; - int interpolate; - int usecolorkey; -}; - -enum -{ - PDF_IMAGE_RAW, - PDF_IMAGE_FAX, - PDF_IMAGE_JPEG, - PDF_IMAGE_RLD, - PDF_IMAGE_FLATE, - PDF_IMAGE_LZW, - PDF_IMAGE_JPX -}; - -typedef struct pdf_document_s pdf_document; - -/* - * tokenizer and low-level object parser - */ - -enum -{ - PDF_TOK_ERROR, PDF_TOK_EOF, - PDF_TOK_OPEN_ARRAY, PDF_TOK_CLOSE_ARRAY, - PDF_TOK_OPEN_DICT, PDF_TOK_CLOSE_DICT, - PDF_TOK_OPEN_BRACE, PDF_TOK_CLOSE_BRACE, - PDF_TOK_NAME, PDF_TOK_INT, PDF_TOK_REAL, PDF_TOK_STRING, PDF_TOK_KEYWORD, - PDF_TOK_R, PDF_TOK_TRUE, PDF_TOK_FALSE, PDF_TOK_NULL, - PDF_TOK_OBJ, PDF_TOK_ENDOBJ, - PDF_TOK_STREAM, PDF_TOK_ENDSTREAM, - PDF_TOK_XREF, PDF_TOK_TRAILER, PDF_TOK_STARTXREF, - PDF_NUM_TOKENS -}; - -enum -{ - PDF_LEXBUF_SMALL = 256, - PDF_LEXBUF_LARGE = 65536 -}; - - - -typedef struct pdf_lexbuf_s pdf_lexbuf; -typedef struct pdf_lexbuf_large_s pdf_lexbuf_large; - -struct pdf_lexbuf_s -{ - int size; - int len; - int i; - float f; - char scratch[PDF_LEXBUF_SMALL]; -}; - -struct pdf_lexbuf_large_s -{ - pdf_lexbuf base; - char scratch[PDF_LEXBUF_LARGE - PDF_LEXBUF_SMALL]; -}; - - - -int pdf_lex(fz_stream *f, pdf_lexbuf *lexbuf); - -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, 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); +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); -/* - * xref and object / stream api - */ - -typedef struct pdf_xref_entry_s pdf_xref_entry; -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; - -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 */ -}; - -struct pdf_ocg_entry_s -{ - int num; - int gen; - int state; -}; - -struct pdf_ocg_descriptor_s -{ - int len; - pdf_ocg_entry *ocgs; - pdf_obj *intent; -}; - -struct pdf_document_s -{ - fz_document super; - - fz_context *ctx; - fz_stream *file; - - int version; - int startxref; - int file_size; - pdf_crypt *crypt; - pdf_obj *trailer; - pdf_ocg_descriptor *ocg; - - int len; - pdf_xref_entry *table; - - int page_len; - int page_cap; - pdf_obj **page_objs; - pdf_obj **page_refs; - - pdf_lexbuf_large lexbuf; -}; +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); -void pdf_cache_object(pdf_document *doc, int num, int gen); 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, 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, pdf_obj *dict, int stm_ofs); -fz_stream *pdf_open_image_decomp_stream(fz_context *ctx, fz_buffer *, pdf_image_params *params, int *factor); + +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. @@ -336,15 +144,8 @@ pdf_document *pdf_open_document_with_stream(fz_stream *file); */ void pdf_close_document(pdf_document *doc); -/* 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 *); -void pdf_resize_xref(pdf_document *doc, int newcap); - -/* - * Encryption - */ +int pdf_needs_password(pdf_document *doc); +int pdf_authenticate_password(pdf_document *doc, char *pw); enum { @@ -359,325 +160,10 @@ enum 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); - -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); - -int pdf_needs_password(pdf_document *doc); -int pdf_authenticate_password(pdf_document *doc, char *pw); 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); -unsigned char *pdf_get_crypt_key(pdf_document *doc); - -void pdf_debug_crypt(pdf_crypt *crypt); - -/* - * Functions, Colorspaces, Shadings and Images - */ - -typedef struct pdf_function_s pdf_function; - -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, pdf_obj *obj); -fz_pixmap *pdf_expand_indexed_pixmap(fz_context *ctx, fz_pixmap *src); - -fz_shade *pdf_load_shading(pdf_document *doc, pdf_obj *obj); - -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 - */ - -typedef struct pdf_pattern_s pdf_pattern; - -struct pdf_pattern_s -{ - fz_storable storable; - int ismask; - float xstep; - float ystep; - fz_matrix matrix; - fz_rect bbox; - pdf_obj *resources; - fz_buffer *contents; -}; - -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); - -/* - * XObject - */ - -typedef struct pdf_xobject_s pdf_xobject; - -struct pdf_xobject_s -{ - fz_storable storable; - fz_matrix matrix; - fz_rect bbox; - int isolated; - int knockout; - int transparency; - fz_colorspace *colorspace; - pdf_obj *resources; - fz_buffer *contents; - pdf_obj *me; -}; - -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); - -/* - * CMap - */ - -typedef struct pdf_cmap_s pdf_cmap; -typedef struct pdf_range_s pdf_range; - -enum { PDF_CMAP_SINGLE, PDF_CMAP_RANGE, PDF_CMAP_TABLE, PDF_CMAP_MULTI }; - -struct pdf_range_s -{ - unsigned short low; - /* Next, we pack 2 fields into the same unsigned short. Top 14 bits - * are the extent, bottom 2 bits are flags: single, range, table, - * multi */ - unsigned short extent_flags; - unsigned short offset; /* range-delta or table-index */ -}; - -struct pdf_cmap_s -{ - fz_storable storable; - char cmap_name[32]; - - char usecmap_name[32]; - pdf_cmap *usecmap; - - int wmode; - - int codespace_len; - struct - { - unsigned short n; - unsigned short low; - unsigned short high; - } codespace[40]; - - int rlen, rcap; - pdf_range *ranges; - - int tlen, tcap; - unsigned short *table; -}; - -pdf_cmap *pdf_new_cmap(fz_context *ctx); -pdf_cmap *pdf_keep_cmap(fz_context *ctx, pdf_cmap *cmap); -void pdf_drop_cmap(fz_context *ctx, pdf_cmap *cmap); -void pdf_free_cmap_imp(fz_context *ctx, fz_storable *cmap); -unsigned int pdf_cmap_size(fz_context *ctx, pdf_cmap *cmap); - -void pdf_debug_cmap(fz_context *ctx, pdf_cmap *cmap); -int pdf_get_wmode(fz_context *ctx, pdf_cmap *cmap); -void pdf_set_wmode(fz_context *ctx, pdf_cmap *cmap, int wmode); -void pdf_set_usecmap(fz_context *ctx, pdf_cmap *cmap, pdf_cmap *usecmap); - -void pdf_add_codespace(fz_context *ctx, pdf_cmap *cmap, int low, int high, int n); -void pdf_map_range_to_table(fz_context *ctx, pdf_cmap *cmap, int low, int *map, int len); -void pdf_map_range_to_range(fz_context *ctx, pdf_cmap *cmap, int srclo, int srchi, int dstlo); -void pdf_map_one_to_many(fz_context *ctx, pdf_cmap *cmap, int one, int *many, int len); -void pdf_sort_cmap(fz_context *ctx, pdf_cmap *cmap); - -int pdf_lookup_cmap(pdf_cmap *cmap, int cpt); -int pdf_lookup_cmap_full(pdf_cmap *cmap, int cpt, int *out); -int pdf_decode_cmap(pdf_cmap *cmap, unsigned char *s, int *cpt); - -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, pdf_obj *ref); - -/* - * Font - */ - -enum -{ - PDF_FD_FIXED_PITCH = 1 << 0, - PDF_FD_SERIF = 1 << 1, - PDF_FD_SYMBOLIC = 1 << 2, - PDF_FD_SCRIPT = 1 << 3, - PDF_FD_NONSYMBOLIC = 1 << 5, - PDF_FD_ITALIC = 1 << 6, - PDF_FD_ALL_CAP = 1 << 16, - PDF_FD_SMALL_CAP = 1 << 17, - PDF_FD_FORCE_BOLD = 1 << 18 -}; - -enum { PDF_ROS_CNS, PDF_ROS_GB, PDF_ROS_JAPAN, PDF_ROS_KOREA }; - -void pdf_load_encoding(char **estrings, char *encoding); -int pdf_lookup_agl(char *name); -const char **pdf_lookup_agl_duplicates(int ucs); - -extern const unsigned short pdf_doc_encoding[256]; -extern const char * const pdf_mac_roman[256]; -extern const char * const pdf_mac_expert[256]; -extern const char * const pdf_win_ansi[256]; -extern const char * const pdf_standard[256]; - -typedef struct pdf_font_desc_s pdf_font_desc; -typedef struct pdf_hmtx_s pdf_hmtx; -typedef struct pdf_vmtx_s pdf_vmtx; - -struct pdf_hmtx_s -{ - unsigned short lo; - unsigned short hi; - int w; /* type3 fonts can be big! */ -}; - -struct pdf_vmtx_s -{ - unsigned short lo; - unsigned short hi; - short x; - short y; - short w; -}; - -struct pdf_font_desc_s -{ - fz_storable storable; - unsigned int size; - - fz_font *font; - - /* FontDescriptor */ - int flags; - float italic_angle; - float ascent; - float descent; - float cap_height; - float x_height; - float missing_width; - - /* Encoding (CMap) */ - pdf_cmap *encoding; - pdf_cmap *to_ttf_cmap; - int cid_to_gid_len; - unsigned short *cid_to_gid; - - /* ToUnicode */ - pdf_cmap *to_unicode; - int cid_to_ucs_len; - unsigned short *cid_to_ucs; - - /* Metrics (given in the PDF file) */ - int wmode; - - int hmtx_len, hmtx_cap; - pdf_hmtx dhmtx; - pdf_hmtx *hmtx; - - int vmtx_len, vmtx_cap; - pdf_vmtx dvmtx; - pdf_vmtx *vmtx; - - int is_embedded; -}; - -void pdf_set_font_wmode(fz_context *ctx, pdf_font_desc *font, int wmode); -void pdf_set_default_hmtx(fz_context *ctx, pdf_font_desc *font, int w); -void pdf_set_default_vmtx(fz_context *ctx, pdf_font_desc *font, int y, int w); -void pdf_add_hmtx(fz_context *ctx, pdf_font_desc *font, int lo, int hi, int w); -void pdf_add_vmtx(fz_context *ctx, pdf_font_desc *font, int lo, int hi, int x, int y, int w); -void pdf_end_hmtx(fz_context *ctx, pdf_font_desc *font); -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, pdf_obj *cmapstm); - -int pdf_font_cid_to_gid(fz_context *ctx, pdf_font_desc *fontdesc, int cid); - -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, 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); -void pdf_drop_font(fz_context *ctx, pdf_font_desc *font); - -void pdf_debug_font(fz_context *ctx, pdf_font_desc *fontdesc); - -/* - * Interactive features - */ - -typedef struct pdf_annot_s pdf_annot; - -struct pdf_annot_s -{ - 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, 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 *, pdf_obj *annots, fz_matrix page_ctm); - -pdf_annot *pdf_load_annots(pdf_document *, pdf_obj *annots); -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 */ - fz_rect mediabox; - int rotate; - int transparency; - pdf_obj *resources; - fz_buffer *contents; - fz_link *links; - pdf_annot *annots; -}; - int pdf_find_page_number(pdf_document *doc, pdf_obj *pageobj); int pdf_count_pages(pdf_document *doc); @@ -715,10 +201,6 @@ fz_rect pdf_bound_page(pdf_document *doc, pdf_page *page); 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. @@ -731,14 +213,5 @@ 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, 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, 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 diff --git a/pdf/pdf_annot.c b/pdf/pdf_annot.c index 81e5d887..bd0ad808 100644 --- a/pdf/pdf_annot.c +++ b/pdf/pdf_annot.c @@ -1,5 +1,5 @@ -#include "fitz.h" -#include "mupdf.h" +#include "fitz-internal.h" +#include "mupdf-internal.h" static pdf_obj * resolve_dest_rec(pdf_document *xref, pdf_obj *dest, int depth) diff --git a/pdf/pdf_cmap.c b/pdf/pdf_cmap.c index 987da592..712ebfe7 100644 --- a/pdf/pdf_cmap.c +++ b/pdf/pdf_cmap.c @@ -15,8 +15,8 @@ * or can trust the parser to give us optimal mappings. */ -#include "fitz.h" -#include "mupdf.h" +#include "fitz-internal.h" +#include "mupdf-internal.h" /* Macros for accessing the combined extent_flags field */ #define pdf_range_high(r) ((r)->low + ((r)->extent_flags >> 2)) diff --git a/pdf/pdf_cmap_load.c b/pdf/pdf_cmap_load.c index d4e161c8..6867d845 100644 --- a/pdf/pdf_cmap_load.c +++ b/pdf/pdf_cmap_load.c @@ -1,5 +1,5 @@ -#include "fitz.h" -#include "mupdf.h" +#include "fitz-internal.h" +#include "mupdf-internal.h" unsigned int pdf_cmap_size(fz_context *ctx, pdf_cmap *cmap) diff --git a/pdf/pdf_cmap_parse.c b/pdf/pdf_cmap_parse.c index 4933dea5..3396e3ae 100644 --- a/pdf/pdf_cmap_parse.c +++ b/pdf/pdf_cmap_parse.c @@ -1,5 +1,5 @@ -#include "fitz.h" -#include "mupdf.h" +#include "fitz-internal.h" +#include "mupdf-internal.h" /* * CMap parser diff --git a/pdf/pdf_cmap_table.c b/pdf/pdf_cmap_table.c index fbe528e0..21dfe5fa 100644 --- a/pdf/pdf_cmap_table.c +++ b/pdf/pdf_cmap_table.c @@ -1,5 +1,5 @@ -#include "fitz.h" -#include "mupdf.h" +#include "fitz-internal.h" +#include "mupdf-internal.h" #ifndef NOCJK #include "../generated/cmap_cns.h" diff --git a/pdf/pdf_colorspace.c b/pdf/pdf_colorspace.c index 05d0c135..5bf84535 100644 --- a/pdf/pdf_colorspace.c +++ b/pdf/pdf_colorspace.c @@ -1,5 +1,5 @@ -#include "fitz.h" -#include "mupdf.h" +#include "fitz-internal.h" +#include "mupdf-internal.h" /* ICCBased */ diff --git a/pdf/pdf_crypt.c b/pdf/pdf_crypt.c index 510acc7b..2927527e 100644 --- a/pdf/pdf_crypt.c +++ b/pdf/pdf_crypt.c @@ -1,5 +1,5 @@ -#include "fitz.h" -#include "mupdf.h" +#include "fitz-internal.h" +#include "mupdf-internal.h" enum { diff --git a/pdf/pdf_encoding.c b/pdf/pdf_encoding.c index 9a42a1c1..eb36ed96 100644 --- a/pdf/pdf_encoding.c +++ b/pdf/pdf_encoding.c @@ -1,5 +1,5 @@ -#include "fitz.h" -#include "mupdf.h" +#include "fitz-internal.h" +#include "mupdf-internal.h" #include "data_encodings.h" #include "data_glyphlist.h" diff --git a/pdf/pdf_font.c b/pdf/pdf_font.c index 5e54e0bb..11c97d37 100644 --- a/pdf/pdf_font.c +++ b/pdf/pdf_font.c @@ -1,5 +1,5 @@ -#include "fitz.h" -#include "mupdf.h" +#include "fitz-internal.h" +#include "mupdf-internal.h" #include <ft2build.h> #include FT_FREETYPE_H diff --git a/pdf/pdf_fontfile.c b/pdf/pdf_fontfile.c index 543ce763..4dbbe91c 100644 --- a/pdf/pdf_fontfile.c +++ b/pdf/pdf_fontfile.c @@ -1,5 +1,5 @@ -#include "fitz.h" -#include "mupdf.h" +#include "fitz-internal.h" +#include "mupdf-internal.h" #ifdef NOCJK #define NOCJKFONT diff --git a/pdf/pdf_function.c b/pdf/pdf_function.c index 681c0157..e1c53beb 100644 --- a/pdf/pdf_function.c +++ b/pdf/pdf_function.c @@ -1,5 +1,5 @@ -#include "fitz.h" -#include "mupdf.h" +#include "fitz-internal.h" +#include "mupdf-internal.h" enum { diff --git a/pdf/pdf_image.c b/pdf/pdf_image.c index 4cdd374a..17996a74 100644 --- a/pdf/pdf_image.c +++ b/pdf/pdf_image.c @@ -1,5 +1,5 @@ -#include "fitz.h" -#include "mupdf.h" +#include "fitz-internal.h" +#include "mupdf-internal.h" typedef struct pdf_image_key_s pdf_image_key; diff --git a/pdf/pdf_interpret.c b/pdf/pdf_interpret.c index ca957d09..1c2a11f3 100644 --- a/pdf/pdf_interpret.c +++ b/pdf/pdf_interpret.c @@ -1,5 +1,5 @@ -#include "fitz.h" -#include "mupdf.h" +#include "fitz-internal.h" +#include "mupdf-internal.h" #define TILE diff --git a/pdf/pdf_lex.c b/pdf/pdf_lex.c index 322d945c..6774167a 100644 --- a/pdf/pdf_lex.c +++ b/pdf/pdf_lex.c @@ -1,5 +1,5 @@ -#include "fitz.h" -#include "mupdf.h" +#include "fitz-internal.h" +#include "mupdf-internal.h" #define IS_NUMBER \ '+':case'-':case'.':case'0':case'1':case'2':case'3':\ diff --git a/pdf/pdf_metrics.c b/pdf/pdf_metrics.c index fc888257..ae4405ed 100644 --- a/pdf/pdf_metrics.c +++ b/pdf/pdf_metrics.c @@ -1,5 +1,5 @@ -#include "fitz.h" -#include "mupdf.h" +#include "fitz-internal.h" +#include "mupdf-internal.h" void pdf_set_font_wmode(fz_context *ctx, pdf_font_desc *font, int wmode) diff --git a/pdf/pdf_nametree.c b/pdf/pdf_nametree.c index 98a10241..b24d2c24 100644 --- a/pdf/pdf_nametree.c +++ b/pdf/pdf_nametree.c @@ -1,5 +1,5 @@ -#include "fitz.h" -#include "mupdf.h" +#include "fitz-internal.h" +#include "mupdf-internal.h" static pdf_obj * pdf_lookup_name_imp(fz_context *ctx, pdf_obj *node, pdf_obj *needle) diff --git a/pdf/pdf_outline.c b/pdf/pdf_outline.c index 793b5f77..d4bea75a 100644 --- a/pdf/pdf_outline.c +++ b/pdf/pdf_outline.c @@ -1,5 +1,5 @@ -#include "fitz.h" -#include "mupdf.h" +#include "fitz-internal.h" +#include "mupdf-internal.h" static fz_outline * pdf_load_outline_imp(pdf_document *xref, pdf_obj *dict) diff --git a/pdf/pdf_page.c b/pdf/pdf_page.c index ca38aacf..5b9106d1 100644 --- a/pdf/pdf_page.c +++ b/pdf/pdf_page.c @@ -1,5 +1,5 @@ -#include "fitz.h" -#include "mupdf.h" +#include "fitz-internal.h" +#include "mupdf-internal.h" struct info { diff --git a/pdf/pdf_parse.c b/pdf/pdf_parse.c index 57ba1d6f..fe9db368 100644 --- a/pdf/pdf_parse.c +++ b/pdf/pdf_parse.c @@ -1,5 +1,5 @@ -#include "fitz.h" -#include "mupdf.h" +#include "fitz-internal.h" +#include "mupdf-internal.h" fz_rect pdf_to_rect(fz_context *ctx, pdf_obj *array) @@ -45,7 +45,7 @@ pdf_to_utf8(fz_context *ctx, pdf_obj *src) for (i = 2; i + 1 < srclen; i += 2) { ucs = srcptr[i] << 8 | srcptr[i+1]; - dstlen += runelen(ucs); + dstlen += fz_runelen(ucs); } dstptr = dst = fz_malloc(ctx, dstlen + 1); @@ -53,7 +53,7 @@ pdf_to_utf8(fz_context *ctx, pdf_obj *src) for (i = 2; i + 1 < srclen; i += 2) { ucs = srcptr[i] << 8 | srcptr[i+1]; - dstptr += runetochar(dstptr, &ucs); + dstptr += fz_runetochar(dstptr, ucs); } } else if (srclen >= 2 && srcptr[0] == 255 && srcptr[1] == 254) @@ -61,7 +61,7 @@ pdf_to_utf8(fz_context *ctx, pdf_obj *src) for (i = 2; i + 1 < srclen; i += 2) { ucs = srcptr[i] | srcptr[i+1] << 8; - dstlen += runelen(ucs); + dstlen += fz_runelen(ucs); } dstptr = dst = fz_malloc(ctx, dstlen + 1); @@ -69,20 +69,20 @@ pdf_to_utf8(fz_context *ctx, pdf_obj *src) for (i = 2; i + 1 < srclen; i += 2) { ucs = srcptr[i] | srcptr[i+1] << 8; - dstptr += runetochar(dstptr, &ucs); + dstptr += fz_runetochar(dstptr, ucs); } } else { for (i = 0; i < srclen; i++) - dstlen += runelen(pdf_doc_encoding[srcptr[i]]); + dstlen += fz_runelen(pdf_doc_encoding[srcptr[i]]); dstptr = dst = fz_malloc(ctx, dstlen + 1); for (i = 0; i < srclen; i++) { ucs = pdf_doc_encoding[srcptr[i]]; - dstptr += runetochar(dstptr, &ucs); + dstptr += fz_runetochar(dstptr, ucs); } } diff --git a/pdf/pdf_pattern.c b/pdf/pdf_pattern.c index 00e4b8fb..14175670 100644 --- a/pdf/pdf_pattern.c +++ b/pdf/pdf_pattern.c @@ -1,5 +1,5 @@ -#include "fitz.h" -#include "mupdf.h" +#include "fitz-internal.h" +#include "mupdf-internal.h" pdf_pattern * pdf_keep_pattern(fz_context *ctx, pdf_pattern *pat) diff --git a/pdf/pdf_repair.c b/pdf/pdf_repair.c index f42198eb..fda1e6b5 100644 --- a/pdf/pdf_repair.c +++ b/pdf/pdf_repair.c @@ -1,5 +1,5 @@ -#include "fitz.h" -#include "mupdf.h" +#include "fitz-internal.h" +#include "mupdf-internal.h" /* Scan file for objects and reconstruct xref table */ diff --git a/pdf/pdf_shade.c b/pdf/pdf_shade.c index c3bddcbc..589b7613 100644 --- a/pdf/pdf_shade.c +++ b/pdf/pdf_shade.c @@ -1,5 +1,5 @@ -#include "fitz.h" -#include "mupdf.h" +#include "fitz-internal.h" +#include "mupdf-internal.h" #define HUGENUM 32000 /* how far to extend axial/radial shadings */ #define FUNSEGS 32 /* size of sampled mesh for function-based shadings */ diff --git a/pdf/pdf_store.c b/pdf/pdf_store.c index 38abe10b..ae8eac9a 100644 --- a/pdf/pdf_store.c +++ b/pdf/pdf_store.c @@ -1,5 +1,5 @@ -#include "fitz.h" -#include "mupdf.h" +#include "fitz-internal.h" +#include "mupdf-internal.h" static int pdf_make_hash_key(fz_store_hash *hash, void *key_) diff --git a/pdf/pdf_stream.c b/pdf/pdf_stream.c index 6afb2cdb..84f966ec 100644 --- a/pdf/pdf_stream.c +++ b/pdf/pdf_stream.c @@ -1,5 +1,5 @@ -#include "fitz.h" -#include "mupdf.h" +#include "fitz-internal.h" +#include "mupdf-internal.h" /* * Check if an object is a stream or not. diff --git a/pdf/pdf_type3.c b/pdf/pdf_type3.c index dc931e22..6603fc8b 100644 --- a/pdf/pdf_type3.c +++ b/pdf/pdf_type3.c @@ -1,5 +1,5 @@ -#include "fitz.h" -#include "mupdf.h" +#include "fitz-internal.h" +#include "mupdf-internal.h" static void pdf_run_glyph_func(void *doc, void *rdb_, fz_buffer *contents, fz_device *dev, fz_matrix ctm, void *gstate) diff --git a/pdf/pdf_unicode.c b/pdf/pdf_unicode.c index edfda708..c94a6683 100644 --- a/pdf/pdf_unicode.c +++ b/pdf/pdf_unicode.c @@ -1,5 +1,5 @@ -#include "fitz.h" -#include "mupdf.h" +#include "fitz-internal.h" +#include "mupdf-internal.h" /* Load or synthesize ToUnicode map for fonts */ diff --git a/pdf/pdf_xobject.c b/pdf/pdf_xobject.c index 36c5c483..ffa86184 100644 --- a/pdf/pdf_xobject.c +++ b/pdf/pdf_xobject.c @@ -1,5 +1,5 @@ -#include "fitz.h" -#include "mupdf.h" +#include "fitz-internal.h" +#include "mupdf-internal.h" pdf_xobject * pdf_keep_xobject(fz_context *ctx, pdf_xobject *xobj) diff --git a/pdf/pdf_xref.c b/pdf/pdf_xref.c index f0dbde96..9e60955c 100644 --- a/pdf/pdf_xref.c +++ b/pdf/pdf_xref.c @@ -1,5 +1,5 @@ -#include "fitz.h" -#include "mupdf.h" +#include "fitz-internal.h" +#include "mupdf-internal.h" static inline int iswhite(int ch) { @@ -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) |