aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/largeglyphblur.cpp
blob: 8723824e13707e1ca58d19489ec67ff02dbb3558 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 * Copyright 2015 Google Inc.
 *
 * Use of this source code is governed by a BD-style license that can be
 * found in the LICENSE file.
 */

#include "gm.h"

#include "SkBlurMask.h"
#include "SkBlurMaskFilter.h"
#include "SkCanvas.h"
#include "SkTextBlob.h"

// This test ensures that glyphs whose point size is less than the SkGlyphCache's maxmium, but
// who have a large blur, are still handled correctly
namespace skiagm {
class LargeGlyphBlur : public GM {
public:
    LargeGlyphBlur() {}

protected:
    SkString onShortName() override {
        return SkString("largeglyphblur");
    }

    SkISize onISize() override {
        return SkISize::Make(kWidth, kHeight);
    }

    void onDraw(SkCanvas* canvas) override {
        const char text[] = "Hamburgefons";

        SkPaint paint;
        sk_tool_utils::set_portable_typeface(&paint);
        paint.setTextSize(256);
        paint.setAntiAlias(true);

        // setup up maskfilter
        static const SkScalar kSigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(40));

        SkPaint blurPaint(paint);
        SkAutoTUnref<SkMaskFilter> mf(SkBlurMaskFilter::Create(kNormal_SkBlurStyle, kSigma));
        blurPaint.setMaskFilter(mf);

        SkTextBlobBuilder builder;

        sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, 0);

        SkAutoTUnref<const SkTextBlob> blob(builder.build());
        canvas->drawTextBlob(blob.get(), 10, 200, blurPaint);
        canvas->drawTextBlob(blob.get(), 10, 200, paint);

        size_t len = strlen(text);
        canvas->drawText(text, len, 10, 500, blurPaint);
        canvas->drawText(text, len, 10, 500, paint);
    }

private:
    static const int kWidth = 1920;
    static const int kHeight = 600;

    typedef GM INHERITED;
};

//////////////////////////////////////////////////////////////////////////////

DEF_GM( return SkNEW(LargeGlyphBlur); )
}