#include #include #include #include #include #include // #define PRINT_RESULTS #define NUM_RUNS 2048 void do_work (gchar *text, PangoContext *context) { int linenum = 0; for(;;) { gchar *start = text; int length = 0; while (start [length] != '\n' && start [length]) { length++; } if (!start [length]) return; if (length) { PangoLayout *layout; PangoRectangle ink_rect, logical_rect; #ifdef PRINT_RESULTS int i; printf ("Line %d [%d]: ", linenum, length); for (i = 0; i < length; i++) printf ("%c", start [i]); printf ("\n"); #endif layout = pango_layout_new (context); pango_layout_set_text (layout, start, length); pango_layout_get_extents (layout, &ink_rect, &logical_rect); g_object_unref (layout); #ifdef PRINT_RESULTS printf ("Line %d [%d]: Ink %d,%d %dx%d Logical %d,%d %dx%d\n", linenum, length, ink_rect.x, ink_rect.y, ink_rect.width, ink_rect.height, logical_rect.x, logical_rect.y, logical_rect.width, logical_rect.height); #endif } text += length + 1; linenum++; } } int main (int argc, char **argv) { PangoFontMap *fontmap; PangoContext *context; gchar *text; int i; fontmap = pango_cairo_font_map_get_default (); context = pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP (fontmap)); if (!g_file_get_contents (argv [1], &text, NULL, NULL)) { fprintf (stderr, "Cannot open input file %s\n", argv [1]); return 1; } for (i = 0; i < NUM_RUNS; i++) do_work (text, context); g_free (text); return 0; }