reed@google.com | ca0062e | 2012-07-20 11:20:32 +0000 | [diff] [blame] | 1 | /* |
| 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.com | 0058324 | 2012-07-20 11:34:36 +0000 | [diff] [blame^] | 12 | #include "SkTemplates.h" |
reed@google.com | ca0062e | 2012-07-20 11:20:32 +0000 | [diff] [blame] | 13 | |
| 14 | class GetPosTextPathGM : public skiagm::GM { |
| 15 | public: |
| 16 | GetPosTextPathGM() {} |
| 17 | |
| 18 | protected: |
| 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 | |
| 57 | static skiagm::GM* F(void*) { return new GetPosTextPathGM; } |
| 58 | |
| 59 | static skiagm::GMRegistry gR(F); |
| 60 | |