2 * Copyright 2016 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
9 #include "sk_tool_utils.h"
10 #include "SkBlurMask.h"
11 #include "SkBlurMaskFilter.h"
13 #include "SkTextBlob.h"
18 static void draw_text(SkCanvas* canvas, sk_sp<SkTextBlob> blob,
19 const SkPaint& paint, const SkPaint& blurPaint,
20 const SkPaint& clearPaint) {
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);
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 {
37 SkString onShortName() override { return SkString("cliperror"); }
39 SkISize onISize() override { return SkISize::Make(WIDTH, HEIGHT); }
41 void onDraw(SkCanvas* canvas) override {
43 paint.setAntiAlias(true);
44 paint.setStyle(SkPaint::kFill_Style);
46 const char text[] = "hambur";
48 sk_tool_utils::set_portable_typeface(&paint);
49 paint.setTextSize(256);
50 paint.setAntiAlias(true);
52 // setup up maskfilter
53 const SkScalar kSigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(50));
55 SkPaint blurPaint(paint);
56 blurPaint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, kSigma));
58 SkTextBlobBuilder builder;
60 sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, 0);
62 sk_sp<SkTextBlob> blob(builder.make());
64 SkPaint clearPaint(paint);
65 clearPaint.setColor(SK_ColorWHITE);
68 canvas->translate(0, 0);
69 canvas->clipRect(SkRect::MakeLTRB(0, 0, WIDTH, 256));
70 draw_text(canvas, blob, paint, blurPaint, clearPaint);
74 canvas->translate(0, 256);
75 canvas->clipRect(SkRect::MakeLTRB(0, 256, WIDTH, 510));
76 draw_text(canvas, blob, paint, blurPaint, clearPaint);
81 typedef skiagm::GM INHERITED;
84 DEF_GM(return new ClipErrorGM;)