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.
8 #include "SkTypeface.h"
12 class FontScalerGM : public GM {
15 this->setBGColor(0xFFFFFFFF);
18 virtual ~FontScalerGM() {
23 SkString onShortName() override {
24 SkString name("fontscaler");
25 name.append(sk_tool_utils::major_platform_os_name());
29 SkISize onISize() override {
30 return SkISize::Make(1450, 750);
33 static void rotate_about(SkCanvas* canvas,
35 SkScalar px, SkScalar py) {
36 canvas->translate(px, py);
37 canvas->rotate(degrees);
38 canvas->translate(-px, -py);
41 void onDraw(SkCanvas* canvas) override {
44 paint.setAntiAlias(true);
45 paint.setLCDRenderText(true);
46 //With freetype the default (normal hinting) can be really ugly.
47 //Most distros now set slight (vertical hinting only) in any event.
48 paint.setHinting(SkPaint::kSlight_Hinting);
50 const char* text = "Hamburgefons ooo mmm";
51 const size_t textLen = strlen(text);
53 for (int j = 0; j < 2; ++j) {
54 // This used to do 6 iterations but it causes the N4 to crash in the MSAA4 config.
55 for (int i = 0; i < 5; ++i) {
56 SkScalar x = SkIntToScalar(10);
57 SkScalar y = SkIntToScalar(20);
59 SkAutoCanvasRestore acr(canvas, true);
60 canvas->translate(SkIntToScalar(50 + i * 230),
62 rotate_about(canvas, SkIntToScalar(i * 5), x, y * 10);
68 r.set(x - SkIntToScalar(3), SkIntToScalar(15),
69 x - SkIntToScalar(1), SkIntToScalar(280));
70 canvas->drawRect(r, p);
73 for (int ps = 6; ps <= 22; ps++) {
74 paint.setTextSize(SkIntToScalar(ps));
75 canvas->drawText(text, textLen, x, y, paint);
76 y += paint.getFontMetrics(nullptr);
79 canvas->translate(0, SkIntToScalar(360));
80 paint.setSubpixelText(true);
88 //////////////////////////////////////////////////////////////////////////////
90 static GM* MyFactory(void*) { return new FontScalerGM; }
91 static GMRegistry reg(MyFactory);