diff options
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/text.c | 45 | ||||
-rw-r--r-- | src/ui/text.h | 9 |
2 files changed, 47 insertions, 7 deletions
diff --git a/src/ui/text.c b/src/ui/text.c index 08c89e47..7f784dec 100644 --- a/src/ui/text.c +++ b/src/ui/text.c | |||
@@ -80,9 +80,9 @@ iChar char_Glyph(const iGlyph *d) { | |||
80 | 80 | ||
81 | iDefineTypeConstructionArgs(Glyph, (iChar ch), ch) | 81 | iDefineTypeConstructionArgs(Glyph, (iChar ch), ch) |
82 | 82 | ||
83 | /*-----------------------------------------------------------------------------------------------*/ | 83 | /*-----------------------------------------------------------------------------------------------*/ |
84 | 84 | ||
85 | struct Impl_Font { | 85 | struct Impl_Font { |
86 | iBlock * data; | 86 | iBlock * data; |
87 | stbtt_fontinfo font; | 87 | stbtt_fontinfo font; |
88 | float scale; | 88 | float scale; |
@@ -92,8 +92,9 @@ struct Impl_Font { | |||
92 | iHash glyphs; | 92 | iHash glyphs; |
93 | iBool isMonospaced; | 93 | iBool isMonospaced; |
94 | iBool manualKernOnly; | 94 | iBool manualKernOnly; |
95 | enum iFontId symbolsFont; /* font to use for symbols */ | 95 | enum iFontId symbolsFont; /* font to use for symbols */ |
96 | enum iFontId japaneseFont; /* font to use for Japanese glyphs */ | 96 | enum iFontId japaneseFont; /* font to use for Japanese glyphs */ |
97 | enum iFontId koreanFont; /* font to use for Korean glyphs */ | ||
97 | uint32_t indexTable[128 - 32]; | 98 | uint32_t indexTable[128 - 32]; |
98 | }; | 99 | }; |
99 | 100 | ||
@@ -109,9 +110,10 @@ static void init_Font(iFont *d, const iBlock *data, int height, float scale, enu | |||
109 | d->vertOffset = height * (1.0f - scale) / 2; | 110 | d->vertOffset = height * (1.0f - scale) / 2; |
110 | int ascent; | 111 | int ascent; |
111 | stbtt_GetFontVMetrics(&d->font, &ascent, NULL, NULL); | 112 | stbtt_GetFontVMetrics(&d->font, &ascent, NULL, NULL); |
112 | d->baseline = (int) ascent * d->scale; | 113 | d->baseline = (int) ascent * d->scale; |
113 | d->symbolsFont = symbolsFont; | 114 | d->symbolsFont = symbolsFont; |
114 | d->japaneseFont = regularJapanese_FontId; | 115 | d->japaneseFont = regularJapanese_FontId; |
116 | d->koreanFont = regularKorean_FontId; | ||
115 | d->isMonospaced = iFalse; | 117 | d->isMonospaced = iFalse; |
116 | memset(d->indexTable, 0xff, sizeof(d->indexTable)); | 118 | memset(d->indexTable, 0xff, sizeof(d->indexTable)); |
117 | } | 119 | } |
@@ -247,6 +249,15 @@ static void initFonts_Text_(iText *d) { | |||
247 | { &fontKosugiMaruRegular_Embedded, textSize * 1.333f, 1.0f, bigSymbols_FontId }, | 249 | { &fontKosugiMaruRegular_Embedded, textSize * 1.333f, 1.0f, bigSymbols_FontId }, |
248 | { &fontKosugiMaruRegular_Embedded, textSize * 1.666f, 1.0f, largeSymbols_FontId }, | 250 | { &fontKosugiMaruRegular_Embedded, textSize * 1.666f, 1.0f, largeSymbols_FontId }, |
249 | { &fontKosugiMaruRegular_Embedded, textSize * 2.000f, 1.0f, hugeSymbols_FontId }, | 251 | { &fontKosugiMaruRegular_Embedded, textSize * 2.000f, 1.0f, hugeSymbols_FontId }, |
252 | /* korean fonts */ | ||
253 | { &fontNanumGothicRegular_Embedded, fontSize_UI, 1.0f, defaultSymbols_FontId }, | ||
254 | { &fontNanumGothicRegular_Embedded, monoSize * 0.750, 1.0f, monospaceSmallSymbols_FontId }, | ||
255 | { &fontNanumGothicRegular_Embedded, monoSize, 1.0f, monospaceSymbols_FontId }, | ||
256 | { &fontNanumGothicRegular_Embedded, textSize, 1.0f, symbols_FontId }, | ||
257 | { &fontNanumGothicRegular_Embedded, textSize * 1.200f, 1.0f, mediumSymbols_FontId }, | ||
258 | { &fontNanumGothicRegular_Embedded, textSize * 1.333f, 1.0f, bigSymbols_FontId }, | ||
259 | { &fontNanumGothicRegular_Embedded, textSize * 1.666f, 1.0f, largeSymbols_FontId }, | ||
260 | { &fontNanumGothicRegular_Embedded, textSize * 2.000f, 1.0f, hugeSymbols_FontId }, | ||
250 | }; | 261 | }; |
251 | iForIndices(i, fontData) { | 262 | iForIndices(i, fontData) { |
252 | iFont *font = &d->fonts[i]; | 263 | iFont *font = &d->fonts[i]; |
@@ -262,7 +273,6 @@ static void initFonts_Text_(iText *d) { | |||
262 | /* Japanese script. */ { | 273 | /* Japanese script. */ { |
263 | /* Everything defaults to the regular sized japanese font, so these are just | 274 | /* Everything defaults to the regular sized japanese font, so these are just |
264 | the other sizes. */ | 275 | the other sizes. */ |
265 | /* TODO: Add these to the table above... */ | ||
266 | font_Text_(default_FontId)->japaneseFont = defaultJapanese_FontId; | 276 | font_Text_(default_FontId)->japaneseFont = defaultJapanese_FontId; |
267 | font_Text_(defaultMedium_FontId)->japaneseFont = defaultJapanese_FontId; | 277 | font_Text_(defaultMedium_FontId)->japaneseFont = defaultJapanese_FontId; |
268 | font_Text_(defaultMonospace_FontId)->japaneseFont = defaultJapanese_FontId; | 278 | font_Text_(defaultMonospace_FontId)->japaneseFont = defaultJapanese_FontId; |
@@ -270,11 +280,22 @@ static void initFonts_Text_(iText *d) { | |||
270 | font_Text_(monospace_FontId)->japaneseFont = monospaceJapanese_FontId; | 280 | font_Text_(monospace_FontId)->japaneseFont = monospaceJapanese_FontId; |
271 | font_Text_(medium_FontId)->japaneseFont = mediumJapanese_FontId; | 281 | font_Text_(medium_FontId)->japaneseFont = mediumJapanese_FontId; |
272 | font_Text_(big_FontId)->japaneseFont = bigJapanese_FontId; | 282 | font_Text_(big_FontId)->japaneseFont = bigJapanese_FontId; |
273 | // font_Text_(bigBold_FontId)->japaneseFont = bigJapanese_FontId; | ||
274 | font_Text_(largeBold_FontId)->japaneseFont = largeJapanese_FontId; | 283 | font_Text_(largeBold_FontId)->japaneseFont = largeJapanese_FontId; |
275 | font_Text_(largeLight_FontId)->japaneseFont = largeJapanese_FontId; | 284 | font_Text_(largeLight_FontId)->japaneseFont = largeJapanese_FontId; |
276 | font_Text_(hugeBold_FontId)->japaneseFont = hugeJapanese_FontId; | 285 | font_Text_(hugeBold_FontId)->japaneseFont = hugeJapanese_FontId; |
277 | } | 286 | } |
287 | /* Korean script. */ { | ||
288 | font_Text_(default_FontId)->koreanFont = defaultKorean_FontId; | ||
289 | font_Text_(defaultMedium_FontId)->koreanFont = defaultKorean_FontId; | ||
290 | font_Text_(defaultMonospace_FontId)->koreanFont = defaultKorean_FontId; | ||
291 | font_Text_(monospaceSmall_FontId)->koreanFont = monospaceSmallKorean_FontId; | ||
292 | font_Text_(monospace_FontId)->koreanFont = monospaceKorean_FontId; | ||
293 | font_Text_(medium_FontId)->koreanFont = mediumKorean_FontId; | ||
294 | font_Text_(big_FontId)->koreanFont = bigKorean_FontId; | ||
295 | font_Text_(largeBold_FontId)->koreanFont = largeKorean_FontId; | ||
296 | font_Text_(largeLight_FontId)->koreanFont = largeKorean_FontId; | ||
297 | font_Text_(hugeBold_FontId)->koreanFont = hugeKorean_FontId; | ||
298 | } | ||
278 | gap_Text = iRound(gap_UI * d->contentFontSize); | 299 | gap_Text = iRound(gap_UI * d->contentFontSize); |
279 | } | 300 | } |
280 | 301 | ||
@@ -491,6 +512,13 @@ iLocalDef iFont *characterFont_Font_(iFont *d, iChar ch, uint32_t *glyphIndex) { | |||
491 | return emoji; | 512 | return emoji; |
492 | } | 513 | } |
493 | } | 514 | } |
515 | /* Could be Korean. */ | ||
516 | if (ch > 0x3000) { | ||
517 | iFont *korean = font_Text_(d->koreanFont); | ||
518 | if (korean != d && (*glyphIndex = glyphIndex_Font_(korean, ch)) != 0) { | ||
519 | return korean; | ||
520 | } | ||
521 | } | ||
494 | /* Japanese perhaps? */ | 522 | /* Japanese perhaps? */ |
495 | if (ch > 0x3040) { | 523 | if (ch > 0x3040) { |
496 | iFont *japanese = font_Text_(d->japaneseFont); | 524 | iFont *japanese = font_Text_(d->japaneseFont); |
@@ -501,6 +529,9 @@ iLocalDef iFont *characterFont_Font_(iFont *d, iChar ch, uint32_t *glyphIndex) { | |||
501 | /* Fall back to Symbola for anything else. */ | 529 | /* Fall back to Symbola for anything else. */ |
502 | iFont *font = font_Text_(d->symbolsFont); | 530 | iFont *font = font_Text_(d->symbolsFont); |
503 | *glyphIndex = glyphIndex_Font_(font, ch); | 531 | *glyphIndex = glyphIndex_Font_(font, ch); |
532 | if (!*glyphIndex) { | ||
533 | fprintf(stderr, "failed to find %08x (%lc)\n", ch, ch); fflush(stderr); | ||
534 | } | ||
504 | return font; | 535 | return font; |
505 | } | 536 | } |
506 | 537 | ||
diff --git a/src/ui/text.h b/src/ui/text.h index 87f69300..35f48528 100644 --- a/src/ui/text.h +++ b/src/ui/text.h | |||
@@ -72,6 +72,15 @@ enum iFontId { | |||
72 | bigJapanese_FontId, | 72 | bigJapanese_FontId, |
73 | largeJapanese_FontId, | 73 | largeJapanese_FontId, |
74 | hugeJapanese_FontId, | 74 | hugeJapanese_FontId, |
75 | /* korean script */ | ||
76 | defaultKorean_FontId, | ||
77 | monospaceSmallKorean_FontId, | ||
78 | monospaceKorean_FontId, | ||
79 | regularKorean_FontId, | ||
80 | mediumKorean_FontId, | ||
81 | bigKorean_FontId, | ||
82 | largeKorean_FontId, | ||
83 | hugeKorean_FontId, | ||
75 | max_FontId, | 84 | max_FontId, |
76 | 85 | ||
77 | /* Meta: */ | 86 | /* Meta: */ |