Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
7643 views
1
#include "mupdf/pdf.h"
2
3
/*
4
Which fonts are embedded is based on a few preprocessor definitions.
5
6
The base 14 fonts are always embedded.
7
For CJK font substitution we embed DroidSansFallback.
8
9
Set NOCJK to skip all CJK support (this also omits embedding the CJK CMaps)
10
Set NOCJKFONT to skip the embedded CJK font.
11
Set NOCJKFULL to embed a smaller CJK font without CJK Extension A support.
12
*/
13
14
#ifdef NOCJK
15
#define NOCJKFONT
16
#endif
17
18
#include "gen_font_base14.h"
19
20
#ifndef NOCJKFONT
21
#ifndef NOCJKFULL
22
#include "gen_font_cjk_full.h"
23
#else
24
#include "gen_font_cjk.h"
25
#endif
26
#endif
27
28
unsigned char *
29
pdf_lookup_builtin_font(fz_context *ctx, const char *name, unsigned int *len)
30
{
31
if (!strcmp("Courier", name)) {
32
*len = sizeof pdf_font_NimbusMono_Regular;
33
return (unsigned char*) pdf_font_NimbusMono_Regular;
34
}
35
if (!strcmp("Courier-Bold", name)) {
36
*len = sizeof pdf_font_NimbusMono_Bold;
37
return (unsigned char*) pdf_font_NimbusMono_Bold;
38
}
39
if (!strcmp("Courier-Oblique", name)) {
40
*len = sizeof pdf_font_NimbusMono_Oblique;
41
return (unsigned char*) pdf_font_NimbusMono_Oblique;
42
}
43
if (!strcmp("Courier-BoldOblique", name)) {
44
*len = sizeof pdf_font_NimbusMono_BoldOblique;
45
return (unsigned char*) pdf_font_NimbusMono_BoldOblique;
46
}
47
if (!strcmp("Helvetica", name)) {
48
*len = sizeof pdf_font_NimbusSanL_Reg;
49
return (unsigned char*) pdf_font_NimbusSanL_Reg;
50
}
51
if (!strcmp("Helvetica-Bold", name)) {
52
*len = sizeof pdf_font_NimbusSanL_Bol;
53
return (unsigned char*) pdf_font_NimbusSanL_Bol;
54
}
55
if (!strcmp("Helvetica-Oblique", name)) {
56
*len = sizeof pdf_font_NimbusSanL_RegIta;
57
return (unsigned char*) pdf_font_NimbusSanL_RegIta;
58
}
59
if (!strcmp("Helvetica-BoldOblique", name)) {
60
*len = sizeof pdf_font_NimbusSanL_BolIta;
61
return (unsigned char*) pdf_font_NimbusSanL_BolIta;
62
}
63
if (!strcmp("Times-Roman", name)) {
64
*len = sizeof pdf_font_NimbusRomNo9L_Reg;
65
return (unsigned char*) pdf_font_NimbusRomNo9L_Reg;
66
}
67
if (!strcmp("Times-Bold", name)) {
68
*len = sizeof pdf_font_NimbusRomNo9L_Med;
69
return (unsigned char*) pdf_font_NimbusRomNo9L_Med;
70
}
71
if (!strcmp("Times-Italic", name)) {
72
*len = sizeof pdf_font_NimbusRomNo9L_RegIta;
73
return (unsigned char*) pdf_font_NimbusRomNo9L_RegIta;
74
}
75
if (!strcmp("Times-BoldItalic", name)) {
76
*len = sizeof pdf_font_NimbusRomNo9L_MedIta;
77
return (unsigned char*) pdf_font_NimbusRomNo9L_MedIta;
78
}
79
if (!strcmp("Symbol", name)) {
80
*len = sizeof pdf_font_StandardSymL;
81
return (unsigned char*) pdf_font_StandardSymL;
82
}
83
if (!strcmp("ZapfDingbats", name)) {
84
*len = sizeof pdf_font_Dingbats;
85
return (unsigned char*) pdf_font_Dingbats;
86
}
87
*len = 0;
88
return NULL;
89
}
90
91
unsigned char *
92
pdf_lookup_substitute_font(fz_context *ctx, int mono, int serif, int bold, int italic, unsigned int *len)
93
{
94
if (mono) {
95
if (bold) {
96
if (italic) return pdf_lookup_builtin_font(ctx, "Courier-BoldOblique", len);
97
else return pdf_lookup_builtin_font(ctx, "Courier-Bold", len);
98
} else {
99
if (italic) return pdf_lookup_builtin_font(ctx, "Courier-Oblique", len);
100
else return pdf_lookup_builtin_font(ctx, "Courier", len);
101
}
102
} else if (serif) {
103
if (bold) {
104
if (italic) return pdf_lookup_builtin_font(ctx, "Times-BoldItalic", len);
105
else return pdf_lookup_builtin_font(ctx, "Times-Bold", len);
106
} else {
107
if (italic) return pdf_lookup_builtin_font(ctx, "Times-Italic", len);
108
else return pdf_lookup_builtin_font(ctx, "Times-Roman", len);
109
}
110
} else {
111
if (bold) {
112
if (italic) return pdf_lookup_builtin_font(ctx, "Helvetica-BoldOblique", len);
113
else return pdf_lookup_builtin_font(ctx, "Helvetica-Bold", len);
114
} else {
115
if (italic) return pdf_lookup_builtin_font(ctx, "Helvetica-Oblique", len);
116
else return pdf_lookup_builtin_font(ctx, "Helvetica", len);
117
}
118
}
119
}
120
121
unsigned char *
122
pdf_lookup_substitute_cjk_font(fz_context *ctx, int ros, int serif, int wmode, unsigned int *len, int *index)
123
{
124
#ifndef NOCJKFONT
125
#ifndef NOCJKFULL
126
*index = wmode;
127
*len = sizeof pdf_font_DroidSansFallbackFull;
128
return (unsigned char*) pdf_font_DroidSansFallbackFull;
129
#else
130
*index = wmode;
131
*len = sizeof pdf_font_DroidSansFallback;
132
return (unsigned char*) pdf_font_DroidSansFallback;
133
#endif
134
#else
135
*len = 0;
136
return NULL;
137
#endif
138
}
139
140