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" 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" 17 18 #include <string.h> 19 20 namespace skiagm { 21 22 class FontScalerGM : public GM { 23 public: FontScalerGM()24 FontScalerGM() { 25 this->setBGColor(0xFFFFFFFF); 26 } 27 28 protected: 29 onShortName()30 SkString onShortName() override { 31 return SkString("fontscaler"); 32 } 33 onISize()34 SkISize onISize() override { 35 return SkISize::Make(1450, 750); 36 } 37 onDraw(SkCanvas * canvas)38 void onDraw(SkCanvas* canvas) override { 39 SkFont font; 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); 44 45 const char* text = "Hamburgefons ooo mmm"; 46 const size_t textLen = strlen(text); 47 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) { 51 SkScalar x = SkIntToScalar(10); 52 SkScalar y = SkIntToScalar(20); 53 54 SkAutoCanvasRestore acr(canvas, true); 55 canvas->translate(SkIntToScalar(50 + i * 230), 56 SkIntToScalar(20)); 57 canvas->rotate(SkIntToScalar(i * 5), x, y * 10); 58 59 { 60 SkPaint p; 61 p.setAntiAlias(true); 62 SkRect r; 63 r.set(x - SkIntToScalar(3), SkIntToScalar(15), 64 x - SkIntToScalar(1), SkIntToScalar(280)); 65 canvas->drawRect(r, p); 66 } 67 68 for (int ps = 6; ps <= 22; ps++) { 69 font.setSize(SkIntToScalar(ps)); 70 canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8, x, y, font, SkPaint()); 71 y += font.getMetrics(nullptr); 72 } 73 } 74 canvas->translate(0, SkIntToScalar(360)); 75 font.setSubpixel(true); 76 font.setLinearMetrics(true); 77 } 78 } 79 80 private: 81 typedef GM INHERITED; 82 }; 83 84 ////////////////////////////////////////////////////////////////////////////// 85 86 DEF_GM( return new FontScalerGM; ) 87 88 } 89