]> git.cworth.org Git - spritext/commitdiff
Move font loading into its own function
authorCarl Worth <cworth@cworth.org>
Wed, 13 Feb 2008 18:47:09 +0000 (10:47 -0800)
committerCarl Worth <cworth@cworth.org>
Wed, 13 Feb 2008 18:47:09 +0000 (10:47 -0800)
spritext.c

index 1c67ab5ffad97416e59d1778836fd049c232134b..62e1d2f681539976672a8c3103c18bd414801604 100644 (file)
@@ -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 );