Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
fontscaler.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2011 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"
10#include "include/core/SkFont.h"
13#include "include/core/SkRect.h"
15#include "include/core/SkSize.h"
18
19#include <string.h>
20
21namespace skiagm {
22
23class FontScalerGM : public GM {
24public:
26 this->setBGColor(0xFFFFFFFF);
27 }
28
29protected:
30 SkString getName() const override { return SkString("fontscaler"); }
31
32 SkISize getISize() override { return SkISize::Make(1450, 750); }
33
34 void onDraw(SkCanvas* canvas) override {
37 //With freetype the default (normal hinting) can be really ugly.
38 //Most distros now set slight (vertical hinting only) in any event.
39 font.setHinting(SkFontHinting::kSlight);
40
41 const char* text = "Hamburgefons ooo mmm";
42 const size_t textLen = strlen(text);
43
44 for (int j = 0; j < 2; ++j) {
45 // This used to do 6 iterations but it causes the N4 to crash in the MSAA4 config.
46 for (int i = 0; i < 5; ++i) {
47 SkScalar x = 10;
48 SkScalar y = 20;
49
50 SkAutoCanvasRestore acr(canvas, true);
51 canvas->translate(SkIntToScalar(50 + i * 230),
52 SkIntToScalar(20));
53 canvas->rotate(SkIntToScalar(i * 5), x, y * 10);
54
55 {
56 SkPaint p;
57 p.setAntiAlias(true);
58 SkRect r;
59 r.setLTRB(x - 3, 15, x - 1, 280);
60 canvas->drawRect(r, p);
61 }
62
63 for (int ps = 6; ps <= 22; ps++) {
64 font.setSize(SkIntToScalar(ps));
65 canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8, x, y, font, SkPaint());
66 y += font.getMetrics(nullptr);
67 }
68 }
69 canvas->translate(0, SkIntToScalar(360));
70 font.setSubpixel(true);
71 font.setLinearMetrics(true);
72 font.setBaselineSnap(false);
73 }
74 }
75
76private:
77 using INHERITED = GM;
78};
79
80//////////////////////////////////////////////////////////////////////////////
81
82DEF_GM( return new FontScalerGM; )
83
84} // namespace skiagm
@ kSlight
minimal modification to improve constrast
@ kUTF8
uses bytes to represent UTF-8 or ASCII
#define SkIntToScalar(x)
Definition SkScalar.h:57
void drawRect(const SkRect &rect, const SkPaint &paint)
void drawSimpleText(const void *text, size_t byteLength, SkTextEncoding encoding, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
void translate(SkScalar dx, SkScalar dy)
void rotate(SkScalar degrees)
@ kSubpixelAntiAlias
glyph positioned in pixel using transparency
SkISize getISize() override
SkString getName() const override
void onDraw(SkCanvas *canvas) override
void setBGColor(SkColor)
Definition gm.cpp:159
float SkScalar
Definition extension.cpp:12
#define DEF_GM(CODE)
Definition gm.h:40
std::u16string text
double y
double x
SkFont DefaultPortableFont()
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20
void setLTRB(float left, float top, float right, float bottom)
Definition SkRect.h:865