Home | History | Annotate | Download | only in gm
      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:
     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 
     24     virtual SkString onShortName() SK_OVERRIDE {
     25         return SkString("android_paint");
     26     }
     27 
     28     virtual SkISize onISize() SK_OVERRIDE {
     29         return SkISize::Make(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 
     38         SkPaintOptionsAndroid options = paint.getPaintOptionsAndroid();
     39         options.setUseFontFallbacks(true);
     40         paint.setPaintOptionsAndroid(options);
     41 
     42         // " foo  bar "
     43         const uint16_t unicodeStr[] = {0x05D0, 0x0020, 0x0066, 0x006F, 0x006F, 0x0020, 0x514D,
     44                                        0x820c, 0x0020, 0x0062, 0x0061, 0x0072, 0x0020, 0x0915};
     45         const int strLength = sizeof(unicodeStr) / sizeof(uint16_t);
     46         const int strByteLength = sizeof(unicodeStr);
     47 
     48         SkScalar posX[strLength];
     49         SkPoint posXY[strLength];
     50 
     51         for (int i = 0; i < strLength; ++i) {
     52             posX[i] = SkIntToScalar(i * 24);
     53             posXY[i].fX = posX[i];
     54             posXY[i].fY = SkIntToScalar(24 + i);
     55         }
     56 
     57         canvas->translate(SkIntToScalar(10), SkIntToScalar(25));
     58         // This currently causes the PDF backend to assert
     59         // canvas->drawText(unicodeStr, strByteLength, 0, 0, paint);
     60 
     61         canvas->translate(0, SkIntToScalar(75));
     62         canvas->drawPosTextH(unicodeStr, strByteLength, posX, 0, paint);
     63 
     64         options.setLanguage("ja");
     65         paint.setPaintOptionsAndroid(options);
     66 
     67         canvas->translate(0, SkIntToScalar(75));
     68         canvas->drawPosText(unicodeStr, strByteLength, posXY, paint);
     69 
     70         SkPath path;
     71         path.moveTo(0, 0);
     72         path.quadTo(50.0f, 100.0f, 250.0f, 150.0f);
     73 
     74         canvas->translate(0, SkIntToScalar(75));
     75         canvas->drawTextOnPath(unicodeStr, strByteLength, path, NULL, paint);
     76     }
     77 
     78 private:
     79     typedef GM INHERITED;
     80 };
     81 
     82 //////////////////////////////////////////////////////////////////////////////
     83 
     84 DEF_GM( return SkNEW(AndroidFallbackGM); )
     85 
     86 }
     87