blob: b35d207ef6d30ae4d33415adf40bb121618773fe [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
9#include "include/core/SkCanvas.h"
10#include "include/core/SkMaskFilter.h"
11#include "include/core/SkTextBlob.h"
12#include "src/core/SkBlurMask.h"
13#include "tools/ToolUtils.h"
Jim Van Verth08576e62016-11-16 10:15:23 -050014
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 Kleinea3f0142019-03-20 11:12:10 -050045 SkFont font(ToolUtils::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;)