blob: 0f3cb3bd922f1d8dfe7a15841a3df3c2897f4cf4 [file] [log] [blame]
reed@google.com14debba2011-11-10 20:06:01 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8
9#include "gm.h"
10#include "SkCanvas.h"
11
12namespace skiagm {
13
14#define TEXT_SIZE 48
15static const char gText[] = "Hello";
16static const size_t gLen = sizeof(gText) - 1;
17
18class VertTextGM : public GM {
19public:
20 VertTextGM() {}
21
22protected:
23
24 SkString onShortName() {
reed@google.com2f6c9572011-11-30 14:58:16 +000025 return SkString("verttext");
reed@google.com14debba2011-11-10 20:06:01 +000026 }
27
28 SkISize onISize() { return make_isize(640, 480); }
29
30 static void drawBaseline(SkCanvas* canvas, const SkPaint& paint,
31 SkScalar x, SkScalar y) {
32 SkScalar total = paint.measureText(gText, gLen);
33
34 SkPaint p;
35 p.setAntiAlias(true);
36 p.setColor(0x80FF0000);
37 canvas->drawLine(x, y,
38 paint.isVerticalText() ? x : x + total,
39 paint.isVerticalText() ? y + total : y,
40 p);
41
42 p.setColor(0xFF0000FF);
43 SkScalar adv[gLen];
44 paint.getTextWidths(gText, gLen, adv, NULL);
45 for (size_t i = 0; i < gLen; ++i) {
46 canvas->drawCircle(x, y, SK_Scalar1 * 3 / 2, p);
47 if (paint.isVerticalText()) {
48 y += adv[i];
49 } else {
50 x += adv[i];
51 }
52 }
53 canvas->drawCircle(x, y, SK_Scalar1 * 3 / 2, p);
54 }
55
56 virtual void onDraw(SkCanvas* canvas) {
57 SkScalar x = SkIntToScalar(100);
58 SkScalar y = SkIntToScalar(50);
59
60 for (int i = 0; i < 4; ++i) {
61 SkPaint paint;
62 paint.setAntiAlias(true);
63 paint.setTextSize(SkIntToScalar(TEXT_SIZE));
64
65
66 paint.setVerticalText(false);
67 drawBaseline(canvas, paint, x, y);
68 canvas->drawText(gText, gLen, x, y, paint);
69
70 paint.setVerticalText(true);
71 drawBaseline(canvas, paint, x, y);
72 canvas->drawText(gText, gLen, x, y, paint);
73
74 x += SkIntToScalar(40);
75 y += SkIntToScalar(120);
76
77 canvas->rotate(SkIntToScalar(-15));
78 }
79 }
80
81private:
82 typedef GM INHERITED;
83};
84
85///////////////////////////////////////////////////////////////////////////////
86
87static GM* MyFactory(void*) { return new VertTextGM; }
88static GMRegistry reg(MyFactory);
89
90}