1 #ifndef MUPDF_PDF_CMAP_H 2 #define MUPDF_PDF_CMAP_H 3 4 #define PDF_MRANGE_CAP 8 5 6 typedef struct 7 { 8 unsigned short low, high, out; 9 } pdf_range; 10 11 typedef struct 12 { 13 unsigned int low, high, out; 14 } pdf_xrange; 15 16 typedef struct 17 { 18 unsigned int low, out; 19 } pdf_mrange; 20 21 typedef struct cmap_splay cmap_splay; 22 23 typedef struct pdf_cmap 24 { 25 fz_storable storable; 26 char cmap_name[32]; 27 28 char usecmap_name[32]; 29 struct pdf_cmap *usecmap; 30 31 int wmode; 32 33 int codespace_len; 34 struct 35 { 36 int n; 37 unsigned int low; 38 unsigned int high; 39 } codespace[40]; 40 41 int rlen, rcap; 42 pdf_range *ranges; 43 44 int xlen, xcap; 45 pdf_xrange *xranges; 46 47 int mlen, mcap; 48 pdf_mrange *mranges; 49 50 int dlen, dcap; 51 int *dict; 52 53 int tlen, tcap, ttop; 54 cmap_splay *tree; 55 } pdf_cmap; 56 57 pdf_cmap *pdf_new_cmap(fz_context *ctx); 58 pdf_cmap *pdf_keep_cmap(fz_context *ctx, pdf_cmap *cmap); 59 void pdf_drop_cmap(fz_context *ctx, pdf_cmap *cmap); 60 void pdf_drop_cmap_imp(fz_context *ctx, fz_storable *cmap); 61 size_t pdf_cmap_size(fz_context *ctx, pdf_cmap *cmap); 62 63 int pdf_cmap_wmode(fz_context *ctx, pdf_cmap *cmap); 64 void pdf_set_cmap_wmode(fz_context *ctx, pdf_cmap *cmap, int wmode); 65 void pdf_set_usecmap(fz_context *ctx, pdf_cmap *cmap, pdf_cmap *usecmap); 66 67 /* 68 Add a codespacerange section. 69 These ranges are used by pdf_decode_cmap to decode 70 multi-byte encoded strings. 71 */ 72 void pdf_add_codespace(fz_context *ctx, pdf_cmap *cmap, unsigned int low, unsigned int high, size_t n); 73 74 /* 75 Add a range of contiguous one-to-one mappings (ie 1..5 maps to 21..25) 76 */ 77 void pdf_map_range_to_range(fz_context *ctx, pdf_cmap *cmap, unsigned int srclo, unsigned int srchi, int dstlo); 78 79 /* 80 Add a single one-to-many mapping. 81 */ 82 void pdf_map_one_to_many(fz_context *ctx, pdf_cmap *cmap, unsigned int one, int *many, size_t len); 83 void pdf_sort_cmap(fz_context *ctx, pdf_cmap *cmap); 84 85 /* 86 Lookup the mapping of a codepoint. 87 */ 88 int pdf_lookup_cmap(pdf_cmap *cmap, unsigned int cpt); 89 int pdf_lookup_cmap_full(pdf_cmap *cmap, unsigned int cpt, int *out); 90 91 /* 92 Use the codespace ranges to extract a codepoint from a 93 multi-byte encoded string. 94 */ 95 int pdf_decode_cmap(pdf_cmap *cmap, unsigned char *s, unsigned char *e, unsigned int *cpt); 96 97 /* 98 Create an Identity-* CMap (for both 1 and 2-byte encodings) 99 */ 100 pdf_cmap *pdf_new_identity_cmap(fz_context *ctx, int wmode, int bytes); 101 pdf_cmap *pdf_load_cmap(fz_context *ctx, fz_stream *file); 102 103 /* 104 Load predefined CMap from system. 105 */ 106 pdf_cmap *pdf_load_system_cmap(fz_context *ctx, const char *name); 107 108 /* 109 Load built-in CMap resource. 110 */ 111 pdf_cmap *pdf_load_builtin_cmap(fz_context *ctx, const char *name); 112 113 /* 114 Load CMap stream in PDF file 115 */ 116 pdf_cmap *pdf_load_embedded_cmap(fz_context *ctx, pdf_document *doc, pdf_obj *ref); 117 118 #endif 119