summarylogtreecommitdiffstats
path: root/0002-pymupdf.patch
blob: a57853cec25b7d5bf4c16edd66a939652fa2717b (plain)
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
diff -ru mupdf-1.17.0-source-orig/include/mupdf/fitz/config.h mupdf-1.17.0-source/include/mupdf/fitz/config.h
--- mupdf-1.17.0-source-orig/include/mupdf/fitz/config.h	2020-05-05 19:29:09.000000000 +0800
+++ mupdf-1.17.0-source/include/mupdf/fitz/config.h	2020-08-09 23:10:55.615700000 +0800
@@ -2,13 +2,13 @@
 
 #define FZ_CONFIG_H
 
-/**
+/*
 	Enable the following for spot (and hence overprint/overprint
 	simulation) capable rendering. This forces FZ_PLOTTERS_N on.
 */
 /* #define FZ_ENABLE_SPOT_RENDERING 1 */
 
-/**
+/*
 	Choose which plotters we need.
 	By default we build all the plotters in. To avoid building
 	plotters in that aren't needed, define the unwanted
@@ -19,7 +19,7 @@
 /* #define FZ_PLOTTERS_CMYK 1 */
 /* #define FZ_PLOTTERS_N 1 */
 
-/**
+/*
 	Choose which document agents to include.
 	By default all are enabled. To avoid building unwanted
 	ones, define FZ_ENABLE_... to 0.
@@ -32,12 +32,12 @@
 /* #define FZ_ENABLE_HTML 1 */
 /* #define FZ_ENABLE_EPUB 1 */
 
-/**
+/*
 	Choose whether to enable ICC color profiles.
 */
-/* #define FZ_ENABLE_ICC 1 */
+#define FZ_ENABLE_ICC 1
 
-/**
+/*
 	Choose whether to enable JPEG2000 decoding.
 	By default, it is enabled, but due to frequent security
 	issues with the third party libraries we support disabling
@@ -45,14 +45,13 @@
 */
 /* #define FZ_ENABLE_JPX 1 */
 
-/**
+/*
 	Choose whether to enable JavaScript.
-	By default JavaScript is enabled both for mutool and PDF
-	interactivity.
+	By default JavaScript is enabled both for mutool and PDF interactivity.
 */
 /* #define FZ_ENABLE_JS 1 */
 
-/**
+/*
 	Choose which fonts to include.
 	By default we include the base 14 PDF fonts,
 	DroidSansFallback from Android for CJK, and
@@ -61,35 +60,32 @@
 	unwanted fonts.
 */
 /* To avoid all noto fonts except CJK, enable: */
-/* #define TOFU */
+#define TOFU // <=== PyMuPDF: not the complete NOTO!
 
-/* To skip the CJK font, enable: (this implicitly enables TOFU_CJK_EXT
- * and TOFU_CJK_LANG) */
+/* To skip the CJK font, enable: (this implicitly enables TOFU_CJK_EXT and TOFU_CJK_LANG) */
 /* #define TOFU_CJK */
 
-/* To skip CJK Extension A, enable: (this implicitly enables
- * TOFU_CJK_LANG) */
-/* #define TOFU_CJK_EXT */
+/* To skip CJK Extension A, enable: (this implicitly enables TOFU_CJK_LANG) */
+#define TOFU_CJK_EXT // <=== PyMuPDF: causes 1.5 MB extra size
 
 /* To skip CJK language specific fonts, enable: */
-/* #define TOFU_CJK_LANG */
+#define TOFU_CJK_LANG // <=== PyMuPDF
 
 /* To skip the Emoji font, enable: */
-/* #define TOFU_EMOJI */
+#define TOFU_EMOJI // <=== PyMuPDF
 
 /* To skip the ancient/historic scripts, enable: */
-/* #define TOFU_HISTORIC */
+#define TOFU_HISTORIC // <=== PyMuPDF
 
 /* To skip the symbol font, enable: */
-/* #define TOFU_SYMBOL */
+#define TOFU_SYMBOL // <=== PyMuPDF
 
 /* To skip the SIL fonts, enable: */
