joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 GrTextUtils_DEFINED |
| 9 | #define GrTextUtils_DEFINED |
| 10 | |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 11 | #include "GrColor.h" |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 12 | #include "SkScalar.h" |
| 13 | |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 14 | class GrAtlasTextBlob; |
| 15 | class GrBatchFontCache; |
| 16 | class GrBatchTextStrike; |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 17 | class GrClip; |
| 18 | class GrContext; |
| 19 | class GrDrawContext; |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 20 | class GrFontScaler; |
| 21 | class SkGlyph; |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 22 | class SkMatrix; |
| 23 | struct SkIRect; |
| 24 | class SkPaint; |
| 25 | struct SkPoint; |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 26 | class SkGlyphCache; |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 27 | class SkSurfaceProps; |
| 28 | |
| 29 | /* |
| 30 | * A class to house a bunch of common text utilities. This class should *ONLY* have static |
| 31 | * functions. It is not a namespace only because we wish to friend SkPaint |
| 32 | * |
| 33 | */ |
| 34 | class GrTextUtils { |
| 35 | public: |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 36 | // Functions for appending BMP text to GrAtlasTextBlob |
| 37 | static void DrawBmpText(GrAtlasTextBlob*, int runIndex, |
joshualitt | e76b4bb3 | 2015-12-28 07:23:58 -0800 | [diff] [blame] | 38 | GrBatchFontCache*, const SkSurfaceProps&, |
| 39 | const SkPaint&, |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 40 | GrColor, const SkMatrix& viewMatrix, |
| 41 | const char text[], size_t byteLength, |
| 42 | SkScalar x, SkScalar y); |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 43 | |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 44 | static void DrawBmpPosText(GrAtlasTextBlob*, int runIndex, |
joshualitt | e76b4bb3 | 2015-12-28 07:23:58 -0800 | [diff] [blame] | 45 | GrBatchFontCache*, const SkSurfaceProps&, const SkPaint&, |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 46 | GrColor, const SkMatrix& viewMatrix, |
| 47 | const char text[], size_t byteLength, |
| 48 | const SkScalar pos[], int scalarsPerPosition, |
| 49 | const SkPoint& offset); |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 50 | |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 51 | // Functions for drawing text as paths |
| 52 | static void DrawTextAsPath(GrContext*, GrDrawContext*, const GrClip& clip, |
| 53 | const SkPaint& origPaint, const SkMatrix& viewMatrix, |
| 54 | const char text[], size_t byteLength, SkScalar x, SkScalar y, |
| 55 | const SkIRect& clipBounds); |
| 56 | |
| 57 | static void DrawPosTextAsPath(GrContext* context, |
| 58 | GrDrawContext* dc, |
| 59 | const SkSurfaceProps& props, |
| 60 | const GrClip& clip, |
| 61 | const SkPaint& origPaint, const SkMatrix& viewMatrix, |
| 62 | const char text[], size_t byteLength, |
| 63 | const SkScalar pos[], int scalarsPerPosition, |
| 64 | const SkPoint& offset, const SkIRect& clipBounds); |
| 65 | private: |
| 66 | static void BmpAppendGlyph(GrAtlasTextBlob*, int runIndex, GrBatchFontCache*, |
| 67 | GrBatchTextStrike**, const SkGlyph&, int left, int top, |
| 68 | GrColor color, GrFontScaler*); |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | #endif |