OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2014 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 "Sk2DPathEffect.h" |
| 10 #include "SkCanvas.h" |
| 11 |
| 12 // PathEffect for a text impacts the paths generated for the text. Big text |
| 13 // and hairline text are drawn by paths, instead of using scalercontext and |
| 14 // caching the glyph. This GM wants to ensure that we draw filled, thick-stroked
, |
| 15 // and hairline-stroked text with path effect correctly on both sides of the |
| 16 // threshold. |
| 17 static void draw_text(SkCanvas* canvas, const SkPaint& paint) { |
| 18 SkPaint p(paint); |
| 19 |
| 20 SkPoint loc = { 250, 225 }; |
| 21 p.setColor(SK_ColorRED); |
| 22 |
| 23 canvas->drawText("P", 1, loc.fX - 225, loc.fY, p); |
| 24 canvas->drawPosText("P", 1, &loc, p); |
| 25 |
| 26 loc.set(250, 450); |
| 27 p.setColor(SK_ColorGREEN); |
| 28 p.setStyle(SkPaint::kStroke_Style); |
| 29 p.setStrokeWidth(10); |
| 30 canvas->drawText("P", 1, loc.fX - 225, loc.fY, p); |
| 31 canvas->drawPosText("P", 1, &loc, p); |
| 32 |
| 33 loc.set(250, 675); |
| 34 p.setColor(SK_ColorBLUE); |
| 35 p.setStrokeWidth(0); |
| 36 canvas->drawText("P", 1, loc.fX - 225, loc.fY, p); |
| 37 canvas->drawPosText("P", 1, &loc, p); |
| 38 } |
| 39 |
| 40 class PathEffect4BigTextGM : public skiagm::GM { |
| 41 public: |
| 42 PathEffect4BigTextGM() {} |
| 43 |
| 44 protected: |
| 45 virtual uint32_t onGetFlags() const SK_OVERRIDE { |
| 46 return kSkipTiled_Flag; |
| 47 } |
| 48 |
| 49 virtual SkString onShortName() SK_OVERRIDE { |
| 50 return SkString("patheffect4bigtext"); |
| 51 } |
| 52 |
| 53 virtual SkISize onISize() SK_OVERRIDE { |
| 54 return SkISize::Make(900, 700); |
| 55 } |
| 56 |
| 57 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 58 SkPaint paint; |
| 59 paint.setAntiAlias(true); |
| 60 |
| 61 SkMatrix lattice; |
| 62 lattice.setScale(SK_Scalar1, SK_Scalar1 * 6, 0, 0); |
| 63 lattice.postRotate(SkIntToScalar(30), 0, 0); |
| 64 paint.setPathEffect(SkLine2DPathEffect::Create(SK_Scalar1 * 2, lattice))
->unref(); |
| 65 |
| 66 SkScalar textSize[2] = {240, 270}; |
| 67 for (size_t i = 0; i < SK_ARRAY_COUNT(textSize); ++i) { |
| 68 paint.setTextSize(textSize[i]); |
| 69 draw_text(canvas, paint); |
| 70 canvas->translate(450, 0); |
| 71 } |
| 72 } |
| 73 |
| 74 private: |
| 75 typedef skiagm::GM INHERITED; |
| 76 }; |
| 77 |
| 78 DEF_GM( return SkNEW(PathEffect4BigTextGM); ) |
OLD | NEW |