-/* #define TOFU_SIL */
+// #define TOFU_SIL // <=== PyMuPDF: ok to have it, only small fonts
 
 /* To skip the Base14 fonts, enable: */
 /* #define TOFU_BASE14 */
-/* (You probably really don't want to do that except for measurement
- * purposes!) */
+/* (You probably really don't want to do that except for measurement purposes!) */
 
 /* ---------- DO NOT EDIT ANYTHING UNDER THIS LINE ---------- */
 
diff -ru mupdf-1.17.0-source-orig/source/fitz/encode-fax.c mupdf-1.17.0-source/source/fitz/encode-fax.c
--- mupdf-1.17.0-source-orig/source/fitz/encode-fax.c	2020-05-05 19:29:09.000000000 +0800
+++ mupdf-1.17.0-source/source/fitz/encode-fax.c	2020-08-09 23:10:55.615700000 +0800
@@ -120,7 +120,7 @@
 {
 	int a, b;
 
-	if (!line)
+	if (!line || x >= w)
 		return w;
 
 	if (x == -1)
@@ -147,7 +147,7 @@
 static inline int
 find_changing_color(const unsigned char *line, int x, int w, int color)
 {
-	if (!line)
+	if (!line || x >= w)
 		return w;
 	x = find_changing(line, x, w);
 	if (x < w && getbit(line, x) != color)
diff -ru mupdf-1.17.0-source-orig/source/pdf/pdf-font-add.c mupdf-1.17.0-source/source/pdf/pdf-font-add.c
--- mupdf-1.17.0-source-orig/source/pdf/pdf-font-add.c	2020-05-05 19:29:09.000000000 +0800
+++ mupdf-1.17.0-source/source/pdf/pdf-font-add.c	2020-08-09 23:10:55.615700000 +0800
@@ -21,10 +21,14 @@
 #else
 	const char *kind = FT_Get_X11_Font_Format(face);
 #endif
-	if (!strcmp(kind, "TrueType")) return 2;
-	if (!strcmp(kind, "Type 1")) return 1;
-	if (!strcmp(kind, "CFF")) return 3;
-	if (!strcmp(kind, "CID Type 1")) return 1;
+	if (!strcmp(kind, "TrueType"))
+		return 2;
+	if (!strcmp(kind, "Type 1"))
+		return 1;
+	if (!strcmp(kind, "CFF"))
+		return 3;
+	if (!strcmp(kind, "CID Type 1"))
+		return 1;
 	return 0;
 }
 
@@ -54,7 +58,7 @@
 	return fz_lookup_base14_font(ctx, pdf_clean_font_name(font->name), &size) == data;
 }
 
-static pdf_obj*
+static pdf_obj *
 pdf_add_font_file(fz_context *ctx, pdf_document *doc, fz_font *font)
 {
 	fz_buffer *buf = font->buffer;
@@ -136,9 +140,15 @@
 			switch (ft_font_file_kind(face))
 			{
 			default:
-			case 1: pdf_dict_put_drop(ctx, fdobj, PDF_NAME(FontFile), fileref); break;
-			case 2: pdf_dict_put_drop(ctx, fdobj, PDF_NAME(FontFile2), fileref); break;
-			case 3: pdf_dict_put_drop(ctx, fdobj, PDF_NAME(FontFile3), fileref); break;
+			case 1:
+				pdf_dict_put_drop(ctx, fdobj, PDF_NAME(FontFile), fileref);
+				break;
+			case 2:
+				pdf_dict_put_drop(ctx, fdobj, PDF_NAME(FontFile2), fileref);
+				break;
+			case 3:
+				pdf_dict_put_drop(ctx, fdobj, PDF_NAME(FontFile3), fileref);
+				break;
 			}
 		}
 
@@ -151,7 +161,7 @@
 }
 
 static void
-pdf_add_simple_font_widths(fz_context *ctx, pdf_document *doc, pdf_obj *fobj, fz_font *font, const char * const encoding[])
+pdf_add_simple_font_widths(fz_context *ctx, pdf_document *doc, pdf_obj *fobj, fz_font *font, const char *const encoding[])
 {
 	int width_table[256];
 	pdf_obj *widths;
@@ -196,7 +206,12 @@
 }
 
 /* Different states of starting, same width as last, or consecutive glyph */
