summaryrefslogtreecommitdiffstatsci
path: root/src/cairo-tests/text.cpp
diff options
context:
space:
mode:
authorsuyambulingamrm <suyambu.rm@samsung.com>2014-08-09 17:40:09 +0530
committersuyambulingamrm <suyambu.rm@samsung.com>2014-08-09 17:40:09 +0530
commit6d68b9b3c7d7a4bd0880268e7c3f57c8f51a77c3 (patch)
tree3fa2423f8ab24d443008c7c2ef6e3279e90cb530 /src/cairo-tests/text.cpp
parent8ab8e7d5de0465aaaa05bb738b121da82e4528dd (diff)
Issue #130. Add cairo text case similar to skia & Minor corrections to skia text case.
Diffstat (limited to 'src/cairo-tests/text.cpp')
-rw-r--r--src/cairo-tests/text.cpp81
1 files changed, 23 insertions, 58 deletions
diff --git a/src/cairo-tests/text.cpp b/src/cairo-tests/text.cpp
index d40f0e6..bf3028d 100644
--- a/src/cairo-tests/text.cpp
+++ b/src/cairo-tests/text.cpp
@@ -8,34 +8,25 @@
#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h>
#include <cairo.h>
+#include <string.h>
#include "caskbench.h"
#include "caskbench_context.h"
#include "cairo-shapes.h"
-// This test converts a text string to glyphs and displays it at various font sizes
-
-static int max_dim;
-static char rand_text_array[19][100];
-
-static 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;
-}
+// This tests basic (non-glyph) text functionality
int
ca_setup_text(caskbench_context_t *ctx)
{
- max_dim = MIN (ctx->canvas_width, ctx->canvas_height)/2;
+ cairo_t *cr = ctx->cairo_cr;
+ cairo_select_font_face(cr, "Serif",
+ CAIRO_FONT_SLANT_NORMAL,
+ CAIRO_FONT_WEIGHT_BOLD);
+
+ cairo_set_font_size(cr, 20);
+ cairo_set_antialias(cr,CAIRO_ANTIALIAS_NONE);
return 1;
}
@@ -47,54 +38,28 @@ ca_teardown_text(void)
int
ca_test_text(caskbench_context_t *ctx)
{
+ char text[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
cairo_t *cr = ctx->cairo_cr;
- double font_size = 18;
- int ypos = 15, xpos = 0;
- int num_glyphs = 0, num_clusters = 0;
-
- double font_factor = 0.5;
+ size_t byteLength = strlen(text) * sizeof(char);
+ cairo_text_extents_t text_metrics;
+ cairo_text_extents (cr, text, &text_metrics);
+ double tw = text_metrics.width + 3; // Adding 3 to make tw value same as skia text.
+ double w = (double) ctx->canvas_width;
+ double h = (double) ctx->canvas_height;
+ double off = abs (w - tw);
cairo_set_source_rgb (cr, 0, 0, 0);
cairo_rectangle (cr, 0, 0, ctx->canvas_width ,ctx->canvas_height);
cairo_fill (cr);
+
for (int i = 0; i < ctx->size; i++)
{
- num_glyphs = 0;
- num_clusters = 0;
- cairo_set_font_size (cr, font_size);
- cairoRandomizeColor (ctx);
-
- cairo_status_t status;
- cairo_scaled_font_t *font;
- font = cairo_get_scaled_font (cr);
- cairo_glyph_t *glyphs = NULL;
- cairo_text_cluster_t *clusters = NULL;
- 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,
- text,font_size,
- glyphs, num_glyphs,
- clusters, num_clusters, cluster_flags);
- }
+ double x = drand48() * off;
+ double y = drand48() * h;
- font_size = font_size+font_factor;
- ypos += (font_size/2);
- if (font_size >= 36)
- font_size = 36;
- if (ypos > ctx->canvas_height/2)
- font_factor = -0.5;
- if (font_size < 18)
- font_size = 18;
+ cairoRandomizeColor(ctx);
+ cairo_move_to(cr, x, y);
+ cairo_show_text(cr, text);
}
return 1;
}