Home | History | Annotate | Download | only in gm
      1 /*
      2  * Copyright 2011 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 #include "SkCanvas.h"
     10 #include "SkPath.h"
     11 #include "SkTypeface.h"
     12 
     13 namespace skiagm {
     14 
     15 class StrokeFillGM : public GM {
     16 public:
     17     StrokeFillGM() {
     18 
     19     }
     20 
     21 protected:
     22     virtual uint32_t onGetFlags() const SK_OVERRIDE {
     23         return kSkipTiled_Flag;
     24     }
     25 
     26     virtual SkString onShortName() {
     27         return SkString("stroke-fill");
     28     }
     29 
     30     virtual SkISize onISize() {
     31         return SkISize::Make(640, 480);
     32     }
     33 
     34     static void show_bold(SkCanvas* canvas, const void* text, int len,
     35                           SkScalar x, SkScalar y, const SkPaint& paint) {
     36         SkPaint p(paint);
     37         canvas->drawText(text, len, x, y, p);
     38         p.setFakeBoldText(true);
     39         canvas->drawText(text, len, x, y + SkIntToScalar(120), p);
     40     }
     41 
     42     virtual void onDraw(SkCanvas* canvas) {
     43         SkScalar x = SkIntToScalar(100);
     44         SkScalar y = SkIntToScalar(88);
     45 
     46         SkPaint paint;
     47         paint.setAntiAlias(true);
     48         paint.setTextSize(SkIntToScalar(100));
     49         paint.setStrokeWidth(SkIntToScalar(5));
     50 
     51         SkTypeface* face = SkTypeface::CreateFromName("Papyrus", SkTypeface::kNormal);
     52         SkSafeUnref(paint.setTypeface(face));
     53         show_bold(canvas, "Hello", 5, x, y, paint);
     54 
     55         face = SkTypeface::CreateFromName("Hiragino Maru Gothic Pro", SkTypeface::kNormal);
     56         SkSafeUnref(paint.setTypeface(face));
     57         const unsigned char hyphen[] = { 0xE3, 0x83, 0xBC };
     58         show_bold(canvas, hyphen, SK_ARRAY_COUNT(hyphen), x + SkIntToScalar(300), y, paint);
     59 
     60         paint.setStyle(SkPaint::kStrokeAndFill_Style);
     61 
     62         SkPath path;
     63         path.setFillType(SkPath::kWinding_FillType);
     64         path.addCircle(x, y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCW_Direction);
     65         path.addCircle(x, y + SkIntToScalar(200), SkIntToScalar(40), SkPath::kCCW_Direction);
     66         canvas->drawPath(path, paint);
     67 
     68         SkPath path2;
     69         path2.setFillType(SkPath::kWinding_FillType);
     70         path2.addCircle(x + SkIntToScalar(120), y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCCW_Direction);
     71         path2.addCircle(x + SkIntToScalar(120), y + SkIntToScalar(200), SkIntToScalar(40), SkPath::kCW_Direction);
     72         canvas->drawPath(path2, paint);
     73 
     74         path2.reset();
     75         path2.addCircle(x + SkIntToScalar(240), y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCCW_Direction);
     76         canvas->drawPath(path2, paint);
     77         SkASSERT(path2.cheapIsDirection(SkPath::kCCW_Direction));
     78 
     79         path2.reset();
     80         SkASSERT(!path2.cheapComputeDirection(NULL));
     81         path2.addCircle(x + SkIntToScalar(360), y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCW_Direction);
     82         SkASSERT(path2.cheapIsDirection(SkPath::kCW_Direction));
     83         canvas->drawPath(path2, paint);
     84     }
     85 
     86 private:
     87     typedef GM INHERITED;
     88 };
     89 
     90 //////////////////////////////////////////////////////////////////////////////
     91 
     92 static GM* MyFactory(void*) { return new StrokeFillGM; }
     93 static GMRegistry reg(MyFactory);
     94 
     95 }
     96