Jim Van Verth | 08576e6 | 2016-11-16 10:15:23 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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" |
Mike Klein | 33d2055 | 2017-03-22 13:47:51 -0400 | [diff] [blame] | 9 | #include "sk_tool_utils.h" |
Jim Van Verth | 08576e6 | 2016-11-16 10:15:23 -0500 | [diff] [blame] | 10 | #include "SkBlurMask.h" |
Jim Van Verth | 08576e6 | 2016-11-16 10:15:23 -0500 | [diff] [blame] | 11 | #include "SkCanvas.h" |
Mike Reed | 1be1f8d | 2018-03-14 13:01:17 -0400 | [diff] [blame] | 12 | #include "SkMaskFilter.h" |
Jim Van Verth | 08576e6 | 2016-11-16 10:15:23 -0500 | [diff] [blame] | 13 | #include "SkTextBlob.h" |
| 14 | |
| 15 | #define WIDTH 800 |
| 16 | #define HEIGHT 800 |
| 17 | |
| 18 | static void draw_text(SkCanvas* canvas, sk_sp<SkTextBlob> blob, |
| 19 | const SkPaint& paint, const SkPaint& blurPaint, |
| 20 | const SkPaint& clearPaint) { |
| 21 | canvas->save(); |
| 22 | canvas->clipRect(SkRect::MakeLTRB(0, 0, 1081, 665)); |
| 23 | canvas->drawRect(SkRect::MakeLTRB(0, 0, 1081, 665), clearPaint); |
| 24 | // draw as blurred to push glyph to be too large for atlas |
| 25 | canvas->drawTextBlob(blob, 0, 256, blurPaint); |
| 26 | canvas->drawTextBlob(blob, 0, 477, paint); |
| 27 | canvas->restore(); |
| 28 | } |
| 29 | |
| 30 | // This test ensures that glyphs that are too large for the atlas |
| 31 | // are both translated and clipped correctly. |
| 32 | class ClipErrorGM : public skiagm::GM { |
| 33 | public: |
| 34 | ClipErrorGM() {} |
| 35 | |
| 36 | protected: |
| 37 | SkString onShortName() override { return SkString("cliperror"); } |
| 38 | |
| 39 | SkISize onISize() override { return SkISize::Make(WIDTH, HEIGHT); } |
| 40 | |
| 41 | void onDraw(SkCanvas* canvas) override { |
| 42 | SkPaint paint; |
| 43 | paint.setAntiAlias(true); |
Jim Van Verth | 08576e6 | 2016-11-16 10:15:23 -0500 | [diff] [blame] | 44 | |
Mike Reed | ea8900e | 2018-12-22 17:37:30 -0500 | [diff] [blame] | 45 | SkFont font(sk_tool_utils::create_portable_typeface(), 256); |
Jim Van Verth | 08576e6 | 2016-11-16 10:15:23 -0500 | [diff] [blame] | 46 | |
| 47 | // setup up maskfilter |
| 48 | const SkScalar kSigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(50)); |
| 49 | |
| 50 | SkPaint blurPaint(paint); |
Mike Reed | 1be1f8d | 2018-03-14 13:01:17 -0400 | [diff] [blame] | 51 | blurPaint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, kSigma)); |
Jim Van Verth | 08576e6 | 2016-11-16 10:15:23 -0500 | [diff] [blame] | 52 | |
Mike Reed | ea8900e | 2018-12-22 17:37:30 -0500 | [diff] [blame] | 53 | const char text[] = "hambur"; |
| 54 | auto blob = SkTextBlob::MakeFromText(text, strlen(text), font); |
Jim Van Verth | 08576e6 | 2016-11-16 10:15:23 -0500 | [diff] [blame] | 55 | |
| 56 | SkPaint clearPaint(paint); |
| 57 | clearPaint.setColor(SK_ColorWHITE); |
| 58 | |
| 59 | canvas->save(); |
| 60 | canvas->translate(0, 0); |
| 61 | canvas->clipRect(SkRect::MakeLTRB(0, 0, WIDTH, 256)); |
| 62 | draw_text(canvas, blob, paint, blurPaint, clearPaint); |
| 63 | canvas->restore(); |
| 64 | |
| 65 | canvas->save(); |
| 66 | canvas->translate(0, 256); |
| 67 | canvas->clipRect(SkRect::MakeLTRB(0, 256, WIDTH, 510)); |
| 68 | draw_text(canvas, blob, paint, blurPaint, clearPaint); |
| 69 | canvas->restore(); |
| 70 | } |
| 71 | |
| 72 | private: |
| 73 | typedef skiagm::GM INHERITED; |
| 74 | }; |
| 75 | |
| 76 | DEF_GM(return new ClipErrorGM;) |