X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=spritext.c;h=1405c48c4ce1d166a2220d42501c4c13abf7bf3a;hb=e84835d20cdfdc0fab3be79eda3335108d36caf4;hp=ebfa8ead044fef4a1b32ea23c08159b6229750ff;hpb=aaa473508cd3073067214769b101207b1eeb3f5d;p=spritext diff --git a/spritext.c b/spritext.c index ebfa8ea..1405c48 100644 --- a/spritext.c +++ b/spritext.c @@ -6,7 +6,6 @@ #include #include #include -#include #ifndef CAIRO_HAS_PNG_FUNCTIONS #error This program requires cairo with PNG support @@ -20,8 +19,10 @@ #define TRUE (1==1) #define FALSE (!TRUE) +#if USE_CGIC static cairo_status_t stdio_write (void *closure, const unsigned char *data, unsigned int length); +#endif double get_max_width (cairo_t *cr, char *characters); @@ -30,8 +31,9 @@ double get_max_height (cairo_t *cr, char *characters); int -cgiMain () +main (void) { + const char font_filename[] = "/srv/rdworth.org/cgi-bin/Verdana.ttf"; char outputJson = FALSE; char characters[] = { @@ -52,14 +54,17 @@ cgiMain () int i; /* QueryString */ - char fontname[20]; int fontsize; char format[5]; char fillcolor[20]; + +#if USE_CGIG + char fontname[20]; cgiFormStringNoNewlines("fontname", fontname, 20); cgiFormInteger("fontsize", &fontsize, 50); cgiFormStringNoNewlines("format", format, 5); cgiFormStringNoNewlines("fillcolor", fillcolor, 20); +#endif int fillcolor_red; int fillcolor_green; @@ -69,12 +74,14 @@ cgiMain () if ( format[0] == 'j' && format[1] == 's' && format[2] == 'o' && format[3] == 'n' ) outputJson = TRUE; +#if USE_CGIC if (outputJson) { cgiHeaderContentType("application/json"); } else { cgiHeaderContentType("image/png"); } +#endif int error; FT_Library library; @@ -84,16 +91,21 @@ cgiMain () FT_Vector kerning; error = FT_Init_FreeType( &library ); - if ( error ) - printf("error"); + if ( error ) { + fprintf (stderr, "Fatal error initializing freetype.\n"); + exit (1); + } - error = FT_New_Face( library,"/srv/rdworth.org/cgi-bin/Verdana.ttf", + error = FT_New_Face( library, font_filename, 0, &ft_face ); - if ( error == FT_Err_Unknown_File_Format ) - printf("File opened. Font format unsupported."); - else if ( error ) - printf("Could not be open or read or broken."); + 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); + } use_kerning = FT_HAS_KERNING( ft_face ); @@ -189,7 +201,7 @@ cgiMain () FT_KERNING_UNSCALED, &kerning ); if ( kerning.x ) - printf(",k%d:%d", characters[j], kerning.x); + printf(",k%d:%ld", characters[j], kerning.x); } printf ("}"); @@ -275,12 +287,15 @@ cairo_mask (cr, gradient); cairo_pattern_destroy (gradient); */ + +#if USE_CGIC if (outputJson) { printf("}"); } else { cairo_surface_write_to_png_stream (surface, stdio_write, cgiOut); } +#endif cairo_destroy (cr); @@ -289,6 +304,7 @@ cairo_pattern_destroy (gradient); return 0; } +#if USE_CGIC static cairo_status_t stdio_write (void *closure, const unsigned char *data, unsigned int length) { @@ -298,6 +314,7 @@ stdio_write (void *closure, const unsigned char *data, unsigned int length) else return CAIRO_STATUS_WRITE_ERROR; } +#endif double get_max_width(cairo_t *cr, char *characters)