stdio_write (void *closure, const unsigned char *data, unsigned int length);
#endif
-double
-get_max_width (cairo_t *cr, char *characters);
+static double
+get_max_width (cairo_t *cr, const 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;
+}
-double
-get_max_height (cairo_t *cr, char *characters);
+static double
+get_max_height (cairo_t *cr, const 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);
+// 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;
+}
typedef struct {
char *family;
return ft_face;
}
+static void
+get_characters_max_width_height (FT_Face ft_face, double size,
+ const char *characters,
+ double *max_width, double *max_height)
+{
+ cairo_surface_t *surface;
+ cairo_t *cr;
+ cairo_font_face_t *cr_face;
+
+ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+ 1, 1);
+
+ 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_set_font_size (cr, size);
+
+ cairo_set_line_width (cr, 1.0);
+
+ *max_width = get_max_width(cr, characters);
+ *max_height = get_max_height(cr, characters);
+
+ cairo_font_face_destroy (cr_face);
+
+ cairo_destroy (cr);
+
+ cairo_surface_destroy(surface);
+}
+
int
main (void)
{
FT_UInt left_index, right_index;
FT_Bool use_kerning;
FT_Vector kerning;
+ double max_width, max_height;
+ cairo_surface_t *surface;
+ cairo_t *cr;
+ cairo_font_face_t *cr_face;
parse_args (&args);
use_kerning = FT_HAS_KERNING( ft_face );
- /* Compute max-width and max-height */
- cairo_surface_t *surface;
- cairo_t *cr;
- cairo_font_face_t *cr_face;
-
- surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
- 1, 1);
-
- 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_set_font_size (cr, args.size);
-
- cairo_set_line_width (cr, 1.0);
-
- double max_width = get_max_width(cr, characters);
- double max_height = get_max_height(cr, characters);
-
- cairo_font_face_destroy (cr_face);
-
- cairo_destroy (cr);
-
- cairo_surface_destroy(surface);
+ get_characters_max_width_height (ft_face, args.size,
+ characters,
+ &max_width, &max_height);
/* Draw */
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
return CAIRO_STATUS_WRITE_ERROR;
}
#endif
-
-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;
-}
-
-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);
-// 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;
-}
-