-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathfont.cpp
More file actions
700 lines (617 loc) · 19.8 KB
/
Copy pathfont.cpp
File metadata and controls
700 lines (617 loc) · 19.8 KB
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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
/******************************************************************************
* MODULE : font.cpp
* DESCRIPTION: fonts
* COPYRIGHT : (C) 1999 Joris van der Hoeven
*******************************************************************************
* This software falls under the GNU general public license version 3 or later.
* It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
* in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
******************************************************************************/
#include "font.hpp"
#include "Freetype/tt_file.hpp"
#include <moebius/data/colors.hpp>
using namespace moebius::data;
#include "convert.hpp"
#include "cork.hpp"
#include "dictionary.hpp"
#include "file.hpp"
#include "iterator.hpp"
#include "preferences.hpp"
#include "scheme.hpp"
#include "tm_debug.hpp"
hashmap<string, double> lsub_guessed_table ();
hashmap<string, double> lsup_guessed_table ();
hashmap<string, double> rsub_guessed_table ();
hashmap<string, double> rsup_guessed_table ();
hashmap<string, double> above_guessed_table ();
hashmap<string, double> below_guessed_table ();
/******************************************************************************
* Constructors for fonts
******************************************************************************/
static int
get_math_type (string s) {
s= locase_all (s);
if (starts (s, "unicode:")) s= s (8, N (s));
if (starts (s, "texgyre")) s= s (7, N (s));
if (starts (s, "stix-") || starts (s, "stixintegrals")) return MATH_TYPE_STIX;
if (starts (s, "bonum-") || starts (s, "pagella-") || starts (s, "schola-") ||
starts (s, "termes-"))
return MATH_TYPE_TEX_GYRE;
return MATH_TYPE_NORMAL;
}
font_rep::font_rep (string s)
: rep<font> (s), type (FONT_TYPE_TEX), math_type (get_math_type (s)),
size_int (0), design_size (0), display_size (0), size_float (0.0),
slope (0.0), spc (0), extra (0), mspc (0), sep (0), last_zoom (0.0),
zoomed_fn (NULL), global_lsub_correct (0), global_lsup_correct (0),
global_rsub_correct (0), global_rsup_correct (0), lsub_correct (0.0),
lsup_correct (0.0), rsub_correct (0.0), rsup_correct (0.0),
above_correct (0.0), below_correct (0.0), protrusion_maps (-1) {
lsub_correct = lsub_guessed_table ();
lsup_correct = lsup_guessed_table ();
rsub_correct = rsub_guessed_table ();
rsup_correct = rsup_guessed_table ();
above_correct= above_guessed_table ();
below_correct= below_guessed_table ();
}
font_rep::font_rep (string s, font fn)
: rep<font> (s), type (fn->type), math_type (fn->math_type),
size_int (fn->size_int), design_size (fn->design_size),
display_size (fn->display_size), size_float (fn->size_float),
slope (fn->slope), spc (fn->spc), extra (fn->extra), mspc (fn->mspc),
sep (fn->sep), last_zoom (0.0), zoomed_fn (NULL), global_lsub_correct (0),
global_lsup_correct (0), global_rsub_correct (0), global_rsup_correct (0),
lsub_correct (0.0), lsup_correct (0.0), rsub_correct (0.0),
rsup_correct (0.0), protrusion_maps (-1) {
lsub_correct = lsub_guessed_table ();
lsup_correct = lsup_guessed_table ();
rsub_correct = rsub_guessed_table ();
rsup_correct = rsup_guessed_table ();
above_correct= above_guessed_table ();
below_correct= below_guessed_table ();
copy_math_pars (fn);
}
void
font_rep::copy_math_pars (font fn) {
y1 = fn->y1;
y2 = fn->y2;
yx = fn->yx;
yfrac = fn->yfrac;
ysub_lo_base= fn->ysub_lo_base;
ysub_hi_lim = fn->ysub_hi_lim;
ysup_lo_lim = fn->ysup_lo_lim;
ysup_lo_base= fn->ysup_lo_base;
ysup_hi_lim = fn->ysup_hi_lim;
yshift = fn->yshift;
wpt = fn->wpt;
hpt = fn->hpt;
wfn = fn->wfn;
wline = fn->wline;
wquad = fn->wquad;
// opentype math parameters
upper_limit_gap_min = fn->upper_limit_gap_min;
upper_limit_baseline_rise_min= fn->upper_limit_baseline_rise_min;
lower_limit_gap_min = fn->lower_limit_gap_min;
lower_limit_baseline_drop_min= fn->lower_limit_baseline_drop_min;
frac_rule_thickness = fn->frac_rule_thickness;
frac_num_shift_up = fn->frac_num_shift_up;
frac_num_disp_shift_up = fn->frac_num_disp_shift_up;
frac_num_gap_min = fn->frac_num_gap_min;
frac_num_disp_gap_min = fn->frac_num_disp_gap_min;
frac_denom_shift_down = fn->frac_denom_shift_down;
frac_denom_disp_shift_down = fn->frac_denom_disp_shift_down;
frac_denom_gap_min = fn->frac_denom_gap_min;
frac_denom_disp_gap_min = fn->frac_denom_disp_gap_min;
sqrt_ver_gap = fn->sqrt_ver_gap;
sqrt_ver_disp_gap = fn->sqrt_ver_disp_gap;
sqrt_rule_thickness = fn->sqrt_rule_thickness;
sqrt_extra_ascender = fn->sqrt_extra_ascender;
sqrt_degree_rise_percent = fn->sqrt_degree_rise_percent;
sqrt_kern_before_degree = fn->sqrt_kern_before_degree;
sqrt_kern_after_degree = fn->sqrt_kern_after_degree;
}
void
font_rep::draw (renderer ren, string s, SI x, SI y, SI xk, bool ext) {
if (ren->zoomf == 1.0 || ren->is_printer ()) {
if (ext) draw_fixed (ren, s, x, y, xk);
else draw_fixed (ren, s, x, y);
}
else if (ren->zoomf != last_zoom) {
last_zoom= ren->zoomf;
zoomed_fn= magnify (ren->zoomf);
draw (ren, s, x, y, xk, ext);
}
else {
// FIXME: low level rendering hack
SI old_ox = ren->ox;
SI old_oy = ren->oy;
SI old_cx1 = ren->cx1;
SI old_cy1 = ren->cy1;
SI old_cx2 = ren->cx2;
SI old_cy2 = ren->cy2;
double old_zoomf = ren->zoomf;
int old_shrinkf = ren->shrinkf;
SI old_thicken = ren->thicken;
SI old_pixel = ren->pixel;
SI old_retina_pixel= ren->retina_pixel;
ren->ox= (SI) tm_round (old_ox * old_zoomf);
ren->oy= (SI) tm_round (old_oy * old_zoomf);
// ren->cx1 = (SI) ::floor (old_cx1 * old_zoomf);
// ren->cx2 = (SI) ::floor (old_cx2 * old_zoomf);
// ren->cy1 = (SI) ::ceil (old_cy1 * old_zoomf);
// ren->cy2 = (SI) ::ceil (old_cy2 * old_zoomf);
ren->cx1 = (SI) tm_round (old_cx1 * old_zoomf);
ren->cx2 = (SI) tm_round (old_cx2 * old_zoomf);
ren->cy1 = (SI) tm_round (old_cy1 * old_zoomf);
ren->cy2 = (SI) tm_round (old_cy2 * old_zoomf);
ren->zoomf = 1.0;
ren->shrinkf = std_shrinkf;
ren->brushpx = ren->pixel;
ren->thicken = (std_shrinkf >> 1) * PIXEL;
ren->pixel = std_shrinkf * PIXEL;
ren->retina_pixel= std_shrinkf * PIXEL;
SI xx= (SI) tm_round (x * old_zoomf);
SI yy= (SI) tm_round (y * old_zoomf);
if (ext) {
SI kk= (SI) tm_round (xk * old_zoomf);
zoomed_fn->draw_fixed (ren, s, xx, yy, kk);
}
else zoomed_fn->draw_fixed (ren, s, xx, yy);
ren->ox = old_ox;
ren->oy = old_oy;
ren->cx1 = old_cx1;
ren->cx2 = old_cx2;
ren->cy1 = old_cy1;
ren->cy2 = old_cy2;
ren->zoomf = old_zoomf;
ren->shrinkf = old_shrinkf;
ren->brushpx = -1;
ren->thicken = old_thicken;
ren->pixel = old_pixel;
ren->retina_pixel= old_retina_pixel;
}
}
void
font_rep::draw (renderer ren, string s, SI x, SI y) {
draw (ren, s, x, y, 0, false);
}
void
font_rep::draw (renderer ren, string s, SI x, SI y, SI xk) {
draw (ren, s, x, y, xk, true);
}
void
font_rep::draw_fixed (renderer ren, string s, SI x, SI y, bool ligf) {
(void) ligf;
draw_fixed (ren, s, x, y);
}
void
font_rep::draw_fixed (renderer ren, string s, SI x, SI y, SI xk) {
STACK_NEW_ARRAY (xpos, SI, N (s) + 1);
get_xpositions (s, xpos, xk);
int i= 0;
while (i < N (s)) {
int old= i;
tm_char_forwards (s, i);
draw_fixed (ren, s (old, i), x + xpos[old], y, false);
}
STACK_DELETE_ARRAY (xpos);
}
double
font_rep::get_left_slope (string s) {
(void) s;
return slope;
}
double
font_rep::get_right_slope (string s) {
(void) s;
return slope;
}
SI
font_rep::get_left_correction (string s) {
(void) s;
return 0;
}
SI
font_rep::get_right_correction (string s) {
(void) s;
return 0;
}
SI
font_rep::get_lsub_correction (string s) {
// cout << "lsub " << this->res_name << ", " << s << LF;
SI r= -get_left_correction (s) + global_lsub_correct;
if (lsub_correct->contains (s)) r+= (SI) (lsub_correct[s] * wfn);
else if (N (s) > 1 && is_alpha (s[0]) && lsub_correct->contains (s (0, 1)))
r+= (SI) (lsub_correct[s (0, 1)] * wfn);
return r;
}
SI
font_rep::get_lsup_correction (string s) {
// cout << "lsup " << this->res_name << ", " << s << LF;
// SI r= get_right_correction (s) + global_lsup_correct;
SI r= global_lsup_correct;
if (lsup_correct->contains (s)) r+= (SI) (lsup_correct[s] * wfn);
else if (N (s) > 1 && is_alpha (s[0]) && lsup_correct->contains (s (0, 1)))
r+= (SI) (lsup_correct[s (0, 1)] * wfn);
return r;
}
SI
font_rep::get_rsub_correction (string s) {
// cout << "rsub " << this->res_name << ", " << s << LF;
SI r= global_rsub_correct;
if (rsub_correct->contains (s)) r+= (SI) (rsub_correct[s] * wfn);
else if (N (s) > 1 && is_alpha (s[N (s) - 1]) &&
rsub_correct->contains (s (N (s) - 1, N (s))))
r+= (SI) (rsub_correct[s (N (s) - 1, N (s))] * wfn);
return r;
}
SI
font_rep::get_rsup_correction (string s) {
// cout << "rsup " << this->res_name << ", " << s << LF;
SI r= get_right_correction (s) + global_rsup_correct;
if (rsup_correct->contains (s)) r+= (SI) (rsup_correct[s] * wfn);
else if (N (s) > 1 && is_alpha (s[N (s) - 1]) &&
rsup_correct->contains (s (N (s) - 1, N (s))))
r+= (SI) (rsup_correct[s (N (s) - 1, N (s))] * wfn);
return r;
}
SI
font_rep::get_wide_correction (string s, int mode) {
if (mode > 0 && above_correct->contains (s))
return (SI) (above_correct[s] * wfn);
else if (mode < 0 && below_correct->contains (s))
return (SI) (below_correct[s] * wfn);
else return 0;
}
void
font_rep::get_extents (string s, metric& ex, bool ligf) {
if (ligf) get_extents (s, ex);
else get_extents (s, ex, 0);
}
void
font_rep::get_extents (string s, metric& ex, SI xk) {
get_extents (s, ex);
STACK_NEW_ARRAY (xpos, SI, N (s) + 1);
get_xpositions (s, xpos, xk);
SI d= xpos[N (s)] - ex->x2;
ex->x2+= d;
ex->x4+= d - xk;
STACK_DELETE_ARRAY (xpos);
}
void
font_rep::get_xpositions (string s, SI* xpos) {
int i= 0;
SI x= 0;
metric ex;
while (i < N (s)) {
if (s[i] == '<')
while ((i < N (s)) && (s[i] != '>')) {
i++;
xpos[i]= x;
}
if (i < N (s)) i++;
get_extents (s (0, i), ex);
x = ex->x2;
xpos[i]= x;
}
}
void
font_rep::get_xpositions (string s, SI* xpos, bool ligf) {
(void) ligf;
get_xpositions (s, xpos);
}
void
font_rep::get_xpositions (string s, SI* xpos, SI xk) {
get_xpositions (s, xpos, false);
int n= tm_string_length (s);
if (n == 0) return;
int i= 0, count= 0;
xpos[0]= xk;
while (i < N (s)) {
SI dx= (2 * count + 1) * xk;
if (s[i] == '<')
while ((i < N (s)) && (s[i] != '>')) {
i++;
xpos[i]+= dx;
}
if (i < N (s)) i++;
count++;
if (i == N (s)) dx= 2 * count * xk;
else dx= (2 * count + 1) * xk;
xpos[i]+= dx;
}
}
void
font_rep::var_get_extents (string s, metric& ex) {
bool flag = true;
int start= 0, end;
get_extents ("", ex);
while (start < N (s)) {
for (end= start; (end < N (s)) && (s[end] != ' '); end++) {
}
if (start < end) {
metric ey;
get_extents (s (start, end), ey);
if (flag) {
ex->x3= ey->x3 + ex->x2;
ex->y3= ey->y3 + ex->x2;
ex->x4= ey->x4;
ex->y4= ey->y4;
ex->x2+= ey->x2;
flag= false;
}
else {
ex->x3= min (ex->x3, ex->x2 + ey->x3);
ex->x4= max (ex->x4, ex->x2 + ey->x4);
ex->y3= min (ex->y3, ey->y3);
ex->y4= max (ex->y4, ey->y4);
ex->x2+= ey->x2;
}
}
for (; (end < N (s)) && (s[end] == ' '); end++)
ex->x2+= spc->def;
start= end;
}
}
void
font_rep::var_get_xpositions (string s, SI* xpos) {
(void) s;
(void) xpos;
TM_FAILED ("not yet implemented");
}
void
font_rep::var_draw (renderer ren, string s, SI x, SI y) {
SI dx = 0;
int start= 0, end;
while (start < N (s)) {
for (end= start; (end < N (s)) && (s[end] != ' '); end++) {
}
if (start < end) {
metric ex;
draw (ren, s (start, end), x + dx, y);
get_extents (s (start, end), ex);
dx+= ex->x2;
}
for (; (end < N (s)) && (s[end] == ' '); end++)
dx+= spc->def;
start= end;
}
}
// bool get_glyph_fatal= true;
bool get_glyph_fatal= false;
void
font_rep::advance_glyph (string s, int& pos, bool ligf) {
(void) ligf;
tm_char_forwards (s, pos);
}
glyph
font_rep::get_glyph (string s) {
if (get_glyph_fatal) {
failed_error << "glyph name: " << s << "\n";
failed_error << "font : " << res_name << "\n";
TM_FAILED ("no bitmap available");
}
else {
cout << "TeXmacs] warning, no bitmap available for " << s << "\n";
if (N (s) == 1)
cout << "TeXmacs] character code " << (int) (unsigned char) (s[0])
<< "\n";
cout << "TeXmacs] in font " << res_name << "\n";
}
return glyph (0, 0, 0, 0);
}
int
font_rep::index_glyph (string s, font_metric& fnm, font_glyphs& fng) {
(void) fnm;
(void) fng;
if (get_glyph_fatal) {
failed_error << "glyph name: " << s << "\n";
failed_error << "font : " << res_name << "\n";
TM_FAILED ("no bitmap available");
}
else {
cout << "TeXmacs] warning, no glyph index available for " << s << "\n";
if (N (s) == 1)
cout << "TeXmacs] character code " << (int) (unsigned char) (s[0])
<< "\n";
cout << "TeXmacs] in font " << res_name << "\n";
}
return -1;
}
font
font_rep::poor_magnify (double zoomx, double zoomy) {
return poor_stretched_font (this, zoomx, zoomy);
}
font
font_rep::magnify (double zoom) {
return magnify (zoom, zoom);
}
/******************************************************************************
* Error font: used to draw unindentified characters
******************************************************************************/
struct error_font_rep : font_rep {
font fn;
error_font_rep (string name, font fn);
bool supports (string c);
void get_extents (string s, metric& ex);
void get_xpositions (string s, SI* xpos);
void draw_fixed (renderer ren, string s, SI x, SI y);
font magnify (double zoomx, double zoomy);
};
error_font_rep::error_font_rep (string name, font fnb)
: font_rep (name, fnb), fn (fnb) {}
bool
error_font_rep::supports (string c) {
(void) c;
return true;
}
void
error_font_rep::get_extents (string s, metric& ex) {
fn->get_extents (s, ex);
}
void
error_font_rep::get_xpositions (string s, SI* xpos) {
fn->get_xpositions (s, xpos);
}
void
error_font_rep::draw_fixed (renderer ren, string s, SI x, SI y) {
ren->set_pencil (red);
fn->draw_fixed (ren, s, x, y);
}
font
error_font_rep::magnify (double zoomx, double zoomy) {
return error_font (fn->magnify (zoomx, zoomy));
}
font
error_font (font fn) {
string name= "error-" * fn->res_name;
return make (font, name, tm_new<error_font_rep> (name, fn));
}
/******************************************************************************
* System dependent fonts
******************************************************************************/
font
x_font (string family, double size, int dpi) {
(void) family;
(void) size;
(void) dpi;
return font ();
}
#ifndef QTTEXMACS
font
qt_font (string family, double size, int dpi) {
(void) family;
(void) size;
(void) dpi;
return font ();
}
#endif
/******************************************************************************
* Miscellaneous
******************************************************************************/
static hashmap<string, font> larger_font_table;
bool has_poor_rubber= true;
bool
use_poor_rubber (font fn) {
return has_poor_rubber && fn->type == FONT_TYPE_UNICODE &&
!starts (fn->res_name, "stix-");
}
font
font_rep::get_subfont (string s) {
(void) s;
return font (this);
}
font
font_rep::make_rubber_font (font fn) {
string name= locase_all (fn->res_name);
if (starts (name, "stix-") || starts (name, "stix,") ||
occurs (",stix,", name) || occurs ("math=stix", name) ||
occurs ("mathrubber=stix", name))
return rubber_stix_font (fn);
else if (occurs ("mathlarge=", name) || occurs ("mathrubber=", name))
return fn;
else if (has_poor_rubber && fn->type == FONT_TYPE_UNICODE)
return poor_rubber_font (fn);
else if (fn->type == FONT_TYPE_UNICODE) return rubber_unicode_font (fn);
else return fn;
}
font
rubber_font (font base) {
if (larger_font_table->contains (base->res_name))
return larger_font_table (base->res_name);
font larger = base->make_rubber_font (base);
larger_font_table (base->res_name)= larger;
return larger;
}
double
script (double sz, int level) {
bench_start ("font_script_calculation");
sz= normalize_half_multiple_size (sz);
if (level < 0) level= 0;
if (level > 2) level= 2;
for (int i= 0; i < level; i++)
sz= (sz * 2.0 + 2.0) / 3.0; // 浮点除法,保持精度
// 输出可能不是0.5倍数,但这是设计允许的
bench_cumul ("font_script_calculation");
return sz;
}
string
default_chinese_font_name () {
if (has_user_preference ("default chinese font name")) {
return get_user_preference ("default chinese font name");
}
// Noto CJK SC is the default Chinese font on all system if exists
if (tt_font_exists ("NotoSerifCJK-Regular")) return "Noto CJK SC";
#if defined(OS_MINGW) || defined(OS_WIN)
// Set default Chinese font for Windows
// see: https://docs.microsoft.com/en-us/typography/fonts/windows_10_font_list
if (tt_font_exists ("simsun")) return "simsun";
#endif
#ifdef OS_MACOS
// Set default Chinese font for macOS
// see: https://developer.apple.com/fonts/system-fonts/
if (tt_font_exists ("Songti")) return "Songti SC";
#endif
return "roman";
}
string
default_japanese_font_name () {
if (has_user_preference ("default japanese font name")) {
return get_user_preference ("default japanese font name");
}
if (tt_font_exists ("NotoSerifCJK-Regular")) return "Noto CJK JP";
#ifdef OS_MACOS
// Set default Japanese font for macOS
// see: https://developer.apple.com/fonts/system-fonts/
if (tt_font_exists ("ヒラギノ角ゴシック W3"))
return "Hiragino Kaku Gothic ProN";
#endif
#if defined(OS_MINGW) || defined(OS_WIN)
if (tt_font_exists ("msmincho")) return "MS PMincho";
#endif
return "roman";
}
string
default_korean_font_name () {
if (has_user_preference ("default korean font name")) {
return get_user_preference ("default korean font name");
}
if (tt_font_exists ("NotoSerifCJK-Regular")) return "Noto CJK KR";
#ifdef OS_MACOS
// Set default Korean font for macOS
// see: https://developer.apple.com/fonts/system-fonts/
if (tt_font_exists ("AppleSDGothicNeo")) return "Apple SD Gothic Neo";
#endif
#if defined(OS_MINGW) || defined(OS_WIN)
if (tt_font_exists ("batang")) return "Batang";
#endif
return "roman";
}
string
default_emoji_font_name () {
if (has_user_preference ("default emoji font name")) {
return get_user_preference ("default emoji font name");
}
// Noto Color Emoji is the default emoji font on all system if exists
if (tt_font_exists ("Mogan-NotoColorEmoji")) return "Noto Color Emoji";
return "roman";
}
bool
use_macos_fonts () {
#ifdef OS_MACOS
return true;
#else
return false;
#endif
}
pair<string, int>
font_name_unpack (string font_name) {
int face_index = 0;
string font_basename= basename (url_system (font_name));
// Extract the subfont_index if exists
string face_index_str= suffix (url_system (font_name));
if (is_int (face_index_str)) {
face_index= as_int (face_index_str);
}
return pair (font_basename, face_index);
}