blob: 8c4649c3729f8cac7b565137063c49711aaa5572 [file] [log] [blame]
commit-bot@chromium.orgc5fd4612013-05-06 22:23:08 +00001/*
2 * Copyright 2013 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
12class DevicePropertiesGM : public GM {
13public:
14 DevicePropertiesGM() {
15 this->setBGColor(0xFFFFFFFF);
16 }
17
18 virtual ~DevicePropertiesGM() {
19 }
20
21protected:
22 virtual SkString onShortName() {
23 return SkString("deviceproperties");
24 }
25
26 virtual SkISize onISize() {
27 return make_isize(1450, 750);
28 }
29
30 static void rotate_about(SkCanvas* canvas,
31 SkScalar degrees,
32 SkScalar px, SkScalar py) {
33 canvas->translate(px, py);
34 canvas->rotate(degrees);
35 canvas->translate(-px, -py);
36 }
37
38 virtual void onDraw(SkCanvas* originalCanvas) {
39 SkISize size = this->getISize();
40 SkBitmap bitmap;
reed@google.comeb9a46c2014-01-25 16:46:20 +000041 bitmap.allocN32Pixels(size.width(), size.height());
commit-bot@chromium.orgc5fd4612013-05-06 22:23:08 +000042 SkDeviceProperties properties = SkDeviceProperties::Make(
43 SkDeviceProperties::Geometry::Make(SkDeviceProperties::Geometry::kVertical_Orientation,
44 SkDeviceProperties::Geometry::kBGR_Layout),
45 SK_Scalar1);
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000046 SkBitmapDevice device(bitmap, properties);
commit-bot@chromium.orgc5fd4612013-05-06 22:23:08 +000047 SkCanvas canvas(&device);
48 canvas.drawColor(SK_ColorWHITE);
49
50 SkPaint paint;
51
52 paint.setAntiAlias(true);
53 paint.setLCDRenderText(true);
54 //With freetype the default (normal hinting) can be really ugly.
55 //Most distros now set slight (vertical hinting only) in any event.
56 paint.setHinting(SkPaint::kSlight_Hinting);
57 SkSafeUnref(paint.setTypeface(SkTypeface::CreateFromName("Times Roman", SkTypeface::kNormal)));
58
59 const char* text = "Hamburgefons ooo mmm";
60 const size_t textLen = strlen(text);
61
62 for (int j = 0; j < 2; ++j) {
63 for (int i = 0; i < 6; ++i) {
64 SkScalar x = SkIntToScalar(10);
65 SkScalar y = SkIntToScalar(20);
66
67 SkAutoCanvasRestore acr(&canvas, true);
68 canvas.translate(SkIntToScalar(50 + i * 230),
69 SkIntToScalar(20));
70 rotate_about(&canvas, SkIntToScalar(i * 5), x, y * 10);
71
72 {
73 SkPaint p;
74 p.setAntiAlias(true);
75 SkRect r;
76 r.set(x - SkIntToScalar(3), SkIntToScalar(15),
77 x - SkIntToScalar(1), SkIntToScalar(280));
78 canvas.drawRect(r, p);
79 }
80
81 int index = 0;
82 for (int ps = 6; ps <= 22; ps++) {
83 paint.setTextSize(SkIntToScalar(ps));
84 canvas.drawText(text, textLen, x, y, paint);
85 y += paint.getFontMetrics(NULL);
86 index += 1;
87 }
88 }
89 canvas.translate(0, SkIntToScalar(360));
90 paint.setSubpixelText(true);
91 }
92 originalCanvas->drawBitmap(bitmap, 0, 0);
93 }
94
95#ifdef SK_BUILD_FOR_ANDROID
96 virtual uint32_t onGetFlags() const SK_OVERRIDE {
97 // On android, we fail due to bad gpu drivers (it seems) by adding too
98 // much to our text atlas (texture).
99 return kSkipGPU_Flag;
100 }
101#endif
102
103private:
104 typedef GM INHERITED;
105};
106
107//////////////////////////////////////////////////////////////////////////////
108
109static GM* MyFactory(void*) { return new DevicePropertiesGM; }
110static GMRegistry reg(MyFactory);
111
112}