-enum { FW_START, FW_SAME, FW_RUN };
+enum
+{
+	FW_START,
+	FW_SAME,
+	FW_RUN
+};
 
 /* ToDo: Ignore the default sized characters */
 static void
@@ -329,7 +344,7 @@
 }
 
 /* Descendant font construction used for CID font creation from ttf or Adobe type1 */
-static pdf_obj*
+static pdf_obj *
 pdf_add_descendant_cid_font(fz_context *ctx, pdf_document *doc, fz_font *font)
 {
 	FT_Face face = font->ft_face;
@@ -372,9 +387,9 @@
 	int n;
 	for (n = 1; k + n < size; ++n)
 	{
-		if ((k & 0xFF00) != ((k+n) & 0xFF00)) /* high byte changes */
+		if ((k & 0xFF00) != ((k + n) & 0xFF00)) /* high byte changes */
 			break;
-		if (table[k] + n != table[k+n])
+		if (table[k] + n != table[k + n])
 			break;
 	}
 	return n;
@@ -474,7 +489,7 @@
 							fz_append_printf(ctx, buf, "%d beginbfrange\n", num_seq);
 						count = 0;
 					}
-					fz_append_printf(ctx, buf, "<%04x> <%04x> <%04x>\n", k, k+n-1, table[k]);
+					fz_append_printf(ctx, buf, "<%04x> <%04x> <%04x>\n", k, k + n - 1, table[k]);
 					++count;
 				}
 			}
@@ -582,7 +597,7 @@
 		const char *glyph = glyph_names[i];
 		if (glyph)
 		{
-			if (last != i-1)
+			if (last != i - 1)
 				pdf_array_push_int(ctx, diff, i);
 			last = i;
 			pdf_array_push_name(ctx, diff, glyph);
@@ -624,9 +639,15 @@
 	switch (encoding)
 	{
 	default:
-	case PDF_SIMPLE_ENCODING_LATIN: enc = fz_glyph_name_from_windows_1252; break;
-	case PDF_SIMPLE_ENCODING_GREEK: enc = fz_glyph_name_from_iso8859_7; break;
-	case PDF_SIMPLE_ENCODING_CYRILLIC: enc = fz_glyph_name_from_koi8u; break;
+	case PDF_SIMPLE_ENCODING_LATIN:
+		enc = fz_glyph_name_from_windows_1252;
+		break;
+	case PDF_SIMPLE_ENCODING_GREEK:
+		enc = fz_glyph_name_from_iso8859_7;
+		break;
+	case PDF_SIMPLE_ENCODING_CYRILLIC:
+		enc = fz_glyph_name_from_koi8u;
+		break;
 	}
 
 	fobj = pdf_add_new_dict(ctx, doc, 10);
@@ -667,8 +688,7 @@
 	return fref;
 }
 
-int
-pdf_font_writing_supported(fz_font *font)
+int pdf_font_writing_supported(fz_font *font)
 {
 	if (font->ft_face == NULL || font->buffer == NULL || font->buffer->len < 4)
 		return 0;
@@ -686,7 +706,7 @@
 {
 	pdf_obj *fref, *font, *subfont, *fontdesc;
 	pdf_obj *dfonts;
-	fz_rect bbox = { -200, -200, 1200, 1200 };
+	fz_rect bbox = {-200, -200, 1200, 1200};
 	unsigned char digest[16];
 	int flags;
 
@@ -769,3 +789,21 @@
 
 	return fref;
 }
+
+void jm_valid_chars(fz_context *ctx, fz_font *font, void *arr)
+{
+	FT_Face face = font->ft_face;
+	FT_ULong ucs;
+	FT_UInt gid;
+	long *table = (long *)arr;
+	fz_lock(ctx, FZ_LOCK_FREETYPE);
+	ucs = FT_Get_First_Char(face, &gid);
+	while (gid > 0)
+	{
+		if (gid < (FT_ULong)face->num_glyphs && face->num_glyphs > 0)
+			table[gid] = (long)ucs;
+		ucs = FT_Get_Next_Char(face, ucs, &gid);
+	}
+	fz_unlock(ctx, FZ_LOCK_FREETYPE);
+	return;
+}