blob: 1f1c64dfe6b674cc0d77e1977245a5ed7bc00690 [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"
bungeman@google.com8ff8a192012-09-25 20:38:28 +000011#include "SkTypeface.h"
reed@google.com14debba2011-11-10 20:06:01 +000012
13namespace skiagm {
14
15#define TEXT_SIZE 48
16static const char gText[] = "Hello";
bungeman@google.com8ff8a192012-09-25 20:38:28 +000017
18//Before shaping
19//static const char gText[] = "「テスト。」";
20//static const char gText[] = {0xE3,0x80,0x8C, 0xE3,0x83,0x86, 0xE3,0x82,0xB9, 0xE3,0x83,0x88, 0xE3,0x80,0x82, 0xE3,0x80,0x8D, 0x0};
21
22//After shaping
23//static const char gText[] = "﹁テスト︒﹂";
24//static const char gText[] = {0xEF,0xB9,0x81, 0xE3,0x83,0x86, 0xE3,0x82,0xB9, 0xE3,0x83,0x88, 0xEF,0xB8,0x92, 0xEF,0xB9,0x82, 0x0};
25
bungeman@google.com33346482013-08-27 19:05:32 +000026static const size_t gLen = sizeof(gText) - sizeof(gText[0]);
reed@google.com14debba2011-11-10 20:06:01 +000027
28class VertTextGM : public GM {
29public:
bungeman@google.com8ff8a192012-09-25 20:38:28 +000030 VertTextGM()
31 // : fFace(SkTypeface::CreateFromName("unifont", SkTypeface::kNormal))
32 // : fFace(SkTypeface::CreateFromFile("MotoyaL04Mincho_3.ttf"))
bungeman@google.comcefd9812013-05-15 15:07:32 +000033
34 // Bitmap fonts on OS X.
35 // : fFace(SkTypeface::CreateFromName("GB18030 Bitmap", SkTypeface::kNormal))
36 // : fFace(SkTypeface::CreateFromName("Apple Color Emoji", SkTypeface::kNormal))
37
38 // OTF CFF fonts on OS X.
39 // : fFace(SkTypeface::CreateFromName("Hiragino Mincho ProN", SkTypeface::kNormal))
40 // : fFace(SkTypeface::CreateFromName("Hiragino Kaku Gothic Pro", SkTypeface::kNormal))
41 // : fFace(SkTypeface::CreateFromName("Hiragino Sans GB", SkTypeface::kNormal))
42 // : fFace(SkTypeface::CreateFromName("STIXGeneral", SkTypeface::kNormal))
43 // : fFace(SkTypeface::CreateFromName("Yuppy SC", SkTypeface::kNormal))
44 // : fFace(SkTypeface::CreateFromName("Yuppy TC", SkTypeface::kNormal))
45
bungeman@google.com8ff8a192012-09-25 20:38:28 +000046 {
47 }
48
49 //SkAutoTUnref<SkTypeface> fFace;
reed@google.com14debba2011-11-10 20:06:01 +000050
51protected:
52
53 SkString onShortName() {
reed@google.com2f6c9572011-11-30 14:58:16 +000054 return SkString("verttext");
reed@google.com14debba2011-11-10 20:06:01 +000055 }
56
57 SkISize onISize() { return make_isize(640, 480); }
58
59 static void drawBaseline(SkCanvas* canvas, const SkPaint& paint,
60 SkScalar x, SkScalar y) {
61 SkScalar total = paint.measureText(gText, gLen);
62
63 SkPaint p;
64 p.setAntiAlias(true);
65 p.setColor(0x80FF0000);
66 canvas->drawLine(x, y,
67 paint.isVerticalText() ? x : x + total,
68 paint.isVerticalText() ? y + total : y,
69 p);
70
71 p.setColor(0xFF0000FF);
72 SkScalar adv[gLen];
bungeman@google.com33346482013-08-27 19:05:32 +000073 int numChars = paint.getTextWidths(gText, gLen, adv, NULL);
74 for (int i = 0; i < numChars; ++i) {
reed@google.com14debba2011-11-10 20:06:01 +000075 canvas->drawCircle(x, y, SK_Scalar1 * 3 / 2, p);
76 if (paint.isVerticalText()) {
77 y += adv[i];
78 } else {
79 x += adv[i];
80 }
81 }
82 canvas->drawCircle(x, y, SK_Scalar1 * 3 / 2, p);
83 }
84
85 virtual void onDraw(SkCanvas* canvas) {
86 SkScalar x = SkIntToScalar(100);
87 SkScalar y = SkIntToScalar(50);
rmistry@google.comae933ce2012-08-23 18:19:56 +000088
reed@google.com14debba2011-11-10 20:06:01 +000089 for (int i = 0; i < 4; ++i) {
bungeman@google.com8ff8a192012-09-25 20:38:28 +000090 SkPaint paint;
reed@google.com14debba2011-11-10 20:06:01 +000091 paint.setAntiAlias(true);
92 paint.setTextSize(SkIntToScalar(TEXT_SIZE));
bungeman@google.com8ff8a192012-09-25 20:38:28 +000093 //paint.setTypeface(fFace);
94 //paint.setFakeBoldText(true);
reed@google.com14debba2011-11-10 20:06:01 +000095
96 paint.setVerticalText(false);
97 drawBaseline(canvas, paint, x, y);
98 canvas->drawText(gText, gLen, x, y, paint);
99
100 paint.setVerticalText(true);
101 drawBaseline(canvas, paint, x, y);
102 canvas->drawText(gText, gLen, x, y, paint);
rmistry@google.comae933ce2012-08-23 18:19:56 +0000103
reed@google.com14debba2011-11-10 20:06:01 +0000104 x += SkIntToScalar(40);
105 y += SkIntToScalar(120);
106
107 canvas->rotate(SkIntToScalar(-15));
108 }
109 }
110
111private:
112 typedef GM INHERITED;
113};
114
115///////////////////////////////////////////////////////////////////////////////
116
117static GM* MyFactory(void*) { return new VertTextGM; }
118static GMRegistry reg(MyFactory);
119
120}