blob: 28f7432b89b44d78897512f140eb6ee8d2796e45 [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"
9#include "SkBlurMask.h"
10#include "SkBlurMaskFilter.h"
11#include "SkCanvas.h"
12#include "SkTextBlob.h"
13
14#define WIDTH 800
15#define HEIGHT 800
16
17static void draw_text(SkCanvas* canvas, sk_sp<SkTextBlob> blob,
18 const SkPaint& paint, const SkPaint& blurPaint,
19 const SkPaint& clearPaint) {
20 canvas->save();
21 canvas->clipRect(SkRect::MakeLTRB(0, 0, 1081, 665));
22 canvas->drawRect(SkRect::MakeLTRB(0, 0, 1081, 665), clearPaint);
23 // draw as blurred to push glyph to be too large for atlas
24 canvas->drawTextBlob(blob, 0, 256, blurPaint);
25 canvas->drawTextBlob(blob, 0, 477, paint);
26 canvas->restore();
27}
28
29// This test ensures that glyphs that are too large for the atlas
30// are both translated and clipped correctly.
31class ClipErrorGM : public skiagm::GM {
32public:
33 ClipErrorGM() {}
34
35protected:
36 SkString onShortName() override { return SkString("cliperror"); }
37
38 SkISize onISize() override { return SkISize::Make(WIDTH, HEIGHT); }
39
40 void onDraw(SkCanvas* canvas) override {
41 SkPaint paint;
42 paint.setAntiAlias(true);
43 paint.setStyle(SkPaint::kFill_Style);
44
45 const char text[] = "hambur";
46
47 sk_tool_utils::set_portable_typeface(&paint);
48 paint.setTextSize(256);
49 paint.setAntiAlias(true);
50
51 // setup up maskfilter
52 const SkScalar kSigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(50));
53
54 SkPaint blurPaint(paint);
55 blurPaint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, kSigma));
56
57 SkTextBlobBuilder builder;
58
59 sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, 0);
60
61 sk_sp<SkTextBlob> blob(builder.make());
62
63 SkPaint clearPaint(paint);
64 clearPaint.setColor(SK_ColorWHITE);
65
66 canvas->save();
67 canvas->translate(0, 0);
68 canvas->clipRect(SkRect::MakeLTRB(0, 0, WIDTH, 256));
69 draw_text(canvas, blob, paint, blurPaint, clearPaint);
70 canvas->restore();
71
72 canvas->save();
73 canvas->translate(0, 256);
74 canvas->clipRect(SkRect::MakeLTRB(0, 256, WIDTH, 510));
75 draw_text(canvas, blob, paint, blurPaint, clearPaint);
76 canvas->restore();
77 }
78
79private:
80 typedef skiagm::GM INHERITED;
81};
82
83DEF_GM(return new ClipErrorGM;)