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 11 #include "GrColor.h" 12 #include "SkScalar.h" 13 14 class GrAtlasTextBlob; 15 class GrBatchFontCache; 16 class GrBatchTextStrike; 17 class GrClip; 18 class GrContext; 19 class GrDrawContext; 20 class GrFontScaler; 21 class GrShaderCaps; 22 class SkGlyph; 23 class SkMatrix; 24 struct SkIRect; 25 class SkPaint; 26 struct SkPoint; 27 class SkGlyphCache; 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: 37 // Functions for appending BMP text to GrAtlasTextBlob 38 static void DrawBmpText(GrAtlasTextBlob*, int runIndex, 39 GrBatchFontCache*, const SkSurfaceProps&, 40 const SkPaint&, 41 GrColor, const SkMatrix& viewMatrix, 42 const char text[], size_t byteLength, 43 SkScalar x, SkScalar y); 44 45 static void DrawBmpPosText(GrAtlasTextBlob*, int runIndex, 46 GrBatchFontCache*, const SkSurfaceProps&, const SkPaint&, 47 GrColor, const SkMatrix& viewMatrix, 48 const char text[], size_t byteLength, 49 const SkScalar pos[], int scalarsPerPosition, 50 const SkPoint& offset); 51 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&, 58 const SkPaint& skPaint, GrColor color, 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&, 65 GrColor color, const SkMatrix& viewMatrix, 66 const char text[], size_t byteLength, 67 const SkScalar pos[], int scalarsPerPosition, 68 const SkPoint& offset); 69 70 // Functions for drawing text as paths 71 static void DrawTextAsPath(GrContext*, GrDrawContext*, const GrClip& clip, 72 const SkPaint& origPaint, const SkMatrix& viewMatrix, 73 const char text[], size_t byteLength, SkScalar x, SkScalar y, 74 const SkIRect& clipBounds); 75 76 static void DrawPosTextAsPath(GrContext* context, 77 GrDrawContext* dc, 78 const SkSurfaceProps& props, 79 const GrClip& clip, 80 const SkPaint& origPaint, const SkMatrix& viewMatrix, 81 const char text[], size_t byteLength, 82 const SkScalar pos[], int scalarsPerPosition, 83 const SkPoint& offset, const SkIRect& clipBounds); 84 85 static bool ShouldDisableLCD(const SkPaint& paint); 86 87 static GrFontScaler* GetGrFontScaler(SkGlyphCache* cache); 88 static uint32_t FilterTextFlags(const SkSurfaceProps& surfaceProps, const SkPaint& paint); 89 90 private: 91 static void InitDistanceFieldPaint(GrAtlasTextBlob* blob, 92 SkPaint* skPaint, 93 SkScalar* textRatio, 94 const SkMatrix& viewMatrix); 95 96 static void BmpAppendGlyph(GrAtlasTextBlob*, int runIndex, GrBatchFontCache*, 97 GrBatchTextStrike**, const SkGlyph&, int left, int top, 98 GrColor color, GrFontScaler*); 99 100 static bool DfAppendGlyph(GrAtlasTextBlob*, int runIndex, GrBatchFontCache*, 101 GrBatchTextStrike**, const SkGlyph&, 102 SkScalar sx, SkScalar sy, GrColor color, 103 GrFontScaler* scaler, 104 SkScalar textRatio, const SkMatrix& viewMatrix); 105 }; 106 107 #endif 108