blob: 6ef37caf70f3da7eb55690d7b15988c522b66b38 [file] [log] [blame]
reed@google.comca0062e2012-07-20 11:20:32 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm.h"
9#include "SkCanvas.h"
10#include "SkPaint.h"
11#include "SkRandom.h"
12
13class GetPosTextPathGM : public skiagm::GM {
14public:
15 GetPosTextPathGM() {}
16
17protected:
18 SkString onShortName() {
19 return SkString("getpostextpath");
20 }
21
22 SkISize onISize() { return skiagm::make_isize(480, 780); }
23
24 virtual void onDraw(SkCanvas* canvas) {
25 const char* text = "Hamburgefons";
26 size_t len = strlen(text);
27
28 SkPaint paint;
29 paint.setAntiAlias(true);
30 paint.setTextSize(SkIntToScalar(48));
31
32 SkAutoTArray<SkPoint> pos(len);
33 SkAutoTArray<SkScalar> widths(len);
34 paint.getTextWidths(text, len, &widths[0]);
35
36 SkRandom rand;
37 SkScalar x = SkIntToScalar(20);
38 SkScalar y = SkIntToScalar(100);
39 for (size_t i = 0; i < len; ++i) {
40 pos[i].set(x, y + rand.nextSScalar1() * 24);
41 x += widths[i];
42 }
43
44 canvas->drawPosText(text, len, &pos[0], paint);
45
46 SkPath path;
47 paint.setColor(SK_ColorRED);
48 paint.setStyle(SkPaint::kStroke_Style);
49 paint.getPosTextPath(text, len, &pos[0], &path);
50 canvas->drawPath(path, paint);
51 }
52};
53
54//////////////////////////////////////////////////////////////////////////////
55
56static skiagm::GM* F(void*) { return new GetPosTextPathGM; }
57
58static skiagm::GMRegistry gR(F);
59