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 7bb418eb..86ac709b 100644 --- a/src/ui/text.c +++ b/src/ui/text.c | |||
@@ -247,8 +247,6 @@ struct Impl_CacheRow { | |||
247 | }; | 247 | }; |
248 | 248 | ||
249 | struct Impl_Text { | 249 | struct Impl_Text { |
250 | // enum iTextFont contentFont; | ||
251 | // enum iTextFont headingFont; | ||
252 | float contentFontSize; | 250 | float contentFontSize; |
253 | iArray fonts; /* fonts currently selected for use (incl. all styles/sizes) */ | 251 | iArray fonts; /* fonts currently selected for use (incl. all styles/sizes) */ |
254 | int overrideFontId; /* always checked for glyphs first, regardless of which font is used */ | 252 | int overrideFontId; /* always checked for glyphs first, regardless of which font is used */ |
@@ -264,7 +262,8 @@ struct Impl_Text { | |||
264 | int ansiFlags; | 262 | int ansiFlags; |
265 | int baseFontId; /* base attributes (for restoring via escapes) */ | 263 | int baseFontId; /* base attributes (for restoring via escapes) */ |
266 | int baseFgColorId; | 264 | int baseFgColorId; |
267 | iBool missingGlyphs; /* true if a glyph couldn't be found */ | 265 | iBool missingGlyphs; /* true if a glyph couldn't be found */ |
266 | iChar missingChars[20]; /* rotating buffer of the latest missing characters */ | ||
268 | }; | 267 | }; |
269 | 268 | ||
270 | iDefineTypeConstructionArgs(Text, (SDL_Renderer *render), render) | 269 | iDefineTypeConstructionArgs(Text, (SDL_Renderer *render), render) |
@@ -341,6 +340,8 @@ static void initFonts_Text_(iText *d) { | |||
341 | printf("[Text] %zu font variants ready\n", size_Array(&d->fonts)); | 340 | printf("[Text] %zu font variants ready\n", size_Array(&d->fonts)); |
342 | #endif | 341 | #endif |
343 | gap_Text = iRound(gap_UI * d->contentFontSize); | 342 | gap_Text = iRound(gap_UI * d->contentFontSize); |
343 | // d->missingGlyphs = iFalse; | ||
344 | // iZap(d->missingChars); | ||
344 | } | 345 | } |
345 | 346 | ||
346 | static void deinitFonts_Text_(iText *d) { | 347 | static void deinitFonts_Text_(iText *d) { |
@@ -403,6 +404,7 @@ void init_Text(iText *d, SDL_Renderer *render) { | |||
403 | d->baseFontId = -1; | 404 | d->baseFontId = -1; |
404 | d->baseFgColorId = -1; | 405 | d->baseFgColorId = -1; |
405 | d->missingGlyphs = iFalse; | 406 | d->missingGlyphs = iFalse; |
407 | iZap(d->missingChars); | ||
406 | d->render = render; | 408 | d->render = render; |
407 | /* A grayscale palette for rasterized glyphs. */ { | 409 | /* A grayscale palette for rasterized glyphs. */ { |
408 | SDL_Color colors[256]; | 410 | SDL_Color colors[256]; |
@@ -589,8 +591,23 @@ iLocalDef iFont *characterFont_Font_(iFont *d, iChar ch, uint32_t *glyphIndex) { | |||
589 | } | 591 | } |
590 | } | 592 | } |
591 | if (!*glyphIndex) { | 593 | if (!*glyphIndex) { |
592 | activeText_->missingGlyphs = iTrue; | 594 | fprintf(stderr, "failed to find %08x (%lc)\n", ch, (int) ch); fflush(stderr); |
593 | fprintf(stderr, "failed to find %08x (%lc)\n", ch, (int)ch); fflush(stderr); | 595 | iText *tx = activeText_; |
596 | tx->missingGlyphs = iTrue; | ||
597 | /* Remember a few of the latest missing characters. */ | ||
598 | iBool gotIt = iFalse; | ||
599 | for (size_t i = 0; i < iElemCount(tx->missingChars); i++) { | ||
600 | if (tx->missingChars[i] == ch) { | ||
601 | gotIt = iTrue; | ||
602 | break; | ||
603 | } | ||
604 | } | ||
605 | if (!gotIt) { | ||
606 | memmove(tx->missingChars + 1, | ||
607 | tx->missingChars, | ||
608 | sizeof(tx->missingChars) - sizeof(tx->missingChars[0])); | ||
609 | tx->missingChars[0] = ch; | ||
610 | } | ||
594 | } | 611 | } |
595 | return d; | 612 | return d; |
596 | } | 613 | } |
@@ -2199,6 +2216,19 @@ iBool checkMissing_Text(void) { | |||
2199 | return missing; | 2216 | return missing; |
2200 | } | 2217 | } |
2201 | 2218 | ||
2219 | iChar missing_Text(size_t index) { | ||
2220 | const iText *d = activeText_; | ||
2221 | if (index >= iElemCount(d->missingChars)) { | ||
2222 | return 0; | ||
2223 | } | ||
2224 | return d->missingChars[index]; | ||
2225 | } | ||
2226 | |||
2227 | void resetMissing_Text(iText *d) { | ||
2228 | d->missingGlyphs = iFalse; | ||
2229 | iZap(d->missingChars); | ||
2230 | } | ||
2231 | |||
2202 | SDL_Texture *glyphCache_Text(void) { | 2232 | SDL_Texture *glyphCache_Text(void) { |
2203 | return activeText_->cache; | 2233 | return activeText_->cache; |
2204 | } | 2234 | } |