blob: 2f87dbb0cccc55220b1b760553c0cf74bbf712b8 [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"
Ben Wagner7fde8e12019-05-01 17:28:53 -04009#include "include/core/SkBlurTypes.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/core/SkCanvas.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040011#include "include/core/SkColor.h"
12#include "include/core/SkFont.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "include/core/SkMaskFilter.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040014#include "include/core/SkPaint.h"
15#include "include/core/SkRect.h"
16#include "include/core/SkRefCnt.h"
17#include "include/core/SkScalar.h"
18#include "include/core/SkSize.h"
19#include "include/core/SkString.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050020#include "include/core/SkTextBlob.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040021#include "include/core/SkTypeface.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050022#include "src/core/SkBlurMask.h"
23#include "tools/ToolUtils.h"
Jim Van Verth08576e62016-11-16 10:15:23 -050024
Ben Wagner7fde8e12019-05-01 17:28:53 -040025#include <string.h>
26
Jim Van Verth08576e62016-11-16 10:15:23 -050027#define WIDTH 800
28#define HEIGHT 800
29
30static void draw_text(SkCanvas* canvas, sk_sp<SkTextBlob> blob,
31 const SkPaint& paint, const SkPaint& blurPaint,
32 const SkPaint& clearPaint) {
33 canvas->save();
34 canvas->clipRect(SkRect::MakeLTRB(0, 0, 1081, 665));
35 canvas->drawRect(SkRect::MakeLTRB(0, 0, 1081, 665), clearPaint);
36 // draw as blurred to push glyph to be too large for atlas
37 canvas->drawTextBlob(blob, 0, 256, blurPaint);
38 canvas->drawTextBlob(blob, 0, 477, paint);
39 canvas->restore();
40}
41
42// This test ensures that glyphs that are too large for the atlas
43// are both translated and clipped correctly.
44class ClipErrorGM : public skiagm::GM {
45public:
46 ClipErrorGM() {}
47
48protected:
49 SkString onShortName() override { return SkString("cliperror"); }
50
51 SkISize onISize() override { return SkISize::Make(WIDTH, HEIGHT); }
52
53 void onDraw(SkCanvas* canvas) override {
54 SkPaint paint;
55 paint.setAntiAlias(true);
Jim Van Verth08576e62016-11-16 10:15:23 -050056
Mike Kleinea3f0142019-03-20 11:12:10 -050057 SkFont font(ToolUtils::create_portable_typeface(), 256);
Jim Van Verth08576e62016-11-16 10:15:23 -050058
59 // setup up maskfilter
60 const SkScalar kSigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(50));
61
62 SkPaint blurPaint(paint);
Mike Reed1be1f8d2018-03-14 13:01:17 -040063 blurPaint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, kSigma));
Jim Van Verth08576e62016-11-16 10:15:23 -050064
Mike Reedea8900e2018-12-22 17:37:30 -050065 const char text[] = "hambur";
66 auto blob = SkTextBlob::MakeFromText(text, strlen(text), font);
Jim Van Verth08576e62016-11-16 10:15:23 -050067
68 SkPaint clearPaint(paint);
69 clearPaint.setColor(SK_ColorWHITE);
70
71 canvas->save();
72 canvas->translate(0, 0);
73 canvas->clipRect(SkRect::MakeLTRB(0, 0, WIDTH, 256));
74 draw_text(canvas, blob, paint, blurPaint, clearPaint);
75 canvas->restore();
76
77 canvas->save();
78 canvas->translate(0, 256);
79 canvas->clipRect(SkRect::MakeLTRB(0, 256, WIDTH, 510));
80 draw_text(canvas, blob, paint, blurPaint, clearPaint);
81 canvas->restore();
82 }
83
84private:
85 typedef skiagm::GM INHERITED;
86};
87
88DEF_GM(return new ClipErrorGM;)