/* ------------------------------------------------------------------------- */ TextureGlyph * texture_font_get_glyph( TextureFont *self, wchar_t charcode ) { size_t i; static wchar_t *buffer = 0; TextureGlyph *glyph; assert( self ); assert( self->filename ); assert( self->atlas ); /* Check if charcode has been already loaded */ for( i=0; i<self->glyphs->size; ++i ) { glyph = (TextureGlyph *) vector_get( self->glyphs, i ); if( glyph->charcode == charcode ) { return glyph; } } /* If not, load it */ if( !buffer) { buffer = (wchar_t *) calloc( 2, sizeof(wchar_t) ); } buffer[0] = charcode; if( texture_font_cache_glyphs( self, buffer ) == 0 ) { return (TextureGlyph *) vector_back( self->glyphs ); } return NULL; }
TextureFont * font_manager_get_from_filename( FontManager *self, const char * filename, const float size ) { size_t i; TextureFont *font; assert( self ); for( i=0; i<self->fonts->size;++i ) { font = (TextureFont *) vector_get( self->fonts, i ); if( (strcmp(font->filename, filename) == 0) && ( font->size == size) ) { return font; } } font = texture_font_new( self->atlas, filename, size ); texture_font_cache_glyphs( font, self->cache ); if( font ) { vector_push_back( self->fonts, font ); } return font; }