forked from koreader/kindlepdfviewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mupdf.patch
169 lines (162 loc) · 4.91 KB
/
mupdf.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
diff --git a/pdf/pdf_font.c b/pdf/pdf_font.c
index 33a1a65..c2fdee3 100644
--- a/pdf/pdf_font.c
+++ b/pdf/pdf_font.c
@@ -185,7 +185,12 @@ pdf_load_builtin_font(fz_context *ctx, pdf_font_desc *fontdesc, char *fontname)
if (!data)
fz_throw(ctx, "cannot find builtin font: '%s'", fontname);
+#ifndef NOBUILTINFONT
fontdesc->font = fz_new_font_from_memory(ctx, fontname, data, len, 0, 1);
+#else
+ fontdesc->font = fz_new_font_from_file(ctx, fontname, data, 0, 1);
+ free(data);
+#endif
if (!strcmp(fontname, "Symbol") || !strcmp(fontname, "ZapfDingbats"))
fontdesc->flags |= PDF_FD_SYMBOLIC;
@@ -201,7 +206,12 @@ pdf_load_substitute_font(fz_context *ctx, pdf_font_desc *fontdesc, char *fontnam
if (!data)
fz_throw(ctx, "cannot find substitute font");
+#ifndef NOBUILTINFONT
fontdesc->font = fz_new_font_from_memory(ctx, fontname, data, len, 0, 1);
+#else
+ fontdesc->font = fz_new_font_from_file(ctx, fontname, data, 0, 1);
+ free(data);
+#endif
fontdesc->font->ft_substitute = 1;
fontdesc->font->ft_bold = bold && !ft_is_bold(fontdesc->font->ft_face);
@@ -219,7 +229,12 @@ pdf_load_substitute_cjk_font(fz_context *ctx, pdf_font_desc *fontdesc, char *fon
fz_throw(ctx, "cannot find builtin CJK font");
/* a glyph bbox cache is too big for droid sans fallback (51k glyphs!) */
+#ifndef NOBUILTINFONT
fontdesc->font = fz_new_font_from_memory(ctx, fontname, data, len, 0, 0);
+#else
+ fontdesc->font = fz_new_font_from_file(ctx, fontname, data, 0, 1);
+ free(data);
+#endif
fontdesc->font->ft_substitute = 1;
}
diff --git a/pdf/pdf_fontfile.c b/pdf/pdf_fontfile.c
index 99565da..a91380f 100644
--- a/pdf/pdf_fontfile.c
+++ b/pdf/pdf_fontfile.c
@@ -15,6 +15,8 @@
Set NODROIDFONT to use the base 14 fonts as substitute fonts.
*/
+#ifndef NOBUILTINFONT
+
#ifdef NOCJK
#define NOCJKFONT
#endif
@@ -152,3 +154,112 @@ pdf_lookup_substitute_cjk_font(int ros, int serif, unsigned int *len)
return NULL;
#endif
}
+
+#else // NOBUILTINFONT
+
+unsigned char *
+get_font_file(char *name)
+{
+ char *fontdir;
+ char *filename;
+ int len;
+ fontdir = getenv("FONTDIR");
+ if(fontdir == NULL) {
+ fontdir = "./fonts";
+ }
+ len = strlen(fontdir) + strlen(name) + 2;
+ filename = malloc(len);
+ if(filename == NULL) {
+ return NULL;
+ }
+ snprintf(filename, len, "%s/%s", fontdir, name);
+ return filename;
+}
+
+unsigned char *
+pdf_lookup_builtin_font(char *name, unsigned int *len)
+{
+ *len = 0;
+ if (!strcmp("Courier", name)) {
+ return get_font_file("NimbusMonL-Regu.cff");
+ }
+ if (!strcmp("Courier-Bold", name)) {
+ return get_font_file("NimbusMonL-Bold.cff");
+ }
+ if (!strcmp("Courier-Oblique", name)) {
+ return get_font_file("NimbusMonL-ReguObli.cff");
+ }
+ if (!strcmp("Courier-BoldOblique", name)) {
+ return get_font_file("NimbusMonL-BoldObli.cff");
+ }
+ if (!strcmp("Helvetica", name)) {
+ return get_font_file("NimbusSanL-Regu.cff");
+ }
+ if (!strcmp("Helvetica-Bold", name)) {
+ return get_font_file("NimbusSanL-Bold.cff");
+ }
+ if (!strcmp("Helvetica-Oblique", name)) {
+ return get_font_file("NimbusSanL-ReguItal.cff");
+ }
+ if (!strcmp("Helvetica-BoldOblique", name)) {
+ return get_font_file("NimbusSanL-BoldItal.cff");
+ }
+ if (!strcmp("Times-Roman", name)) {
+ return get_font_file("NimbusRomNo9L-Regu.cff");
+ }
+ if (!strcmp("Times-Bold", name)) {
+ return get_font_file("NimbusRomNo9L-Medi.cff");
+ }
+ if (!strcmp("Times-Italic", name)) {
+ return get_font_file("NimbusRomNo9L-ReguItal.cff");
+ }
+ if (!strcmp("Times-BoldItalic", name)) {
+ return get_font_file("NimbusRomNo9L-MediItal.cff");
+ }
+ if (!strcmp("Symbol", name)) {
+ return get_font_file("StandardSymL.cff");
+ }
+ if (!strcmp("ZapfDingbats", name)) {
+ return get_font_file("Dingbats.cff");
+ }
+ return NULL;
+}
+
+unsigned char *
+pdf_lookup_substitute_font(int mono, int serif, int bold, int italic, unsigned int *len)
+{
+ if (mono) {
+ if (bold) {
+ if (italic) return pdf_lookup_builtin_font("Courier-BoldOblique", len);
+ else return pdf_lookup_builtin_font("Courier-Bold", len);
+ } else {
+ if (italic) return pdf_lookup_builtin_font("Courier-Oblique", len);
+ else return pdf_lookup_builtin_font("Courier", len);
+ }
+ } else if (serif) {
+ if (bold) {
+ if (italic) return pdf_lookup_builtin_font("Times-BoldItalic", len);
+ else return pdf_lookup_builtin_font("Times-Bold", len);
+ } else {
+ if (italic) return pdf_lookup_builtin_font("Times-Italic", len);
+ else return pdf_lookup_builtin_font("Times-Roman", len);
+ }
+ } else {
+ if (bold) {
+ if (italic) return pdf_lookup_builtin_font("Helvetica-BoldOblique", len);
+ else return pdf_lookup_builtin_font("Helvetica-Bold", len);
+ } else {
+ if (italic) return pdf_lookup_builtin_font("Helvetica-Oblique", len);
+ else return pdf_lookup_builtin_font("Helvetica", len);
+ }
+ }
+}
+
+unsigned char *
+pdf_lookup_substitute_cjk_font(int ros, int serif, unsigned int *len)
+{
+ *len = 0;
+ return get_font_file("droid/DroidSansFallback.ttf");
+}
+
+#endif // NOBUILTINFONT