summaryrefslogtreecommitdiffstatsci
path: root/src/cairo-tests
diff options
context:
space:
mode:
authorchevalam <chevalam.s@samsung.com>2014-04-15 18:22:55 +0530
committerBryce Harrington <b.harrington@samsung.com>2014-04-16 19:10:33 -0700
commita096450ace7edeaadaa6ee94b2fa5a415bd06bf3 (patch)
treefd449c126019cf24432ae7e6cca9276d60d7881f /src/cairo-tests
parentad528b4f59cb34aff8b1bc422226119dcb5b0b9b (diff)
Issue#8 - Add a new test for text rendering.
Signed-off-by: Bryce Harrington <b.harrington@samsung.com>
Diffstat (limited to 'src/cairo-tests')
-rw-r--r--src/cairo-tests/text.cpp112
1 files changed, 97 insertions, 15 deletions
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 <stdio.h>
#include <stdlib.h>
#include <cairo.h>
-
+#include <unistd.h>
#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; i<ctx->size; i++) {
- cairo_text_extents_t extents;
- cairo_font_options_t *font_options;
- float offsetY,offsetX;
- int align;
- unsigned int flags;
+ for (int i = 0; i < ctx->size; i++)
+ {
+ double font_size = 18;
+ int ypos = 0, xpos = 0;
- randomize_color(cr);
- cairo_move_to (cr, 150, 50);
- cairo_show_text (cr, "TextRendering");
- }
+ cairo_set_source_rgb (cr, 0, 0, 0);
+ cairo_rectangle (cr, 0, 0, ctx->canvas_width ,ctx->canvas_height);
+ cairo_fill (cr);
- return 1;
+
+ 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;
}