From a096450ace7edeaadaa6ee94b2fa5a415bd06bf3 Mon Sep 17 00:00:00 2001 From: chevalam Date: Tue, 15 Apr 2014 18:22:55 +0530 Subject: Issue#8 - Add a new test for text rendering. Signed-off-by: Bryce Harrington --- src/cairo-tests/text.cpp | 116 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 99 insertions(+), 17 deletions(-) (limited to 'src/cairo-tests/text.cpp') diff --git a/src/cairo-tests/text.cpp b/src/cairo-tests/text.cpp index 1ebe7d2..69480df 100644 --- a/src/cairo-tests/text.cpp +++ b/src/cairo-tests/text.cpp @@ -1,15 +1,30 @@ #include #include #include - +#include #include "caskbench.h" static int max_dim; +static char rand_text_array[19][100]; +void gen_random(char *s, const int len) { + static const char alphanum[] = + "ABCD EFG HIJKL MNOPQ RSTUVW XYZ"; + + for (int i = 0; i < len; ++i) { + s[i] = alphanum[rand() % (sizeof(alphanum) - 1)]; + } + + s[len] = 0; +} int ca_setup_text(caskbench_context_t *ctx) { - max_dim = MIN(ctx->canvas_width, ctx->canvas_height)/2; + max_dim = MIN (ctx->canvas_width, ctx->canvas_height)/2; + for(int i = 0;i<19;i++) + { + gen_random (rand_text_array[i],i+18); + } return 1; } @@ -18,24 +33,91 @@ ca_teardown_text(void) { } + int ca_test_text(caskbench_context_t *ctx) { - int i, x, y, r; + cairo_t *cr = ctx->cairo_cr; - cairo_set_font_size (cr, 40); - - for (i=0; isize; i++) { - cairo_text_extents_t extents; - cairo_font_options_t *font_options; - float offsetY,offsetX; - int align; - unsigned int flags; - - randomize_color(cr); - cairo_move_to (cr, 150, 50); - cairo_show_text (cr, "TextRendering"); - } - return 1; + for (int i = 0; i < ctx->size; i++) + { + double font_size = 18; + int ypos = 0, xpos = 0; + + cairo_set_source_rgb (cr, 0, 0, 0); + cairo_rectangle (cr, 0, 0, ctx->canvas_width ,ctx->canvas_height); + cairo_fill (cr); + + + for(font_size = 18; font_size <= 36; font_size++) + { + cairo_set_font_size (cr, font_size); + randomize_color (cr); + + cairo_status_t status; + cairo_scaled_font_t *font; + font = cairo_get_scaled_font (cr); + cairo_glyph_t *glyphs = NULL; + int num_glyphs; + cairo_text_cluster_t *clusters = NULL; + int num_clusters; + cairo_text_cluster_flags_t cluster_flags; + + char text[(int)font_size]; + gen_random (text,font_size); + + status = cairo_scaled_font_text_to_glyphs (font, + xpos, ypos, + text, font_size, + &glyphs, &num_glyphs, + &clusters, &num_clusters, &cluster_flags); + + if (status == CAIRO_STATUS_SUCCESS) { + cairo_show_text_glyphs (cr, + rand_text_array[(int)font_size-18],font_size, + glyphs, num_glyphs, + clusters, num_clusters, cluster_flags); + } + ypos += (font_size/2); + } + + for(font_size = 36; font_size >= 18; font_size--) + { + + cairo_set_font_size (cr, font_size); + + randomize_color (cr); + + cairo_status_t status; + cairo_scaled_font_t *font; + font = cairo_get_scaled_font (cr); + cairo_glyph_t *glyphs = NULL; + int num_glyphs; + cairo_text_cluster_t *clusters = NULL; + int num_clusters; + cairo_text_cluster_flags_t cluster_flags; + + + char text[(int)font_size]; + gen_random (text,font_size); + + status = cairo_scaled_font_text_to_glyphs (font, + xpos, ypos, + text, font_size, + &glyphs, &num_glyphs, + &clusters, &num_clusters, &cluster_flags); + + if (status == CAIRO_STATUS_SUCCESS) { + cairo_show_text_glyphs (cr, + rand_text_array[(int)font_size-18],font_size, + glyphs, num_glyphs, + clusters, num_clusters, cluster_flags); + } + ypos += (font_size/2); + } + + } + + return 1; } -- cgit v1.3.1-4-g156e