blob: a4f10369f14b061caa74d36826a1836b0ad1255f [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:
19 virtual SkString onShortName() SK_OVERRIDE {
20 return SkString("android_paint");
21 }
22
23 virtual SkISize onISize() SK_OVERRIDE {
24 return make_isize(500, 500);
25 }
26
27 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
28
29 SkPaint paint;
30 paint.setTextEncoding(SkPaint::kUTF16_TextEncoding);
31 paint.setTextSize(24);
32
djsollen@google.comf7f5b7c2013-10-03 17:38:50 +000033#ifdef SK_BUILD_FOR_ANDROID
djsollen@google.com5df5e612013-10-03 14:42:24 +000034 SkPaintOptionsAndroid options = paint.getPaintOptionsAndroid();
35 options.setUseFontFallbacks(true);
36 paint.setPaintOptionsAndroid(options);
37#endif
38
39 // "ื foo ๅ…่ˆŒ bar เค•"
40 const uint16_t unicodeStr[] = {0x05D0, 0x0020, 0x0066, 0x006F, 0x006F, 0x0020, 0x514D,
41 0x820c, 0x0020, 0x0062, 0x0061, 0x0072, 0x0020, 0x0915};
42 const int strLength = sizeof(unicodeStr) / sizeof(uint16_t);
43 const int strByteLength = sizeof(unicodeStr);
44
45 SkScalar posX[strLength];
46 SkPoint posXY[strLength];
47
48 for (int i = 0; i < strLength; ++i) {
49 posX[i] = SkIntToScalar(i * 24);
50 posXY[i].fX = posX[i];
51 posXY[i].fY = SkIntToScalar(24 + i);
52 }
53
54 canvas->translate(SkIntToScalar(10), SkIntToScalar(25));
55 // This currently causes the PDF backend to assert
56 // canvas->drawText(unicodeStr, strByteLength, 0, 0, paint);
57
58 canvas->translate(0, SkIntToScalar(75));
59 canvas->drawPosTextH(unicodeStr, strByteLength, posX, 0, paint);
60
djsollen@google.comf7f5b7c2013-10-03 17:38:50 +000061#ifdef SK_BUILD_FOR_ANDROID
djsollen@google.com5df5e612013-10-03 14:42:24 +000062 options.setLanguage("ja");
63 paint.setPaintOptionsAndroid(options);
64#endif
65
66 canvas->translate(0, SkIntToScalar(75));
67 canvas->drawPosText(unicodeStr, strByteLength, posXY, paint);
68
69 SkPath path;
70 path.moveTo(0, 0);
71 path.quadTo(50.0f, 100.0f, 250.0f, 150.0f);
72
73 canvas->translate(0, SkIntToScalar(75));
74 canvas->drawTextOnPath(unicodeStr, strByteLength, path, NULL, paint);
75 }
76
77private:
78 typedef GM INHERITED;
79};
80
81//////////////////////////////////////////////////////////////////////////////
82
djsollen@google.comf7f5b7c2013-10-03 17:38:50 +000083#ifdef SK_BUILD_FOR_ANDROID
djsollen@google.com5df5e612013-10-03 14:42:24 +000084DEF_GM( return SkNEW(AndroidFallbackGM); )
85#endif
86
87}