• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2013 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/gm.h"
9 #include "include/core/SkCanvas.h"
10 #include "include/core/SkColor.h"
11 #include "include/core/SkFont.h"
12 #include "include/core/SkFontTypes.h"
13 #include "include/core/SkPaint.h"
14 #include "include/core/SkPoint.h"
15 #include "include/core/SkRect.h"
16 #include "include/core/SkSize.h"
17 #include "include/core/SkString.h"
18 #include "include/core/SkTypeface.h"
19 #include "tools/Resources.h"
20 #include "tools/ToolUtils.h"
21 
22 /**
23  *  Skia may draw from outlines when the size is very large, so we exercise that
24  *  here.
25 */
26 
27 class BigTextGM : public skiagm::GM {
28 public:
BigTextGM()29     BigTextGM() {}
30 
31 protected:
32 
onShortName()33     SkString onShortName() override {
34         return SkString("bigtext");
35     }
36 
onISize()37     SkISize onISize() override {
38         return SkISize::Make(640, 480);
39     }
40 
onDraw(SkCanvas * canvas)41     void onDraw(SkCanvas* canvas) override {
42         SkPaint paint;
43         paint.setAntiAlias(true);
44         SkFont font(ToolUtils::create_portable_typeface(), 1500);
45 
46         SkRect r;
47         (void)font.measureText("/", 1, SkTextEncoding::kUTF8, &r);
48         SkPoint pos = {
49             this->width()/2 - r.centerX(),
50             this->height()/2 - r.centerY()
51         };
52 
53         paint.setColor(SK_ColorRED);
54         canvas->drawSimpleText("/", 1, SkTextEncoding::kUTF8, pos.fX, pos.fY, font, paint);
55 
56         paint.setColor(SK_ColorBLUE);
57         canvas->drawSimpleText("\\", 1, SkTextEncoding::kUTF8, pos.fX, pos.fY, font, paint);
58     }
59 
60 private:
61     using INHERITED = skiagm::GM;
62 };
63 
64 DEF_GM(return new BigTextGM;)
65 
66 // Exercise the case where the glyph is sufficiently large that we should just draw with a path,
67 // but the DirectWrite scaler context failed to calculate the bounds and reported empty bounds.
68 // With empty bounds the glyph was discarded instead of rendered from path. See crbug.com/1370488
69 DEF_SIMPLE_GM(bigtext_crbug_1370488, canvas, 512, 512) {
70     auto typeface = MakeResourceAsTypeface("fonts/SpiderSymbol.ttf");
71     const char* text = "\xEF\x80\xA1";
72     if (!typeface) {
73         text = "H";
74     }
75 
76     SkFont font(typeface, 12.f);
77     canvas->translate(-1800.f, 1800.f);
78     canvas->scale(437.5f, 437.5f);
79     SkPaint paint;
80     paint.setAntiAlias(true);
81     canvas->drawString(text, 0.f, 0.f, font, paint);
82 }
83