2 * Copyright 2011 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "SkTypeface.h"
12 class FontScalerGM : public GM {
15 this->setBGColor(0xFFFFFFFF);
18 virtual ~FontScalerGM() {
23 SkString onShortName() SK_OVERRIDE {
24 return SkString("fontscaler");
27 SkISize onISize() SK_OVERRIDE {
28 return SkISize::Make(1450, 750);
31 static void rotate_about(SkCanvas* canvas,
33 SkScalar px, SkScalar py) {
34 canvas->translate(px, py);
35 canvas->rotate(degrees);
36 canvas->translate(-px, -py);
39 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
42 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);
47 sk_tool_utils::set_portable_typeface(&paint, "Times Roman", SkTypeface::kNormal);
49 const char* text = "Hamburgefons ooo mmm";
50 const size_t textLen = strlen(text);
52 for (int j = 0; j < 2; ++j) {
53 // 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) {
55 SkScalar x = SkIntToScalar(10);
56 SkScalar y = SkIntToScalar(20);
58 SkAutoCanvasRestore acr(canvas, true);
59 canvas->translate(SkIntToScalar(50 + i * 230),
61 rotate_about(canvas, SkIntToScalar(i * 5), x, y * 10);
67 r.set(x - SkIntToScalar(3), SkIntToScalar(15),
68 x - SkIntToScalar(1), SkIntToScalar(280));
69 canvas->drawRect(r, p);
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);
78 canvas->translate(0, SkIntToScalar(360));
79 paint.setSubpixelText(true);
87 //////////////////////////////////////////////////////////////////////////////
89 static GM* MyFactory(void*) { return new FontScalerGM; }
90 static GMRegistry reg(MyFactory);