Loading demos/cartoon.c +0 −6 Original line number Diff line number Diff line Loading @@ -87,21 +87,15 @@ void init( void ) font->rendermode = RENDER_OUTLINE_POSITIVE; font->outline_thickness = 7; add_text( buffer, font, "Freetype GL", pen, black, black ); texture_font_close( font, MODE_ALWAYS_OPEN, MODE_FREE_CLOSE ); font = texture_font_new_from_file( atlas, 128, "fonts/LuckiestGuy.ttf" ); font->rendermode = RENDER_OUTLINE_POSITIVE; font->outline_thickness = 5; add_text( buffer, font, "Freetype GL", pen, yellow, yellow ); texture_font_close( font, MODE_ALWAYS_OPEN, MODE_FREE_CLOSE ); font = texture_font_new_from_file( atlas, 128, "fonts/LuckiestGuy.ttf" ); font->rendermode = RENDER_OUTLINE_EDGE; font->outline_thickness = 3; add_text( buffer, font, "Freetype GL", pen, black, black ); texture_font_close( font, MODE_ALWAYS_OPEN, MODE_FREE_CLOSE ); font = texture_font_new_from_file( atlas, 128, "fonts/LuckiestGuy.ttf" ); font->rendermode = RENDER_NORMAL; font->outline_thickness = 0; add_text( buffer, font, "Freetype GL", pen, orange1, orange2 ); Loading texture-font.c +43 −10 Original line number Diff line number Diff line Loading @@ -53,8 +53,11 @@ texture_glyph_new(void) self->codepoint = -1; self->width = 0; self->height = 0; /* Attributes that can have different images for the same codepoint */ self->rendermode = RENDER_NORMAL; self->outline_thickness = 0.0; self->glyphmode = GLYPH_END; /* End of attribute part */ self->offset_x = 0; self->offset_y = 0; self->advance_x = 0.0; Loading Loading @@ -492,7 +495,7 @@ texture_font_delete( texture_font_t *self ) GLYPHS_ITERATOR_END2; if( glyph0 ) { fprintf(stderr, "free %p cp %x\n", glyph0, glyph0->codepoint); // fprintf(stderr, "free %p cp %x\n", glyph0, glyph0->codepoint); texture_glyph_delete( glyph0 ); } vector_delete( self->glyphs ); Loading @@ -506,7 +509,7 @@ texture_font_find_glyph( texture_font_t * self, uint32_t ucodepoint = utf8_to_utf32( codepoint ); uint32_t i = ucodepoint >> 8; uint32_t j = ucodepoint & 0xFF; texture_glyph_t **glyph_index1; texture_glyph_t **glyph_index1, *glyph; if(ucodepoint == -1) return (texture_glyph_t *)self->atlas->special; Loading @@ -519,16 +522,29 @@ texture_font_find_glyph( texture_font_t * self, if(!glyph_index1) return NULL; else return glyph_index1[j]; glyph = glyph_index1[j]; while( glyph && // if no glyph is there, we are done here glyph->rendermode != self->rendermode && glyph->outline_thickness != self->outline_thickness ) { // fprintf(stderr, "glyph r/ot/g: %d %f %d\n", // glyph->rendermode, glyph->outline_thickness, glyph->glyphmode); if( glyph->glyphmode != GLYPH_CONT) return NULL; glyph++; // fprintf(stderr, "look for another glyph %p %d\n", glyph, glyph->glyphmode); } return glyph; } void texture_font_index_glyph( texture_font_t * self, int texture_font_index_glyph( texture_font_t * self, texture_glyph_t *glyph, uint32_t codepoint) { uint32_t i = codepoint >> 8; uint32_t j = codepoint & 0xFF; texture_glyph_t ***glyph_index1; texture_glyph_t ***glyph_index1, *glyph_insert; if(self->glyphs->size <= i) { vector_resize( self->glyphs, i+1); Loading @@ -540,7 +556,20 @@ void texture_font_index_glyph( texture_font_t * self, *glyph_index1 = calloc( 0x100, sizeof(texture_glyph_t*) ); } if(( glyph_insert = (*glyph_index1)[j] )) { int i = 0; // fprintf(stderr, "glyph already there\n"); while (glyph_insert[i].glyphmode != GLYPH_END) i++; // fprintf(stderr, "Insert a glyph after position %d\n", i); glyph_insert[i].glyphmode = GLYPH_CONT; (*glyph_index1)[j] = glyph_insert = realloc( glyph_insert, sizeof(texture_glyph_t)*(i+2) ); memcpy( glyph_insert+(i+1), glyph, sizeof(texture_glyph_t) ); return 1; } else { (*glyph_index1)[j] = glyph; return 0; } } // ------------------------------------------------ texture_font_load_glyph --- Loading Loading @@ -819,9 +848,13 @@ cleanup_stroker: glyph->advance_y = slot->advance.y * self->scale / HRESf; } texture_font_index_glyph(self, glyph, ucodepoint); int free_glyph = texture_font_index_glyph(self, glyph, ucodepoint); if(!glyph_index) { texture_font_index_glyph(self, glyph, 0); free_glyph &= texture_font_index_glyph(self, glyph, 0); } if(free_glyph) { // fprintf(stderr, "Free glyph\n"); free(glyph); } if( self->rendermode != RENDER_NORMAL && self->rendermode != RENDER_SIGNED_DISTANCE_FIELD ) Loading texture-font.h +21 −4 Original line number Diff line number Diff line Loading @@ -64,6 +64,15 @@ typedef enum rendermode_t RENDER_SIGNED_DISTANCE_FIELD } rendermode_t; /** * Glyph array end mark type */ typedef enum glyphmode_t { GLYPH_END=0, GLYPH_CONT=1 } glyphmode_t; /* * Glyph metrics: * -------------- Loading Loading @@ -179,6 +188,11 @@ typedef struct texture_glyph_t */ float outline_thickness; /** * Glyph scan end mark */ glyphmode_t glyphmode; } texture_glyph_t; /** Loading Loading @@ -501,8 +515,11 @@ typedef struct texture_font_t * * @param self A valid texture font * @param glyph The glyph to index in the font * @param codepoint The codepoint to insert into * * @return 1 if glyph was copied, 0 if it was inserted */ void int texture_font_index_glyph( texture_font_t * self, texture_glyph_t * glyph, uint32_t codepoint ); Loading Loading
demos/cartoon.c +0 −6 Original line number Diff line number Diff line Loading @@ -87,21 +87,15 @@ void init( void ) font->rendermode = RENDER_OUTLINE_POSITIVE; font->outline_thickness = 7; add_text( buffer, font, "Freetype GL", pen, black, black ); texture_font_close( font, MODE_ALWAYS_OPEN, MODE_FREE_CLOSE ); font = texture_font_new_from_file( atlas, 128, "fonts/LuckiestGuy.ttf" ); font->rendermode = RENDER_OUTLINE_POSITIVE; font->outline_thickness = 5; add_text( buffer, font, "Freetype GL", pen, yellow, yellow ); texture_font_close( font, MODE_ALWAYS_OPEN, MODE_FREE_CLOSE ); font = texture_font_new_from_file( atlas, 128, "fonts/LuckiestGuy.ttf" ); font->rendermode = RENDER_OUTLINE_EDGE; font->outline_thickness = 3; add_text( buffer, font, "Freetype GL", pen, black, black ); texture_font_close( font, MODE_ALWAYS_OPEN, MODE_FREE_CLOSE ); font = texture_font_new_from_file( atlas, 128, "fonts/LuckiestGuy.ttf" ); font->rendermode = RENDER_NORMAL; font->outline_thickness = 0; add_text( buffer, font, "Freetype GL", pen, orange1, orange2 ); Loading
texture-font.c +43 −10 Original line number Diff line number Diff line Loading @@ -53,8 +53,11 @@ texture_glyph_new(void) self->codepoint = -1; self->width = 0; self->height = 0; /* Attributes that can have different images for the same codepoint */ self->rendermode = RENDER_NORMAL; self->outline_thickness = 0.0; self->glyphmode = GLYPH_END; /* End of attribute part */ self->offset_x = 0; self->offset_y = 0; self->advance_x = 0.0; Loading Loading @@ -492,7 +495,7 @@ texture_font_delete( texture_font_t *self ) GLYPHS_ITERATOR_END2; if( glyph0 ) { fprintf(stderr, "free %p cp %x\n", glyph0, glyph0->codepoint); // fprintf(stderr, "free %p cp %x\n", glyph0, glyph0->codepoint); texture_glyph_delete( glyph0 ); } vector_delete( self->glyphs ); Loading @@ -506,7 +509,7 @@ texture_font_find_glyph( texture_font_t * self, uint32_t ucodepoint = utf8_to_utf32( codepoint ); uint32_t i = ucodepoint >> 8; uint32_t j = ucodepoint & 0xFF; texture_glyph_t **glyph_index1; texture_glyph_t **glyph_index1, *glyph; if(ucodepoint == -1) return (texture_glyph_t *)self->atlas->special; Loading @@ -519,16 +522,29 @@ texture_font_find_glyph( texture_font_t * self, if(!glyph_index1) return NULL; else return glyph_index1[j]; glyph = glyph_index1[j]; while( glyph && // if no glyph is there, we are done here glyph->rendermode != self->rendermode && glyph->outline_thickness != self->outline_thickness ) { // fprintf(stderr, "glyph r/ot/g: %d %f %d\n", // glyph->rendermode, glyph->outline_thickness, glyph->glyphmode); if( glyph->glyphmode != GLYPH_CONT) return NULL; glyph++; // fprintf(stderr, "look for another glyph %p %d\n", glyph, glyph->glyphmode); } return glyph; } void texture_font_index_glyph( texture_font_t * self, int texture_font_index_glyph( texture_font_t * self, texture_glyph_t *glyph, uint32_t codepoint) { uint32_t i = codepoint >> 8; uint32_t j = codepoint & 0xFF; texture_glyph_t ***glyph_index1; texture_glyph_t ***glyph_index1, *glyph_insert; if(self->glyphs->size <= i) { vector_resize( self->glyphs, i+1); Loading @@ -540,7 +556,20 @@ void texture_font_index_glyph( texture_font_t * self, *glyph_index1 = calloc( 0x100, sizeof(texture_glyph_t*) ); } if(( glyph_insert = (*glyph_index1)[j] )) { int i = 0; // fprintf(stderr, "glyph already there\n"); while (glyph_insert[i].glyphmode != GLYPH_END) i++; // fprintf(stderr, "Insert a glyph after position %d\n", i); glyph_insert[i].glyphmode = GLYPH_CONT; (*glyph_index1)[j] = glyph_insert = realloc( glyph_insert, sizeof(texture_glyph_t)*(i+2) ); memcpy( glyph_insert+(i+1), glyph, sizeof(texture_glyph_t) ); return 1; } else { (*glyph_index1)[j] = glyph; return 0; } } // ------------------------------------------------ texture_font_load_glyph --- Loading Loading @@ -819,9 +848,13 @@ cleanup_stroker: glyph->advance_y = slot->advance.y * self->scale / HRESf; } texture_font_index_glyph(self, glyph, ucodepoint); int free_glyph = texture_font_index_glyph(self, glyph, ucodepoint); if(!glyph_index) { texture_font_index_glyph(self, glyph, 0); free_glyph &= texture_font_index_glyph(self, glyph, 0); } if(free_glyph) { // fprintf(stderr, "Free glyph\n"); free(glyph); } if( self->rendermode != RENDER_NORMAL && self->rendermode != RENDER_SIGNED_DISTANCE_FIELD ) Loading
texture-font.h +21 −4 Original line number Diff line number Diff line Loading @@ -64,6 +64,15 @@ typedef enum rendermode_t RENDER_SIGNED_DISTANCE_FIELD } rendermode_t; /** * Glyph array end mark type */ typedef enum glyphmode_t { GLYPH_END=0, GLYPH_CONT=1 } glyphmode_t; /* * Glyph metrics: * -------------- Loading Loading @@ -179,6 +188,11 @@ typedef struct texture_glyph_t */ float outline_thickness; /** * Glyph scan end mark */ glyphmode_t glyphmode; } texture_glyph_t; /** Loading Loading @@ -501,8 +515,11 @@ typedef struct texture_font_t * * @param self A valid texture font * @param glyph The glyph to index in the font * @param codepoint The codepoint to insert into * * @return 1 if glyph was copied, 0 if it was inserted */ void int texture_font_index_glyph( texture_font_t * self, texture_glyph_t * glyph, uint32_t codepoint ); Loading