mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-06-19 19:49:30 +01:00
Change: [UI] Remove substitution of missing glyph with '?' glyph. (#12736)
When a glyph does not exist, we substitute it with the '?' glyph instead, but layouters are not aware of this substitution.
This commit is contained in:
parent
9c19cf06e4
commit
de16655f76
@ -46,7 +46,6 @@ void TrueTypeFontCache::ClearFontCache()
|
|||||||
if (this->glyph_to_sprite[i] == nullptr) continue;
|
if (this->glyph_to_sprite[i] == nullptr) continue;
|
||||||
|
|
||||||
for (int j = 0; j < 256; j++) {
|
for (int j = 0; j < 256; j++) {
|
||||||
if (this->glyph_to_sprite[i][j].duplicate) continue;
|
|
||||||
free(this->glyph_to_sprite[i][j].sprite);
|
free(this->glyph_to_sprite[i][j].sprite);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,7 +66,7 @@ TrueTypeFontCache::GlyphEntry *TrueTypeFontCache::GetGlyphPtr(GlyphID key)
|
|||||||
return &this->glyph_to_sprite[GB(key, 8, 8)][GB(key, 0, 8)];
|
return &this->glyph_to_sprite[GB(key, 8, 8)][GB(key, 0, 8)];
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrueTypeFontCache::SetGlyphPtr(GlyphID key, const GlyphEntry *glyph, bool duplicate)
|
void TrueTypeFontCache::SetGlyphPtr(GlyphID key, const GlyphEntry *glyph)
|
||||||
{
|
{
|
||||||
if (this->glyph_to_sprite == nullptr) {
|
if (this->glyph_to_sprite == nullptr) {
|
||||||
Debug(fontcache, 3, "Allocating root glyph cache for size {}", this->fs);
|
Debug(fontcache, 3, "Allocating root glyph cache for size {}", this->fs);
|
||||||
@ -82,7 +81,6 @@ void TrueTypeFontCache::SetGlyphPtr(GlyphID key, const GlyphEntry *glyph, bool d
|
|||||||
Debug(fontcache, 4, "Set glyph for unicode character 0x{:04X}, size {}", key, this->fs);
|
Debug(fontcache, 4, "Set glyph for unicode character 0x{:04X}, size {}", key, this->fs);
|
||||||
this->glyph_to_sprite[GB(key, 8, 8)][GB(key, 0, 8)].sprite = glyph->sprite;
|
this->glyph_to_sprite[GB(key, 8, 8)][GB(key, 0, 8)].sprite = glyph->sprite;
|
||||||
this->glyph_to_sprite[GB(key, 8, 8)][GB(key, 0, 8)].width = glyph->width;
|
this->glyph_to_sprite[GB(key, 8, 8)][GB(key, 0, 8)].width = glyph->width;
|
||||||
this->glyph_to_sprite[GB(key, 8, 8)][GB(key, 0, 8)].duplicate = duplicate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TrueTypeFontCache::GetDrawGlyphShadow()
|
bool TrueTypeFontCache::GetDrawGlyphShadow()
|
||||||
@ -111,52 +109,5 @@ const Sprite *TrueTypeFontCache::GetGlyph(GlyphID key)
|
|||||||
GlyphEntry *glyph = this->GetGlyphPtr(key);
|
GlyphEntry *glyph = this->GetGlyphPtr(key);
|
||||||
if (glyph != nullptr && glyph->sprite != nullptr) return glyph->sprite;
|
if (glyph != nullptr && glyph->sprite != nullptr) return glyph->sprite;
|
||||||
|
|
||||||
if (key == 0) {
|
|
||||||
GlyphID question_glyph = this->MapCharToGlyph('?');
|
|
||||||
if (question_glyph == 0) {
|
|
||||||
/* The font misses the '?' character. Use built-in sprite.
|
|
||||||
* Note: We cannot use the baseset as this also has to work in the bootstrap GUI. */
|
|
||||||
#define CPSET { 0, 0, 0, 0, 1 }
|
|
||||||
#define CP___ { 0, 0, 0, 0, 0 }
|
|
||||||
static SpriteLoader::CommonPixel builtin_questionmark_data[10 * 8] = {
|
|
||||||
CP___, CP___, CPSET, CPSET, CPSET, CPSET, CP___, CP___,
|
|
||||||
CP___, CPSET, CPSET, CP___, CP___, CPSET, CPSET, CP___,
|
|
||||||
CP___, CP___, CP___, CP___, CP___, CPSET, CPSET, CP___,
|
|
||||||
CP___, CP___, CP___, CP___, CPSET, CPSET, CP___, CP___,
|
|
||||||
CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, CP___,
|
|
||||||
CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, CP___,
|
|
||||||
CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, CP___,
|
|
||||||
CP___, CP___, CP___, CP___, CP___, CP___, CP___, CP___,
|
|
||||||
CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, CP___,
|
|
||||||
CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, CP___,
|
|
||||||
};
|
|
||||||
#undef CPSET
|
|
||||||
#undef CP___
|
|
||||||
static const SpriteLoader::SpriteCollection builtin_questionmark = {{ {
|
|
||||||
10, // height
|
|
||||||
8, // width
|
|
||||||
0, // x_offs
|
|
||||||
0, // y_offs
|
|
||||||
SpriteType::Font,
|
|
||||||
SCC_PAL,
|
|
||||||
builtin_questionmark_data
|
|
||||||
} }};
|
|
||||||
|
|
||||||
Sprite *spr = BlitterFactory::GetCurrentBlitter()->Encode(builtin_questionmark, SimpleSpriteAlloc);
|
|
||||||
assert(spr != nullptr);
|
|
||||||
GlyphEntry new_glyph;
|
|
||||||
new_glyph.sprite = spr;
|
|
||||||
new_glyph.width = spr->width + (this->fs != FS_NORMAL);
|
|
||||||
this->SetGlyphPtr(key, &new_glyph, false);
|
|
||||||
return new_glyph.sprite;
|
|
||||||
} else {
|
|
||||||
/* Use '?' for missing characters. */
|
|
||||||
this->GetGlyph(question_glyph);
|
|
||||||
glyph = this->GetGlyphPtr(question_glyph);
|
|
||||||
this->SetGlyphPtr(key, glyph, true);
|
|
||||||
return glyph->sprite;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return this->InternalGetGlyph(key, GetFontAAState());
|
return this->InternalGetGlyph(key, GetFontAAState());
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,7 @@ protected:
|
|||||||
/** Container for information about a glyph. */
|
/** Container for information about a glyph. */
|
||||||
struct GlyphEntry {
|
struct GlyphEntry {
|
||||||
Sprite *sprite; ///< The loaded sprite.
|
Sprite *sprite; ///< The loaded sprite.
|
||||||
uint8_t width; ///< The width of the glyph.
|
uint8_t width; ///< The width of the glyph.
|
||||||
bool duplicate; ///< Whether this glyph entry is a duplicate, i.e. may this be freed?
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,7 +49,7 @@ protected:
|
|||||||
GlyphEntry **glyph_to_sprite;
|
GlyphEntry **glyph_to_sprite;
|
||||||
|
|
||||||
GlyphEntry *GetGlyphPtr(GlyphID key);
|
GlyphEntry *GetGlyphPtr(GlyphID key);
|
||||||
void SetGlyphPtr(GlyphID key, const GlyphEntry *glyph, bool duplicate = false);
|
void SetGlyphPtr(GlyphID key, const GlyphEntry *glyph);
|
||||||
|
|
||||||
virtual const Sprite *InternalGetGlyph(GlyphID key, bool aa) = 0;
|
virtual const Sprite *InternalGetGlyph(GlyphID key, bool aa) = 0;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user