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