djsollen@google.com | 5df5e61 | 2013-10-03 14:42:24 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 10 | namespace skiagm { |
| 11 | |
| 12 | class AndroidFallbackGM : public GM { |
| 13 | public: |
| 14 | AndroidFallbackGM() { |
| 15 | this->setBGColor(0xFFCCCCCC); |
| 16 | } |
| 17 | |
| 18 | protected: |
mtklein@google.com | 745f248 | 2013-10-28 20:40:41 +0000 | [diff] [blame] | 19 | 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.com | 5df5e61 | 2013-10-03 14:42:24 +0000 | [diff] [blame] | 24 | 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.com | f7f5b7c | 2013-10-03 17:38:50 +0000 | [diff] [blame] | 38 | #ifdef SK_BUILD_FOR_ANDROID |
djsollen@google.com | 5df5e61 | 2013-10-03 14:42:24 +0000 | [diff] [blame] | 39 | 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.com | f7f5b7c | 2013-10-03 17:38:50 +0000 | [diff] [blame] | 66 | #ifdef SK_BUILD_FOR_ANDROID |
djsollen@google.com | 5df5e61 | 2013-10-03 14:42:24 +0000 | [diff] [blame] | 67 | 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 | |
| 82 | private: |
| 83 | typedef GM INHERITED; |
| 84 | }; |
| 85 | |
| 86 | ////////////////////////////////////////////////////////////////////////////// |
| 87 | |
djsollen@google.com | f7f5b7c | 2013-10-03 17:38:50 +0000 | [diff] [blame] | 88 | #ifdef SK_BUILD_FOR_ANDROID |
djsollen@google.com | 5df5e61 | 2013-10-03 14:42:24 +0000 | [diff] [blame] | 89 | DEF_GM( return SkNEW(AndroidFallbackGM); ) |
| 90 | #endif |
| 91 | |
| 92 | } |