2011-07-28 14:26:00 +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.
|
|
|
|
*/
|
2018-08-08 15:36:17 +00:00
|
|
|
#include "Sample.h"
|
2018-02-08 20:45:51 +00:00
|
|
|
|
2010-05-17 14:50:04 +00:00
|
|
|
#include "SkBlurMaskFilter.h"
|
|
|
|
#include "SkCanvas.h"
|
2018-02-08 20:45:51 +00:00
|
|
|
#include "SkColorFilter.h"
|
|
|
|
#include "SkColorPriv.h"
|
2011-09-28 15:24:00 +00:00
|
|
|
#include "SkColorShader.h"
|
2010-05-17 14:50:04 +00:00
|
|
|
#include "SkGradientShader.h"
|
|
|
|
#include "SkGraphics.h"
|
2018-02-08 20:45:51 +00:00
|
|
|
#include "SkOSFile.h"
|
2010-05-17 14:50:04 +00:00
|
|
|
#include "SkPath.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkRegion.h"
|
|
|
|
#include "SkShader.h"
|
2018-02-08 20:45:51 +00:00
|
|
|
#include "SkShaper.h"
|
|
|
|
#include "SkStream.h"
|
|
|
|
#include "SkTextBlob.h"
|
2010-05-17 14:50:04 +00:00
|
|
|
#include "SkTime.h"
|
|
|
|
#include "SkTypeface.h"
|
2018-08-21 15:45:46 +00:00
|
|
|
#include "SkUTF.h"
|
2010-05-17 14:50:04 +00:00
|
|
|
|
2011-03-02 14:34:11 +00:00
|
|
|
static const char gText[] =
|
2012-08-23 18:19:56 +00:00
|
|
|
"When in the Course of human events it becomes necessary for one people "
|
|
|
|
"to dissolve the political bands which have connected them with another "
|
|
|
|
"and to assume among the powers of the earth, the separate and equal "
|
|
|
|
"station to which the Laws of Nature and of Nature's God entitle them, "
|
|
|
|
"a decent respect to the opinions of mankind requires that they should "
|
|
|
|
"declare the causes which impel them to the separation.";
|
2010-05-17 14:50:04 +00:00
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
class TextBoxView : public Sample {
|
2011-03-02 14:34:11 +00:00
|
|
|
public:
|
2019-02-15 19:46:18 +00:00
|
|
|
TextBoxView() : fShaper(SkShaper::Make()) {}
|
2011-03-02 14:34:11 +00:00
|
|
|
|
2010-05-17 14:50:04 +00:00
|
|
|
protected:
|
2018-08-08 15:36:17 +00:00
|
|
|
bool onQuery(Sample::Event* evt) override {
|
|
|
|
if (Sample::TitleQ(*evt)) {
|
|
|
|
Sample::TitleR(evt, "TextBox");
|
2010-05-17 14:50:04 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
2011-03-02 14:34:11 +00:00
|
|
|
|
2011-09-28 15:24:00 +00:00
|
|
|
void drawTest(SkCanvas* canvas, SkScalar w, SkScalar h, SkColor fg, SkColor bg) {
|
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
|
|
|
|
|
|
canvas->clipRect(SkRect::MakeWH(w, h));
|
|
|
|
canvas->drawColor(bg);
|
2018-02-08 20:45:51 +00:00
|
|
|
|
2012-08-23 18:19:56 +00:00
|
|
|
SkScalar margin = 20;
|
2010-05-17 14:50:04 +00:00
|
|
|
|
2012-08-23 18:19:56 +00:00
|
|
|
SkPaint paint;
|
2011-09-28 15:24:00 +00:00
|
|
|
paint.setColor(fg);
|
2010-05-17 14:50:04 +00:00
|
|
|
|
2012-08-23 18:19:56 +00:00
|
|
|
for (int i = 9; i < 24; i += 2) {
|
2019-02-08 22:46:38 +00:00
|
|
|
SkTextBlobBuilderRunHandler builder(gText);
|
2019-01-08 19:00:08 +00:00
|
|
|
SkFont font(nullptr, SkIntToScalar(i));
|
|
|
|
font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
|
|
|
|
|
2019-02-15 19:46:18 +00:00
|
|
|
SkPoint end = fShaper->shape(&builder, font, gText, strlen(gText), true,
|
|
|
|
{ margin, margin }, w - margin);
|
2018-12-12 15:54:49 +00:00
|
|
|
canvas->drawTextBlob(builder.makeBlob(), 0, 0, paint);
|
2018-02-08 20:45:51 +00:00
|
|
|
|
|
|
|
canvas->translate(0, end.y());
|
2012-08-23 18:19:56 +00:00
|
|
|
}
|
2010-05-17 14:50:04 +00:00
|
|
|
}
|
2011-03-02 14:34:11 +00:00
|
|
|
|
2018-02-08 20:45:51 +00:00
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
2011-09-28 15:24:00 +00:00
|
|
|
SkScalar width = this->width() / 3;
|
|
|
|
drawTest(canvas, width, this->height(), SK_ColorBLACK, SK_ColorWHITE);
|
|
|
|
canvas->translate(width, 0);
|
|
|
|
drawTest(canvas, width, this->height(), SK_ColorWHITE, SK_ColorBLACK);
|
|
|
|
canvas->translate(width, 0);
|
|
|
|
drawTest(canvas, width, this->height()/2, SK_ColorGRAY, SK_ColorWHITE);
|
|
|
|
canvas->translate(0, this->height()/2);
|
|
|
|
drawTest(canvas, width, this->height()/2, SK_ColorGRAY, SK_ColorBLACK);
|
|
|
|
}
|
|
|
|
|
2010-05-17 14:50:04 +00:00
|
|
|
private:
|
2019-02-15 19:46:18 +00:00
|
|
|
std::unique_ptr<SkShaper> fShaper;
|
2018-08-08 15:36:17 +00:00
|
|
|
typedef Sample INHERITED;
|
2010-05-17 14:50:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
DEF_SAMPLE( return new TextBoxView(); )
|