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: AndroidFallbackGM()14 AndroidFallbackGM() { 15 this->setBGColor(0xFFCCCCCC); 16 } 17 18 protected: onGetFlags() const19 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 onShortName()24 virtual SkString onShortName() SK_OVERRIDE { 25 return SkString("android_paint"); 26 } 27 onISize()28 virtual SkISize onISize() SK_OVERRIDE { 29 return make_isize(500, 500); 30 } 31 onDraw(SkCanvas * canvas)32 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { 33 34 SkPaint paint; 35 paint.setTextEncoding(SkPaint::kUTF16_TextEncoding); 36 paint.setTextSize(24); 37 38 #ifdef SK_BUILD_FOR_ANDROID 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 66 #ifdef SK_BUILD_FOR_ANDROID 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 88 #ifdef SK_BUILD_FOR_ANDROID 89 DEF_GM( return SkNEW(AndroidFallbackGM); ) 90 #endif 91 92 } 93