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 #include <SkFont.h> 8 #include "gm.h" 9 #include "sk_tool_utils.h" 10 #include "SkTypeface.h" 11 12 namespace skiagm { 13 14 class FontScalerGM : public GM { 15 public: FontScalerGM()16 FontScalerGM() { 17 this->setBGColor(0xFFFFFFFF); 18 } 19 20 protected: 21 onShortName()22 SkString onShortName() override { 23 SkString name("fontscaler"); 24 name.append(sk_tool_utils::platform_font_manager()); 25 return name; 26 } 27 onISize()28 SkISize onISize() override { 29 return SkISize::Make(1450, 750); 30 } 31 onDraw(SkCanvas * canvas)32 void onDraw(SkCanvas* canvas) override { 33 SkFont font; 34 font.setEdging(SkFont::Edging::kSubpixelAntiAlias); 35 //With freetype the default (normal hinting) can be really ugly. 36 //Most distros now set slight (vertical hinting only) in any event. 37 font.setHinting(kSlight_SkFontHinting); 38 39 const char* text = "Hamburgefons ooo mmm"; 40 const size_t textLen = strlen(text); 41 42 for (int j = 0; j < 2; ++j) { 43 // This used to do 6 iterations but it causes the N4 to crash in the MSAA4 config. 44 for (int i = 0; i < 5; ++i) { 45 SkScalar x = SkIntToScalar(10); 46 SkScalar y = SkIntToScalar(20); 47 48 SkAutoCanvasRestore acr(canvas, true); 49 canvas->translate(SkIntToScalar(50 + i * 230), 50 SkIntToScalar(20)); 51 canvas->rotate(SkIntToScalar(i * 5), x, y * 10); 52 53 { 54 SkPaint p; 55 p.setAntiAlias(true); 56 SkRect r; 57 r.set(x - SkIntToScalar(3), SkIntToScalar(15), 58 x - SkIntToScalar(1), SkIntToScalar(280)); 59 canvas->drawRect(r, p); 60 } 61 62 for (int ps = 6; ps <= 22; ps++) { 63 font.setSize(SkIntToScalar(ps)); 64 canvas->drawSimpleText(text, textLen, kUTF8_SkTextEncoding, x, y, font, SkPaint()); 65 y += font.getMetrics(nullptr); 66 } 67 } 68 canvas->translate(0, SkIntToScalar(360)); 69 font.setSubpixel(true); 70 } 71 } 72 73 private: 74 typedef GM INHERITED; 75 }; 76 77 ////////////////////////////////////////////////////////////////////////////// 78 79 DEF_GM( return new FontScalerGM; ) 80 81 } 82