Mike Reed | 331ccfd | 2018-10-25 12:36:06 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | #ifndef SkTextUtils_DEFINED |
| 9 | #define SkTextUtils_DEFINED |
| 10 | |
| 11 | #include "SkCanvas.h" |
| 12 | #include "SkPaint.h" |
| 13 | #include "SkFont.h" |
| 14 | #include "SkString.h" |
| 15 | |
| 16 | class SkTextUtils { |
| 17 | public: |
Mike Reed | 3a42ec0 | 2018-10-30 12:53:21 -0400 | [diff] [blame^] | 18 | enum Align { |
| 19 | kLeft_Align, |
| 20 | kCenter_Align, |
| 21 | kRight_Align, |
| 22 | }; |
| 23 | |
Mike Reed | 331ccfd | 2018-10-25 12:36:06 -0400 | [diff] [blame] | 24 | static void DrawText(SkCanvas*, const void* text, size_t size, SkScalar x, SkScalar y, |
Mike Reed | 3a42ec0 | 2018-10-30 12:53:21 -0400 | [diff] [blame^] | 25 | const SkPaint&, Align = kLeft_Align); |
Mike Reed | 331ccfd | 2018-10-25 12:36:06 -0400 | [diff] [blame] | 26 | |
| 27 | static void DrawString(SkCanvas* canvas, const char text[], SkScalar x, SkScalar y, |
Mike Reed | 3a42ec0 | 2018-10-30 12:53:21 -0400 | [diff] [blame^] | 28 | const SkPaint& paint, Align align = kLeft_Align) { |
Mike Reed | 331ccfd | 2018-10-25 12:36:06 -0400 | [diff] [blame] | 29 | DrawText(canvas, text, strlen(text), x, y, paint, align); |
| 30 | } |
| 31 | static void DrawString(SkCanvas* canvas, const SkString& str, SkScalar x, SkScalar y, |
Mike Reed | 3a42ec0 | 2018-10-30 12:53:21 -0400 | [diff] [blame^] | 32 | const SkPaint& paint, Align align = kLeft_Align) { |
Mike Reed | 331ccfd | 2018-10-25 12:36:06 -0400 | [diff] [blame] | 33 | DrawText(canvas, str.c_str(), str.size(), x, y, paint, align); |
| 34 | } |
| 35 | }; |
| 36 | |
| 37 | #endif |