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