diff options
Diffstat (limited to 'src/ui/text.c')
-rw-r--r-- | src/ui/text.c | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/src/ui/text.c b/src/ui/text.c index c19aed2f..51531057 100644 --- a/src/ui/text.c +++ b/src/ui/text.c | |||
@@ -258,8 +258,6 @@ static int cmp_PrioMapItem_(const void *a, const void *b) { | |||
258 | } | 258 | } |
259 | 259 | ||
260 | struct Impl_Text { | 260 | struct Impl_Text { |
261 | // enum iTextFont contentFont; | ||
262 | // enum iTextFont headingFont; | ||
263 | float contentFontSize; | 261 | float contentFontSize; |
264 | iArray fonts; /* fonts currently selected for use (incl. all styles/sizes) */ | 262 | iArray fonts; /* fonts currently selected for use (incl. all styles/sizes) */ |
265 | int overrideFontId; /* always checked for glyphs first, regardless of which font is used */ | 263 | int overrideFontId; /* always checked for glyphs first, regardless of which font is used */ |
@@ -276,7 +274,8 @@ struct Impl_Text { | |||
276 | int ansiFlags; | 274 | int ansiFlags; |
277 | int baseFontId; /* base attributes (for restoring via escapes) */ | 275 | int baseFontId; /* base attributes (for restoring via escapes) */ |
278 | int baseFgColorId; | 276 | int baseFgColorId; |
279 | iBool missingGlyphs; /* true if a glyph couldn't be found */ | 277 | iBool missingGlyphs; /* true if a glyph couldn't be found */ |
278 | iChar missingChars[20]; /* rotating buffer of the latest missing characters */ | ||
280 | }; | 279 | }; |
281 | 280 | ||
282 | iDefineTypeConstructionArgs(Text, (SDL_Renderer *render), render) | 281 | iDefineTypeConstructionArgs(Text, (SDL_Renderer *render), render) |
@@ -357,6 +356,8 @@ static void initFonts_Text_(iText *d) { | |||
357 | printf("[Text] %zu font variants ready\n", size_Array(&d->fonts)); | 356 | printf("[Text] %zu font variants ready\n", size_Array(&d->fonts)); |
358 | #endif | 357 | #endif |
359 | gap_Text = iRound(gap_UI * d->contentFontSize); | 358 | gap_Text = iRound(gap_UI * d->contentFontSize); |
359 | // d->missingGlyphs = iFalse; | ||
360 | // iZap(d->missingChars); | ||
360 | } | 361 | } |
361 | 362 | ||
362 | static void deinitFonts_Text_(iText *d) { | 363 | static void deinitFonts_Text_(iText *d) { |
@@ -424,6 +425,7 @@ void init_Text(iText *d, SDL_Renderer *render) { | |||
424 | d->baseFontId = -1; | 425 | d->baseFontId = -1; |
425 | d->baseFgColorId = -1; | 426 | d->baseFgColorId = -1; |
426 | d->missingGlyphs = iFalse; | 427 | d->missingGlyphs = iFalse; |
428 | iZap(d->missingChars); | ||
427 | d->render = render; | 429 | d->render = render; |
428 | /* A grayscale palette for rasterized glyphs. */ { | 430 | /* A grayscale palette for rasterized glyphs. */ { |
429 | SDL_Color colors[256]; | 431 | SDL_Color colors[256]; |
@@ -610,8 +612,23 @@ iLocalDef iFont *characterFont_Font_(iFont *d, iChar ch, uint32_t *glyphIndex) { | |||
610 | } | 612 | } |
611 | } | 613 | } |
612 | if (!*glyphIndex) { | 614 | if (!*glyphIndex) { |
613 | activeText_->missingGlyphs = iTrue; | 615 | fprintf(stderr, "failed to find %08x (%lc)\n", ch, (int) ch); fflush(stderr); |
614 | fprintf(stderr, "failed to find %08x (%lc)\n", ch, (int)ch); fflush(stderr); | 616 | iText *tx = activeText_; |
617 | tx->missingGlyphs = iTrue; | ||
618 | /* Remember a few of the latest missing characters. */ | ||
619 | iBool gotIt = iFalse; | ||
620 | for (size_t i = 0; i < iElemCount(tx->missingChars); i++) { | ||
621 | if (tx->missingChars[i] == ch) { | ||
622 | gotIt = iTrue; | ||
623 | break; | ||
624 | } | ||
625 | } | ||
626 | if (!gotIt) { | ||
627 | memmove(tx->missingChars + 1, | ||
628 | tx->missingChars, | ||
629 | sizeof(tx->missingChars) - sizeof(tx->missingChars[0])); | ||
630 | tx->missingChars[0] = ch; | ||
631 | } | ||
615 | } | 632 | } |
616 | return d; | 633 | return d; |
617 | } | 634 | } |
@@ -2250,6 +2267,19 @@ iBool checkMissing_Text(void) { | |||
2250 | return missing; | 2267 | return missing; |
2251 | } | 2268 | } |
2252 | 2269 | ||
2270 | iChar missing_Text(size_t index) { | ||
2271 | const iText *d = activeText_; | ||
2272 | if (index >= iElemCount(d->missingChars)) { | ||
2273 | return 0; | ||
2274 | } | ||
2275 | return d->missingChars[index]; | ||
2276 | } | ||
2277 | |||
2278 | void resetMissing_Text(iText *d) { | ||
2279 | d->missingGlyphs = iFalse; | ||
2280 | iZap(d->missingChars); | ||
2281 | } | ||
2282 | |||
2253 | SDL_Texture *glyphCache_Text(void) { | 2283 | SDL_Texture *glyphCache_Text(void) { |
2254 | return activeText_->cache; | 2284 | return activeText_->cache; |
2255 | } | 2285 | } |