void InitializeUnicodeGlyphMap() { for (FontSize size = FS_BEGIN; size != FS_END; size++) { /* Clear out existing glyph map if it exists */ if (_unicode_glyph_map[size] != NULL) { for (uint i = 0; i < 256; i++) { free(_unicode_glyph_map[size][i]); } free(_unicode_glyph_map[size]); _unicode_glyph_map[size] = NULL; } SpriteID base = GetFontBase(size); for (uint i = ASCII_LETTERSTART; i < 256; i++) { SpriteID sprite = base + i - ASCII_LETTERSTART; if (!SpriteExists(sprite)) continue; SetUnicodeGlyph(size, i, sprite); SetUnicodeGlyph(size, i + SCC_SPRITE_START, sprite); } for (uint i = 0; i < lengthof(_default_unicode_map); i++) { byte key = _default_unicode_map[i].key; if (key == CLRA) { /* Clear the glyph. This happens if the glyph at this code point * is non-standard and should be accessed by an SCC_xxx enum * entry only. */ SetUnicodeGlyph(size, _default_unicode_map[i].code, 0); } else { SpriteID sprite = base + key - ASCII_LETTERSTART; SetUnicodeGlyph(size, _default_unicode_map[i].code, sprite); } } } }
void SpriteFontCache::InitializeUnicodeGlyphMap() { /* Clear out existing glyph map if it exists */ this->ClearGlyphToSpriteMap(); SpriteID base; switch (this->fs) { default: NOT_REACHED(); case FS_MONO: // Use normal as default for mono spaced font, i.e. FALL THROUGH case FS_NORMAL: base = SPR_ASCII_SPACE; break; case FS_SMALL: base = SPR_ASCII_SPACE_SMALL; break; case FS_LARGE: base = SPR_ASCII_SPACE_BIG; break; } for (uint i = ASCII_LETTERSTART; i < 256; i++) { SpriteID sprite = base + i - ASCII_LETTERSTART; if (!SpriteExists(sprite)) continue; this->SetUnicodeGlyph(i, sprite); this->SetUnicodeGlyph(i + SCC_SPRITE_START, sprite); } for (uint i = 0; i < lengthof(_default_unicode_map); i++) { byte key = _default_unicode_map[i].key; if (key == CLRA) { /* Clear the glyph. This happens if the glyph at this code point * is non-standard and should be accessed by an SCC_xxx enum * entry only. */ this->SetUnicodeGlyph(_default_unicode_map[i].code, 0); } else { SpriteID sprite = base + key - ASCII_LETTERSTART; this->SetUnicodeGlyph(_default_unicode_map[i].code, sprite); } } }
uint GetGlyphWidth(FontSize size, WChar key) { FT_Face face = GetFontFace(size); GlyphEntry *glyph; if (face == NULL || (key >= SCC_SPRITE_START && key <= SCC_SPRITE_END)) { SpriteID sprite = GetUnicodeGlyph(size, key); if (sprite == 0) sprite = GetUnicodeGlyph(size, '?'); return SpriteExists(sprite) ? GetSprite(sprite, ST_FONT)->width + (size != FS_NORMAL && size != FS_MONO) : 0; } glyph = GetGlyphPtr(size, key); if (glyph == NULL || glyph->sprite == NULL) { GetGlyph(size, key); glyph = GetGlyphPtr(size, key); } return glyph->width; }
uint SpriteFontCache::GetGlyphWidth(GlyphID key) { SpriteID sprite = this->GetUnicodeGlyph(key); if (sprite == 0) sprite = this->GetUnicodeGlyph('?'); return SpriteExists(sprite) ? GetSprite(sprite, ST_FONT)->width + (this->fs != FS_NORMAL) : 0; }