blob: 62fbcc97db8c5680c0a682b46aaa0739cadf49e3 [file] [log] [blame]
djsollen@google.com5df5e612013-10-03 14:42:24 +00001/*
2 * Copyright 2013 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#include "gm.h"
9
10namespace skiagm {
11
12class AndroidFallbackGM : public GM {
13public:
14 AndroidFallbackGM() {
15 this->setBGColor(0xFFCCCCCC);
16 }
17
18protected:
mtklein@google.com745f2482013-10-28 20:40:41 +000019 virtual uint32_t onGetFlags() const SK_OVERRIDE {
20 // TODO(scroggo): Undo this if we decide to fix skia:1763.
21 return GM::kSkipPipe_Flag;
22 }
23
djsollen@google.com5df5e612013-10-03 14:42:24 +000024 virtual SkString onShortName() SK_OVERRIDE {
25 return SkString("android_paint");
26 }
27
28 virtual SkISize onISize() SK_OVERRIDE {
29 return make_isize(500, 500);
30 }
31
32 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
33
34 SkPaint paint;
35 paint.setTextEncoding(SkPaint::kUTF16_TextEncoding);
36 paint.setTextSize(24);
37
djsollen@google.comf7f5b7c2013-10-03 17:38:50 +000038#ifdef SK_BUILD_FOR_ANDROID
djsollen@google.com5df5e612013-10-03 14:42:24 +000039 SkPaintOptionsAndroid options = paint.getPaintOptionsAndroid();
40 options.setUseFontFallbacks(true);
41 paint.setPaintOptionsAndroid(options);
42#endif
43
44 // "ื foo ๅ…่ˆŒ bar เค•"
45 const uint16_t unicodeStr[] = {0x05D0, 0x0020, 0x0066, 0x006F, 0x006F, 0x0020, 0x514D,
46 0x820c, 0x0020, 0x0062, 0x0061, 0x0072, 0x0020, 0x0915};
47 const int strLength = sizeof(unicodeStr) / sizeof(uint16_t);
48 const int strByteLength = sizeof(unicodeStr);
49
50 SkScalar posX[strLength];
51 SkPoint posXY[strLength];
52
53 for (int i = 0; i < strLength; ++i) {
54 posX[i] = SkIntToScalar(i * 24);
55 posXY[i].fX = posX[i];
56 posXY[i].fY = SkIntToScalar(24 + i);
57 }
58
59 canvas->translate(SkIntToScalar(10), SkIntToScalar(25));
60 // This currently causes the PDF backend to assert
61 // canvas->drawText(unicodeStr, strByteLength, 0, 0, paint);
62
63 canvas->translate(0, SkIntToScalar(75));
64 canvas->drawPosTextH(unicodeStr, strByteLength, posX, 0, paint);
65
djsollen@google.comf7f5b7c2013-10-03 17:38:50 +000066#ifdef SK_BUILD_FOR_ANDROID
djsollen@google.com5df5e612013-10-03 14:42:24 +000067 options.setLanguage("ja");
68 paint.setPaintOptionsAndroid(options);
69#endif
70
71 canvas->translate(0, SkIntToScalar(75));
72 canvas->drawPosText(unicodeStr, strByteLength, posXY, paint);
73
74 SkPath path;
75 path.moveTo(0, 0);
76 path.quadTo(50.0f, 100.0f, 250.0f, 150.0f);
77
78 canvas->translate(0, SkIntToScalar(75));
79 canvas->drawTextOnPath(unicodeStr, strByteLength, path, NULL, paint);
80 }
81
82private:
83 typedef GM INHERITED;
84};
85
86//////////////////////////////////////////////////////////////////////////////
87
djsollen@google.comf7f5b7c2013-10-03 17:38:50 +000088#ifdef SK_BUILD_FOR_ANDROID
djsollen@google.com5df5e612013-10-03 14:42:24 +000089DEF_GM( return SkNEW(AndroidFallbackGM); )
90#endif
91
92}