2 * Copyright 2013 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 "SkBitmapDevice.h"
9 #include "SkTypeface.h"
13 class DevicePropertiesGM : public GM {
15 DevicePropertiesGM() {
16 this->setBGColor(0xFFFFFFFF);
19 virtual ~DevicePropertiesGM() {
23 virtual SkString onShortName() {
24 return SkString("deviceproperties");
27 virtual SkISize onISize() {
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 virtual void onDraw(SkCanvas* originalCanvas) {
40 SkISize size = this->getISize();
42 bitmap.allocN32Pixels(size.width(), size.height());
43 SkDeviceProperties properties = SkDeviceProperties::Make(
44 SkDeviceProperties::Geometry::Make(SkDeviceProperties::Geometry::kVertical_Orientation,
45 SkDeviceProperties::Geometry::kBGR_Layout),
47 SkBitmapDevice device(bitmap, properties);
48 SkCanvas canvas(&device);
49 canvas.drawColor(SK_ColorWHITE);
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);
58 sk_tool_utils::set_portable_typeface(&paint, "Times Roman", SkTypeface::kNormal);
60 const char* text = "Hamburgefons ooo mmm";
61 const size_t textLen = strlen(text);
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);
68 SkAutoCanvasRestore acr(&canvas, true);
69 canvas.translate(SkIntToScalar(50 + i * 230),
71 rotate_about(&canvas, SkIntToScalar(i * 5), x, y * 10);
77 r.set(x - SkIntToScalar(3), SkIntToScalar(15),
78 x - SkIntToScalar(1), SkIntToScalar(280));
79 canvas.drawRect(r, p);
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);
90 canvas.translate(0, SkIntToScalar(360));
91 paint.setSubpixelText(true);
93 originalCanvas->drawBitmap(bitmap, 0, 0);
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;
105 typedef GM INHERITED;
108 //////////////////////////////////////////////////////////////////////////////
110 static GM* MyFactory(void*) { return new DevicePropertiesGM; }
111 static GMRegistry reg(MyFactory);