1213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/* 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2011 Google Inc. 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 7213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com */ 8213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com 9ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 10213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com/* Tests text rendering with LCD and subpixel rendering turned on and off. 11213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com */ 12213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com 13213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com#include "gm.h" 14213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com#include "SkCanvas.h" 15213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com 16213c42bb69d375818cc0713a51c28c48ab501763epoger@google.comnamespace skiagm { 17213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com 18213c42bb69d375818cc0713a51c28c48ab501763epoger@google.comclass LcdTextGM : public GM { 19213c42bb69d375818cc0713a51c28c48ab501763epoger@google.compublic: 20213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com LcdTextGM() { 21213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com const int pointSize = 36; 22213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com textHeight = SkIntToScalar(pointSize); 23213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com } 24213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com 25213c42bb69d375818cc0713a51c28c48ab501763epoger@google.comprotected: 26213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com 27213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com SkString onShortName() { 28213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com return SkString("lcdtext"); 29213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com } 30213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com 31f539318f0d3dba743ec1886d5d9df0fb1be628a1tfarina SkISize onISize() { return SkISize::Make(640, 480); } 32213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com 33213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com virtual void onDraw(SkCanvas* canvas) { 34d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 35213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com y = textHeight; 36213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com drawText(canvas, SkString("TEXT: SubpixelTrue LCDRenderTrue"), 37213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com true, true); 38213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com drawText(canvas, SkString("TEXT: SubpixelTrue LCDRenderFalse"), 39213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com true, false); 40213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com drawText(canvas, SkString("TEXT: SubpixelFalse LCDRenderTrue"), 41213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com false, true); 42213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com drawText(canvas, SkString("TEXT: SubpixelFalse LCDRenderFalse"), 43213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com false, false); 44213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com } 45213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com 46213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com void drawText(SkCanvas* canvas, const SkString& string, 47213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com bool subpixelTextEnabled, bool lcdRenderTextEnabled) { 48213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com SkPaint paint; 49213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com paint.setColor(SK_ColorBLACK); 50213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com paint.setDither(true); 51213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com paint.setAntiAlias(true); 52992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark sk_tool_utils::set_portable_typeface(&paint); 53213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com paint.setSubpixelText(subpixelTextEnabled); 54213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com paint.setLCDRenderText(lcdRenderTextEnabled); 55213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com paint.setTextSize(textHeight); 56213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com 57213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com canvas->drawText(string.c_str(), string.size(), 0, y, paint); 58213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com y += textHeight; 59213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com } 60213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com 61213c42bb69d375818cc0713a51c28c48ab501763epoger@google.comprivate: 62213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com typedef GM INHERITED; 63213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com SkScalar y, textHeight; 64213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com}; 65213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com 66213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com/////////////////////////////////////////////////////////////////////////////// 67213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com 68213c42bb69d375818cc0713a51c28c48ab501763epoger@google.comstatic GM* MyFactory(void*) { return new LcdTextGM; } 69213c42bb69d375818cc0713a51c28c48ab501763epoger@google.comstatic GMRegistry reg(MyFactory); 70213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com 71213c42bb69d375818cc0713a51c28c48ab501763epoger@google.com} 72