blob: f1b810cd20b1be618499bb6226b9512583006615 [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"
reed@google.com00583242012-07-20 11:34:36 +000012#include "SkTemplates.h"
reed@google.comca0062e2012-07-20 11:20:32 +000013
14class GetPosTextPathGM : public skiagm::GM {
15public:
16 GetPosTextPathGM() {}
17
18protected:
19 SkString onShortName() {
20 return SkString("getpostextpath");
21 }
22
23 SkISize onISize() { return skiagm::make_isize(480, 780); }
24
25 virtual void onDraw(SkCanvas* canvas) {
26 const char* text = "Hamburgefons";
27 size_t len = strlen(text);
28
29 SkPaint paint;
30 paint.setAntiAlias(true);
31 paint.setTextSize(SkIntToScalar(48));
32
33 SkAutoTArray<SkPoint> pos(len);
34 SkAutoTArray<SkScalar> widths(len);
35 paint.getTextWidths(text, len, &widths[0]);
36
37 SkRandom rand;
38 SkScalar x = SkIntToScalar(20);
39 SkScalar y = SkIntToScalar(100);
40 for (size_t i = 0; i < len; ++i) {
41 pos[i].set(x, y + rand.nextSScalar1() * 24);
42 x += widths[i];
43 }
44
45 canvas->drawPosText(text, len, &pos[0], paint);
46
47 SkPath path;
48 paint.setColor(SK_ColorRED);
49 paint.setStyle(SkPaint::kStroke_Style);
50 paint.getPosTextPath(text, len, &pos[0], &path);
51 canvas->drawPath(path, paint);
52 }
53};
54
55//////////////////////////////////////////////////////////////////////////////
56
57static skiagm::GM* F(void*) { return new GetPosTextPathGM; }
58
59static skiagm::GMRegistry gR(F);
60