summaryrefslogtreecommitdiffstatsci
diff options
context:
space:
mode:
authorBryce Harrington <b.harrington@samsung.com>2014-07-30 11:31:57 -0700
committerBryce Harrington <bryce@osg.samsung.com>2014-08-06 16:30:40 -0700
commit5e600581208ef9115313cc0ab63020928d5e57ce (patch)
tree9603979eba3bc83d8a9563f13413ff0840444329
parent8c6f384feaa255c137b1133910ef4ed5719eb372 (diff)
tests: Add text test replicating FlashCanvas functionality
-rw-r--r--src/cairo-tests/text-glyphs.cpp3
-rw-r--r--src/cairo-tests/text.cpp111
-rw-r--r--src/skia-tests/text.cpp82
3 files changed, 195 insertions, 1 deletions
diff --git a/src/cairo-tests/text-glyphs.cpp b/src/cairo-tests/text-glyphs.cpp
index e1a3170..34d17ce 100644
--- a/src/cairo-tests/text-glyphs.cpp
+++ b/src/cairo-tests/text-glyphs.cpp
@@ -20,7 +20,8 @@
static int max_dim;
static char rand_text_array[19][100];
-void gen_random(char *s, const int len) {
+static void
+gen_random(char *s, const int len) {
static const char alphanum[] =
"ABCD EFG HIJKL MNOPQ RSTUVW XYZ";
diff --git a/src/cairo-tests/text.cpp b/src/cairo-tests/text.cpp
new file mode 100644
index 0000000..d40f0e6
--- /dev/null
+++ b/src/cairo-tests/text.cpp
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2014 © Samsung Research America, Silicon Valley
+ *
+ * Use of this source code is governed by the 3-Clause BSD license
+ * specified in the COPYING file included with this source code.
+ */
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <cairo.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;
+}
+
+int
+ca_setup_text(caskbench_context_t *ctx)
+{
+ max_dim = MIN (ctx->canvas_width, ctx->canvas_height)/2;
+ return 1;
+}
+
+void
+ca_teardown_text(void)
+{
+}
+
+int
+ca_test_text(caskbench_context_t *ctx)
+{
+ 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;
+
+ 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);
+ }
+
+ 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;
+ }
+ return 1;
+}
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
diff --git a/src/skia-tests/text.cpp b/src/skia-tests/text.cpp
new file mode 100644
index 0000000..bff88eb
--- /dev/null
+++ b/src/skia-tests/text.cpp
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2014 © Samsung Research America, Silicon Valley
+ *
+ * Use of this source code is governed by the 3-Clause BSD license
+ * specified in the COPYING file included with this source code.
+ */
+#include <config.h>
+
+#include <unistd.h>
+
+#include <SkCanvas.h>
+#include <SkPaint.h>
+#include <SkGpuDevice.h>
+#include <SkString.h>
+#include <SkTemplates.h>
+#include <SkTypeface.h>
+#include <effects/SkGradientShader.h>
+#include <SkDraw.h>
+#include <effects/SkGradientShader.h>
+#include <SkGraphics.h>
+
+#include "caskbench.h"
+#include "caskbench_context.h"
+#include "skia-shapes.h"
+
+// This tests basic (non-glyph) text functionality
+
+int
+sk_setup_text(caskbench_context_t *ctx)
+{
+ SkTypeface *style = SkTypeface::CreateFromName("Serif", SkTypeface::kBold);
+
+ ctx->skia_paint->setTypeface(style);
+ ctx->skia_paint->setAntiAlias(false);
+ ctx->skia_paint->setStyle(SkPaint::kFill_Style);
+ ctx->skia_paint->setTextSize(20.0f);
+
+ style->unref();
+
+ return 1;
+}
+
+void
+sk_teardown_text(void)
+{
+}
+
+int
+sk_test_text(caskbench_context_t *ctx)
+{
+ char text[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ size_t byteLength = strlen(text) * sizeof(char);
+ double tw = SkScalarToDouble(ctx->skia_paint->measureText(text, byteLength));
+ double w = (double)ctx->skia_canvas->getDevice()->width();
+ double h = (double)ctx->skia_canvas->getDevice()->height();
+ double off = abs (w - tw);
+
+ ctx->skia_canvas->drawColor(SK_ColorBLACK);
+
+ for (int i = 0; i < ctx->size; i++)
+ {
+ double x = drand48() * off;
+ double y = drand48() * h;
+
+ skiaRandomizePaintColor(ctx);
+
+ ctx->skia_canvas->drawText(text, byteLength, SkDoubleToScalar(x),
+ SkDoubleToScalar(y), *(ctx->skia_paint));
+ }
+ return 1;
+}
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :