2 * Copyright 2012 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
9 #include "sk_tool_utils.h"
14 #include "SkTemplates.h"
16 static void strokePath(SkCanvas* canvas, const SkPath& path) {
18 paint.setAntiAlias(true);
19 paint.setColor(SK_ColorRED);
20 paint.setStyle(SkPaint::kStroke_Style);
21 canvas->drawPath(path, paint);
23 DEF_SIMPLE_GM(getpostextpath, canvas, 480, 780) {
24 // explicitly add spaces, to test a prev. bug
25 const char* text = "Ham bur ge fons";
26 int len = SkToInt(strlen(text));
30 paint.setAntiAlias(true);
31 sk_tool_utils::set_portable_typeface(&paint);
32 paint.setTextSize(SkIntToScalar(48));
34 canvas->translate(SkIntToScalar(10), SkIntToScalar(64));
36 canvas->drawText(text, len, 0, 0, paint);
37 paint.getTextPath(text, len, 0, 0, &path);
38 strokePath(canvas, path);
41 SkAutoTArray<SkPoint> pos(len);
42 SkAutoTArray<SkScalar> widths(len);
43 paint.getTextWidths(text, len, &widths[0]);
46 SkScalar x = SkIntToScalar(20);
47 SkScalar y = SkIntToScalar(100);
48 for (int i = 0; i < len; ++i) {
49 pos[i].set(x, y + rand.nextSScalar1() * 24);
53 canvas->translate(0, SkIntToScalar(64));
55 canvas->drawPosText(text, len, &pos[0], paint);
56 paint.getPosTextPath(text, len, &pos[0], &path);
57 strokePath(canvas, path);