Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
bigtext.cpp
Go to the documentation of this file.
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"
11#include "include/core/SkData.h"
12#include "include/core/SkFont.h"
16#include "include/core/SkRect.h"
17#include "include/core/SkSize.h"
20#include "tools/Resources.h"
21#include "tools/ToolUtils.h"
23
24/**
25 * Skia may draw from outlines when the size is very large, so we exercise that
26 * here.
27*/
28
29class BigTextGM : public skiagm::GM {
30public:
32
33protected:
34 SkString getName() const override { return SkString("bigtext"); }
35
36 SkISize getISize() override { return SkISize::Make(640, 480); }
37
38 void onDraw(SkCanvas* canvas) override {
40 paint.setAntiAlias(true);
42
43 SkRect r;
44 (void)font.measureText("/", 1, SkTextEncoding::kUTF8, &r);
45 SkPoint pos = {
46 this->width()/2 - r.centerX(),
47 this->height()/2 - r.centerY()
48 };
49
50 paint.setColor(SK_ColorRED);
51 canvas->drawSimpleText("/", 1, SkTextEncoding::kUTF8, pos.fX, pos.fY, font, paint);
52
53 paint.setColor(SK_ColorBLUE);
54 canvas->drawSimpleText("\\", 1, SkTextEncoding::kUTF8, pos.fX, pos.fY, font, paint);
55 }
56
57private:
58 using INHERITED = skiagm::GM;
59};
60
61DEF_GM(return new BigTextGM;)
62
63// Exercise the case where the glyph is sufficiently large that we should just draw with a path,
64// but the DirectWrite scaler context failed to calculate the bounds and reported empty bounds.
65// With empty bounds the glyph was discarded instead of rendered from path. See crbug.com/1370488
66DEF_SIMPLE_GM(bigtext_crbug_1370488, canvas, 512, 512) {
67 auto typeface = ToolUtils::CreateTypefaceFromResource("fonts/SpiderSymbol.ttf");
68 const char* text = "\xEF\x80\xA1";
69 if (!typeface) {
71 text = "H";
72 }
73
74 SkFont font(typeface, 12.f);
75 canvas->translate(-1800.f, 1800.f);
76 canvas->scale(437.5f, 437.5f);
78 paint.setAntiAlias(true);
79 canvas->drawString(text, 0.f, 0.f, font, paint);
80}
SkPoint pos
constexpr SkColor SK_ColorBLUE
Definition SkColor.h:135
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
@ kUTF8
uses bytes to represent UTF-8 or ASCII
void onDraw(SkCanvas *canvas) override
Definition bigtext.cpp:38
SkString getName() const override
Definition bigtext.cpp:34
SkISize getISize() override
Definition bigtext.cpp:36
void drawSimpleText(const void *text, size_t byteLength, SkTextEncoding encoding, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
SkScalar width()
Definition gm.h:159
SkScalar height()
Definition gm.h:162
const Paint & paint
#define DEF_GM(CODE)
Definition gm.h:40
#define DEF_SIMPLE_GM(NAME, CANVAS, W, H)
Definition gm.h:50
std::u16string text
sk_sp< SkTypeface > DefaultPortableTypeface()
sk_sp< SkTypeface > CreateTypefaceFromResource(const char *resource, int ttcIndex)
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20
float fX
x-axis value
float fY
y-axis value
constexpr float centerX() const
Definition SkRect.h:776
constexpr float centerY() const
Definition SkRect.h:785