From: Carl Worth Date: Wed, 13 Feb 2008 18:47:09 +0000 (-0800) Subject: Move font loading into its own function X-Git-Url: https://git.cworth.org/git?p=spritext;a=commitdiff_plain;h=3c2d06be34f800ee5fee855bd2b9bb55f661fc8d Move font loading into its own function --- diff --git a/spritext.c b/spritext.c index 1c67ab5..62e1d2f 100644 --- a/spritext.c +++ b/spritext.c @@ -75,13 +75,41 @@ parse_args (args_t *args) #endif } -int -main (void) +static FT_Face +load_ft_face_for_family (const char *family) { /* XXX: Instead of a hard-coded filename here, we should really be - * taking args.family and using fontconfig to map that to a + * taking family and using fontconfig to map that to a * filename. */ const char font_filename[] = "./Vera.ttf"; + + int error; + FT_Face ft_face; + FT_Library library; + + error = FT_Init_FreeType( &library ); + if ( error ) { + fprintf (stderr, "Fatal error initializing freetype.\n"); + exit (1); + } + + error = FT_New_Face( library, font_filename, + 0, + &ft_face ); + if ( error == FT_Err_Unknown_File_Format ) { + fprintf (stderr, "Unsupported font format: %s\n", font_filename); + exit (1); + } else if ( error ) { + fprintf (stderr, "Failed to open file: %s\n", font_filename); + exit (1); + } + + return ft_face; +} + +int +main (void) +{ char outputJson = FALSE; char characters[] = { @@ -101,6 +129,10 @@ main (void) int i; args_t args; + FT_Face ft_face; + FT_UInt left_index, right_index; + FT_Bool use_kerning; + FT_Vector kerning; parse_args (&args); @@ -113,29 +145,7 @@ main (void) } #endif - int error; - FT_Library library; - FT_Face ft_face; - FT_Bool use_kerning; - FT_UInt left_index, right_index; - FT_Vector kerning; - - error = FT_Init_FreeType( &library ); - if ( error ) { - fprintf (stderr, "Fatal error initializing freetype.\n"); - exit (1); - } - - error = FT_New_Face( library, font_filename, - 0, - &ft_face ); - if ( error == FT_Err_Unknown_File_Format ) { - fprintf (stderr, "Unsupported font format: %s\n", font_filename); - exit (1); - } else if ( error ) { - fprintf (stderr, "Failed to open file: %s\n", font_filename); - exit (1); - } + ft_face = load_ft_face_for_family (args.family); use_kerning = FT_HAS_KERNING( ft_face );