char outputJson = FALSE;
char characters[] = {
- '!', '"', '#', '$', '%', '&','\'', '(',
- ')', '*', '+', ',', '-', '.', '/', '0',
- '1', '2', '3', '4', '5', '6', '7', '8',
- '9', ':', ';', '<', '=', '>', '?', '@',
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
- 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
- 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
- 'Y', 'Z', '[','\\', ']', '^', '_', '`',
- 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
- 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
- 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
- 'y', 'z', '{', '|', '}', '~'
+ '!', '"', '#', '$', '%', '&','\'', '(',
+ ')', '*', '+', ',', '-', '.', '/', '0',
+ '1', '2', '3', '4', '5', '6', '7', '8',
+ '9', ':', ';', '<', '=', '>', '?', '@',
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
+ 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
+ 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
+ 'Y', 'Z', '[','\\', ']', '^', '_', '`',
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
+ 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
+ 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
+ 'y', 'z', '{', '|', '}', '~'
};
int i;
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;
+ outputJson = TRUE;
if (outputJson)
{
- cgiHeaderContentType("application/json");
+ cgiHeaderContentType("application/json");
} else {
- cgiHeaderContentType("image/png");
+ cgiHeaderContentType("image/png");
}
int error;
error = FT_Init_FreeType( &library );
if ( error )
- printf("error");
+ printf("error");
error = FT_New_Face( library,"/srv/rdworth.org/cgi-bin/Verdana.ttf",
0,
cr = cairo_create (surface);
/*
- cairo_select_font_face (cr, fontname,
- CAIRO_FONT_SLANT_NORMAL,
- CAIRO_FONT_WEIGHT_NORMAL);
+ cairo_select_font_face (cr, fontname,
+ CAIRO_FONT_SLANT_NORMAL,
+ CAIRO_FONT_WEIGHT_NORMAL);
*/
cr_face = cairo_ft_font_face_create_for_ft_face (ft_face, 0);
cairo_set_font_face (cr, cr_face);
/* Draw */
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
- (max_width + 8) * 10,
- (max_height + 8) * 10);
+ (max_width + 8) * 10,
+ (max_height + 8) * 10);
cr = cairo_create (surface);
/*
- cairo_select_font_face (cr, fontname,
- CAIRO_FONT_SLANT_NORMAL,
- CAIRO_FONT_WEIGHT_NORMAL);
+ cairo_select_font_face (cr, fontname,
+ CAIRO_FONT_SLANT_NORMAL,
+ CAIRO_FONT_WEIGHT_NORMAL);
*/
cr_face = cairo_ft_font_face_create_for_ft_face (ft_face, 0);
cairo_set_font_face (cr, cr_face);
double y = 0.0;
if (outputJson)
- printf("{");
+ printf("{");
cairo_translate (cr, 0, -(max_height / 2.50));
string[1] = '\0';
for (i = 0; i < ARRAY_SIZE(characters); i++)
{
- if (i % 10 == 0)
- {
- x = 0.;
- y += max_height + 8;
- }
- string[0] = characters[i];
-
- cairo_text_extents (cr, string, &extents);
-
- if (outputJson)
- {
- if (i > 0)
- printf (",\n");
- printf ("u%i:{", characters[i]);
- printf ("x:%.1f,y:%.1f,w:%.1f,h:%.1f",
- x,
- y - (max_height * 1.15),
- extents.width + extents.x_bearing,
- extents.height);
- int j;
- for ( j = 0; j < ARRAY_SIZE(characters); j++ )
- {
- right_index = FT_Get_Char_Index( ft_face, characters[i] );
- left_index = FT_Get_Char_Index( ft_face, characters[j] );
+ if (i % 10 == 0)
+ {
+ x = 0.;
+ y += max_height + 8;
+ }
+ string[0] = characters[i];
+
+ cairo_text_extents (cr, string, &extents);
+
+ if (outputJson)
+ {
+ if (i > 0)
+ printf (",\n");
+ printf ("u%i:{", characters[i]);
+ printf ("x:%.1f,y:%.1f,w:%.1f,h:%.1f",
+ x,
+ y - (max_height * 1.15),
+ extents.width + extents.x_bearing,
+ extents.height);
+ int j;
+ for ( j = 0; j < ARRAY_SIZE(characters); j++ )
+ {
+ right_index = FT_Get_Char_Index( ft_face, characters[i] );
+ left_index = FT_Get_Char_Index( ft_face, characters[j] );
- FT_Get_Kerning( ft_face, left_index, right_index,
- FT_KERNING_UNSCALED, &kerning );
+ FT_Get_Kerning( ft_face, left_index, right_index,
+ FT_KERNING_UNSCALED, &kerning );
- if ( kerning.x )
- printf(",k%d:%d", characters[j], kerning.x);
- }
+ if ( kerning.x )
+ printf(",k%d:%d", characters[j], kerning.x);
+ }
- printf ("}");
- }
+ printf ("}");
+ }
- x -= extents.x_bearing;
+ x -= extents.x_bearing;
- cairo_move_to (cr, x, y);
- cairo_set_source_rgb (cr, 0., 0., 0.); // black
- if ( 0 <= fillcolor_red && fillcolor_red <= 255.0
- && 0 <= fillcolor_green && fillcolor_green <= 255.0
- && 0 <= fillcolor_blue && fillcolor_blue <= 255.0 )
- cairo_set_source_rgb (cr, fillcolor_red / 255.0, fillcolor_green / 255.0, fillcolor_blue / 255.0);
- cairo_text_path (cr, string);
- cairo_fill (cr);
-
- x += extents.x_bearing;
- x += max_width + 8;
+ cairo_move_to (cr, x, y);
+ cairo_set_source_rgb (cr, 0., 0., 0.); // black
+ if ( 0 <= fillcolor_red && fillcolor_red <= 255.0
+ && 0 <= fillcolor_green && fillcolor_green <= 255.0
+ && 0 <= fillcolor_blue && fillcolor_blue <= 255.0 )
+ cairo_set_source_rgb (cr, fillcolor_red / 255.0, fillcolor_green / 255.0, fillcolor_blue / 255.0);
+ cairo_text_path (cr, string);
+ cairo_fill (cr);
+
+ x += extents.x_bearing;
+ x += max_width + 8;
}
/*
- int thick_width = 4;
- int thin_width = 0;
+ int thick_width = 4;
+ int thin_width = 0;
- for (c = 'A'; c <= 'I'; c++)
- {
- string[0] = c;
- int spacing = ((c - 'A') * letterspacing) + 1;
+ for (c = 'A'; c <= 'I'; c++)
+ {
+ string[0] = c;
+ int spacing = ((c - 'A') * letterspacing) + 1;
- cairo_save(cr);
+ cairo_save(cr);
- cairo_move_to (cr, spacing, 0);
- cairo_text_path (cr, string);
+ cairo_move_to (cr, spacing, 0);
+ cairo_text_path (cr, string);
// cairo_set_source_rgb (cr, 0.1, 0.2, 0.2); // gray
- cairo_set_source_rgb (cr, 0.8, 0.8, 0.85); // silver
- cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
+cairo_set_source_rgb (cr, 0.8, 0.8, 0.85); // silver
+cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
- cairo_push_group (cr);
- cairo_set_line_width (cr, thick_width);
- cairo_stroke_preserve (cr);
- cairo_set_line_width (cr, thin_width);
- cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
- cairo_stroke_preserve (cr);
- cairo_fill (cr);
- cairo_pop_group_to_source (cr);
+cairo_push_group (cr);
+cairo_set_line_width (cr, thick_width);
+cairo_stroke_preserve (cr);
+cairo_set_line_width (cr, thin_width);
+cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
+cairo_stroke_preserve (cr);
+cairo_fill (cr);
+cairo_pop_group_to_source (cr);
- cairo_paint (cr);
+cairo_paint (cr);
- cairo_restore(cr);
+cairo_restore(cr);
- cairo_move_to (cr, spacing, 0);
- cairo_text_path (cr, string);
- cairo_set_source_rgb (cr, 0.4, 0.45, 0.7); // blue
+cairo_move_to (cr, spacing, 0);
+cairo_text_path (cr, string);
+cairo_set_source_rgb (cr, 0.4, 0.45, 0.7); // blue
- cairo_fill (cr);
- }
+cairo_fill (cr);
+}
*/
cairo_scale (cr, 1, -1);
cairo_push_group (cr);
/*
- cairo_pattern_t *gradient;
+cairo_pattern_t *gradient;
- for (i = 0; i < 9; i++)
- {
- char c[2];
- strncpy(c, STRING + i, 1);
- c[1] = '\0';
- int spacing = (i * letterspacing) + 1;
- cairo_move_to (cr, spacing, -3);
- cairo_show_text (cr, c);
+for (i = 0; i < 9; i++)
+{
+char c[2];
+strncpy(c, STRING + i, 1);
+c[1] = '\0';
+int spacing = (i * letterspacing) + 1;
+cairo_move_to (cr, spacing, -3);
+cairo_show_text (cr, c);
- }
- cairo_pop_group_to_source (cr);
+}
+cairo_pop_group_to_source (cr);
- gradient = cairo_pattern_create_linear (0, 0, 0, -fontsize);
- cairo_pattern_add_color_stop_rgba (gradient, 0.0, 1, 1, 1, 0.5);
- cairo_pattern_add_color_stop_rgba (gradient, 0.7, 1, 1, 1, 0.0);
+gradient = cairo_pattern_create_linear (0, 0, 0, -fontsize);
+cairo_pattern_add_color_stop_rgba (gradient, 0.0, 1, 1, 1, 0.5);
+cairo_pattern_add_color_stop_rgba (gradient, 0.7, 1, 1, 1, 0.0);
- cairo_mask (cr, gradient);
+cairo_mask (cr, gradient);
- cairo_pattern_destroy (gradient);
+cairo_pattern_destroy (gradient);
*/
if (outputJson)
{
- printf("}");
+ printf("}");
} else {
- cairo_surface_write_to_png_stream (surface, stdio_write, cgiOut);
+ cairo_surface_write_to_png_stream (surface, stdio_write, cgiOut);
}
cairo_destroy (cr);
double
get_max_width(cairo_t *cr, char *characters)
{
- int i;
- double max_width = 0.;
- char string[2];
- string[1] = '\0';
- for (i = 0; i < ARRAY_SIZE(characters); i++) {
- cairo_text_extents_t extents;
- string[0] = characters[i];
- cairo_text_extents (cr, string, &extents);
- if ((extents.width + (extents.x_bearing * 2)) > max_width)
- max_width = extents.width + (extents.x_bearing * 2);
- }
- return max_width;
+ int i;
+ double max_width = 0.;
+ char string[2];
+ string[1] = '\0';
+ for (i = 0; i < ARRAY_SIZE(characters); i++) {
+ cairo_text_extents_t extents;
+ string[0] = characters[i];
+ cairo_text_extents (cr, string, &extents);
+ if ((extents.width + (extents.x_bearing * 2)) > max_width)
+ max_width = extents.width + (extents.x_bearing * 2);
+ }
+ return max_width;
}
double
get_max_height(cairo_t *cr, char *characters)
{
- int i;
- double max_height = 0.;
- char string[2];
- string[1] = '\0';
- for (i = 0; i < ARRAY_SIZE(characters); i++) {
- cairo_text_extents_t extents;
- string[0] = characters[i];
- cairo_text_extents (cr, string, &extents);
+ int i;
+ double max_height = 0.;
+ char string[2];
+ string[1] = '\0';
+ for (i = 0; i < ARRAY_SIZE(characters); i++) {
+ cairo_text_extents_t extents;
+ string[0] = characters[i];
+ cairo_text_extents (cr, string, &extents);
// if ((extents.height - extents.y_bearing) > max_height)
// max_height = extents.height - extents.y_bearing;
- if ((extents.height) > max_height)
- max_height = extents.height;
- }
- return max_height;
+ if ((extents.height) > max_height)
+ max_height = extents.height;
+ }
+ return max_height;
}