1 #ifndef MUPDF_PDF_FONT_H 2 #define MUPDF_PDF_FONT_H 3 4 #include "mupdf/pdf/cmap.h" 5 6 enum 7 { 8 PDF_FD_FIXED_PITCH = 1 << 0, 9 PDF_FD_SERIF = 1 << 1, 10 PDF_FD_SYMBOLIC = 1 << 2, 11 PDF_FD_SCRIPT = 1 << 3, 12 PDF_FD_NONSYMBOLIC = 1 << 5, 13 PDF_FD_ITALIC = 1 << 6, 14 PDF_FD_ALL_CAP = 1 << 16, 15 PDF_FD_SMALL_CAP = 1 << 17, 16 PDF_FD_FORCE_BOLD = 1 << 18 17 }; 18 19 void pdf_load_encoding(const char **estrings, const char *encoding); 20 21 typedef struct 22 { 23 unsigned short lo; 24 unsigned short hi; 25 int w; /* type3 fonts can be big! */ 26 } pdf_hmtx; 27 28 typedef struct 29 { 30 unsigned short lo; 31 unsigned short hi; 32 short x; 33 short y; 34 short w; 35 } pdf_vmtx; 36 37 typedef struct 38 { 39 fz_storable storable; 40 size_t size; 41 42 fz_font *font; 43 44 /* FontDescriptor */ 45 int flags; 46 float italic_angle; 47 float ascent; 48 float descent; 49 float cap_height; 50 float x_height; 51 float missing_width; 52 53 /* Encoding (CMap) */ 54 pdf_cmap *encoding; 55 pdf_cmap *to_ttf_cmap; 56 size_t cid_to_gid_len; 57 unsigned short *cid_to_gid; 58 59 /* ToUnicode */ 60 pdf_cmap *to_unicode; 61 size_t cid_to_ucs_len; 62 unsigned short *cid_to_ucs; 63 64 /* Metrics (given in the PDF file) */ 65 int wmode; 66 67 int hmtx_len, hmtx_cap; 68 pdf_hmtx dhmtx; 69 pdf_hmtx *hmtx; 70 71 int vmtx_len, vmtx_cap; 72 pdf_vmtx dvmtx; 73 pdf_vmtx *vmtx; 74 75 int is_embedded; 76 } pdf_font_desc; 77 78 void pdf_set_font_wmode(fz_context *ctx, pdf_font_desc *font, int wmode); 79 void pdf_set_default_hmtx(fz_context *ctx, pdf_font_desc *font, int w); 80 void pdf_set_default_vmtx(fz_context *ctx, pdf_font_desc *font, int y, int w); 81 void pdf_add_hmtx(fz_context *ctx, pdf_font_desc *font, int lo, int hi, int w); 82 void pdf_add_vmtx(fz_context *ctx, pdf_font_desc *font, int lo, int hi, int x, int y, int w); 83 void pdf_end_hmtx(fz_context *ctx, pdf_font_desc *font); 84 void pdf_end_vmtx(fz_context *ctx, pdf_font_desc *font); 85 pdf_hmtx pdf_lookup_hmtx(fz_context *ctx, pdf_font_desc *font, int cid); 86 pdf_vmtx pdf_lookup_vmtx(fz_context *ctx, pdf_font_desc *font, int cid); 87 88 void pdf_load_to_unicode(fz_context *ctx, pdf_document *doc, pdf_font_desc *font, const char **strings, char *collection, pdf_obj *cmapstm); 89 90 int pdf_font_cid_to_gid(fz_context *ctx, pdf_font_desc *fontdesc, int cid); 91 const char *pdf_clean_font_name(const char *fontname); 92 93 const unsigned char *pdf_lookup_substitute_font(fz_context *ctx, int mono, int serif, int bold, int italic, int *len); 94 95 pdf_font_desc *pdf_load_type3_font(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *obj); 96 void pdf_load_type3_glyphs(fz_context *ctx, pdf_document *doc, pdf_font_desc *fontdesc); 97 pdf_font_desc *pdf_load_font(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *obj); 98 pdf_font_desc *pdf_load_hail_mary_font(fz_context *ctx, pdf_document *doc); 99 100 pdf_font_desc *pdf_new_font_desc(fz_context *ctx); 101 pdf_font_desc *pdf_keep_font(fz_context *ctx, pdf_font_desc *fontdesc); 102 void pdf_drop_font(fz_context *ctx, pdf_font_desc *font); 103 104 void pdf_print_font(fz_context *ctx, fz_output *out, pdf_font_desc *fontdesc); 105 106 void pdf_run_glyph(fz_context *ctx, pdf_document *doc, pdf_obj *resources, fz_buffer *contents, fz_device *dev, fz_matrix ctm, void *gstate, fz_default_colorspaces *default_cs); 107 108 pdf_obj *pdf_add_simple_font(fz_context *ctx, pdf_document *doc, fz_font *font, int encoding); 109 110 /* 111 Creates CID font with Identity-H CMap and a ToUnicode CMap that 112 is created by using the TTF cmap table "backwards" to go from 113 the GID to a Unicode value. 114 115 We can possibly get width information that may have been embedded 116 in the PDF /W array (or W2 if vertical text) 117 */ 118 pdf_obj *pdf_add_cid_font(fz_context *ctx, pdf_document *doc, fz_font *font); 119 120 /* 121 Add a non-embedded UTF16-encoded CID-font for the CJK scripts: 122 CNS1, GB1, Japan1, or Korea1 123 */ 124 pdf_obj *pdf_add_cjk_font(fz_context *ctx, pdf_document *doc, fz_font *font, int script, int wmode, int serif); 125 126 int pdf_font_writing_supported(fz_font *font); 127 128 #endif 129