2 * Copyright 2011 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
11 #include "SkTypeface.h"
16 constexpr char gText[] = "Hello";
19 //constexpr char gText[] = "「テスト。」";
20 //constexpr char gText[] = {0xE3,0x80,0x8C, 0xE3,0x83,0x86, 0xE3,0x82,0xB9, 0xE3,0x83,0x88, 0xE3,0x80,0x82, 0xE3,0x80,0x8D, 0x0};
23 //constexpr char gText[] = "﹁テスト︒﹂";
24 //constexpr char gText[] = {0xEF,0xB9,0x81, 0xE3,0x83,0x86, 0xE3,0x82,0xB9, 0xE3,0x83,0x88, 0xEF,0xB8,0x92, 0xEF,0xB9,0x82, 0x0};
26 constexpr size_t gLen = sizeof(gText) - sizeof(gText[0]);
28 class VertTextGM : public GM {
31 // : fFace(SkTypeface::CreateFromName("unifont", SkTypeface::kNormal))
32 // : fFace(SkTypeface::CreateFromFile("MotoyaL04Mincho_3.ttf"))
34 // Bitmap fonts on OS X.
35 // : fFace(SkTypeface::CreateFromName("GB18030 Bitmap", SkTypeface::kNormal))
36 // : fFace(SkTypeface::CreateFromName("Apple Color Emoji", SkTypeface::kNormal))
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))
49 //sk_sp<SkTypeface> fFace;
53 SkString onShortName() override {
54 return SkString("verttext");
57 SkISize onISize() override { return SkISize::Make(640, 480); }
59 static void drawBaseline(SkCanvas* canvas, const SkPaint& paint,
60 SkScalar x, SkScalar y) {
61 SkScalar total = paint.measureText(gText, gLen);
65 p.setColor(0x80FF0000);
66 canvas->drawLine(x, y,
67 paint.isVerticalText() ? x : x + total,
68 paint.isVerticalText() ? y + total : y,
71 p.setColor(0xFF0000FF);
73 int numChars = paint.getTextWidths(gText, gLen, adv, nullptr);
74 for (int i = 0; i < numChars; ++i) {
75 canvas->drawCircle(x, y, SK_Scalar1 * 3 / 2, p);
76 if (paint.isVerticalText()) {
82 canvas->drawCircle(x, y, SK_Scalar1 * 3 / 2, p);
85 void onDraw(SkCanvas* canvas) override {
86 SkScalar x = SkIntToScalar(100);
87 SkScalar y = SkIntToScalar(50);
89 for (int i = 0; i < 4; ++i) {
91 paint.setAntiAlias(true);
92 paint.setTextSize(SkIntToScalar(TEXT_SIZE));
93 //paint.setTypeface(fFace);
94 //paint.setFakeBoldText(true);
96 paint.setVerticalText(false);
97 drawBaseline(canvas, paint, x, y);
98 canvas->drawText(gText, gLen, x, y, paint);
100 paint.setVerticalText(true);
101 drawBaseline(canvas, paint, x, y);
102 canvas->drawText(gText, gLen, x, y, paint);
104 x += SkIntToScalar(40);
105 y += SkIntToScalar(120);
107 canvas->rotate(SkIntToScalar(-15));
112 typedef GM INHERITED;
115 ///////////////////////////////////////////////////////////////////////////////
117 static GM* MyFactory(void*) { return new VertTextGM; }
118 static GMRegistry reg(MyFactory);