summaryrefslogtreecommitdiffstatsci
path: root/src
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
parentad528b4f59cb34aff8b1bc422226119dcb5b0b9b (diff)
Issue#8 - Add a new test for text rendering.
Signed-off-by: Bryce Harrington <b.harrington@samsung.com>
Diffstat (limited to 'src')
-rw-r--r--src/cairo-tests/text.cpp112
-rw-r--r--src/skia-tests/text.cpp100
2 files changed, 185 insertions, 27 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;
}
diff --git a/src/skia-tests/text.cpp b/src/skia-tests/text.cpp
index cfd8dda..4013830 100644
--- a/src/skia-tests/text.cpp
+++ b/src/skia-tests/text.cpp
@@ -9,12 +9,32 @@
#include "SkString.h"
#include "SkTemplates.h"
#include "SkTypeface.h"
+#include "effects/SkGradientShader.h"
+#include "unistd.h"
+#include "SkUnitMappers.h"
+#include "SkDraw.h"
+#include "effects/SkGradientShader.h"
+#include "SkGraphics.h"
static int max_dim;
+static char rand_text_array[19][100];
+void gen_skia_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
sk_setup_text(caskbench_context_t *ctx)
{
max_dim = MIN(ctx->canvas_width, ctx->canvas_height)/2;
+ for(int i = 0;i<19;i++)
+ {
+ gen_skia_random(rand_text_array[i],i+18);
+ }
return 1;
}
@@ -23,21 +43,77 @@ sk_teardown_text(void)
{
}
+static void getGlyphPositions(const SkPaint& paint, const uint16_t glyphs[],
+ int count, SkScalar x, SkScalar y, SkPoint pos[]) {
+ SkASSERT(SkPaint::kGlyphID_TextEncoding == paint.getTextEncoding());
+
+ SkAutoSTMalloc<128, SkScalar> widthStorage (count);
+ SkScalar* widths = widthStorage.get();
+ paint.getTextWidths (glyphs, count * sizeof(uint16_t), widths);
+
+ for (int i = 0; i < count; ++i) {
+ pos[i].set(x, y);
+ x += widths[i];
+ }
+}
+
+
+
int
sk_test_text(caskbench_context_t *ctx)
{
unsigned char red, green, blue, alpha;
- int i;
- ctx->skia_paint->setTextSize(SkIntToScalar(40));
- SkString text("TextRendering");
- for (i=0; i<ctx->size; i++) {
- red = int( 255 * (double)rand()/RAND_MAX );
- green = int( 255 * (double)rand()/RAND_MAX );
- blue = int( 255 * (double)rand()/RAND_MAX );
- alpha = int( 255 * (double)rand()/RAND_MAX );
- ctx->skia_paint->setLCDRenderText(false);
- ctx->skia_paint->setARGB(alpha, red, green, blue);
- ctx->skia_canvas->drawText(text.c_str(), text.size(), 150, 50, *ctx->skia_paint);
- }
+ for (int i = 0; i < ctx->size; i++)
+ {
+ double font_size = 18;
+ int ypos = 0, xpos = 0;
+ ctx->skia_canvas->drawColor(SK_ColorBLACK);
+
+ for(font_size = 18; font_size <= 36; font_size++)
+ {
+ ctx->skia_paint->setTextSize (SkIntToScalar (font_size));
+ red = int( 255 * (double)rand()/RAND_MAX );
+ green = int( 255 * (double)rand()/RAND_MAX );
+ blue = int( 255 * (double)rand()/RAND_MAX );
+ alpha = int( 255 * (double)rand()/RAND_MAX );
+ ctx->skia_paint->setARGB (alpha,red,green,blue);
+
+ SkPaint newpaint (*ctx->skia_paint);;
+ newpaint.setTextEncoding (SkPaint::kGlyphID_TextEncoding);
+
+ SkAutoSTMalloc<128, uint16_t> glyphStorage (font_size);
+ uint16_t* glyphs = glyphStorage.get();
+
+ char text[(int)font_size];
+ gen_skia_random (text,font_size);
+
+ int glyphCount = ctx->skia_paint->textToGlyphs (text, font_size, glyphs);
+ ctx->skia_canvas->drawText (glyphs, glyphCount * sizeof(uint16_t), xpos,ypos, newpaint);
+ ypos += (font_size/2);
+ }
+
+ for(font_size = 36; font_size >= 18; font_size--)
+ {
+ ctx->skia_paint->setTextSize (SkIntToScalar (font_size));
+ red = int( 255 * (double)rand()/RAND_MAX );
+ green = int( 255 * (double)rand()/RAND_MAX );
+ blue = int( 255 * (double)rand()/RAND_MAX );
+ alpha = int( 255 * (double)rand()/RAND_MAX );
+ ctx->skia_paint->setARGB (alpha,red,green,blue);
+
+ SkPaint localPaint (*ctx->skia_paint);;
+ localPaint.setTextEncoding (SkPaint::kGlyphID_TextEncoding);
+
+ SkAutoSTMalloc<128, uint16_t> glyphStorage (font_size);
+ uint16_t* glyphs = glyphStorage.get();
+ char text[(int)font_size];
+ gen_skia_random (text,font_size);
+
+ int glyphCount = ctx->skia_paint->textToGlyphs (text, font_size, glyphs);
+ ctx->skia_canvas->drawText (glyphs, glyphCount * sizeof(uint16_t), xpos,ypos, localPaint);
+ ypos += (font_size/2);
+ }
+
+ }
return 1;
}