mupdf
Loading...
Searching...
No Matches
font.h
Go to the documentation of this file.
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
30enum
31{
33 PDF_FD_SERIF = 1 << 1,
35 PDF_FD_SCRIPT = 1 << 3,
37 PDF_FD_ITALIC = 1 << 6,
38 PDF_FD_ALL_CAP = 1 << 16,
41};
42
43void pdf_load_encoding(const char **estrings, const char *encoding);
44
45typedef struct
46{
47 unsigned short lo;
48 unsigned short hi;
49 int w; /* type3 fonts can be big! */
50} pdf_hmtx;
51
52typedef struct
53{
54 unsigned short lo;
55 unsigned short hi;
56 short x;
57 short y;
58 short w;
59} pdf_vmtx;
60
61typedef struct
62{
64 size_t size;
65
67
68 /* FontDescriptor */
69 int flags;
71 float ascent;
72 float descent;
74 float x_height;
76
77 /* Encoding (CMap) */
81 unsigned short *cid_to_gid;
82
83 /* ToUnicode */
86 unsigned short *cid_to_ucs;
87
88 /* Metrics (given in the PDF file) */
89 int wmode;
90
94
98
101
102void pdf_set_font_wmode(fz_context *ctx, pdf_font_desc *font, int wmode);
104void pdf_set_default_vmtx(fz_context *ctx, pdf_font_desc *font, int y, int w);
105void pdf_add_hmtx(fz_context *ctx, pdf_font_desc *font, int lo, int hi, int w);
106void pdf_add_vmtx(fz_context *ctx, pdf_font_desc *font, int lo, int hi, int x, int y, int w);
111
112void pdf_load_to_unicode(fz_context *ctx, pdf_document *doc, pdf_font_desc *font, const char **strings, char *collection, pdf_obj *cmapstm);
113
114int pdf_font_cid_to_gid(fz_context *ctx, pdf_font_desc *fontdesc, int cid);
115const char *pdf_clean_font_name(const char *fontname);
116
117const unsigned char *pdf_lookup_substitute_font(fz_context *ctx, int mono, int serif, int bold, int italic, int *len);
118
123
127
129
130void 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);
131
133
134/*
135 Creates CID font with Identity-H CMap and a ToUnicode CMap that
136 is created by using the TTF cmap table "backwards" to go from
137 the GID to a Unicode value.
138
139 We can possibly get width information that may have been embedded
140 in the PDF /W array (or W2 if vertical text)
141*/
143
144/*
145 Add a non-embedded UTF16-encoded CID-font for the CJK scripts:
146 CNS1, GB1, Japan1, or Korea1
147*/
148pdf_obj *pdf_add_cjk_font(fz_context *ctx, pdf_document *doc, fz_font *font, int script, int wmode, int serif);
149
150/*
151 Add a substitute font for any script.
152*/
154
156
157/*
158 Subset fonts by scanning the document to establish usage, and then
159 rewriting the font files.
160
161 Calling with pages_len == 0 means do the whole document.
162
163 EXPERIMENTAL AND SUBJECT TO CHANGE.
164*/
165void pdf_subset_fonts(fz_context *ctx, pdf_document *doc, int pages_len, const int *pages);
166
167#endif
struct pdf_obj pdf_obj
Definition object.h:44
pdf_font_desc * pdf_keep_font(fz_context *ctx, pdf_font_desc *fontdesc)
void pdf_load_to_unicode(fz_context *ctx, pdf_document *doc, pdf_font_desc *font, const char **strings, char *collection, pdf_obj *cmapstm)
pdf_font_desc * pdf_new_font_desc(fz_context *ctx)
void pdf_add_hmtx(fz_context *ctx, pdf_font_desc *font, int lo, int hi, int w)
pdf_font_desc * pdf_load_font(fz_context *ctx, pdf_document *doc, pdf_resource_stack *rdb, pdf_obj *obj)
void pdf_set_default_vmtx(fz_context *ctx, pdf_font_desc *font, int y, int w)
void pdf_drop_font(fz_context *ctx, pdf_font_desc *font)
void pdf_add_vmtx(fz_context *ctx, pdf_font_desc *font, int lo, int hi, int x, int y, int w)
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)
pdf_font_desc * pdf_load_hail_mary_font(fz_context *ctx, pdf_document *doc)
const unsigned char * pdf_lookup_substitute_font(fz_context *ctx, int mono, int serif, int bold, int italic, int *len)
const char * pdf_clean_font_name(const char *fontname)
void pdf_end_hmtx(fz_context *ctx, pdf_font_desc *font)
pdf_vmtx pdf_lookup_vmtx(fz_context *ctx, pdf_font_desc *font, int cid)
pdf_obj * pdf_add_cid_font(fz_context *ctx, pdf_document *doc, fz_font *font)
pdf_obj * pdf_add_substitute_font(fz_context *ctx, pdf_document *doc, fz_font *font)
void pdf_load_type3_glyphs(fz_context *ctx, pdf_document *doc, pdf_font_desc *fontdesc)
int pdf_font_writing_supported(fz_context *ctx, fz_font *font)
void pdf_set_default_hmtx(fz_context *ctx, pdf_font_desc *font, int w)
pdf_obj * pdf_add_simple_font(fz_context *ctx, pdf_document *doc, fz_font *font, int encoding)
pdf_hmtx pdf_lookup_hmtx(fz_context *ctx, pdf_font_desc *font, int cid)
void pdf_set_font_wmode(fz_context *ctx, pdf_font_desc *font, int wmode)
void pdf_subset_fonts(fz_context *ctx, pdf_document *doc, int pages_len, const int *pages)
pdf_obj * pdf_add_cjk_font(fz_context *ctx, pdf_document *doc, fz_font *font, int script, int wmode, int serif)
int pdf_font_cid_to_gid(fz_context *ctx, pdf_font_desc *fontdesc, int cid)
pdf_font_desc * pdf_load_type3_font(fz_context *ctx, pdf_document *doc, pdf_resource_stack *rdb, pdf_obj *obj)
void pdf_print_font(fz_context *ctx, fz_output *out, pdf_font_desc *fontdesc)
void pdf_end_vmtx(fz_context *ctx, pdf_font_desc *font)
@ PDF_FD_ALL_CAP
Definition font.h:38
@ PDF_FD_SMALL_CAP
Definition font.h:39
@ PDF_FD_FIXED_PITCH
Definition font.h:32
@ PDF_FD_SYMBOLIC
Definition font.h:34
@ PDF_FD_NONSYMBOLIC
Definition font.h:36
@ PDF_FD_ITALIC
Definition font.h:37
@ PDF_FD_FORCE_BOLD
Definition font.h:40
@ PDF_FD_SCRIPT
Definition font.h:35
@ PDF_FD_SERIF
Definition font.h:33
void pdf_load_encoding(const char **estrings, const char *encoding)
Definition buffer.h:41
Definition context.h:886
Definition color.h:339
Definition device.h:290
Definition font.h:776
Definition geometry.h:388
Definition output.h:111
Definition store.h:76
Definition cmap.h:52
Definition document.h:463
Definition font.h:62
unsigned short * cid_to_ucs
Definition font.h:86
pdf_hmtx dhmtx
Definition font.h:92
int hmtx_cap
Definition font.h:91
fz_font * font
Definition font.h:66
int is_embedded
Definition font.h:99
int wmode
Definition font.h:89
pdf_vmtx dvmtx
Definition font.h:96
size_t cid_to_ucs_len
Definition font.h:85
pdf_cmap * to_ttf_cmap
Definition font.h:79
size_t size
Definition font.h:64
unsigned short * cid_to_gid
Definition font.h:81
float italic_angle
Definition font.h:70
pdf_cmap * to_unicode
Definition font.h:84
size_t cid_to_gid_len
Definition font.h:80
float missing_width
Definition font.h:75
float x_height
Definition font.h:74
int hmtx_len
Definition font.h:91
pdf_hmtx * hmtx
Definition font.h:93
fz_storable storable
Definition font.h:63
float cap_height
Definition font.h:73
float descent
Definition font.h:72
pdf_cmap * encoding
Definition font.h:78
float ascent
Definition font.h:71
int vmtx_cap
Definition font.h:95
int flags
Definition font.h:69
pdf_vmtx * vmtx
Definition font.h:97
int vmtx_len
Definition font.h:95
Definition font.h:46
unsigned short lo
Definition font.h:47
unsigned short hi
Definition font.h:48
int w
Definition font.h:49
Definition interpret.h:44
Definition font.h:53
short y
Definition font.h:57
unsigned short hi
Definition font.h:55
short w
Definition font.h:58
unsigned short lo
Definition font.h:54
short x
Definition font.h:56