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.
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SampleCode.h"
|
2013-09-06 14:16:12 +00:00
|
|
|
#include "SkBlurMask.h"
|
2012-03-15 15:01:34 +00:00
|
|
|
#include "SkBlurDrawLooper.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkPath.h"
|
|
|
|
#include "SkPathMeasure.h"
|
|
|
|
|
2012-03-15 15:01:34 +00:00
|
|
|
#define REPEAT_COUNT 1
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2012-03-15 15:01:34 +00:00
|
|
|
static void textStrokePath(SkCanvas* canvas) {
|
2008-12-17 15:59:43 +00:00
|
|
|
SkPaint paint;
|
2012-03-15 15:01:34 +00:00
|
|
|
SkPath path;
|
|
|
|
SkRect rect;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2012-03-15 15:01:34 +00:00
|
|
|
canvas->save();
|
|
|
|
canvas->scale(SkIntToScalar(250),SkIntToScalar(250));
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2013-11-25 19:44:07 +00:00
|
|
|
rect.set(0.0f, 0.21f,
|
|
|
|
0.78f, 0.99f);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2012-03-15 15:01:34 +00:00
|
|
|
path.addArc(rect, SkIntToScalar(280), SkIntToScalar(350));
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
paint.setAntiAlias(true);
|
2012-03-15 15:01:34 +00:00
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setColor(0xFFFF0000);
|
2013-11-25 19:44:07 +00:00
|
|
|
paint.setTextSize(0.085f);
|
|
|
|
paint.setStrokeWidth(.005f);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2012-03-15 15:01:34 +00:00
|
|
|
canvas->drawPath(path, paint);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2014-04-15 15:48:36 +00:00
|
|
|
paint.setLooper(SkBlurDrawLooper::Create(SK_ColorBLACK,
|
|
|
|
SkBlurMask::ConvertRadiusToSigma(0.002f),
|
|
|
|
0.0f,
|
|
|
|
0.0f))->unref();
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2012-03-15 15:01:34 +00:00
|
|
|
const char* text = "DRAWING STROKED TEXT WITH A BLUR ON A PATH";
|
|
|
|
size_t len = strlen(text);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2012-05-08 13:15:37 +00:00
|
|
|
canvas->drawTextOnPathHV(text, len, path, 0,
|
2013-11-25 19:44:07 +00:00
|
|
|
-0.025f, paint);
|
2012-03-15 15:01:34 +00:00
|
|
|
canvas->restore();
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
2012-03-15 15:01:34 +00:00
|
|
|
static void textPathMatrix(SkCanvas* canvas) {
|
2008-12-17 15:59:43 +00:00
|
|
|
SkPaint paint;
|
|
|
|
SkPath path;
|
|
|
|
SkMatrix matrix;
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2012-03-15 15:01:34 +00:00
|
|
|
path.moveTo(SkIntToScalar(050), SkIntToScalar(200));
|
|
|
|
path.quadTo(SkIntToScalar(250), SkIntToScalar(000),
|
|
|
|
SkIntToScalar(450), SkIntToScalar(200));
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
paint.setAntiAlias(true);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
2012-03-15 15:01:34 +00:00
|
|
|
canvas->drawPath(path, paint);
|
2008-12-17 15:59:43 +00:00
|
|
|
paint.setStyle(SkPaint::kFill_Style);
|
|
|
|
paint.setTextSize(SkIntToScalar(48));
|
|
|
|
paint.setTextAlign(SkPaint::kRight_Align);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2010-12-20 18:26:13 +00:00
|
|
|
const char* text = "Reflection";
|
2008-12-17 15:59:43 +00:00
|
|
|
size_t len = strlen(text);
|
2012-03-15 15:01:34 +00:00
|
|
|
|
|
|
|
SkPathMeasure meas(path, false);
|
|
|
|
SkScalar pathLen = meas.getLength();
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
canvas->drawTextOnPath(text, len, path, NULL, paint);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
matrix.setScale(-SK_Scalar1, SK_Scalar1);
|
|
|
|
matrix.postTranslate(pathLen, 0);
|
|
|
|
canvas->drawTextOnPath(text, len, path, &matrix, paint);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
matrix.setScale(SK_Scalar1, -SK_Scalar1);
|
|
|
|
canvas->drawTextOnPath(text, len, path, &matrix, paint);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
paint.setColor(SK_ColorGREEN);
|
|
|
|
matrix.setScale(-SK_Scalar1, -SK_Scalar1);
|
|
|
|
matrix.postTranslate(pathLen, 0);
|
|
|
|
canvas->drawTextOnPath(text, len, path, &matrix, paint);
|
|
|
|
}
|
|
|
|
|
2011-04-22 14:10:48 +00:00
|
|
|
class TextOnPathView : public SampleView {
|
2008-12-17 15:59:43 +00:00
|
|
|
public:
|
|
|
|
SkPath fPath;
|
|
|
|
SkScalar fHOffset;
|
|
|
|
|
2015-02-25 17:04:04 +00:00
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
2008-12-17 15:59:43 +00:00
|
|
|
SkRect r;
|
|
|
|
r.set(SkIntToScalar(100), SkIntToScalar(100),
|
|
|
|
SkIntToScalar(300), SkIntToScalar(300));
|
|
|
|
fPath.addOval(r);
|
2012-03-15 15:01:34 +00:00
|
|
|
fPath.offset(SkIntToScalar(-50), SkIntToScalar(-50));
|
2010-12-20 18:26:13 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
fHOffset = SkIntToScalar(50);
|
|
|
|
}
|
|
|
|
|
|
|
|
// overrides from SkEventSink
|
2015-03-26 01:17:31 +00:00
|
|
|
bool onQuery(SkEvent* evt) override {
|
2008-12-17 15:59:43 +00:00
|
|
|
if (SampleCode::TitleQ(*evt)) {
|
|
|
|
SampleCode::TitleR(evt, "Text On Path");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
2008-12-17 15:59:43 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
2012-03-15 15:01:34 +00:00
|
|
|
paint.setTextSize(SkIntToScalar(48));
|
|
|
|
|
|
|
|
const char* text = "Hamburgefons";
|
|
|
|
size_t len = strlen(text);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
for (int j = 0; j < REPEAT_COUNT; j++) {
|
|
|
|
SkScalar x = fHOffset;
|
|
|
|
|
|
|
|
paint.setColor(SK_ColorBLACK);
|
2012-03-15 15:01:34 +00:00
|
|
|
canvas->drawTextOnPathHV(text, len, fPath,
|
2008-12-17 15:59:43 +00:00
|
|
|
x, paint.getTextSize()/2, paint);
|
|
|
|
|
|
|
|
paint.setColor(SK_ColorRED);
|
2012-03-15 15:01:34 +00:00
|
|
|
canvas->drawTextOnPathHV(text, len, fPath,
|
2008-12-17 15:59:43 +00:00
|
|
|
x + SkIntToScalar(50), 0, paint);
|
|
|
|
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
2012-03-15 15:01:34 +00:00
|
|
|
canvas->drawTextOnPathHV(text, len, fPath,
|
2008-12-17 15:59:43 +00:00
|
|
|
x + SkIntToScalar(100), -paint.getTextSize()/2, paint);
|
|
|
|
}
|
2012-03-15 15:01:34 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
paint.setColor(SK_ColorGREEN);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
2012-03-15 15:01:34 +00:00
|
|
|
canvas->drawPath(fPath, paint);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2012-03-15 15:01:34 +00:00
|
|
|
canvas->translate(SkIntToScalar(275), 0);
|
|
|
|
textStrokePath(canvas);
|
|
|
|
|
|
|
|
canvas->translate(SkIntToScalar(-275), SkIntToScalar(250));
|
|
|
|
textPathMatrix(canvas);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
if (REPEAT_COUNT > 1)
|
|
|
|
this->inval(NULL);
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) override {
|
2008-12-17 15:59:43 +00:00
|
|
|
fHints += 1;
|
|
|
|
this->inval(NULL);
|
2013-01-08 16:17:50 +00:00
|
|
|
return this->INHERITED::onFindClickHandler(x, y, modi);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool onClick(Click* click) override {
|
2008-12-17 15:59:43 +00:00
|
|
|
return this->INHERITED::onClick(click);
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
private:
|
|
|
|
int fHints;
|
2011-04-22 14:10:48 +00:00
|
|
|
typedef SampleView INHERITED;
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static SkView* MyFactory() {
|
|
|
|
return new TextOnPathView;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SkViewRegister reg(MyFactory);
|