blob: 8aef8f0ebe37798099dc48083b131731ccaa0b74 [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:
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +000022 virtual uint32_t onGetFlags() const SK_OVERRIDE {
23 return kSkipTiled_Flag;
24 }
25
bungeman@google.com0f0c2882011-11-04 15:47:41 +000026 virtual SkString onShortName() {
27 return SkString("fontscaler");
28 }
29
30 virtual SkISize onISize() {
tfarinaf5393182014-06-09 23:59:03 -070031 return SkISize::Make(1450, 750);
bungeman@google.com0f0c2882011-11-04 15:47:41 +000032 }
33
bungeman@google.coma682b932012-01-05 18:10:48 +000034 static void rotate_about(SkCanvas* canvas,
35 SkScalar degrees,
36 SkScalar px, SkScalar py) {
bungeman@google.com0f0c2882011-11-04 15:47:41 +000037 canvas->translate(px, py);
38 canvas->rotate(degrees);
39 canvas->translate(-px, -py);
40 }
41
42 virtual void onDraw(SkCanvas* canvas) {
43 SkPaint paint;
44
bungeman@google.com0f0c2882011-11-04 15:47:41 +000045 paint.setAntiAlias(true);
46 paint.setLCDRenderText(true);
47 //With freetype the default (normal hinting) can be really ugly.
48 //Most distros now set slight (vertical hinting only) in any event.
49 paint.setHinting(SkPaint::kSlight_Hinting);
Cary Clark992c7b02014-07-31 08:58:44 -040050 sk_tool_utils::set_portable_typeface(&paint, "Times Roman", SkTypeface::kNormal);
bungeman@google.com0f0c2882011-11-04 15:47:41 +000051
bungeman@google.com0f0c2882011-11-04 15:47:41 +000052 const char* text = "Hamburgefons ooo mmm";
53 const size_t textLen = strlen(text);
54
55 for (int j = 0; j < 2; ++j) {
bsalomon@google.com4121f952013-09-09 16:19:40 +000056 // This used to do 6 iterations but it causes the N4 to crash in the MSAA4 config.
57 for (int i = 0; i < 5; ++i) {
bungeman@google.com0f0c2882011-11-04 15:47:41 +000058 SkScalar x = SkIntToScalar(10);
59 SkScalar y = SkIntToScalar(20);
60
61 SkAutoCanvasRestore acr(canvas, true);
62 canvas->translate(SkIntToScalar(50 + i * 230),
63 SkIntToScalar(20));
64 rotate_about(canvas, SkIntToScalar(i * 5), x, y * 10);
65
66 {
67 SkPaint p;
68 p.setAntiAlias(true);
69 SkRect r;
bungeman@google.coma682b932012-01-05 18:10:48 +000070 r.set(x - SkIntToScalar(3), SkIntToScalar(15),
71 x - SkIntToScalar(1), SkIntToScalar(280));
bungeman@google.com0f0c2882011-11-04 15:47:41 +000072 canvas->drawRect(r, p);
73 }
74
75 int index = 0;
76 for (int ps = 6; ps <= 22; ps++) {
77 paint.setTextSize(SkIntToScalar(ps));
78 canvas->drawText(text, textLen, x, y, paint);
79 y += paint.getFontMetrics(NULL);
80 index += 1;
81 }
82 }
bungeman@google.coma682b932012-01-05 18:10:48 +000083 canvas->translate(0, SkIntToScalar(360));
bungeman@google.com0f0c2882011-11-04 15:47:41 +000084 paint.setSubpixelText(true);
85 }
86 }
87
88private:
bungeman@google.com0f0c2882011-11-04 15:47:41 +000089 typedef GM INHERITED;
90};
91
92//////////////////////////////////////////////////////////////////////////////
borenet@google.com0682ca62012-06-26 17:23:52 +000093
bungeman@google.com0f0c2882011-11-04 15:47:41 +000094static GM* MyFactory(void*) { return new FontScalerGM; }
95static GMRegistry reg(MyFactory);
borenet@google.com0682ca62012-06-26 17:23:52 +000096
bungeman@google.com0f0c2882011-11-04 15:47:41 +000097}