bouncy balls
[carveJwlIkooP6JGAAIwe30JlM.git] / font.h
diff --git a/font.h b/font.h
index 4c7d8f46f1e09ad0a970bf13d34af0b8b22c6b20..75f2573c29f4bd9d292531d605b5529849ec6bab 100644 (file)
--- a/font.h
+++ b/font.h
@@ -86,6 +86,17 @@ VG_STATIC void font3d_bind( font3d *font, camera *cam )
    mesh_bind( &font->mesh );
 }
 
+VG_STATIC ent_glyph *font3d_glyph( font3d *font, u32 variant_id, u32 utf32 )
+{
+   if( utf32 < font->info.glyph_utf32_base ) return NULL;
+   if( utf32 >= font->info.glyph_utf32_base+font->info.glyph_count) return NULL;
+
+   u32 index = utf32 - font->info.glyph_utf32_base;
+       index += font->info.glyph_start;
+       index += font->info.glyph_count * variant_id;
+   return mdl_arritm( &font->glyphs, index );
+}
+
 VG_STATIC 
 void font3d_simple_draw( font3d *font, u32 variant_id, const char *text, 
                          camera *cam, m4x3f transform )
@@ -105,13 +116,8 @@ void font3d_simple_draw( font3d *font, u32 variant_id, const char *text,
       u32 c = text[i];
       if(!c) break;
 
-      if( c < font->info.glyph_utf32_base ) continue;
-      if( c >= font->info.glyph_utf32_base+font->info.glyph_count) continue;
-
-      u32 index = c - font->info.glyph_utf32_base;
-          index += font->info.glyph_start;
-          index += font->info.glyph_count * variant_id;
-      ent_glyph *glyph = mdl_arritm( &font->glyphs, index );
+      ent_glyph *glyph = font3d_glyph( font, variant_id, c );
+      if( !glyph ) continue;
 
       if( glyph->indice_count ){
          shader_model_font_uOffset( offset );
@@ -129,13 +135,8 @@ float font3d_string_width( font3d *font, u32 variant_id, const char *text )
       u32 c = text[i];
       if(!c) break;
 
-      if( c < font->info.glyph_utf32_base ) continue;
-      if( c >= font->info.glyph_utf32_base+font->info.glyph_count) continue;
-
-      u32 index = c - font->info.glyph_utf32_base;
-          index += font->info.glyph_start;
-          index += font->info.glyph_count * variant_id;
-      ent_glyph *glyph = mdl_arritm( &font->glyphs, index );
+      ent_glyph *glyph = font3d_glyph( font, variant_id, c );
+      if( !glyph ) continue;
 
       width += glyph->size[0];
    }