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" |
brianosman | 32f7782 | 2016-04-07 06:25:45 -0700 | [diff] [blame] | 12 | #include "SkPaint.h" |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 13 | #include "SkScalar.h" |
| 14 | |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 15 | class GrAtlasTextBlob; |
| 16 | class GrBatchFontCache; |
| 17 | class GrBatchTextStrike; |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 18 | class GrClip; |
| 19 | class GrContext; |
| 20 | class GrDrawContext; |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 21 | class GrFontScaler; |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 22 | class GrShaderCaps; |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 23 | class SkGlyph; |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 24 | class SkMatrix; |
| 25 | struct SkIRect; |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 26 | struct SkPoint; |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 27 | class SkGlyphCache; |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 28 | class SkSurfaceProps; |
| 29 | |
| 30 | /* |
| 31 | * A class to house a bunch of common text utilities. This class should *ONLY* have static |
| 32 | * functions. It is not a namespace only because we wish to friend SkPaint |
| 33 | * |
| 34 | */ |
| 35 | class GrTextUtils { |
| 36 | public: |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 37 | // Functions for appending BMP text to GrAtlasTextBlob |
| 38 | static void DrawBmpText(GrAtlasTextBlob*, int runIndex, |
joshualitt | e76b4bb3 | 2015-12-28 07:23:58 -0800 | [diff] [blame] | 39 | GrBatchFontCache*, const SkSurfaceProps&, |
| 40 | const SkPaint&, |
brianosman | a1e8f8d | 2016-04-08 06:47:54 -0700 | [diff] [blame] | 41 | GrColor, uint32_t scalerContextFlags, const SkMatrix& viewMatrix, |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 42 | const char text[], size_t byteLength, |
| 43 | SkScalar x, SkScalar y); |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 44 | |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 45 | static void DrawBmpPosText(GrAtlasTextBlob*, int runIndex, |
joshualitt | e76b4bb3 | 2015-12-28 07:23:58 -0800 | [diff] [blame] | 46 | GrBatchFontCache*, const SkSurfaceProps&, const SkPaint&, |
brianosman | a1e8f8d | 2016-04-08 06:47:54 -0700 | [diff] [blame] | 47 | GrColor, uint32_t scalerContextFlags, const SkMatrix& viewMatrix, |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 48 | const char text[], size_t byteLength, |
| 49 | const SkScalar pos[], int scalarsPerPosition, |
| 50 | const SkPoint& offset); |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 51 | |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 52 | // functions for appending distance field text |
| 53 | static bool CanDrawAsDistanceFields(const SkPaint& skPaint, const SkMatrix& viewMatrix, |
| 54 | const SkSurfaceProps& props, const GrShaderCaps& caps); |
| 55 | |
| 56 | static void DrawDFText(GrAtlasTextBlob* blob, int runIndex, |
| 57 | GrBatchFontCache*, const SkSurfaceProps&, |
brianosman | a1e8f8d | 2016-04-08 06:47:54 -0700 | [diff] [blame] | 58 | const SkPaint& skPaint, GrColor color, uint32_t scalerContextFlags, |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 59 | const SkMatrix& viewMatrix, |
| 60 | const char text[], size_t byteLength, |
| 61 | SkScalar x, SkScalar y); |
| 62 | |
| 63 | static void DrawDFPosText(GrAtlasTextBlob* blob, int runIndex, |
| 64 | GrBatchFontCache*, const SkSurfaceProps&, const SkPaint&, |
brianosman | a1e8f8d | 2016-04-08 06:47:54 -0700 | [diff] [blame] | 65 | GrColor color, uint32_t scalerContextFlags, |
| 66 | const SkMatrix& viewMatrix, |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 67 | const char text[], size_t byteLength, |
| 68 | const SkScalar pos[], int scalarsPerPosition, |
| 69 | const SkPoint& offset); |
| 70 | |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 71 | // Functions for drawing text as paths |
| 72 | static void DrawTextAsPath(GrContext*, GrDrawContext*, const GrClip& clip, |
| 73 | const SkPaint& origPaint, const SkMatrix& viewMatrix, |
| 74 | const char text[], size_t byteLength, SkScalar x, SkScalar y, |
| 75 | const SkIRect& clipBounds); |
| 76 | |
| 77 | static void DrawPosTextAsPath(GrContext* context, |
| 78 | GrDrawContext* dc, |
| 79 | const SkSurfaceProps& props, |
| 80 | const GrClip& clip, |
| 81 | const SkPaint& origPaint, const SkMatrix& viewMatrix, |
| 82 | const char text[], size_t byteLength, |
| 83 | const SkScalar pos[], int scalarsPerPosition, |
| 84 | const SkPoint& offset, const SkIRect& clipBounds); |
joshualitt | 8e84a1e | 2016-02-16 11:09:25 -0800 | [diff] [blame] | 85 | |
| 86 | static bool ShouldDisableLCD(const SkPaint& paint); |
| 87 | |
| 88 | static GrFontScaler* GetGrFontScaler(SkGlyphCache* cache); |
| 89 | static uint32_t FilterTextFlags(const SkSurfaceProps& surfaceProps, const SkPaint& paint); |
| 90 | |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 91 | private: |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 92 | static void InitDistanceFieldPaint(GrAtlasTextBlob* blob, |
| 93 | SkPaint* skPaint, |
| 94 | SkScalar* textRatio, |
| 95 | const SkMatrix& viewMatrix); |
| 96 | |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 97 | static void BmpAppendGlyph(GrAtlasTextBlob*, int runIndex, GrBatchFontCache*, |
| 98 | GrBatchTextStrike**, const SkGlyph&, int left, int top, |
| 99 | GrColor color, GrFontScaler*); |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 100 | |
| 101 | static bool DfAppendGlyph(GrAtlasTextBlob*, int runIndex, GrBatchFontCache*, |
| 102 | GrBatchTextStrike**, const SkGlyph&, |
| 103 | SkScalar sx, SkScalar sy, GrColor color, |
| 104 | GrFontScaler* scaler, |
| 105 | SkScalar textRatio, const SkMatrix& viewMatrix); |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | #endif |