2 * Copyright 2011 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
9 #include "include/core/SkCanvas.h"
10 #include "include/core/SkFont.h"
11 #include "include/core/SkFontTypes.h"
12 #include "include/core/SkPaint.h"
13 #include "include/core/SkRect.h"
14 #include "include/core/SkScalar.h"
15 #include "include/core/SkSize.h"
16 #include "include/core/SkString.h"
22 class FontScalerGM : public GM {
25 this->setBGColor(0xFFFFFFFF);
30 SkString onShortName() override {
31 return SkString("fontscaler");
34 SkISize onISize() override {
35 return SkISize::Make(1450, 750);
38 void onDraw(SkCanvas* canvas) override {
40 font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
41 //With freetype the default (normal hinting) can be really ugly.
42 //Most distros now set slight (vertical hinting only) in any event.
43 font.setHinting(SkFontHinting::kSlight);
45 const char* text = "Hamburgefons ooo mmm";
46 const size_t textLen = strlen(text);
48 for (int j = 0; j < 2; ++j) {
49 // This used to do 6 iterations but it causes the N4 to crash in the MSAA4 config.
50 for (int i = 0; i < 5; ++i) {
54 SkAutoCanvasRestore acr(canvas, true);
55 canvas->translate(SkIntToScalar(50 + i * 230),
57 canvas->rotate(SkIntToScalar(i * 5), x, y * 10);
63 r.setLTRB(x - 3, 15, x - 1, 280);
64 canvas->drawRect(r, p);
67 for (int ps = 6; ps <= 22; ps++) {
68 font.setSize(SkIntToScalar(ps));
69 canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8, x, y, font, SkPaint());
70 y += font.getMetrics(nullptr);
73 canvas->translate(0, SkIntToScalar(360));
74 font.setSubpixel(true);
75 font.setLinearMetrics(true);
76 font.setBaselineSnap(false);
84 //////////////////////////////////////////////////////////////////////////////
86 DEF_GM( return new FontScalerGM; )