blob: 3fefd56080e6e99041b807228fa9c0fcfb85a116 [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
mtklein72c9faa2015-01-09 10:06:39 -080023 SkString onShortName() SK_OVERRIDE {
bungeman@google.com0f0c2882011-11-04 15:47:41 +000024 return SkString("fontscaler");
25 }
26
mtklein72c9faa2015-01-09 10:06:39 -080027 SkISize onISize() SK_OVERRIDE {
tfarinaf5393182014-06-09 23:59:03 -070028 return SkISize::Make(1450, 750);
bungeman@google.com0f0c2882011-11-04 15:47:41 +000029 }
30
bungeman@google.coma682b932012-01-05 18:10:48 +000031 static void rotate_about(SkCanvas* canvas,
32 SkScalar degrees,
33 SkScalar px, SkScalar py) {
bungeman@google.com0f0c2882011-11-04 15:47:41 +000034 canvas->translate(px, py);
35 canvas->rotate(degrees);
36 canvas->translate(-px, -py);
37 }
38
mtklein72c9faa2015-01-09 10:06:39 -080039 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
bungeman@google.com0f0c2882011-11-04 15:47:41 +000040 SkPaint paint;
41
bungeman@google.com0f0c2882011-11-04 15:47:41 +000042 paint.setAntiAlias(true);
43 paint.setLCDRenderText(true);
44 //With freetype the default (normal hinting) can be really ugly.
45 //Most distros now set slight (vertical hinting only) in any event.
46 paint.setHinting(SkPaint::kSlight_Hinting);
Cary Clark992c7b02014-07-31 08:58:44 -040047 sk_tool_utils::set_portable_typeface(&paint, "Times Roman", SkTypeface::kNormal);
bungeman@google.com0f0c2882011-11-04 15:47:41 +000048
bungeman@google.com0f0c2882011-11-04 15:47:41 +000049 const char* text = "Hamburgefons ooo mmm";
50 const size_t textLen = strlen(text);
51
52 for (int j = 0; j < 2; ++j) {
bsalomon@google.com4121f952013-09-09 16:19:40 +000053 // This used to do 6 iterations but it causes the N4 to crash in the MSAA4 config.
54 for (int i = 0; i < 5; ++i) {
bungeman@google.com0f0c2882011-11-04 15:47:41 +000055 SkScalar x = SkIntToScalar(10);
56 SkScalar y = SkIntToScalar(20);
57
58 SkAutoCanvasRestore acr(canvas, true);
59 canvas->translate(SkIntToScalar(50 + i * 230),
60 SkIntToScalar(20));
61 rotate_about(canvas, SkIntToScalar(i * 5), x, y * 10);
62
63 {
64 SkPaint p;
65 p.setAntiAlias(true);
66 SkRect r;
bungeman@google.coma682b932012-01-05 18:10:48 +000067 r.set(x - SkIntToScalar(3), SkIntToScalar(15),
68 x - SkIntToScalar(1), SkIntToScalar(280));
bungeman@google.com0f0c2882011-11-04 15:47:41 +000069 canvas->drawRect(r, p);
70 }
71
bungeman@google.com0f0c2882011-11-04 15:47:41 +000072 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);
bungeman@google.com0f0c2882011-11-04 15:47:41 +000076 }
77 }
bungeman@google.coma682b932012-01-05 18:10:48 +000078 canvas->translate(0, SkIntToScalar(360));
bungeman@google.com0f0c2882011-11-04 15:47:41 +000079 paint.setSubpixelText(true);
80 }
81 }
82
83private:
bungeman@google.com0f0c2882011-11-04 15:47:41 +000084 typedef GM INHERITED;
85};
86
87//////////////////////////////////////////////////////////////////////////////
borenet@google.com0682ca62012-06-26 17:23:52 +000088
bungeman@google.com0f0c2882011-11-04 15:47:41 +000089static GM* MyFactory(void*) { return new FontScalerGM; }
90static GMRegistry reg(MyFactory);
borenet@google.com0682ca62012-06-26 17:23:52 +000091
bungeman@google.com0f0c2882011-11-04 15:47:41 +000092}