2011-12-21 20:06:30 +00: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"
|
2017-03-22 17:47:51 +00:00
|
|
|
#include "sk_tool_utils.h"
|
2011-12-21 20:06:30 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkTypeface.h"
|
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
class VertText2GM : public GM {
|
|
|
|
public:
|
2016-05-12 17:09:30 +00:00
|
|
|
VertText2GM() {}
|
2011-12-21 20:06:30 +00:00
|
|
|
|
|
|
|
protected:
|
2015-05-21 13:15:28 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
|
|
|
const int pointSize = 24;
|
|
|
|
textHeight = SkIntToScalar(pointSize);
|
2017-11-14 15:45:32 +00:00
|
|
|
fProp = SkTypeface::MakeFromName("sans-serif", SkFontStyle());
|
|
|
|
fMono = SkTypeface::MakeFromName("monospace", SkFontStyle());
|
2015-05-21 13:15:28 +00:00
|
|
|
}
|
2011-12-21 20:06:30 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2015-07-24 18:08:01 +00:00
|
|
|
SkString name("verttext2");
|
2017-11-13 16:03:16 +00:00
|
|
|
name.append(sk_tool_utils::platform_font_manager());
|
2015-07-24 18:08:01 +00:00
|
|
|
return name;
|
2011-12-21 20:06:30 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override { return SkISize::Make(640, 480); }
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2011-12-21 20:06:30 +00:00
|
|
|
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 19:24:50 +00:00
|
|
|
fProp, SkPaint::kLeft_Align);
|
2011-12-21 20:06:30 +00:00
|
|
|
drawText(canvas, SkString("< Proportional / Centered >"),
|
2012-06-26 19:24:50 +00:00
|
|
|
fProp, SkPaint::kCenter_Align);
|
2011-12-21 20:06:30 +00:00
|
|
|
drawText(canvas, SkString("Monospaced / Top Aligned"),
|
2012-06-26 19:24:50 +00:00
|
|
|
fMono, SkPaint::kLeft_Align);
|
2011-12-21 20:06:30 +00:00
|
|
|
drawText(canvas, SkString("< Monospaced / Centered >"),
|
2012-06-26 19:24:50 +00:00
|
|
|
fMono, SkPaint::kCenter_Align);
|
2011-12-21 20:06:30 +00: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,
|
2016-05-12 17:09:30 +00:00
|
|
|
sk_sp<SkTypeface> family, SkPaint::Align alignment) {
|
2011-12-21 20:06:30 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(SK_ColorBLACK);
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setVerticalText(true);
|
|
|
|
paint.setTextAlign(alignment);
|
2016-05-12 17:09:30 +00:00
|
|
|
paint.setTypeface(std::move(family));
|
2011-12-21 20:06:30 +00:00
|
|
|
paint.setTextSize(textHeight);
|
|
|
|
|
2017-04-28 19:35:12 +00:00
|
|
|
canvas->drawString(string, y,
|
2012-04-10 17:42:21 +00:00
|
|
|
SkIntToScalar(alignment == SkPaint::kLeft_Align ? 10 : 240),
|
|
|
|
paint);
|
2011-12-21 20:06:30 +00:00
|
|
|
y += textHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
SkScalar y, textHeight;
|
2016-05-12 17:09:30 +00:00
|
|
|
sk_sp<SkTypeface> fProp;
|
|
|
|
sk_sp<SkTypeface> fMono;
|
2011-12-21 20:06:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static GM* MyFactory(void*) { return new VertText2GM; }
|
|
|
|
static GMRegistry reg(MyFactory);
|
|
|
|
|
|
|
|
}
|