blob: 33f6779d2c295577432e78e988385e5b94ff170a [file] [log] [blame]
bungeman@google.com0f0c2882011-11-04 15:47:41 +00001/*
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 "gm.h"
8#include "SkTypeface.h"
9
10namespace skiagm {
11
bungeman@google.com0f0c2882011-11-04 15:47:41 +000012class FontScalerGM : public GM {
13public:
14 FontScalerGM() {
15 this->setBGColor(0xFFFFFFFF);
bungeman@google.com0f0c2882011-11-04 15:47:41 +000016 }
17
18 virtual ~FontScalerGM() {
bungeman@google.com0f0c2882011-11-04 15:47:41 +000019 }
20
21protected:
22 virtual SkString onShortName() {
23 return SkString("fontscaler");
24 }
25
26 virtual SkISize onISize() {
bungeman@google.com24babf42011-11-07 16:33:40 +000027 return make_isize(1450, 750);
bungeman@google.com0f0c2882011-11-04 15:47:41 +000028 }
29
bungeman@google.coma682b932012-01-05 18:10:48 +000030 static void rotate_about(SkCanvas* canvas,
31 SkScalar degrees,
32 SkScalar px, SkScalar py) {
bungeman@google.com0f0c2882011-11-04 15:47:41 +000033 canvas->translate(px, py);
34 canvas->rotate(degrees);
35 canvas->translate(-px, -py);
36 }
37
38 virtual void onDraw(SkCanvas* canvas) {
39 SkPaint paint;
40
bungeman@google.com0f0c2882011-11-04 15:47:41 +000041 paint.setAntiAlias(true);
42 paint.setLCDRenderText(true);
43 //With freetype the default (normal hinting) can be really ugly.
44 //Most distros now set slight (vertical hinting only) in any event.
45 paint.setHinting(SkPaint::kSlight_Hinting);
46 SkSafeUnref(paint.setTypeface(SkTypeface::CreateFromName("Times Roman", SkTypeface::kNormal)));
47
bungeman@google.com0f0c2882011-11-04 15:47:41 +000048 const char* text = "Hamburgefons ooo mmm";
49 const size_t textLen = strlen(text);
50
51 for (int j = 0; j < 2; ++j) {
bsalomon@google.com4121f952013-09-09 16:19:40 +000052 // This used to do 6 iterations but it causes the N4 to crash in the MSAA4 config.
53 for (int i = 0; i < 5; ++i) {
bungeman@google.com0f0c2882011-11-04 15:47:41 +000054 SkScalar x = SkIntToScalar(10);
55 SkScalar y = SkIntToScalar(20);
56
57 SkAutoCanvasRestore acr(canvas, true);
58 canvas->translate(SkIntToScalar(50 + i * 230),
59 SkIntToScalar(20));
60 rotate_about(canvas, SkIntToScalar(i * 5), x, y * 10);
61
62 {
63 SkPaint p;
64 p.setAntiAlias(true);
65 SkRect r;
bungeman@google.coma682b932012-01-05 18:10:48 +000066 r.set(x - SkIntToScalar(3), SkIntToScalar(15),
67 x - SkIntToScalar(1), SkIntToScalar(280));
bungeman@google.com0f0c2882011-11-04 15:47:41 +000068 canvas->drawRect(r, p);
69 }
70
71 int index = 0;
72 for (int ps = 6; ps <= 22; ps++) {
73 paint.setTextSize(SkIntToScalar(ps));
74 canvas->drawText(text, textLen, x, y, paint);
75 y += paint.getFontMetrics(NULL);
76 index += 1;
77 }
78 }
bungeman@google.coma682b932012-01-05 18:10:48 +000079 canvas->translate(0, SkIntToScalar(360));
bungeman@google.com0f0c2882011-11-04 15:47:41 +000080 paint.setSubpixelText(true);
81 }
82 }
83
84private:
bungeman@google.com0f0c2882011-11-04 15:47:41 +000085 typedef GM INHERITED;
86};
87
88//////////////////////////////////////////////////////////////////////////////
borenet@google.com0682ca62012-06-26 17:23:52 +000089
bungeman@google.com0f0c2882011-11-04 15:47:41 +000090static GM* MyFactory(void*) { return new FontScalerGM; }
91static GMRegistry reg(MyFactory);
borenet@google.com0682ca62012-06-26 17:23:52 +000092
bungeman@google.com0f0c2882011-11-04 15:47:41 +000093}