2011-12-22 00:06:30 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/* Tests text vertical text rendering with different fonts and centering.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gm.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkTypeface.h"
|
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
class VertText2GM : public GM {
|
|
|
|
public:
|
|
|
|
VertText2GM() {
|
|
|
|
const int pointSize = 24;
|
|
|
|
textHeight = SkIntToScalar(pointSize);
|
2012-06-26 23:24:50 +04:00
|
|
|
fProp = SkTypeface::CreateFromName("Helvetica", SkTypeface::kNormal);
|
|
|
|
fMono = SkTypeface::CreateFromName("Courier New", SkTypeface::kNormal);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~VertText2GM() {
|
|
|
|
SkSafeUnref(fProp);
|
|
|
|
SkSafeUnref(fMono);
|
2011-12-22 00:06:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
SkString onShortName() {
|
|
|
|
return SkString("verttext2");
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize onISize() { return make_isize(640, 480); }
|
|
|
|
|
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
y = textHeight;
|
|
|
|
canvas->drawLine(0, SkIntToScalar(10),
|
|
|
|
SkIntToScalar(110), SkIntToScalar(10), paint);
|
|
|
|
canvas->drawLine(0, SkIntToScalar(240),
|
|
|
|
SkIntToScalar(110), SkIntToScalar(240), paint);
|
|
|
|
canvas->drawLine(0, SkIntToScalar(470),
|
|
|
|
SkIntToScalar(110), SkIntToScalar(470), paint);
|
|
|
|
drawText(canvas, SkString("Proportional / Top Aligned"),
|
2012-06-26 23:24:50 +04:00
|
|
|
fProp, SkPaint::kLeft_Align);
|
2011-12-22 00:06:30 +04:00
|
|
|
drawText(canvas, SkString("< Proportional / Centered >"),
|
2012-06-26 23:24:50 +04:00
|
|
|
fProp, SkPaint::kCenter_Align);
|
2011-12-22 00:06:30 +04:00
|
|
|
drawText(canvas, SkString("Monospaced / Top Aligned"),
|
2012-06-26 23:24:50 +04:00
|
|
|
fMono, SkPaint::kLeft_Align);
|
2011-12-22 00:06:30 +04:00
|
|
|
drawText(canvas, SkString("< Monospaced / Centered >"),
|
2012-06-26 23:24:50 +04:00
|
|
|
fMono, SkPaint::kCenter_Align);
|
2011-12-22 00:06:30 +04:00
|
|
|
canvas->rotate(SkIntToScalar(-15));
|
|
|
|
canvas->translate(textHeight * 4, SkIntToScalar(50));
|
|
|
|
if (i > 0) {
|
|
|
|
canvas->translate(0, SkIntToScalar(50));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawText(SkCanvas* canvas, const SkString& string,
|
|
|
|
SkTypeface* family, SkPaint::Align alignment) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(SK_ColorBLACK);
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setVerticalText(true);
|
|
|
|
paint.setTextAlign(alignment);
|
|
|
|
paint.setTypeface(family);
|
|
|
|
paint.setTextSize(textHeight);
|
|
|
|
|
|
|
|
canvas->drawText(string.c_str(), string.size(), y,
|
2012-04-10 21:42:21 +04:00
|
|
|
SkIntToScalar(alignment == SkPaint::kLeft_Align ? 10 : 240),
|
|
|
|
paint);
|
2011-12-22 00:06:30 +04:00
|
|
|
y += textHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
SkScalar y, textHeight;
|
2012-06-26 23:24:50 +04:00
|
|
|
SkTypeface* fProp;
|
|
|
|
SkTypeface* fMono;
|
2011-12-22 00:06:30 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static GM* MyFactory(void*) { return new VertText2GM; }
|
|
|
|
static GMRegistry reg(MyFactory);
|
|
|
|
|
|
|
|
}
|