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" |
Mike Reed | 331ccfd | 2018-10-25 12:36:06 -0400 | [diff] [blame] | 12 | #include "SkFont.h" |
Mike Reed | dc5863c | 2018-12-23 23:19:14 -0500 | [diff] [blame] | 13 | #include "SkPaint.h" |
Mike Reed | 331ccfd | 2018-10-25 12:36:06 -0400 | [diff] [blame] | 14 | #include "SkString.h" |
| 15 | |
Mike Reed | f78b7ea | 2018-12-25 22:06:17 -0500 | [diff] [blame^] | 16 | class SkPath; |
| 17 | |
Mike Reed | 331ccfd | 2018-10-25 12:36:06 -0400 | [diff] [blame] | 18 | class SkTextUtils { |
| 19 | public: |
Mike Reed | 3a42ec0 | 2018-10-30 12:53:21 -0400 | [diff] [blame] | 20 | enum Align { |
| 21 | kLeft_Align, |
| 22 | kCenter_Align, |
| 23 | kRight_Align, |
| 24 | }; |
| 25 | |
Mike Reed | dc5863c | 2018-12-23 23:19:14 -0500 | [diff] [blame] | 26 | static void Draw(SkCanvas*, const void* text, size_t size, SkTextEncoding, |
| 27 | SkScalar x, SkScalar y, const SkFont&, const SkPaint&, Align = kLeft_Align); |
Mike Reed | 331ccfd | 2018-10-25 12:36:06 -0400 | [diff] [blame] | 28 | |
| 29 | static void DrawString(SkCanvas* canvas, const char text[], SkScalar x, SkScalar y, |
Mike Reed | dc5863c | 2018-12-23 23:19:14 -0500 | [diff] [blame] | 30 | const SkFont& font, const SkPaint& paint, Align align = kLeft_Align) { |
| 31 | SkASSERT(paint.getTextEncoding() == kUTF8_SkTextEncoding); |
| 32 | Draw(canvas, text, strlen(text), kUTF8_SkTextEncoding, x, y, font, paint, align); |
Mike Reed | 331ccfd | 2018-10-25 12:36:06 -0400 | [diff] [blame] | 33 | } |
Mike Reed | dc5863c | 2018-12-23 23:19:14 -0500 | [diff] [blame] | 34 | |
| 35 | #if 1 |
| 36 | static void DrawString(SkCanvas* canvas, const char text[], SkScalar x, SkScalar y, |
| 37 | const SkPaint& paint, Align align = kLeft_Align) { |
| 38 | SkASSERT(paint.getTextEncoding() == kUTF8_SkTextEncoding); |
| 39 | Draw(canvas, text, strlen(text), kUTF8_SkTextEncoding, x, y, |
| 40 | SkFont::LEGACY_ExtractFromPaint(paint), paint, align); |
| 41 | } |
| 42 | |
| 43 | static void DrawText(SkCanvas* canvas, const void* text, size_t size, SkScalar x, SkScalar y, |
| 44 | const SkPaint& paint, Align align = kLeft_Align) { |
| 45 | Draw(canvas, text, size, paint.getTextEncoding(), x, y, |
| 46 | SkFont::LEGACY_ExtractFromPaint(paint), paint, align); |
| 47 | } |
| 48 | |
Mike Reed | 331ccfd | 2018-10-25 12:36:06 -0400 | [diff] [blame] | 49 | static void DrawString(SkCanvas* canvas, const SkString& str, SkScalar x, SkScalar y, |
Mike Reed | 3a42ec0 | 2018-10-30 12:53:21 -0400 | [diff] [blame] | 50 | const SkPaint& paint, Align align = kLeft_Align) { |
Mike Reed | 331ccfd | 2018-10-25 12:36:06 -0400 | [diff] [blame] | 51 | DrawText(canvas, str.c_str(), str.size(), x, y, paint, align); |
| 52 | } |
Mike Reed | dc5863c | 2018-12-23 23:19:14 -0500 | [diff] [blame] | 53 | #endif |
Mike Reed | f78b7ea | 2018-12-25 22:06:17 -0500 | [diff] [blame^] | 54 | |
| 55 | static void GetPath(const void* text, size_t length, SkTextEncoding, SkScalar x, SkScalar y, |
| 56 | const SkFont&, SkPath*); |
Mike Reed | 331ccfd | 2018-10-25 12:36:06 -0400 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | #endif |