Some more fixes for fast lookup tables

parent 3e04465a
......@@ -266,7 +266,7 @@ void init( void )
// back to 32 points
// Just load another glyph if you want to see difference (draw render a '@')
glyph = load_glyph( "fonts/Vera.ttf", "@", 512, 64, 0.1);
texture_font_index_glyph( font, &glyph );
texture_font_index_glyph( font, glyph, '@' );
glyph = texture_font_get_glyph( font, "@");
......
......@@ -101,7 +101,7 @@ void init()
char *f_normal = match_description("Droid Serif:size=24");
char *f_bold = match_description("Droid Serif:size=24:weight=bold");
char *f_italic = match_description("Droid Serif:size=24:slant=italic");
char *f_japanese = match_description("Droid Sans:size=18:lang=ja");
char *f_japanese = match_description("Droid Sans Japanese:size=18");
char *f_math = match_description("DejaVu Sans:size=24");
markup_t normal = {
......
......@@ -84,6 +84,7 @@ texture_atlas_delete( texture_atlas_t *self )
{
assert( self );
vector_delete( self->nodes );
texture_glyph_delete( self->special );
if( self->data )
{
free( self->data );
......
......@@ -341,9 +341,10 @@ texture_font_delete( texture_font_t *self )
if(self->location == TEXTURE_FONT_FILE && self->filename)
free( self->filename );
GLYPHS_ITERATOR(i, glyph, self->glyphs)
texture_glyph_delete( glyph );
GLYPHS_ITERATOR_END1
GLYPHS_ITERATOR(i, glyph, self->glyphs) {
if((__i | i << 8) == glyph->codepoint)
texture_glyph_delete( glyph );
} GLYPHS_ITERATOR_END1
free( __glyphs );
GLYPHS_ITERATOR_END2
......@@ -363,22 +364,29 @@ texture_font_find_glyph( texture_font_t * self,
if(ucodepoint == -1)
return (texture_glyph_t *)self->atlas->special;
if(self->glyphs->size <= i)
fprintf(stderr, "Lookup [%i][%i]=%s ", i, j, codepoint);
if(self->glyphs->size <= i) {
return NULL;
fprintf(stderr, "(null)\n");
}
glyph_index1 = *(texture_glyph_t ***) vector_get( self->glyphs, i );
if(!glyph_index1)
if(!glyph_index1) {
return NULL;
else
fprintf(stderr, "(null)\n");
} else {
fprintf(stderr, "%p\n", glyph_index1[j]);
return glyph_index1[j];
}
}
void texture_font_index_glyph( texture_font_t * self,
texture_glyph_t *glyph )
texture_glyph_t *glyph,
uint32_t codepoint)
{
uint32_t i = glyph->codepoint >> 8;
uint32_t j = glyph->codepoint & 0xFF;
uint32_t i = codepoint >> 8;
uint32_t j = codepoint & 0xFF;
texture_glyph_t ***glyph_index1;
if(self->glyphs->size <= i) {
......@@ -391,6 +399,7 @@ void texture_font_index_glyph( texture_font_t * self,
*glyph_index1 = calloc( 0x100, sizeof(texture_glyph_t*) );
}
fprintf(stderr, "Assign glyph[%i][%i]=%p\n", i, j, glyph);
(*glyph_index1)[j] = glyph;
}
......@@ -439,8 +448,11 @@ texture_font_load_glyph( texture_font_t * self,
ucodepoint = (FT_ULong)utf8_to_utf32( codepoint );
glyph_index = FT_Get_Char_Index( face, ucodepoint );
if(!glyph_index) {
ucodepoint = 0xFFFD; // all invalids are the same
if (texture_font_find_glyph(self, "\uFFFD")) {
fprintf(stderr, "Invalid glyph %x detected\n", ucodepoint);
texture_glyph_t * glyph;
if ((glyph = texture_font_find_glyph(self, "\xEF\xBF\xBD"))) {
fprintf(stderr, "Double invalid glyph assigned to %x\n", ucodepoint);
texture_font_index_glyph( self, glyph, ucodepoint );
FT_Done_Face(face);
FT_Done_FreeType(library);
return 1;
......@@ -622,7 +634,8 @@ cleanup_stroker:
free( buffer );
glyph = texture_glyph_new( );
glyph->codepoint = utf8_to_utf32( codepoint );
glyph->codepoint = glyph_index ? utf8_to_utf32( codepoint ) : 0xFFFD;
;
glyph->width = tgt_w;
glyph->height = tgt_h;
glyph->rendermode = self->rendermode;
......@@ -640,8 +653,13 @@ cleanup_stroker:
glyph->advance_x = slot->advance.x / HRESf;
glyph->advance_y = slot->advance.y / HRESf;
texture_font_index_glyph(self, glyph);
texture_font_index_glyph(self, glyph, ucodepoint);
if(!glyph_index) {
fprintf(stderr, "Invalid glyph assigned to %x\n", ucodepoint);
texture_font_index_glyph(self, glyph, 0xFFFD);
}
if( self->rendermode != RENDER_NORMAL && self->rendermode != RENDER_SIGNED_DISTANCE_FIELD )
FT_Done_Glyph( ft_glyph );
......
......@@ -412,7 +412,8 @@ typedef struct texture_font_t
*/
void
texture_font_index_glyph( texture_font_t * self,
texture_glyph_t * glyph );
texture_glyph_t * glyph,
uint32_t codepoint );
/**
* Request the loading of a given glyph.
......
......@@ -59,22 +59,22 @@ utf8_to_utf32( const char * character )
return character[0];
}
if( ( character[0] & 0xC0 ) == 0xC0 )
if( ( character[0] & 0xE0 ) == 0xC0 )
{
return ( ( character[0] & 0x3F ) << 6 ) | ( character[1] & 0x3F );
}
if( ( character[0] & 0xE0 ) == 0xE0 )
if( ( character[0] & 0xF0 ) == 0xE0 )
{
return ( ( character[0] & 0x1F ) << ( 6 + 6 ) ) | ( ( character[1] & 0x3F ) << 6 ) | ( character[2] & 0x3F );
}
if( ( character[0] & 0xF0 ) == 0xF0 )
if( ( character[0] & 0xF8 ) == 0xF0 )
{
return ( ( character[0] & 0x0F ) << ( 6 + 6 + 6 ) ) | ( ( character[1] & 0x3F ) << ( 6 + 6 ) ) | ( ( character[2] & 0x3F ) << 6 ) | ( character[3] & 0x3F );
}
if( ( character[0] & 0xF8 ) == 0xF8 )
if( ( character[0] & 0xFC ) == 0xF8 )
{
return ( ( character[0] & 0x07 ) << ( 6 + 6 + 6 + 6 ) ) | ( ( character[1] & 0x3F ) << ( 6 + 6 + 6 ) ) | ( ( character[2] & 0x3F ) << ( 6 + 6 ) ) | ( ( character[3] & 0x3F ) << 6 ) | ( character[4] & 0x3F );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment