comparison mupdf-source/include/mupdf/pdf/font.h @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 // Copyright (C) 2004-2025 Artifex Software, Inc.
2 //
3 // This file is part of MuPDF.
4 //
5 // MuPDF is free software: you can redistribute it and/or modify it under the
6 // terms of the GNU Affero General Public License as published by the Free
7 // Software Foundation, either version 3 of the License, or (at your option)
8 // any later version.
9 //
10 // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY
11 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Affero General Public License
16 // along with MuPDF. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>
17 //
18 // Alternative licensing terms are available from the licensor.
19 // For commercial licensing, see <https://www.artifex.com/> or contact
20 // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
21 // CA 94129, USA, for further information.
22
23 #ifndef MUPDF_PDF_FONT_H
24 #define MUPDF_PDF_FONT_H
25
26 #include "mupdf/pdf/cmap.h"
27 #include "mupdf/fitz/device.h"
28 #include "mupdf/fitz/font.h"
29
30 enum
31 {
32 PDF_FD_FIXED_PITCH = 1 << 0,
33 PDF_FD_SERIF = 1 << 1,
34 PDF_FD_SYMBOLIC = 1 << 2,
35 PDF_FD_SCRIPT = 1 << 3,
36 PDF_FD_NONSYMBOLIC = 1 << 5,
37 PDF_FD_ITALIC = 1 << 6,
38 PDF_FD_ALL_CAP = 1 << 16,
39 PDF_FD_SMALL_CAP = 1 << 17,
40 PDF_FD_FORCE_BOLD = 1 << 18
41 };
42
43 void pdf_load_encoding(const char **estrings, const char *encoding);
44
45 typedef struct
46 {
47 unsigned short lo;
48 unsigned short hi;
49 int w; /* type3 fonts can be big! */
50 } pdf_hmtx;
51
52 typedef struct
53 {
54 unsigned short lo;
55 unsigned short hi;
56 short x;
57 short y;
58 short w;
59 } pdf_vmtx;
60
61 typedef struct
62 {
63 fz_storable storable;
64 size_t size;
65
66 fz_font *font;
67
68 /* FontDescriptor */
69 int flags;
70 float italic_angle;
71 float ascent;
72 float descent;
73 float cap_height;
74 float x_height;
75 float missing_width;
76
77 /* Encoding (CMap) */
78 pdf_cmap *encoding;
79 pdf_cmap *to_ttf_cmap;
80 size_t cid_to_gid_len;
81 unsigned short *cid_to_gid;
82
83 /* ToUnicode */
84 pdf_cmap *to_unicode;
85 size_t cid_to_ucs_len;
86 unsigned short *cid_to_ucs;
87
88 /* Metrics (given in the PDF file) */
89 int wmode;
90
91 int hmtx_len, hmtx_cap;
92 pdf_hmtx dhmtx;
93 pdf_hmtx *hmtx;
94
95 int vmtx_len, vmtx_cap;
96 pdf_vmtx dvmtx;
97 pdf_vmtx *vmtx;
98
99 int is_embedded;
100 int t3loading;
101 } pdf_font_desc;
102
103 void pdf_set_font_wmode(fz_context *ctx, pdf_font_desc *font, int wmode);
104 void pdf_set_default_hmtx(fz_context *ctx, pdf_font_desc *font, int w);
105 void pdf_set_default_vmtx(fz_context *ctx, pdf_font_desc *font, int y, int w);
106 void pdf_add_hmtx(fz_context *ctx, pdf_font_desc *font, int lo, int hi, int w);
107 void pdf_add_vmtx(fz_context *ctx, pdf_font_desc *font, int lo, int hi, int x, int y, int w);
108 void pdf_end_hmtx(fz_context *ctx, pdf_font_desc *font);
109 void pdf_end_vmtx(fz_context *ctx, pdf_font_desc *font);
110 pdf_hmtx pdf_lookup_hmtx(fz_context *ctx, pdf_font_desc *font, int cid);
111 pdf_vmtx pdf_lookup_vmtx(fz_context *ctx, pdf_font_desc *font, int cid);
112
113 void pdf_load_to_unicode(fz_context *ctx, pdf_document *doc, pdf_font_desc *font, const char **strings, char *collection, pdf_obj *cmapstm);
114
115 int pdf_font_cid_to_gid(fz_context *ctx, pdf_font_desc *fontdesc, int cid);
116 const char *pdf_clean_font_name(const char *fontname);
117
118 const unsigned char *pdf_lookup_substitute_font(fz_context *ctx, int mono, int serif, int bold, int italic, int *len);
119
120 pdf_font_desc *pdf_load_type3_font(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *obj);
121 void pdf_load_type3_glyphs(fz_context *ctx, pdf_document *doc, pdf_font_desc *fontdesc);
122 pdf_font_desc *pdf_load_font(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *obj);
123 pdf_font_desc *pdf_load_hail_mary_font(fz_context *ctx, pdf_document *doc);
124
125 pdf_font_desc *pdf_new_font_desc(fz_context *ctx);
126 pdf_font_desc *pdf_keep_font(fz_context *ctx, pdf_font_desc *fontdesc);
127 void pdf_drop_font(fz_context *ctx, pdf_font_desc *font);
128
129 void pdf_print_font(fz_context *ctx, fz_output *out, pdf_font_desc *fontdesc);
130
131 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, void *fill_gstate, void *stroke_gstate);
132
133 pdf_obj *pdf_add_simple_font(fz_context *ctx, pdf_document *doc, fz_font *font, int encoding);
134
135 /*
136 Creates CID font with Identity-H CMap and a ToUnicode CMap that
137 is created by using the TTF cmap table "backwards" to go from
138 the GID to a Unicode value.
139
140 We can possibly get width information that may have been embedded
141 in the PDF /W array (or W2 if vertical text)
142 */
143 pdf_obj *pdf_add_cid_font(fz_context *ctx, pdf_document *doc, fz_font *font);
144
145 /*
146 Add a non-embedded UTF16-encoded CID-font for the CJK scripts:
147 CNS1, GB1, Japan1, or Korea1
148 */
149 pdf_obj *pdf_add_cjk_font(fz_context *ctx, pdf_document *doc, fz_font *font, int script, int wmode, int serif);
150
151 /*
152 Add a substitute font for any script.
153 */
154 pdf_obj *pdf_add_substitute_font(fz_context *ctx, pdf_document *doc, fz_font *font);
155
156 int pdf_font_writing_supported(fz_context *ctx, fz_font *font);
157
158 /*
159 Subset fonts by scanning the document to establish usage, and then
160 rewriting the font files.
161
162 Calling with pages_len == 0 means do the whole document.
163
164 EXPERIMENTAL AND SUBJECT TO CHANGE.
165 */
166 void pdf_subset_fonts(fz_context *ctx, pdf_document *doc, int pages_len, const int *pages);
167
168 #endif