From c26d2c5ef90c49e3854d6630c2ade6d7069865d8 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Thu, 5 Aug 2010 17:06:45 +0100 Subject: [PATCH] test-text-perf: Scale the text if the settings will not fit If the font size or the number of characters causes the label not to fit on the stage, instead of aborting it will now scale the labels so that it fits within one of the dimensions. This makes it easier to test with large glyph sizes. --- tests/micro-bench/test-text-perf.c | 37 ++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/tests/micro-bench/test-text-perf.c b/tests/micro-bench/test-text-perf.c index f21cdc30b..8d0ac5edd 100644 --- a/tests/micro-bench/test-text-perf.c +++ b/tests/micro-bench/test-text-perf.c @@ -75,6 +75,7 @@ main (int argc, char *argv[]) ClutterActor *label; int w, h; int row, col; + float scale = 1.0f; g_setenv ("CLUTTER_VBLANK", "none", FALSE); g_setenv ("CLUTTER_DEFAULT_FPS", "1000", FALSE); @@ -101,21 +102,43 @@ main (int argc, char *argv[]) label = create_label (); w = clutter_actor_get_width (label); h = clutter_actor_get_height (label); - cols = STAGE_WIDTH / w; - rows = STAGE_HEIGHT / h; - clutter_actor_destroy (label); - if (cols == 0 || rows == 0) + /* If the label is too big to fit on the stage then scale it so that + it will fit */ + if (w > STAGE_WIDTH || h > STAGE_HEIGHT) { - g_printerr("Too many characters to fit in stage\n"); - exit(1); + float x_scale = STAGE_WIDTH / (float) w; + float y_scale = STAGE_HEIGHT / (float) h; + + if (x_scale < y_scale) + { + scale = x_scale; + cols = 1; + rows = STAGE_HEIGHT / (h * scale); + } + else + { + scale = y_scale; + cols = STAGE_WIDTH / (w * scale); + rows = 1; + } + + g_print ("Text scaled by %f to fit on the stage\n", scale); } + else + { + cols = STAGE_WIDTH / w; + rows = STAGE_HEIGHT / h; + } + + clutter_actor_destroy (label); for (row=0; row