#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
-
static double
get_max_width (cairo_t *cr, const char *characters, int num_characters)
{
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;
}
{
/* First some defaults */
args->family = "Vera";
- args->size = 20;
+ args->size = 40;
args->color.red = 0.0;
- args->color.green = 0.0;
+ args->color.green = 0.3;
args->color.blue = 0.0;
/* XXX: Next, we should override the defaults based on
cr = cairo_create (surface);
-/*
- 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);
cairo_font_face_t *cr_face;
int i;
-/*
- 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 x = 0.0;
double y = 0.0;
- cairo_translate (cr, 0, -(character_height / 2.50));
-
-// cairo_translate (cr, 0, -5.0);
-
char string[2];
string[1] = '\0';
+
+ cairo_set_line_width (cr, 2.0);
for (i = 0; i < num_characters; i++)
{
- if (i % 10 == 0)
- {
- x = 0.;
- y += character_height + 8;
- }
+ cairo_rectangle (cr, x, y, character_width, character_height);
+ cairo_stroke_preserve (cr);
+ cairo_save (cr);
+ cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
+ cairo_fill (cr);
+ cairo_restore (cr);
+
string[0] = characters[i];
cairo_text_extents (cr, string, &extents);
- x -= extents.x_bearing;
-
- cairo_move_to (cr, x, y);
- cairo_text_path (cr, string);
- cairo_fill (cr);
+ cairo_move_to (cr, x - extents.x_bearing, y - extents.y_bearing);
+ cairo_show_text (cr, string);
- x += extents.x_bearing;
- x += character_width + 8;
+ if ((i+1) % 10 == 0)
+ {
+ x = 0.;
+ y += character_height;
+ } else {
+ x += character_width;
+ }
}
-/*
- int thick_width = 4;
- int thin_width = 0;
-
- for (c = 'A'; c <= 'I'; c++)
- {
- string[0] = c;
- int spacing = ((c - 'A') * letterspacing) + 1;
-
-
- cairo_save(cr);
-
- 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_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_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_fill (cr);
-}
-*/
-
cairo_scale (cr, 1, -1);
cairo_push_group (cr);
-/*
-
-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);
-
-}
-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);
-
-cairo_mask (cr, gradient);
-
-cairo_pattern_destroy (gradient);
-*/
}
int
parse_args (&args);
-#if USE_CGIC
- if (outputJson)
- {
- cgiHeaderContentType("application/json");
- } else {
- cgiHeaderContentType("image/png");
- }
-#endif
-
ft_face = load_ft_face_for_family (args.family);
get_characters_max_width_height (ft_face, args.size,
/* Draw */
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
- (max_width + 8) * 10,
- (max_height + 8) * 10);
+ max_width * 10,
+ max_height * 10);
cr = cairo_create (surface);
characters, ARRAY_SIZE (characters),
max_width, max_height);
-#if USE_CGIC
- if (outputJson)
- {
- printf("}");
- } else {
- cairo_surface_write_to_png_stream (surface, stdio_write, cgiOut);
- }
-#endif
-
cairo_surface_write_to_png (surface, "spritext-output.png");
printf ("Result written to spritext-output.png\n");
return 0;
}
-
-#if USE_CGIC
-static cairo_status_t
-stdio_write (void *closure, const unsigned char *data, unsigned int length)
-{
- FILE *file = closure;
- if (fwrite (data, 1, length, file) == length)
- return CAIRO_STATUS_SUCCESS;
- else
- return CAIRO_STATUS_WRITE_ERROR;
-}
-#endif