Commit 46ebc293 authored by William Light's avatar William Light

implement texture_font_new_from_*() functions

this commit renames texture_font_new() to texture_font_new_from_file()
and also implements texture_font_new_from_memory() for creating
texture fonts from font files that are already loaded somewhere in
memory (for example, fonts embedded inside an application).
parent c1c48ec7
......@@ -148,31 +148,31 @@ build_buffer( void )
if( p_family == VERA)
{
font = texture_font_new( atlas, "fonts/Vera.ttf", p_size );
font = texture_font_new_from_file( atlas, p_size, "fonts/Vera.ttf" );
}
else if( p_family == VERA_MONO)
{
font = texture_font_new( atlas, "fonts/VeraMono.ttf", p_size );
font = texture_font_new_from_file( atlas, p_size, "fonts/VeraMono.ttf" );
}
else if( p_family == GEORGIA)
{
font = texture_font_new( atlas, "fonts/Georgia.ttf", p_size );
font = texture_font_new_from_file( atlas, p_size, "fonts/Georgia.ttf" );
}
else if( p_family == TIMES )
{
font = texture_font_new( atlas, "fonts/Times.ttf", p_size );
font = texture_font_new_from_file( atlas, p_size, "fonts/Times.ttf" );
}
else if( p_family == TAHOMA )
{
font = texture_font_new( atlas, "fonts/Tahoma.ttf", p_size );
font = texture_font_new_from_file( atlas, p_size, "fonts/Tahoma.ttf" );
}
else if( p_family == ARIAL )
{
font = texture_font_new( atlas, "fonts/Arial.ttf", p_size );
font = texture_font_new_from_file( atlas, p_size, "fonts/Arial.ttf" );
}
else if( p_family == VERDANA )
{
font = texture_font_new( atlas, "fonts/Verdana.ttf", p_size );
font = texture_font_new_from_file( atlas, p_size, "fonts/Verdana.ttf" );
}
else
{
......@@ -180,6 +180,9 @@ build_buffer( void )
return;
}
if (!font)
return;
markup.font = font;
font->hinting = p_hinting;
font->kerning = p_kerning;
......
......@@ -228,7 +228,7 @@ int main( int argc, char **argv )
fprintf( stderr, "Using GLEW %s\n", glewGetString(GLEW_VERSION) );
atlas = texture_atlas_new( 512, 512, 1 );
font = texture_font_new( atlas, "fonts/VeraMono.ttf", 12 );
font = texture_font_new_from_file( atlas, 12, "fonts/VeraMono.ttf" );
buffer = vertex_buffer_new( "vertex:3f,tex_coord:2f,color:4f" );
pen.y = -font->descender;
......
......@@ -169,7 +169,8 @@ int main( int argc, char **argv )
atlas = texture_atlas_new( 1024, 1024, 1 );
buffer = vertex_buffer_new( "vertex:3f,tex_coord:2f,color:4f" );
texture_font_t *font = texture_font_new( atlas, "fonts/ObelixPro.ttf", 128 );
texture_font_t *font =
texture_font_new_from_file( atlas, 128, "fonts/ObelixPro.ttf" );
vec2 pen = {{50, 50}};
vec4 black = {{0.0, 0.0, 0.0, 1.0}};
......
......@@ -145,20 +145,20 @@ console_new( void )
normal.strikethrough = 0;
normal.strikethrough_color = white;
normal.font = texture_font_new( atlas, "fonts/VeraMono.ttf", 13 );
normal.font = texture_font_new_from_file( atlas, 13, "fonts/VeraMono.ttf" );
markup_t bold = normal;
bold.bold = 1;
bold.font = texture_font_new( atlas, "fonts/VeraMoBd.ttf", 13 );
bold.font = texture_font_new_from_file( atlas, 13, "fonts/VeraMoBd.ttf" );
markup_t italic = normal;
italic.italic = 1;
bold.font = texture_font_new( atlas, "fonts/VeraMoIt.ttf", 13 );
bold.font = texture_font_new_from_file( atlas, 13, "fonts/VeraMoIt.ttf" );
markup_t bold_italic = normal;
bold.bold = 1;
italic.italic = 1;
italic.font = texture_font_new( atlas, "fonts/VeraMoBI.ttf", 13 );
italic.font = texture_font_new_from_file( atlas, 13, "fonts/VeraMoBI.ttf" );
markup_t faint = normal;
faint.foreground_color.r = 0.35;
......
......@@ -285,7 +285,7 @@ main( int argc, char **argv )
buffer = vertex_buffer_new( "vertex:3f,tex_coord:2f,color:4f" );
vec2 pen = {{0,0}};
vec4 black = {{1,1,1,1}};
font = texture_font_new( atlas, filename, 48 );
font = texture_font_new_from_file( atlas, 48, filename );
vec4 bbox = add_text( buffer, font, text, &black, &pen );
size_t i;
vector_t * vertices = buffer->vertices;
......
......@@ -438,7 +438,7 @@ main( int argc, char **argv )
"shaders/distance-field-3.frag" );
glUseProgram( program );
atlas = texture_atlas_new( 512, 512, 1 );
font = texture_font_new( atlas, "fonts/Vera.ttf", 32 );
font = texture_font_new_from_file( atlas, 32, "fonts/Vera.ttf" );
texture_glyph_t *glyph;
......
......@@ -269,7 +269,7 @@ main( int argc, char **argv )
L"`abcdefghijklmnopqrstuvwxyz{|}~";
atlas = texture_atlas_new( 512, 512, 1 );
font = texture_font_new( atlas, filename, 72 );
font = texture_font_new_from_file( atlas, 72, filename );
texture_font_load_glyphs( font, cache );
texture_font_delete( font );
......
......@@ -175,7 +175,7 @@ int main( int argc, char **argv )
vec4 black = {{0,0,0,1}};
for( i=7; i < 27; ++i)
{
font = texture_font_new( atlas, filename, i );
font = texture_font_new_from_file( atlas, i, filename );
pen.x = 5;
pen.y -= font->height;
texture_font_load_glyphs( font, text );
......
......@@ -199,9 +199,9 @@ int main( int argc, char **argv )
vec4 black = {{0,0,0,1}};
texture_atlas_t * atlas = texture_atlas_new( 512, 512, 1);
texture_font_t * big = texture_font_new( atlas, "fonts/Vera.ttf", 400);
texture_font_t * small = texture_font_new( atlas, "fonts/Vera.ttf", 18);
texture_font_t * title = texture_font_new( atlas, "fonts/Vera.ttf", 32);
texture_font_t * big = texture_font_new_from_file( atlas, 400, "fonts/Vera.ttf");
texture_font_t * small = texture_font_new_from_file( atlas, 18, "fonts/Vera.ttf");
texture_font_t * title = texture_font_new_from_file( atlas, 32, "fonts/Vera.ttf");
text_buffer = vertex_buffer_new( "vertex:3f,tex_coord:2f,color:4f" );
line_buffer = vertex_buffer_new( "vertex:3f,color:4f" );
......
......@@ -193,7 +193,7 @@ int main( int argc, char **argv )
for( i=7; i < 27; ++i)
{
font = texture_font_new( atlas, filename, i );
font = texture_font_new_from_file( atlas, i, filename );
pen.x = 0;
pen.y -= font->height;
texture_font_load_glyphs( font, text );
......
......@@ -225,7 +225,7 @@ int main( int argc, char **argv )
markup.strikethrough_color = white;
markup.font = 0;
markup.font = texture_font_new( atlas, "fonts/Vera.ttf", markup.size );
markup.font = texture_font_new_from_file( atlas, markup.size, "fonts/Vera.ttf" );
markup.font->outline_type = 1;
......
......@@ -126,7 +126,7 @@ int main( int argc, char **argv )
for( i=minsize; i < maxsize; ++i )
{
texture_font_t * font = texture_font_new( atlas, filename, i );
texture_font_t * font = texture_font_new_from_file( atlas, i, filename );
missed += texture_font_load_glyphs( font, cache );
texture_font_delete( font );
}
......
......@@ -157,7 +157,7 @@ font_manager_get_from_filename( font_manager_t *self,
return font;
}
}
font = texture_font_new( self->atlas, filename, size );
font = texture_font_new_from_file( self->atlas, size, filename );
if( font )
{
vector_push_back( self->fonts, &font );
......
......@@ -232,7 +232,7 @@ int main( int argc, char **argv )
}
texture_atlas_t * atlas = texture_atlas_new( 128, 128, 1 );
texture_font_t * font = texture_font_new( atlas, font_filename, font_size );
texture_font_t * font = texture_font_new_from_file( atlas, font_size, font_filename );
glutInit( &argc, argv );
glutInitWindowSize( atlas->width, atlas->height );
......
This diff is collapsed.
......@@ -229,9 +229,27 @@ typedef struct
texture_atlas_t * atlas;
/**
* Font filename
* font location
*/
char * filename;
enum {
TEXTURE_FONT_FILE = 0,
TEXTURE_FONT_MEMORY,
} location;
union {
/**
* Font filename, for when location == TEXTURE_FONT_FILE
*/
char *filename;
/**
* Font memory address, for when location == TEXTURE_FONT_MEMORY
*/
struct {
const void *base;
size_t size;
} memory;
};
/**
* Font size
......@@ -329,17 +347,38 @@ typedef struct
* freetype implementation).
*
* @param atlas A texture atlas
* @param pt_size Size of font to be created (in points)
* @param filename A font filename
* @param size Size of font to be created (in points)
*
* @return A new empty font (no glyph inside yet)
*
*/
texture_font_t *
texture_font_new( texture_atlas_t * atlas,
const char * filename,
const float size );
texture_font_new_from_file( texture_atlas_t * atlas,
const float pt_size,
const char * filename );
/**
* This function creates a new texture font from a memory location and size.
* The texture atlas is used to store glyph on demand. Note the depth of the
* atlas will determine if the font is rendered as alpha channel only
* (depth = 1) or RGB (depth = 3) that correspond to subpixel rendering (if
* available on your freetype implementation).
*
* @param atlas A texture atlas
* @param pt_size Size of font to be created (in points)
* @param memory_base Start of the font file in memory
* @param memory_size Size of the font file memory region, in bytes
*
* @return A new empty font (no glyph inside yet)
*
*/
texture_font_t *
texture_font_new_from_memory( texture_atlas_t *atlas,
float pt_size,
const void *memory_base,
size_t memory_size );
/**
* Delete a texture font. Note that this does not delete the glyph from the
......
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