blob: eb38013cb1bdd44f021d2ba3a5cfe239d2ae9ffa [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
bungeman@google.com0f0c2882011-11-04 15:47:41 +000075 for (int ps = 6; ps <= 22; ps++) {
76 paint.setTextSize(SkIntToScalar(ps));
77 canvas->drawText(text, textLen, x, y, paint);
78 y += paint.getFontMetrics(NULL);
bungeman@google.com0f0c2882011-11-04 15:47:41 +000079 }
80 }
bungeman@google.coma682b932012-01-05 18:10:48 +000081 canvas->translate(0, SkIntToScalar(360));
bungeman@google.com0f0c2882011-11-04 15:47:41 +000082 paint.setSubpixelText(true);
83 }
84 }
85
86private:
bungeman@google.com0f0c2882011-11-04 15:47:41 +000087 typedef GM INHERITED;
88};
89
90//////////////////////////////////////////////////////////////////////////////
borenet@google.com0682ca62012-06-26 17:23:52 +000091
bungeman@google.com0f0c2882011-11-04 15:47:41 +000092static GM* MyFactory(void*) { return new FontScalerGM; }
93static GMRegistry reg(MyFactory);
borenet@google.com0682ca62012-06-26 17:23:52 +000094
bungeman@google.com0f0c2882011-11-04 15:47:41 +000095}