comparison mupdf-source/include/mupdf/fitz/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_FITZ_FONT_H
24 #define MUPDF_FITZ_FONT_H
25
26 #include "mupdf/fitz/system.h"
27 #include "mupdf/fitz/context.h"
28 #include "mupdf/fitz/geometry.h"
29 #include "mupdf/fitz/buffer.h"
30 #include "mupdf/fitz/color.h"
31
32 /* forward declaration for circular dependency */
33 struct fz_device;
34
35 /* Various font encoding tables and lookup functions */
36
37 FZ_DATA extern const char *fz_glyph_name_from_adobe_standard[256];
38 FZ_DATA extern const char *fz_glyph_name_from_iso8859_7[256];
39 FZ_DATA extern const char *fz_glyph_name_from_koi8u[256];
40 FZ_DATA extern const char *fz_glyph_name_from_mac_expert[256];
41 FZ_DATA extern const char *fz_glyph_name_from_mac_roman[256];
42 FZ_DATA extern const char *fz_glyph_name_from_win_ansi[256];
43 FZ_DATA extern const char *fz_glyph_name_from_windows_1252[256];
44
45 FZ_DATA extern const unsigned short fz_unicode_from_iso8859_1[256];
46 FZ_DATA extern const unsigned short fz_unicode_from_iso8859_7[256];
47 FZ_DATA extern const unsigned short fz_unicode_from_koi8u[256];
48 FZ_DATA extern const unsigned short fz_unicode_from_pdf_doc_encoding[256];
49 FZ_DATA extern const unsigned short fz_unicode_from_windows_1250[256];
50 FZ_DATA extern const unsigned short fz_unicode_from_windows_1251[256];
51 FZ_DATA extern const unsigned short fz_unicode_from_windows_1252[256];
52
53 int fz_iso8859_1_from_unicode(int u);
54 int fz_iso8859_7_from_unicode(int u);
55 int fz_koi8u_from_unicode(int u);
56 int fz_windows_1250_from_unicode(int u);
57 int fz_windows_1251_from_unicode(int u);
58 int fz_windows_1252_from_unicode(int u);
59
60 int fz_unicode_from_glyph_name(const char *name);
61 int fz_unicode_from_glyph_name_strict(const char *name);
62 const char **fz_duplicate_glyph_names_from_unicode(int unicode);
63 const char *fz_glyph_name_from_unicode_sc(int unicode);
64
65 /**
66 * A text decoder (to read arbitrary encodings and convert to unicode).
67 */
68 typedef struct fz_text_decoder fz_text_decoder;
69
70 struct fz_text_decoder {
71 // get maximum size estimate of converted text (fast)
72 int (*decode_bound)(fz_text_decoder *dec, unsigned char *input, int n);
73
74 // get exact size of converted text (slow)
75 int (*decode_size)(fz_text_decoder *dec, unsigned char *input, int n);
76
77 // convert text into output buffer
78 void (*decode)(fz_text_decoder *dec, char *output, unsigned char *input, int n);
79
80 // for internal use only; do not touch!
81 void *table1;
82 void *table2;
83 };
84
85 /* Initialize a text decoder using an IANA encoding name.
86 * See source/fitz/text-decoder.c for the exact list of supported encodings.
87 * Will throw an exception if the requested encoding is not available.
88 *
89 * The following is a subset of the supported encodings (see source/fitz/text-decoder.c for the full list):
90 * iso-8859-1
91 * iso-8859-7
92 * koi8-r
93 * euc-jp
94 * shift_jis
95 * euc-kr
96 * euc-cn
97 * gb18030
98 * euc-tw
99 * big5
100 */
101 void fz_init_text_decoder(fz_context *ctx, fz_text_decoder *dec, const char *encoding);
102
103 /**
104 An abstract font handle.
105 */
106 typedef struct fz_font fz_font;
107
108 /**
109 Fonts come in two variants:
110 Regular fonts are handled by FreeType.
111 Type 3 fonts have callbacks to the interpreter.
112 */
113
114 /**
115 Retrieve the FT_Face handle
116 for the font.
117
118 font: The font to query
119
120 Returns the FT_Face handle for the font, or NULL
121 if not a freetype handled font. (Cast to void *
122 to avoid nasty header exposure).
123 */
124 void *fz_font_ft_face(fz_context *ctx, fz_font *font);
125
126 /**
127 Retrieve the Type3 procs
128 for a font.
129
130 font: The font to query
131
132 Returns the t3_procs pointer. Will be NULL for a
133 non type-3 font.
134 */
135 fz_buffer **fz_font_t3_procs(fz_context *ctx, fz_font *font);
136
137 /* common CJK font collections */
138 enum { FZ_ADOBE_CNS, FZ_ADOBE_GB, FZ_ADOBE_JAPAN, FZ_ADOBE_KOREA };
139
140 /**
141 Every fz_font carries a set of flags
142 within it, in a fz_font_flags_t structure.
143 */
144 typedef struct
145 {
146 unsigned int is_mono : 1;
147 unsigned int is_serif : 1;
148 unsigned int is_bold : 1;
149 unsigned int is_italic : 1;
150 unsigned int ft_substitute : 1; /* use substitute metrics */
151 unsigned int ft_stretch : 1; /* stretch to match PDF metrics */
152
153 unsigned int fake_bold : 1; /* synthesize bold */
154 unsigned int fake_italic : 1; /* synthesize italic */
155 unsigned int has_opentype : 1; /* has opentype shaping tables */
156 unsigned int invalid_bbox : 1;
157
158 unsigned int cjk : 1;
159 unsigned int cjk_lang : 2; /* CNS, GB, JAPAN, or KOREA */
160
161 unsigned int embed : 1;
162 unsigned int never_embed : 1;
163 } fz_font_flags_t;
164
165 /**
166 Retrieve a pointer to the font flags
167 for a given font. These can then be updated as required.
168
169 font: The font to query
170
171 Returns a pointer to the flags structure (or NULL, if
172 the font is NULL).
173 */
174 fz_font_flags_t *fz_font_flags(fz_font *font);
175
176 /**
177 In order to shape a given font, we need to
178 declare it to a shaper library (harfbuzz, by default, but others
179 are possible). To avoid redeclaring it every time we need to
180 shape, we hold a shaper handle and the destructor for it within
181 the font itself. The handle is initialised by the caller when
182 first required and the destructor is called when the fz_font is
183 destroyed.
184 */
185 typedef struct
186 {
187 void *shaper_handle;
188 void (*destroy)(fz_context *ctx, void *); /* Destructor for shape_handle */
189 } fz_shaper_data_t;
190
191 /**
192 Retrieve a pointer to the shaper data
193 structure for the given font.
194
195 font: The font to query.
196
197 Returns a pointer to the shaper data structure (or NULL if
198 font is NULL).
199 */
200 fz_shaper_data_t *fz_font_shaper_data(fz_context *ctx, fz_font *font);
201
202 /**
203 Retrieve a pointer to the name of the font.
204
205 font: The font to query.
206
207 Returns a pointer to an internal copy of the font name.
208 Will never be NULL, but may be the empty string.
209 */
210 const char *fz_font_name(fz_context *ctx, fz_font *font);
211
212 /**
213 Query whether the font flags say that this font is bold.
214 */
215 int fz_font_is_bold(fz_context *ctx, fz_font *font);
216
217 /**
218 Query whether the font flags say that this font is italic.
219 */
220 int fz_font_is_italic(fz_context *ctx, fz_font *font);
221
222 /**
223 Query whether the font flags say that this font is serif.
224 */
225 int fz_font_is_serif(fz_context *ctx, fz_font *font);
226
227 /**
228 Query whether the font flags say that this font is monospaced.
229 */
230 int fz_font_is_monospaced(fz_context *ctx, fz_font *font);
231
232 /**
233 Retrieve the font bbox.
234
235 font: The font to query.
236
237 Returns the font bbox by value; it is valid only if
238 fz_font_flags(font)->invalid_bbox is zero.
239 */
240 fz_rect fz_font_bbox(fz_context *ctx, fz_font *font);
241
242 /**
243 Type for user supplied system font loading hook.
244
245 name: The name of the font to load.
246
247 bold: 1 if a bold font desired, 0 otherwise.
248
249 italic: 1 if an italic font desired, 0 otherwise.
250 needs_exact_metrics: 1 if an exact metric match is required for
251 the font requested.
252
253 Returns a new font handle, or NULL if no font found (or on error).
254 */
255 typedef fz_font *(fz_load_system_font_fn)(fz_context *ctx, const char *name, int bold, int italic, int needs_exact_metrics);
256
257 /**
258 Type for user supplied cjk font loading hook.
259
260 name: The name of the font to load.
261
262 ordering: The ordering for which to load the font (e.g.
263 FZ_ADOBE_KOREA)
264
265 serif: 1 if a serif font is desired, 0 otherwise.
266
267 Returns a new font handle, or NULL if no font found (or on error).
268 */
269 typedef fz_font *(fz_load_system_cjk_font_fn)(fz_context *ctx, const char *name, int ordering, int serif);
270
271 /**
272 Type for user supplied fallback font loading hook.
273
274 name: The name of the font to load.
275
276 script: UCDN script enum.
277
278 language: FZ_LANG enum.
279
280 serif, bold, italic: boolean style flags.
281
282 Returns a new font handle, or NULL if no font found (or on error).
283 */
284 typedef fz_font *(fz_load_system_fallback_font_fn)(fz_context *ctx, int script, int language, int serif, int bold, int italic);
285
286 /**
287 Install functions to allow MuPDF to request fonts from the
288 system.
289
290 Only one set of hooks can be in use at a time.
291 */
292 void fz_install_load_system_font_funcs(fz_context *ctx,
293 fz_load_system_font_fn *f,
294 fz_load_system_cjk_font_fn *f_cjk,
295 fz_load_system_fallback_font_fn *f_fallback);
296
297 /**
298 Attempt to load a given font from the system.
299
300 name: The name of the desired font.
301
302 bold: 1 if bold desired, 0 otherwise.
303
304 italic: 1 if italic desired, 0 otherwise.
305
306 needs_exact_metrics: 1 if an exact metrical match is required,
307 0 otherwise.
308
309 Returns a new font handle, or NULL if no matching font was found
310 (or on error).
311 */
312 fz_font *fz_load_system_font(fz_context *ctx, const char *name, int bold, int italic, int needs_exact_metrics);
313
314 /**
315 Attempt to load a given font from
316 the system.
317
318 name: The name of the desired font.
319
320 ordering: The ordering to load the font from (e.g. FZ_ADOBE_KOREA)
321
322 serif: 1 if serif desired, 0 otherwise.
323
324 Returns a new font handle, or NULL if no matching font was found
325 (or on error).
326 */
327 fz_font *fz_load_system_cjk_font(fz_context *ctx, const char *name, int ordering, int serif);
328
329 /**
330 Search the builtin fonts for a match.
331 Whether a given font is present or not will depend on the
332 configuration in which MuPDF is built.
333
334 name: The name of the font desired.
335
336 bold: 1 if bold desired, 0 otherwise.
337
338 italic: 1 if italic desired, 0 otherwise.
339
340 len: Pointer to a place to receive the length of the discovered
341 font buffer.
342
343 Returns a pointer to the font file data, or NULL if not present.
344 */
345 const unsigned char *fz_lookup_builtin_font(fz_context *ctx, const char *name, int bold, int italic, int *len);
346
347 /**
348 Search the builtin base14 fonts for a match.
349 Whether a given font is present or not will depend on the
350 configuration in which MuPDF is built.
351
352 name: The name of the font desired.
353
354 len: Pointer to a place to receive the length of the discovered
355 font buffer.
356
357 Returns a pointer to the font file data, or NULL if not present.
358 */
359 const unsigned char *fz_lookup_base14_font(fz_context *ctx, const char *name, int *len);
360
361 /**
362 Search the builtin cjk fonts for a match.
363 Whether a font is present or not will depend on the
364 configuration in which MuPDF is built.
365
366 ordering: The desired ordering of the font (e.g. FZ_ADOBE_KOREA).
367
368 len: Pointer to a place to receive the length of the discovered
369 font buffer.
370
371 Returns a pointer to the font file data, or NULL if not present.
372 */
373 const unsigned char *fz_lookup_cjk_font(fz_context *ctx, int ordering, int *len, int *index);
374
375 /**
376 Search the builtin cjk fonts for a match for a given language.
377 Whether a font is present or not will depend on the
378 configuration in which MuPDF is built.
379
380 lang: Pointer to a (case sensitive) language string (e.g.
381 "ja", "ko", "zh-Hant" etc).
382
383 len: Pointer to a place to receive the length of the discovered
384 font buffer.
385
386 subfont: Pointer to a place to store the subfont index of the
387 discovered font.
388
389 Returns a pointer to the font file data, or NULL if not present.
390 */
391 const unsigned char *fz_lookup_cjk_font_by_language(fz_context *ctx, const char *lang, int *len, int *subfont);
392
393 /**
394 Return the matching FZ_ADOBE_* ordering
395 for the given language tag, such as "zh-Hant", "zh-Hans", "ja", or "ko".
396 */
397 int fz_lookup_cjk_ordering_by_language(const char *name);
398
399 /**
400 Search the builtin noto fonts for a match.
401 Whether a font is present or not will depend on the
402 configuration in which MuPDF is built.
403
404 script: The script desired (e.g. UCDN_SCRIPT_KATAKANA).
405
406 lang: The language desired (e.g. FZ_LANG_ja).
407
408 len: Pointer to a place to receive the length of the discovered
409 font buffer.
410
411 Returns a pointer to the font file data, or NULL if not present.
412 */
413 const unsigned char *fz_lookup_noto_font(fz_context *ctx, int script, int lang, int *len, int *subfont);
414
415 /**
416 Search the builtin noto fonts specific symbol fonts.
417 Whether a font is present or not will depend on the
418 configuration in which MuPDF is built.
419 */
420 const unsigned char *fz_lookup_noto_math_font(fz_context *ctx, int *len);
421 const unsigned char *fz_lookup_noto_music_font(fz_context *ctx, int *len);
422 const unsigned char *fz_lookup_noto_symbol1_font(fz_context *ctx, int *len);
423 const unsigned char *fz_lookup_noto_symbol2_font(fz_context *ctx, int *len);
424 const unsigned char *fz_lookup_noto_emoji_font(fz_context *ctx, int *len);
425 const unsigned char *fz_lookup_noto_boxes_font(fz_context *ctx, int *len);
426
427 /**
428 Look up the Noto font file name for a given script.
429 From the returned font stem, you can look for Noto fonts on the system in the form:
430 Noto(Sans|Serif)${STEM}-Regular.(otf|ttf)
431 */
432 const char *fz_lookup_noto_stem_from_script(fz_context *ctx, int script, int language);
433 const char *fz_lookup_script_name(fz_context *ctx, int script, int language);
434
435 /**
436 Try to load a fallback font for the
437 given combination of font attributes. Whether a font is
438 present or not will depend on the configuration in which
439 MuPDF is built.
440
441 script: The script desired (e.g. UCDN_SCRIPT_KATAKANA).
442
443 language: The language desired (e.g. FZ_LANG_ja).
444
445 serif: 1 if serif desired, 0 otherwise.
446
447 bold: 1 if bold desired, 0 otherwise.
448
449 italic: 1 if italic desired, 0 otherwise.
450
451 Returns a new font handle, or NULL if not available.
452 */
453 fz_font *fz_load_fallback_font(fz_context *ctx, int script, int language, int serif, int bold, int italic);
454
455 /**
456 Create a new (empty) type3 font.
457
458 name: Name of font (or NULL).
459
460 matrix: Font matrix.
461
462 Returns a new font handle, or throws exception on
463 allocation failure.
464 */
465 fz_font *fz_new_type3_font(fz_context *ctx, const char *name, fz_matrix matrix);
466
467 /**
468 Create a new font from a font file in memory.
469
470 Fonts created in this way, will be eligible for embedding by default.
471
472 name: Name of font (leave NULL to use name from font).
473
474 data: Pointer to the font file data.
475
476 len: Length of the font file data.
477
478 index: Which font from the file to load (0 for default).
479
480 use_glyph_box: 1 if we should use the glyph bbox, 0 otherwise.
481
482 Returns new font handle, or throws exception on error.
483 */
484 fz_font *fz_new_font_from_memory(fz_context *ctx, const char *name, const unsigned char *data, int len, int index, int use_glyph_bbox);
485
486 /**
487 Create a new font from a font file in a fz_buffer.
488
489 Fonts created in this way, will be eligible for embedding by default.
490
491 name: Name of font (leave NULL to use name from font).
492
493 buffer: Buffer to load from.
494
495 index: Which font from the file to load (0 for default).
496
497 use_glyph_box: 1 if we should use the glyph bbox, 0 otherwise.
498
499 Returns new font handle, or throws exception on error.
500 */
501 fz_font *fz_new_font_from_buffer(fz_context *ctx, const char *name, fz_buffer *buffer, int index, int use_glyph_bbox);
502
503 /**
504 Create a new font from a font file.
505
506 Fonts created in this way, will be eligible for embedding by default.
507
508 name: Name of font (leave NULL to use name from font).
509
510 path: File path to load from.
511
512 index: Which font from the file to load (0 for default).
513
514 use_glyph_box: 1 if we should use the glyph bbox, 0 otherwise.
515
516 Returns new font handle, or throws exception on error.
517 */
518 fz_font *fz_new_font_from_file(fz_context *ctx, const char *name, const char *path, int index, int use_glyph_bbox);
519
520 /**
521 Create a new font from one of the built-in fonts.
522 */
523 fz_font *fz_new_base14_font(fz_context *ctx, const char *name);
524 fz_font *fz_new_cjk_font(fz_context *ctx, int ordering);
525 fz_font *fz_new_builtin_font(fz_context *ctx, const char *name, int is_bold, int is_italic);
526
527 /**
528 Control whether a given font should be embedded or not when writing.
529 */
530 void fz_set_font_embedding(fz_context *ctx, fz_font *font, int embed);
531
532 /**
533 Add a reference to an existing fz_font.
534
535 font: The font to add a reference to.
536
537 Returns the same font.
538 */
539 fz_font *fz_keep_font(fz_context *ctx, fz_font *font);
540
541 /**
542 Drop a reference to a fz_font, destroying the
543 font when the last reference is dropped.
544
545 font: The font to drop a reference to.
546 */
547 void fz_drop_font(fz_context *ctx, fz_font *font);
548
549 /**
550 Set the font bbox.
551
552 font: The font to set the bbox for.
553
554 xmin, ymin, xmax, ymax: The bounding box.
555 */
556 void fz_set_font_bbox(fz_context *ctx, fz_font *font, float xmin, float ymin, float xmax, float ymax);
557
558 /**
559 Return a bbox for a given glyph in a font.
560
561 font: The font to look for the glyph in.
562
563 gid: The glyph to bound.
564
565 trm: The matrix to apply to the glyph before bounding.
566
567 Returns rectangle by value containing the bounds of the given
568 glyph.
569 */
570 fz_rect fz_bound_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix trm);
571
572 /**
573 Determine if a given glyph in a font
574 is cacheable. Certain glyphs in a type 3 font cannot safely
575 be cached, as their appearance depends on the enclosing
576 graphic state.
577
578 font: The font to look for the glyph in.
579
580 gif: The glyph to query.
581
582 Returns non-zero if cacheable, 0 if not.
583 */
584 int fz_glyph_cacheable(fz_context *ctx, fz_font *font, int gid);
585
586 /**
587 Run a glyph from a Type3 font to
588 a given device.
589
590 font: The font to find the glyph in.
591
592 gid: The glyph to run.
593
594 trm: The transform to apply.
595
596 dev: The device to render onto.
597 */
598 void fz_run_t3_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix trm, struct fz_device *dev);
599
600 /**
601 Return the advance for a given glyph.
602
603 font: The font to look for the glyph in.
604
605 glyph: The glyph to find the advance for.
606
607 wmode: 1 for vertical mode, 0 for horizontal.
608
609 Returns the advance for the glyph.
610 */
611 float fz_advance_glyph(fz_context *ctx, fz_font *font, int glyph, int wmode);
612
613 /**
614 Find the glyph id for a given unicode
615 character within a font.
616
617 font: The font to look for the unicode character in.
618
619 unicode: The unicode character to encode.
620
621 Returns the glyph id for the given unicode value, or 0 if
622 unknown.
623 */
624 int fz_encode_character(fz_context *ctx, fz_font *font, int unicode);
625
626 /**
627 Encode character, preferring small-caps variant if available.
628
629 font: The font to look for the unicode character in.
630
631 unicode: The unicode character to encode.
632
633 Returns the glyph id for the given unicode value, or 0 if
634 unknown.
635 */
636 int fz_encode_character_sc(fz_context *ctx, fz_font *font, int unicode);
637
638 /**
639 Encode character.
640
641 Either by direct lookup of glyphname within a font, or, failing
642 that, by mapping glyphname to unicode and thence to the glyph
643 index within the given font.
644
645 Returns zero for type3 fonts.
646 */
647 int fz_encode_character_by_glyph_name(fz_context *ctx, fz_font *font, const char *glyphname);
648
649 /**
650 Find the glyph id for
651 a given unicode character within a font, falling back to
652 an alternative if not found.
653
654 font: The font to look for the unicode character in.
655
656 unicode: The unicode character to encode.
657
658 script: The script in use.
659
660 language: The language in use.
661
662 out_font: The font handle in which the given glyph represents
663 the requested unicode character. The caller does not own the
664 reference it is passed, so should call fz_keep_font if it is
665 not simply to be used immediately.
666
667 Returns the glyph id for the given unicode value in the supplied
668 font (and sets *out_font to font) if it is present. Otherwise
669 an alternative fallback font (based on script/language) is
670 searched for. If the glyph is found therein, *out_font is set
671 to this reference, and the glyph reference is returned. If it
672 cannot be found anywhere, the function returns 0.
673 */
674 int fz_encode_character_with_fallback(fz_context *ctx, fz_font *font, int unicode, int script, int language, fz_font **out_font);
675
676 /**
677 Find the name of a glyph
678
679 font: The font to look for the glyph in.
680
681 glyph: The glyph id to look for.
682
683 buf: Pointer to a buffer for the name to be inserted into.
684
685 size: The size of the buffer.
686
687 If a font contains a name table, then the name of the glyph
688 will be returned in the supplied buffer. Otherwise a name
689 is synthesised. The name will be truncated to fit in
690 the buffer.
691 */
692 void fz_get_glyph_name(fz_context *ctx, fz_font *font, int glyph, char *buf, int size);
693
694 /**
695 Retrieve font ascender in ems.
696 */
697 float fz_font_ascender(fz_context *ctx, fz_font *font);
698
699 /**
700 Retrieve font descender in ems.
701 */
702 float fz_font_descender(fz_context *ctx, fz_font *font);
703
704 /**
705 Retrieve the MD5 digest for the font's data.
706 */
707 void fz_font_digest(fz_context *ctx, fz_font *font, unsigned char digest[16]);
708
709 /* Implementation details: subject to change. */
710
711 void fz_decouple_type3_font(fz_context *ctx, fz_font *font, void *t3doc);
712
713 /**
714 map an FT error number to a
715 static string.
716
717 err: The error number to lookup.
718
719 Returns a pointer to a static textual representation
720 of a freetype error.
721 */
722 const char *ft_error_string(int err);
723 int ft_char_index(void *face, int cid);
724 int ft_name_index(void *face, const char *name);
725
726 /**
727 Internal functions for our Harfbuzz integration
728 to work around the lack of thread safety.
729 */
730
731 /**
732 Lock against Harfbuzz being called
733 simultaneously in several threads. This reuses
734 FZ_LOCK_FREETYPE.
735 */
736 void fz_hb_lock(fz_context *ctx);
737
738 /**
739 Unlock after a Harfbuzz call. This reuses
740 FZ_LOCK_FREETYPE.
741 */
742 void fz_hb_unlock(fz_context *ctx);
743
744 /**
745 Callback for use in font cmap enumeration.
746 */
747 typedef void (fz_cmap_callback)(fz_context *ctx, void *opaque, unsigned long ucs, unsigned int gid);
748
749 /**
750 Enumerate a cmap using a callback.
751 */
752 void fz_enumerate_font_cmap(fz_context *ctx, fz_font *font, fz_cmap_callback *cb, void *opaque);
753
754 /**
755 Ensure that a font has its ascender/descender values calculated
756 from the actual bbox of the glyphs.
757
758 Note, that we combine the declared values from the font (or the
759 default values if those are not present) with the actual bbox to
760 get the final result. So this can only cause ascender/descender
761 to move further apart!
762 */
763 void fz_calculate_font_ascender_descender(fz_context *ctx, fz_font *font);
764
765 typedef enum
766 {
767 FZ_ASCDESC_FROM_FONT,
768 FZ_ASCDESC_DEFAULT,
769 FZ_ASCDESC_FROM_BOUNDS
770 } fz_ascdesc_source;
771
772 #define FZ_MAX_TRUSTWORTHY_ASCENT 8
773 #define FZ_MAX_TRUSTWORTHY_DESCENT -2
774
775 struct fz_font
776 {
777 int refs;
778 char name[32];
779 fz_buffer *buffer;
780
781 fz_font_flags_t flags;
782
783 void *ft_face; /* has an FT_Face if used */
784 fz_shaper_data_t shaper_data;
785
786 fz_matrix t3matrix;
787 void *t3resources;
788 fz_buffer **t3procs; /* has 256 entries if used */
789 struct fz_display_list **t3lists; /* has 256 entries if used */
790 float *t3widths; /* has 256 entries if used */
791 unsigned short *t3flags; /* has 256 entries if used */
792 void *t3doc; /* a pdf_document for the callback */
793 void (*t3run)(fz_context *ctx, void *doc, void *resources, fz_buffer *contents, struct fz_device *dev, fz_matrix ctm, void *gstate, fz_default_colorspaces *default_cs, void *fill_gstate, void *stroke_gstate);
794 void (*t3freeres)(fz_context *ctx, void *doc, void *resources);
795
796 fz_rect bbox; /* font bbox is used only for t3 fonts */
797
798 float ascender;
799 float descender;
800 fz_ascdesc_source ascdesc_src;
801
802 int glyph_count;
803
804 /* per glyph bounding box cache. */
805 fz_rect **bbox_table;
806 int use_glyph_bbox;
807
808 /* substitute metrics */
809 int width_count;
810 short width_default; /* in 1000 units */
811 short *width_table; /* in 1000 units */
812
813 /* cached glyph metrics */
814 float **advance_cache;
815
816 /* cached encoding lookup */
817 uint16_t *encoding_cache[256];
818
819 /* cached md5sum for caching */
820 int has_digest;
821 unsigned char digest[16];
822
823 /* Which font to use in a collection. */
824 int subfont;
825 };
826
827 void fz_ft_lock(fz_context *ctx);
828
829 void fz_ft_unlock(fz_context *ctx);
830
831 /* Internal function. Must be called with FT_ALLOC_LOCK
832 * held. Returns 1 if this thread (context!) already holds
833 * the freeetype lock. */
834 int fz_ft_lock_held(fz_context *ctx);
835
836 /* Internal function: Extract a ttf from the ttc that underlies
837 * a given fz_font. Caller takes ownership of the returned
838 * buffer.
839 */
840 fz_buffer *fz_extract_ttf_from_ttc(fz_context *ctx, fz_font *font);
841
842 /* Internal function: Given a ttf in a buffer, create a subset
843 * ttf in a new buffer that only provides the required gids.
844 * Caller takes ownership of the returned buffer.
845 *
846 * EXPERIMENTAL AND VERY SUBJECT TO CHANGE.
847 */
848 fz_buffer *fz_subset_ttf_for_gids(fz_context *ctx, fz_buffer *orig, int *gids, int num_gids, int symbolic, int cidfont);
849
850 /* Internal function: Given a cff in a buffer, create a subset
851 * cff in a new buffer that only provides the required gids.
852 * Caller takes ownership of the returned buffer.
853 *
854 * EXPERIMENTAL AND VERY SUBJECT TO CHANGE.
855 */
856 fz_buffer *fz_subset_cff_for_gids(fz_context *ctx, fz_buffer *orig, int *gids, int num_gids, int symbolic, int cidfont);
857
858 #endif