summaryrefslogtreecommitdiff
path: root/source/fitz/noto.c
blob: 5d467a7cc19aaecf472cd355aeff29989a7da129 (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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
#include "mupdf/fitz.h"

/*
	Base 14 PDF fonts from URW.
	Noto fonts from Google.
	Source Han Sans from Adobe for CJK.
	DroidSansFallback from Android for CJK.
	Charis SIL from SIL.

	Define TOFU to only include the Base14 and CJK fonts.

	Define TOFU_CJK_LANG to skip Source Han Sans per-language fonts.
	Define TOFU_CJK_EXT to skip DroidSansFallbackFull (and the above).
	Define TOFU_CJK to skip DroidSansFallback (and the above).

	Define TOFU_EMOJI to skip emoji font.
	Define TOFU_HISTORIC to skip ancient/historic scripts.
	Define TOFU_SYMBOL to skip symbol font.
	Define TOFU_SIL to skip the SIL fonts.

	Define TOFU_BASE14 to skip the Base 14 fonts (warning: makes PDF unusable).
*/

#ifdef NOTO_SMALL
#define TOFU_CJK_EXT
#define TOFU_EMOJI
#define TOFU_HISTORIC
#define TOFU_SYMBOL
#define TOFU_SIL
#endif

#ifdef NOCJK
#define TOFU_CJK
#endif

#ifdef TOFU
#define TOFU_EMOJI
#define TOFU_HISTORIC
#define TOFU_SYMBOL
#define TOFU_SIL
#endif

#define RETURN(NAME) \
	do { \
	extern const int fz_font_ ## NAME ## _size; \
	extern const char fz_font_ ## NAME []; \
	return *size = fz_font_ ## NAME ## _size, fz_font_ ## NAME; \
	} while (0)

const char *
fz_lookup_base14_font(fz_context *ctx, const char *name, int *size)
{
#ifndef TOFU_BASE14
	if (!strcmp(name, "Courier")) RETURN(NimbusMonoPS_Regular_cff);
	if (!strcmp(name, "Courier-Oblique")) RETURN(NimbusMonoPS_Italic_cff);
	if (!strcmp(name, "Courier-Bold")) RETURN(NimbusMonoPS_Bold_cff);
	if (!strcmp(name, "Courier-BoldOblique")) RETURN(NimbusMonoPS_BoldItalic_cff);
	if (!strcmp(name, "Helvetica")) RETURN(NimbusSans_Regular_cff);
	if (!strcmp(name, "Helvetica-Oblique")) RETURN(NimbusSans_Oblique_cff);
	if (!strcmp(name, "Helvetica-Bold")) RETURN(NimbusSans_Bold_cff);
	if (!strcmp(name, "Helvetica-BoldOblique")) RETURN(NimbusSans_BoldOblique_cff);
	if (!strcmp(name, "Times-Roman")) RETURN(NimbusRoman_Regular_cff);
	if (!strcmp(name, "Times-Italic")) RETURN(NimbusRoman_Italic_cff);
	if (!strcmp(name, "Times-Bold")) RETURN(NimbusRoman_Bold_cff);
	if (!strcmp(name, "Times-BoldItalic")) RETURN(NimbusRoman_BoldItalic_cff);
	if (!strcmp(name, "Symbol")) RETURN(StandardSymbolsPS_cff);
	if (!strcmp(name, "ZapfDingbats")) RETURN(Dingbats_cff);
#endif
	return *size = 0, NULL;
}

#define FAMILY(R, I, B, BI) \
	if (!is_bold) { \
		if (!is_italic) RETURN(R); else RETURN(I); \
	} else { \
		if (!is_italic) RETURN(B); else RETURN(BI); \
	}

const char *
fz_lookup_builtin_font(fz_context *ctx, const char *name, int is_bold, int is_italic, int *size)
{
#ifndef TOFU_BASE14
	if (!strcmp(name, "Courier")) {
		FAMILY(NimbusMonoPS_Regular_cff,
				NimbusMonoPS_Italic_cff,
				NimbusMonoPS_Bold_cff,
				NimbusMonoPS_BoldItalic_cff)
	}
	if (!strcmp(name, "Helvetica") || !strcmp(name, "Arial")) {
		FAMILY(NimbusSans_Regular_cff,
				NimbusSans_Oblique_cff,
				NimbusSans_Bold_cff,
				NimbusSans_BoldOblique_cff)
	}
	if (!strcmp(name, "Times") || !strcmp(name, "Times Roman") || !strcmp(name, "Times New Roman")) {
		FAMILY(NimbusRoman_Regular_cff,
				NimbusRoman_Italic_cff,
				NimbusRoman_Bold_cff,
				NimbusRoman_BoldItalic_cff)
	}
	if (!strcmp(name, "Dingbats") || !strcmp(name, "Zapf Dingbats")) {
		RETURN(Dingbats_cff);
	}
	if (!strcmp(name, "Symbol")) {
		RETURN(StandardSymbolsPS_cff);
	}
#endif
#ifndef TOFU_SIL
	if (!strcmp(name, "Charis SIL")) {
		FAMILY(CharisSIL_R_cff,
				CharisSIL_I_cff,
				CharisSIL_B_cff,
				CharisSIL_BI_cff)
	}
#endif
#ifndef TOFU
	if (!strcmp(name, "Noto Serif")) {
		RETURN(NotoSerif_Regular_ttf);
	}
	if (!strcmp(name, "Noto Sans")) {
		RETURN(NotoSans_Regular_ttf);
	}
#endif
#ifndef TOFU_EMOJI
	if (!strcmp(name, "Emoji") || !strcmp(name, "Noto Emoji")) {
		RETURN(NotoEmoji_Regular_ttf);
	}
#endif
	return *size = 0, NULL;
}

const char *
fz_lookup_cjk_font(fz_context *ctx, int registry, int serif, int wmode, int *size, int *index)
{
	if (index) *index = 0;
#ifndef TOFU_CJK
#ifndef TOFU_CJK_EXT
#ifndef TOFU_CJK_LANG
	switch (registry) {
	case FZ_ADOBE_JAPAN_1: RETURN(SourceHanSansJP_Regular_otf);
	case FZ_ADOBE_KOREA_1: RETURN(SourceHanSansKR_Regular_otf);
	default:
	case FZ_ADOBE_GB_1: RETURN(SourceHanSansCN_Regular_otf);
	case FZ_ADOBE_CNS_1: RETURN(SourceHanSansTW_Regular_otf);
	}
#else
	RETURN(DroidSansFallbackFull_ttf);
#endif
#else
	RETURN(DroidSansFallback_ttf);
#endif
#else
	return *size = 0, NULL;
#endif
}

#define Noto(SANS) RETURN(Noto ## SANS ## _Regular_ttf)

#define Noto2(SANS,SERIF) \
	if (serif) { RETURN(Noto ## SERIF ## _Regular_ttf); } else { RETURN(Noto ## SANS ## _Regular_ttf); }

const char *
fz_lookup_noto_font(fz_context *ctx, int script, int language, int serif, int *size)
{
	/* TODO: Noto(SansSyriacEstrangela); */
	/* TODO: Noto(SansSyriacWestern); */

	switch (script)
	{
	default:
	case UCDN_SCRIPT_COMMON:
	case UCDN_SCRIPT_INHERITED:
	case UCDN_SCRIPT_UNKNOWN:
		break;

	case UCDN_SCRIPT_HANGUL:
		return fz_lookup_cjk_font(ctx, FZ_ADOBE_KOREA_1, serif, 0, size, NULL);
	case UCDN_SCRIPT_HIRAGANA:
	case UCDN_SCRIPT_KATAKANA:
		return fz_lookup_cjk_font(ctx, FZ_ADOBE_JAPAN_1, serif, 0, size, NULL);
	case UCDN_SCRIPT_BOPOMOFO:
		return fz_lookup_cjk_font(ctx, FZ_ADOBE_GB_1, serif, 0, size, NULL);
	case UCDN_SCRIPT_HAN:
		switch (language)
		{
		case FZ_LANG_ja: return fz_lookup_cjk_font(ctx, FZ_ADOBE_JAPAN_1, serif, 0, size, NULL);
		case FZ_LANG_ko: return fz_lookup_cjk_font(ctx, FZ_ADOBE_KOREA_1, serif, 0, size, NULL);
		case FZ_LANG_zh_Hant: return fz_lookup_cjk_font(ctx, FZ_ADOBE_CNS_1, serif, 0, size, NULL);
		default:
		case FZ_LANG_zh_Hans: return fz_lookup_cjk_font(ctx, FZ_ADOBE_GB_1, serif, 0, size, NULL);
		}

#ifndef TOFU
	case UCDN_SCRIPT_LATIN: Noto2(Sans, Serif);
	case UCDN_SCRIPT_GREEK: Noto2(Sans, Serif);
	case UCDN_SCRIPT_CYRILLIC: Noto2(Sans, Serif);

	case UCDN_SCRIPT_ARABIC:
		if (language == FZ_LANG_ur || language == FZ_LANG_urd)
			Noto(NastaliqUrdu);
		Noto2(KufiArabic, NaskhArabic);

	case UCDN_SCRIPT_ARMENIAN: Noto2(SansArmenian, SerifArmenian);
	case UCDN_SCRIPT_BALINESE: Noto(SansBalinese);
	case UCDN_SCRIPT_BAMUM: Noto(SansBamum);
	case UCDN_SCRIPT_BATAK: Noto(SansBatak);
	case UCDN_SCRIPT_BENGALI: Noto2(SansBengali, SerifBengali);
	case UCDN_SCRIPT_CANADIAN_ABORIGINAL: Noto(SansCanadianAboriginal);
	case UCDN_SCRIPT_CHAM: Noto(SansCham);
	case UCDN_SCRIPT_CHEROKEE: Noto(SansCherokee);
	case UCDN_SCRIPT_DEVANAGARI: Noto2(SansDevanagari, SerifDevanagari);
	case UCDN_SCRIPT_ETHIOPIC: Noto(SansEthiopic);
	case UCDN_SCRIPT_GEORGIAN: Noto2(SansGeorgian, SerifGeorgian);
	case UCDN_SCRIPT_GUJARATI: Noto2(SansGujarati, SerifGujarati);
	case UCDN_SCRIPT_GURMUKHI: Noto(SansGurmukhi);
	case UCDN_SCRIPT_HEBREW: Noto(SansHebrew);
	case UCDN_SCRIPT_JAVANESE: Noto(SansJavanese);
	case UCDN_SCRIPT_KANNADA: Noto2(SansKannada, SerifKannada);
	case UCDN_SCRIPT_KAYAH_LI: Noto(SansKayahLi);
	case UCDN_SCRIPT_KHMER: Noto2(SansKhmer, SerifKhmer);
	case UCDN_SCRIPT_LAO: Noto2(SansLao, SerifLao);
	case UCDN_SCRIPT_LEPCHA: Noto(SansLepcha);
	case UCDN_SCRIPT_LIMBU: Noto(SansLimbu);
	case UCDN_SCRIPT_LISU: Noto(SansLisu);
	case UCDN_SCRIPT_MALAYALAM: Noto2(SansMalayalam, SerifMalayalam);
	case UCDN_SCRIPT_MANDAIC: Noto(SansMandaic);
	case UCDN_SCRIPT_MEETEI_MAYEK: Noto(SansMeeteiMayek);
	case UCDN_SCRIPT_MONGOLIAN: Noto(SansMongolian);
	case UCDN_SCRIPT_MYANMAR: Noto(SansMyanmar);
	case UCDN_SCRIPT_NEW_TAI_LUE: Noto(SansNewTaiLue);
	case UCDN_SCRIPT_NKO: Noto(SansNKo);
	case UCDN_SCRIPT_OL_CHIKI: Noto(SansOlChiki);
	case UCDN_SCRIPT_ORIYA: Noto(SansOriya);
	case UCDN_SCRIPT_SAURASHTRA: Noto(SansSaurashtra);
	case UCDN_SCRIPT_SINHALA: Noto(SansSinhala);
	case UCDN_SCRIPT_SUNDANESE: Noto(SansSundanese);
	case UCDN_SCRIPT_SYLOTI_NAGRI: Noto(SansSylotiNagri);
	case UCDN_SCRIPT_SYRIAC: Noto(SansSyriacEastern);
	case UCDN_SCRIPT_TAI_LE: Noto(SansTaiLe);
	case UCDN_SCRIPT_TAI_THAM: Noto(SansTaiTham);
	case UCDN_SCRIPT_TAI_VIET: Noto(SansTaiViet);
	case UCDN_SCRIPT_TAMIL: Noto2(SansTamil, SerifTamil);
	case UCDN_SCRIPT_TELUGU: Noto2(SansTelugu, SerifTelugu);
	case UCDN_SCRIPT_THAANA: Noto(SansThaana);
	case UCDN_SCRIPT_THAI: Noto2(SansThai, SerifThai);
	case UCDN_SCRIPT_TIBETAN: Noto(SansTibetan);
	case UCDN_SCRIPT_TIFINAGH: Noto(SansTifinagh);
	case UCDN_SCRIPT_VAI: Noto(SansVai);
	case UCDN_SCRIPT_YI: Noto(SansYi);

#ifndef TOFU_HISTORIC
	case UCDN_SCRIPT_AVESTAN: Noto(SansAvestan);
	case UCDN_SCRIPT_BRAHMI: Noto(SansBrahmi);
	case UCDN_SCRIPT_BUGINESE: Noto(SansBuginese);
	case UCDN_SCRIPT_BUHID: Noto(SansBuhid);
	case UCDN_SCRIPT_CARIAN: Noto(SansCarian);
	case UCDN_SCRIPT_COPTIC: Noto(SansCoptic);
	case UCDN_SCRIPT_CUNEIFORM: Noto(SansCuneiform);
	case UCDN_SCRIPT_CYPRIOT: Noto(SansCypriot);
	case UCDN_SCRIPT_DESERET: Noto(SansDeseret);
	case UCDN_SCRIPT_EGYPTIAN_HIEROGLYPHS: Noto(SansEgyptianHieroglyphs);
	case UCDN_SCRIPT_GLAGOLITIC: Noto(SansGlagolitic);
	case UCDN_SCRIPT_GOTHIC: Noto(SansGothic);
	case UCDN_SCRIPT_HANUNOO: Noto(SansHanunoo);
	case UCDN_SCRIPT_IMPERIAL_ARAMAIC: Noto(SansImperialAramaic);
	case UCDN_SCRIPT_INSCRIPTIONAL_PAHLAVI: Noto(SansInscriptionalPahlavi);
	case UCDN_SCRIPT_INSCRIPTIONAL_PARTHIAN: Noto(SansInscriptionalParthian);
	case UCDN_SCRIPT_KAITHI: Noto(SansKaithi);
	case UCDN_SCRIPT_KHAROSHTHI: Noto(SansKharoshthi);
	case UCDN_SCRIPT_LINEAR_B: Noto(SansLinearB);
	case UCDN_SCRIPT_LYCIAN: Noto(SansLycian);
	case UCDN_SCRIPT_LYDIAN: Noto(SansLydian);
	case UCDN_SCRIPT_OGHAM: Noto(SansOgham);
	case UCDN_SCRIPT_OLD_ITALIC: Noto(SansOldItalic);
	case UCDN_SCRIPT_OLD_PERSIAN: Noto(SansOldPersian);
	case UCDN_SCRIPT_OLD_SOUTH_ARABIAN: Noto(SansOldSouthArabian);
	case UCDN_SCRIPT_OLD_TURKIC: Noto(SansOldTurkic);
	case UCDN_SCRIPT_OSMANYA: Noto(SansOsmanya);
	case UCDN_SCRIPT_PHAGS_PA: Noto(SansPhagsPa);
	case UCDN_SCRIPT_PHOENICIAN: Noto(SansPhoenician);
	case UCDN_SCRIPT_REJANG: Noto(SansRejang);
	case UCDN_SCRIPT_RUNIC: Noto(SansRunic);
	case UCDN_SCRIPT_SAMARITAN: Noto(SansSamaritan);
	case UCDN_SCRIPT_SHAVIAN: Noto(SansShavian);
	case UCDN_SCRIPT_TAGALOG: Noto(SansTagalog);
	case UCDN_SCRIPT_TAGBANWA: Noto(SansTagbanwa);
	case UCDN_SCRIPT_UGARITIC: Noto(SansUgaritic);
#endif

	/* No fonts available for these scripts: */
	case UCDN_SCRIPT_ADLAM: break;
	case UCDN_SCRIPT_BRAILLE: break; /* no dedicated font; fallback to NotoSansSymbols will cover this */
	case UCDN_SCRIPT_CHAKMA: break;
	case UCDN_SCRIPT_MIAO: break;
	case UCDN_SCRIPT_NEWA: break;
#ifndef TOFU_HISTORIC
	case UCDN_SCRIPT_AHOM: break;
	case UCDN_SCRIPT_ANATOLIAN_HIEROGLYPHS: break;
	case UCDN_SCRIPT_BASSA_VAH: break;
	case UCDN_SCRIPT_BHAIKSUKI: break;
	case UCDN_SCRIPT_CAUCASIAN_ALBANIAN: break;
	case UCDN_SCRIPT_DUPLOYAN: break;
	case UCDN_SCRIPT_ELBASAN: break;
	case UCDN_SCRIPT_GRANTHA: break;
	case UCDN_SCRIPT_HATRAN: break;
	case UCDN_SCRIPT_KHOJKI: break;
	case UCDN_SCRIPT_KHUDAWADI: break;
	case UCDN_SCRIPT_LINEAR_A: break;
	case UCDN_SCRIPT_MAHAJANI: break;
	case UCDN_SCRIPT_MANICHAEAN: break;
	case UCDN_SCRIPT_MARCHEN: break;
	case UCDN_SCRIPT_MENDE_KIKAKUI: break;
	case UCDN_SCRIPT_MEROITIC_CURSIVE: break;
	case UCDN_SCRIPT_MEROITIC_HIEROGLYPHS: break;
	case UCDN_SCRIPT_MODI: break;
	case UCDN_SCRIPT_MRO: break;
	case UCDN_SCRIPT_MULTANI: break;
	case UCDN_SCRIPT_NABATAEAN: break;
	case UCDN_SCRIPT_OLD_HUNGARIAN: break;
	case UCDN_SCRIPT_OLD_NORTH_ARABIAN: break;
	case UCDN_SCRIPT_OLD_PERMIC: break;
	case UCDN_SCRIPT_OSAGE: break;
	case UCDN_SCRIPT_PAHAWH_HMONG: break;
	case UCDN_SCRIPT_PALMYRENE: break;
	case UCDN_SCRIPT_PAU_CIN_HAU: break;
	case UCDN_SCRIPT_PSALTER_PAHLAVI: break;
	case UCDN_SCRIPT_SHARADA: break;
	case UCDN_SCRIPT_SIDDHAM: break;
	case UCDN_SCRIPT_SIGNWRITING: break;
	case UCDN_SCRIPT_SORA_SOMPENG: break;
	case UCDN_SCRIPT_TAKRI: break;
	case UCDN_SCRIPT_TANGUT: break;
	case UCDN_SCRIPT_TIRHUTA: break;
	case UCDN_SCRIPT_WARANG_CITI: break;
#endif

#endif
	}

	return *size = 0, NULL;
}

const char *
fz_lookup_noto_symbol_font(fz_context *ctx, int *size)
{
#ifndef TOFU_SYMBOL
	RETURN(NotoSansSymbols_Regular_ttf);
#else
	return *size = 0, NULL;
#endif
}

const char *
fz_lookup_noto_emoji_font(fz_context *ctx, int *size)
{
#ifndef TOFU_EMOJI
	RETURN(NotoEmoji_Regular_ttf);
#else
	return *size = 0, NULL;
#endif
}