1/* 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; 41 bitmap.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height()); 42 bitmap.allocPixels(); 43 SkDeviceProperties properties = SkDeviceProperties::Make( 44 SkDeviceProperties::Geometry::Make(SkDeviceProperties::Geometry::kVertical_Orientation, 45 SkDeviceProperties::Geometry::kBGR_Layout), 46 SK_Scalar1); 47 SkDevice device(bitmap, properties); 48 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); 58 SkSafeUnref(paint.setTypeface(SkTypeface::CreateFromName("Times Roman", SkTypeface::kNormal))); 59 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} 114