blob: 7e9c4ce5e2a782d8445fd7648db6e93065e10d22 [file] [log] [blame]
Jim Van Verth08576e62016-11-16 10:15:23 -05001/*
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 Klein33d20552017-03-22 13:47:51 -04009#include "sk_tool_utils.h"
Jim Van Verth08576e62016-11-16 10:15:23 -050010#include "SkBlurMask.h"
Jim Van Verth08576e62016-11-16 10:15:23 -050011#include "SkCanvas.h"
Mike Reed1be1f8d2018-03-14 13:01:17 -040012#include "SkMaskFilter.h"
Jim Van Verth08576e62016-11-16 10:15:23 -050013#include "SkTextBlob.h"
14
15#define WIDTH 800
16#define HEIGHT 800
17
18static 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.
32class ClipErrorGM : public skiagm::GM {
33public:
34 ClipErrorGM() {}
35
36protected:
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 Verth08576e62016-11-16 10:15:23 -050044
Mike Reedea8900e2018-12-22 17:37:30 -050045 SkFont font(sk_tool_utils::create_portable_typeface(), 256);
Jim Van Verth08576e62016-11-16 10:15:23 -050046
47 // setup up maskfilter
48 const SkScalar kSigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(50));
49
50 SkPaint blurPaint(paint);
Mike Reed1be1f8d2018-03-14 13:01:17 -040051 blurPaint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, kSigma));
Jim Van Verth08576e62016-11-16 10:15:23 -050052
Mike Reedea8900e2018-12-22 17:37:30 -050053 const char text[] = "hambur";
54 auto blob = SkTextBlob::MakeFromText(text, strlen(text), font);
Jim Van Verth08576e62016-11-16 10:15:23 -050055
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
72private:
73 typedef skiagm::GM INHERITED;
74};
75
76DEF_GM(return new ClipErrorGM;)