1 /*
2  * Copyright 2015 Google Inc.
3  *
4  * Use of this source code is governed by a BD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "gm.h"
9 
10 #include "SkBlurMask.h"
11 #include "SkBlurMaskFilter.h"
12 #include "SkCanvas.h"
13 #include "SkTextBlob.h"
14 
15 // This test ensures that glyphs whose point size is less than the SkGlyphCache's maxmium, but
16 // who have a large blur, are still handled correctly
17 namespace skiagm {
18 class LargeGlyphBlur : public GM {
19 public:
LargeGlyphBlur()20     LargeGlyphBlur() {}
21 
22 protected:
onShortName()23     SkString onShortName() override {
24         return SkString("largeglyphblur");
25     }
26 
onISize()27     SkISize onISize() override {
28         return SkISize::Make(kWidth, kHeight);
29     }
30 
onDraw(SkCanvas * canvas)31     void onDraw(SkCanvas* canvas) override {
32         const char text[] = "Hamburgefons";
33 
34         SkPaint paint;
35         sk_tool_utils::set_portable_typeface(&paint);
36         paint.setTextSize(256);
37         paint.setAntiAlias(true);
38 
39         // setup up maskfilter
40         static const SkScalar kSigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(40));
41 
42         SkPaint blurPaint(paint);
43         SkAutoTUnref<SkMaskFilter> mf(SkBlurMaskFilter::Create(kNormal_SkBlurStyle, kSigma));
44         blurPaint.setMaskFilter(mf);
45 
46         SkTextBlobBuilder builder;
47 
48         sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, 0);
49 
50         SkAutoTUnref<const SkTextBlob> blob(builder.build());
51         canvas->drawTextBlob(blob.get(), 10, 200, blurPaint);
52         canvas->drawTextBlob(blob.get(), 10, 200, paint);
53 
54         size_t len = strlen(text);
55         canvas->drawText(text, len, 10, 500, blurPaint);
56         canvas->drawText(text, len, 10, 500, paint);
57     }
58 
59 private:
60     static const int kWidth = 1920;
61     static const int kHeight = 600;
62 
63     typedef GM INHERITED;
64 };
65 
66 //////////////////////////////////////////////////////////////////////////////
67 
68 DEF_GM( return SkNEW(LargeGlyphBlur); )
69 }
70