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-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkFont.h"
|
|
|
|
#include "include/core/SkFontTypes.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPath.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkPoint.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkTextBlob.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkTypeface.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/private/SkTemplates.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
|
|
|
#include "src/core/SkFontPriv.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "tools/ToolUtils.h"
|
|
|
|
|
|
|
|
#include <string.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));
|
|
|
|
|
2019-05-07 19:38:46 +00:00
|
|
|
canvas->drawSimpleText(text, len, SkTextEncoding::kUTF8, 0, 0, font, paint);
|
|
|
|
ToolUtils::get_text_path(font, text, len, SkTextEncoding::kUTF8, &path, nullptr);
|
2018-12-21 15:58:25 +00:00
|
|
|
strokePath(canvas, path);
|
|
|
|
path.reset();
|
|
|
|
|
2019-05-07 19:38:46 +00:00
|
|
|
SkAutoToGlyphs atg(font, text, len, SkTextEncoding::kUTF8);
|
2018-12-21 15:58:25 +00:00
|
|
|
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-05-07 19:38:46 +00:00
|
|
|
ToolUtils::get_text_path(font, text, len, SkTextEncoding::kUTF8, &path, &pos[0]);
|
2018-12-21 15:58:25 +00:00
|
|
|
strokePath(canvas, path);
|
2015-09-09 15:16:41 +00:00
|
|
|
}
|