comparison mupdf-source/platform/java/jni/android/androidfonts.c @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
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 /* Android font functions */
24
25 static fz_font *load_noto(fz_context *ctx, const char *a, const char *b, const char *c, int idx)
26 {
27 char buf[500];
28 fz_font *font = NULL;
29 fz_try(ctx)
30 {
31 fz_snprintf(buf, sizeof buf, "/system/fonts/%s%s%s.ttf", a, b, c);
32 if (!fz_file_exists(ctx, buf))
33 fz_snprintf(buf, sizeof buf, "/system/fonts/%s%s%s.otf", a, b, c);
34 if (!fz_file_exists(ctx, buf))
35 fz_snprintf(buf, sizeof buf, "/system/fonts/%s%s%s.ttc", a, b, c);
36 if (fz_file_exists(ctx, buf))
37 font = fz_new_font_from_file(ctx, NULL, buf, idx, 0);
38 }
39 fz_catch(ctx)
40 return NULL;
41 return font;
42 }
43
44 static fz_font *load_noto_cjk(fz_context *ctx, int lang)
45 {
46 fz_font *font = load_noto(ctx, "NotoSerif", "CJK", "-Regular", lang);
47 if (!font) font = load_noto(ctx, "NotoSans", "CJK", "-Regular", lang);
48 if (!font) font = load_noto(ctx, "DroidSans", "Fallback", "", 0);
49 return font;
50 }
51
52 static fz_font *load_noto_arabic(fz_context *ctx)
53 {
54 fz_font *font = load_noto(ctx, "Noto", "Naskh", "-Regular", 0);
55 if (!font) font = load_noto(ctx, "Noto", "NaskhArabic", "-Regular", 0);
56 if (!font) font = load_noto(ctx, "Droid", "Naskh", "-Regular", 0);
57 if (!font) font = load_noto(ctx, "NotoSerif", "Arabic", "-Regular", 0);
58 if (!font) font = load_noto(ctx, "NotoSans", "Arabic", "-Regular", 0);
59 if (!font) font = load_noto(ctx, "DroidSans", "Arabic", "-Regular", 0);
60 return font;
61 }
62
63 static fz_font *load_noto_try(fz_context *ctx, const char *stem)
64 {
65 fz_font *font = load_noto(ctx, "NotoSerif", stem, "-Regular", 0);
66 if (!font) font = load_noto(ctx, "NotoSerif", stem, "-VF", 0);
67 if (!font) font = load_noto(ctx, "NotoSans", stem, "-Regular", 0);
68 if (!font) font = load_noto(ctx, "NotoSans", stem, "-VF", 0);
69 if (!font) font = load_noto(ctx, "DroidSans", stem, "-Regular", 0);
70 return font;
71 }
72
73 enum { JP, KR, SC, TC };
74
75 fz_font *load_droid_fallback_font(fz_context *ctx, int script, int language, int serif, int bold, int italic)
76 {
77 const char *stem = NULL;
78 switch (script)
79 {
80 case UCDN_SCRIPT_HANGUL: return load_noto_cjk(ctx, KR);
81 case UCDN_SCRIPT_HIRAGANA: return load_noto_cjk(ctx, JP);
82 case UCDN_SCRIPT_KATAKANA: return load_noto_cjk(ctx, JP);
83 case UCDN_SCRIPT_BOPOMOFO: return load_noto_cjk(ctx, TC);
84 case UCDN_SCRIPT_HAN:
85 switch (language)
86 {
87 case FZ_LANG_ja: return load_noto_cjk(ctx, JP);
88 case FZ_LANG_ko: return load_noto_cjk(ctx, KR);
89 case FZ_LANG_zh_Hans: return load_noto_cjk(ctx, SC);
90 default:
91 case FZ_LANG_zh_Hant: return load_noto_cjk(ctx, TC);
92 }
93 case UCDN_SCRIPT_ARABIC:
94 return load_noto_arabic(ctx);
95 default:
96 stem = fz_lookup_noto_stem_from_script(ctx, script, language);
97 if (stem)
98 return load_noto_try(ctx, stem);
99 }
100 return NULL;
101 }
102
103 fz_font *load_droid_cjk_font(fz_context *ctx, const char *name, int ros, int serif)
104 {
105 switch (ros)
106 {
107 case FZ_ADOBE_CNS: return load_noto_cjk(ctx, TC);
108 case FZ_ADOBE_GB: return load_noto_cjk(ctx, SC);
109 case FZ_ADOBE_JAPAN: return load_noto_cjk(ctx, JP);
110 case FZ_ADOBE_KOREA: return load_noto_cjk(ctx, KR);
111 }
112 return NULL;
113 }
114
115 fz_font *load_droid_font(fz_context *ctx, const char *name, int bold, int italic, int needs_exact_metrics)
116 {
117 return NULL;
118 }