Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
7858 views
1
#ifndef MUPDF_FITZ_FONT_H
2
#define MUPDF_FITZ_FONT_H
3
4
#include "mupdf/fitz/system.h"
5
#include "mupdf/fitz/context.h"
6
#include "mupdf/fitz/math.h"
7
#include "mupdf/fitz/buffer.h"
8
9
/*
10
An abstract font handle. Currently there are no public API functions
11
for handling these.
12
*/
13
typedef struct fz_font_s fz_font;
14
15
/*
16
* Fonts come in two variants:
17
* Regular fonts are handled by FreeType.
18
* Type 3 fonts have callbacks to the interpreter.
19
*/
20
21
char *ft_error_string(int err);
22
23
/* forward declaration for circular dependency */
24
struct fz_device_s;
25
struct fz_display_list_s;
26
27
struct fz_font_s
28
{
29
int refs;
30
char name[32];
31
32
void *ft_face; /* has an FT_Face if used */
33
int ft_substitute; /* ... substitute metrics */
34
int ft_bold; /* ... synthesize bold */
35
int ft_italic; /* ... synthesize italic */
36
int ft_hint; /* ... force hinting for DynaLab fonts */
37
38
/* origin of font data */
39
fz_buffer *ft_buffer;
40
char *ft_filepath; /* kept for downstream consumers (such as SumatraPDF) */
41
42
fz_matrix t3matrix;
43
void *t3resources;
44
fz_buffer **t3procs; /* has 256 entries if used */
45
struct fz_display_list_s **t3lists; /* has 256 entries if used */
46
float *t3widths; /* has 256 entries if used */
47
unsigned short *t3flags; /* has 256 entries if used */
48
void *t3doc; /* a pdf_document for the callback */
49
void (*t3run)(fz_context *ctx, void *doc, void *resources, fz_buffer *contents, struct fz_device_s *dev, const fz_matrix *ctm, void *gstate, int nestedDepth);
50
void (*t3freeres)(fz_context *ctx, void *doc, void *resources);
51
52
fz_rect bbox; /* font bbox is used only for t3 fonts */
53
54
/* per glyph bounding box cache */
55
int use_glyph_bbox;
56
int bbox_count;
57
fz_rect *bbox_table;
58
59
/* substitute metrics */
60
int width_count;
61
int *width_table; /* in 1000 units */
62
};
63
64
/* common CJK font collections */
65
enum { FZ_ADOBE_CNS_1, FZ_ADOBE_GB_1, FZ_ADOBE_JAPAN_1, FZ_ADOBE_KOREA_1 };
66
67
void fz_new_font_context(fz_context *ctx);
68
fz_font_context *fz_keep_font_context(fz_context *ctx);
69
void fz_drop_font_context(fz_context *ctx);
70
71
typedef fz_font *(*fz_load_system_font_func)(fz_context *ctx, const char *name, int bold, int italic, int needs_exact_metrics);
72
typedef fz_font *(*fz_load_system_cjk_font_func)(fz_context *ctx, const char *name, int ros, int serif);
73
void fz_install_load_system_font_funcs(fz_context *ctx, fz_load_system_font_func f, fz_load_system_cjk_font_func f_cjk);
74
/* fz_load_*_font returns NULL if no font could be loaded (also on error) */
75
fz_font *fz_load_system_font(fz_context *ctx, const char *name, int bold, int italic, int needs_exact_metrics);
76
fz_font *fz_load_system_cjk_font(fz_context *ctx, const char *name, int ros, int serif);
77
78
fz_font *fz_new_type3_font(fz_context *ctx, const char *name, const fz_matrix *matrix);
79
80
fz_font *fz_new_font_from_memory(fz_context *ctx, const char *name, unsigned char *data, int len, int index, int use_glyph_bbox);
81
fz_font *fz_new_font_from_buffer(fz_context *ctx, const char *name, fz_buffer *buffer, int index, int use_glyph_bbox);
82
fz_font *fz_new_font_from_file(fz_context *ctx, const char *name, const char *path, int index, int use_glyph_bbox);
83
84
fz_font *fz_keep_font(fz_context *ctx, fz_font *font);
85
void fz_drop_font(fz_context *ctx, fz_font *font);
86
87
void fz_set_font_bbox(fz_context *ctx, fz_font *font, float xmin, float ymin, float xmax, float ymax);
88
fz_rect *fz_bound_glyph(fz_context *ctx, fz_font *font, int gid, const fz_matrix *trm, fz_rect *r);
89
int fz_glyph_cacheable(fz_context *ctx, fz_font *font, int gid);
90
91
void fz_run_t3_glyph(fz_context *ctx, fz_font *font, int gid, const fz_matrix *trm, struct fz_device_s *dev);
92
93
void fz_decouple_type3_font(fz_context *ctx, fz_font *font, void *t3doc);
94
95
float fz_advance_glyph(fz_context *ctx, fz_font *font, int glyph);
96
int fz_encode_character(fz_context *ctx, fz_font *font, int unicode);
97
98
#ifndef NDEBUG
99
void fz_print_font(fz_context *ctx, FILE *out, fz_font *font);
100
#endif
101
102
#endif
103
104