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 200108ed..ab2af2b2 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) { |
@@ -407,6 +408,7 @@ void init_Text(iText *d, SDL_Renderer *render) { | |||
407 | d->baseFontId = -1; | 408 | d->baseFontId = -1; |
408 | d->baseFgColorId = -1; | 409 | d->baseFgColorId = -1; |
409 | d->missingGlyphs = iFalse; | 410 | d->missingGlyphs = iFalse; |
411 | iZap(d->missingChars); | ||
410 | d->render = render; | 412 | d->render = render; |
411 | /* A grayscale palette for rasterized glyphs. */ { | 413 | /* A grayscale palette for rasterized glyphs. */ { |
412 | SDL_Color colors[256]; | 414 | SDL_Color colors[256]; |
@@ -593,8 +595,23 @@ iLocalDef iFont *characterFont_Font_(iFont *d, iChar ch, uint32_t *glyphIndex) { | |||
593 | } | 595 | } |
594 | } | 596 | } |
595 | if (!*glyphIndex) { | 597 | if (!*glyphIndex) { |
596 | activeText_->missingGlyphs = iTrue; | 598 | fprintf(stderr, "failed to find %08x (%lc)\n", ch, (int) ch); fflush(stderr); |
597 | fprintf(stderr, "failed to find %08x (%lc)\n", ch, (int)ch); fflush(stderr); | 599 | iText *tx = activeText_; |
600 | tx->missingGlyphs = iTrue; | ||
601 | /* Remember a few of the latest missing characters. */ | ||
602 | iBool gotIt = iFalse; | ||
603 | for (size_t i = 0; i < iElemCount(tx->missingChars); i++) { | ||
604 | if (tx->missingChars[i] == ch) { | ||
605 | gotIt = iTrue; | ||
606 | break; | ||
607 | } | ||
608 | } | ||
609 | if (!gotIt) { | ||
610 | memmove(tx->missingChars + 1, | ||
611 | tx->missingChars, | ||
612 | sizeof(tx->missingChars) - sizeof(tx->missingChars[0])); | ||
613 | tx->missingChars[0] = ch; | ||
614 | } | ||
598 | } | 615 | } |
599 | return d; | 616 | return d; |
600 | } | 617 | } |
@@ -2233,6 +2250,19 @@ iBool checkMissing_Text(void) { | |||
2233 | return missing; | 2250 | return missing; |
2234 | } | 2251 | } |
2235 | 2252 | ||
2253 | iChar missing_Text(size_t index) { | ||
2254 | const iText *d = activeText_; | ||
2255 | if (index >= iElemCount(d->missingChars)) { | ||
2256 | return 0; | ||
2257 | } | ||
2258 | return d->missingChars[index]; | ||
2259 | } | ||
2260 | |||
2261 | void resetMissing_Text(iText *d) { | ||
2262 | d->missingGlyphs = iFalse; | ||
2263 | iZap(d->missingChars); | ||
2264 | } | ||
2265 | |||
2236 | SDL_Texture *glyphCache_Text(void) { | 2266 | SDL_Texture *glyphCache_Text(void) { |
2237 | return activeText_->cache; | 2267 | return activeText_->cache; |
2238 | } | 2268 | } |