3 * Copyright 2011 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
10 /* Tests text vertical text rendering with different fonts and centering.
15 #include "SkTypeface.h"
19 class VertText2GM : public GM {
22 const int pointSize = 24;
23 textHeight = SkIntToScalar(pointSize);
24 fProp = sk_tool_utils::create_portable_typeface("Helvetica", SkTypeface::kNormal);
25 fMono = sk_tool_utils::create_portable_typeface("Courier New", SkTypeface::kNormal);
28 virtual ~VertText2GM() {
36 SkString onShortName() SK_OVERRIDE {
37 return SkString("verttext2");
40 SkISize onISize() SK_OVERRIDE { return SkISize::Make(640, 480); }
42 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
43 for (int i = 0; i < 3; ++i) {
45 paint.setColor(SK_ColorRED);
46 paint.setAntiAlias(true);
48 canvas->drawLine(0, SkIntToScalar(10),
49 SkIntToScalar(110), SkIntToScalar(10), paint);
50 canvas->drawLine(0, SkIntToScalar(240),
51 SkIntToScalar(110), SkIntToScalar(240), paint);
52 canvas->drawLine(0, SkIntToScalar(470),
53 SkIntToScalar(110), SkIntToScalar(470), paint);
54 drawText(canvas, SkString("Proportional / Top Aligned"),
55 fProp, SkPaint::kLeft_Align);
56 drawText(canvas, SkString("< Proportional / Centered >"),
57 fProp, SkPaint::kCenter_Align);
58 drawText(canvas, SkString("Monospaced / Top Aligned"),
59 fMono, SkPaint::kLeft_Align);
60 drawText(canvas, SkString("< Monospaced / Centered >"),
61 fMono, SkPaint::kCenter_Align);
62 canvas->rotate(SkIntToScalar(-15));
63 canvas->translate(textHeight * 4, SkIntToScalar(50));
65 canvas->translate(0, SkIntToScalar(50));
70 void drawText(SkCanvas* canvas, const SkString& string,
71 SkTypeface* family, SkPaint::Align alignment) {
73 paint.setColor(SK_ColorBLACK);
74 paint.setAntiAlias(true);
75 paint.setVerticalText(true);
76 paint.setTextAlign(alignment);
77 paint.setTypeface(family);
78 paint.setTextSize(textHeight);
80 canvas->drawText(string.c_str(), string.size(), y,
81 SkIntToScalar(alignment == SkPaint::kLeft_Align ? 10 : 240),
88 SkScalar y, textHeight;
93 ///////////////////////////////////////////////////////////////////////////////
95 static GM* MyFactory(void*) { return new VertText2GM; }
96 static GMRegistry reg(MyFactory);