+typedef struct {
+ char *family;
+ double size;
+ struct {
+ double red;
+ double green;
+ double blue;
+ } color;
+} args_t;
+
+static void
+parse_args (args_t *args)
+{
+ /* First some defaults */
+ args->family = "Vera";
+ args->size = 20;
+ args->color.red = 0.0;
+ args->color.green = 0.0;
+ args->color.blue = 0.0;
+
+ /* XXX: Next, we should override the defaults based on
+ * command-line arguments. */
+
+ /* XXX: Finally, we'll want to allow CGI-based arguments as
+ * well. */
+#if USE_CGIG
+ /* QueryString */
+ int fontsize;
+ char format[5];
+ char fillcolor[20];
+ char fontname[20];
+ cgiFormStringNoNewlines("fontname", fontname, 20);
+ cgiFormInteger("fontsize", &fontsize, 50);
+ cgiFormStringNoNewlines("format", format, 5);
+ cgiFormStringNoNewlines("fillcolor", fillcolor, 20);
+
+ int fillcolor_red;
+ int fillcolor_green;
+ int fillcolor_blue;
+ sscanf (fillcolor, " rgb : %d , %d , %d ", &fillcolor_red, &fillcolor_green, &fillcolor_blue);
+ if ( format[0] == 'j' && format[1] == 's' && format[2] == 'o' && format[3] == 'n' )
+ outputJson = TRUE;
+#endif
+}
+
+static FT_Face
+load_ft_face_for_family (const char *family)
+{
+ /* XXX: Instead of a hard-coded filename here, we should really be
+ * 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;
+}
+