2012-07-20 11:20:32 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-03-20 16:12:10 +00:00
|
|
|
#include "ToolUtils.h"
|
2012-07-20 11:20:32 +00:00
|
|
|
#include "gm.h"
|
2018-06-13 13:59:02 +00:00
|
|
|
|
2012-07-20 11:20:32 +00:00
|
|
|
#include "SkCanvas.h"
|
2018-12-21 15:58:25 +00:00
|
|
|
#include "SkFontPriv.h"
|
2012-07-20 11:20:32 +00:00
|
|
|
#include "SkPaint.h"
|
2015-08-05 20:57:49 +00:00
|
|
|
#include "SkPath.h"
|
2012-07-20 11:20:32 +00:00
|
|
|
#include "SkRandom.h"
|
2012-07-20 11:34:36 +00:00
|
|
|
#include "SkTemplates.h"
|
2018-12-21 15:58:25 +00:00
|
|
|
#include "SkTextBlob.h"
|
2012-07-20 11:20:32 +00:00
|
|
|
|
2015-09-09 15:16:41 +00:00
|
|
|
static void strokePath(SkCanvas* canvas, const SkPath& path) {
|
2018-12-21 15:58:25 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
canvas->drawPath(path, paint);
|
2015-09-09 15:16:41 +00:00
|
|
|
}
|
|
|
|
DEF_SIMPLE_GM(getpostextpath, canvas, 480, 780) {
|
2018-12-21 15:58:25 +00:00
|
|
|
// explicitly add spaces, to test a prev. bug
|
|
|
|
const char* text = "Ham bur ge fons";
|
|
|
|
size_t len = strlen(text);
|
|
|
|
SkPath path;
|
|
|
|
|
|
|
|
SkFont font;
|
2019-03-20 16:12:10 +00:00
|
|
|
font.setTypeface(ToolUtils::create_portable_typeface());
|
2018-12-21 15:58:25 +00:00
|
|
|
font.setSize(48);
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
|
|
|
|
canvas->translate(SkIntToScalar(10), SkIntToScalar(64));
|
|
|
|
|
|
|
|
canvas->drawSimpleText(text, len, kUTF8_SkTextEncoding, 0, 0, font, paint);
|
2019-03-20 16:12:10 +00:00
|
|
|
ToolUtils::get_text_path(font, text, len, kUTF8_SkTextEncoding, &path, nullptr);
|
2018-12-21 15:58:25 +00:00
|
|
|
strokePath(canvas, path);
|
|
|
|
path.reset();
|
|
|
|
|
|
|
|
SkAutoToGlyphs atg(font, text, len, kUTF8_SkTextEncoding);
|
|
|
|
const int count = atg.count();
|
|
|
|
SkAutoTArray<SkPoint> pos(count);
|
|
|
|
SkAutoTArray<SkScalar> widths(count);
|
|
|
|
font.getWidths(atg.glyphs(), count, &widths[0]);
|
|
|
|
|
|
|
|
SkRandom rand;
|
|
|
|
SkScalar x = SkIntToScalar(20);
|
|
|
|
SkScalar y = SkIntToScalar(100);
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
pos[i].set(x, y + rand.nextSScalar1() * 24);
|
|
|
|
x += widths[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
canvas->translate(0, SkIntToScalar(64));
|
|
|
|
|
|
|
|
canvas->drawTextBlob(SkTextBlob::MakeFromPosText(text, len, &pos[0], font), 0, 0, paint);
|
2019-03-20 16:12:10 +00:00
|
|
|
ToolUtils::get_text_path(font, text, len, kUTF8_SkTextEncoding, &path, &pos[0]);
|
2018-12-21 15:58:25 +00:00
|
|
|
strokePath(canvas, path);
|
2015-09-09 15:16:41 +00:00
|
|
|
}
|