blob: d6b7e94ea2381ccd7580a43fa042ac801ecc0012 [file] [log] [blame]
joshualitt0a42e682015-12-10 13:20:58 -08001/*
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
joshualitt29677982015-12-11 06:08:59 -080011#include "GrColor.h"
joshualitt0a42e682015-12-10 13:20:58 -080012#include "SkScalar.h"
13
joshualitt29677982015-12-11 06:08:59 -080014class GrAtlasTextBlob;
15class GrBatchFontCache;
16class GrBatchTextStrike;
joshualitt0a42e682015-12-10 13:20:58 -080017class GrClip;
18class GrContext;
19class GrDrawContext;
joshualitt29677982015-12-11 06:08:59 -080020class GrFontScaler;
joshualitt0d2199b2016-01-20 06:36:09 -080021class GrShaderCaps;
joshualitt29677982015-12-11 06:08:59 -080022class SkGlyph;
joshualitt0a42e682015-12-10 13:20:58 -080023class SkMatrix;
24struct SkIRect;
25class SkPaint;
26struct SkPoint;
joshualitt29677982015-12-11 06:08:59 -080027class SkGlyphCache;
joshualitt0a42e682015-12-10 13:20:58 -080028class 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 */
35class GrTextUtils {
36public:
joshualitt29677982015-12-11 06:08:59 -080037 // Functions for appending BMP text to GrAtlasTextBlob
38 static void DrawBmpText(GrAtlasTextBlob*, int runIndex,
joshualitte76b4bb32015-12-28 07:23:58 -080039 GrBatchFontCache*, const SkSurfaceProps&,
40 const SkPaint&,
joshualitt29677982015-12-11 06:08:59 -080041 GrColor, const SkMatrix& viewMatrix,
42 const char text[], size_t byteLength,
43 SkScalar x, SkScalar y);
joshualitt0a42e682015-12-10 13:20:58 -080044
joshualitt29677982015-12-11 06:08:59 -080045 static void DrawBmpPosText(GrAtlasTextBlob*, int runIndex,
joshualitte76b4bb32015-12-28 07:23:58 -080046 GrBatchFontCache*, const SkSurfaceProps&, const SkPaint&,
joshualitt29677982015-12-11 06:08:59 -080047 GrColor, const SkMatrix& viewMatrix,
48 const char text[], size_t byteLength,
49 const SkScalar pos[], int scalarsPerPosition,
50 const SkPoint& offset);
joshualitt0a42e682015-12-10 13:20:58 -080051
joshualitt0d2199b2016-01-20 06:36:09 -080052 // 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
joshualitt29677982015-12-11 06:08:59 -080070 // 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);
84private:
joshualitt0d2199b2016-01-20 06:36:09 -080085 static void InitDistanceFieldPaint(GrAtlasTextBlob* blob,
86 SkPaint* skPaint,
87 SkScalar* textRatio,
88 const SkMatrix& viewMatrix);
89
joshualitt29677982015-12-11 06:08:59 -080090 static void BmpAppendGlyph(GrAtlasTextBlob*, int runIndex, GrBatchFontCache*,
91 GrBatchTextStrike**, const SkGlyph&, int left, int top,
92 GrColor color, GrFontScaler*);
joshualitt0d2199b2016-01-20 06:36:09 -080093
94 static bool DfAppendGlyph(GrAtlasTextBlob*, int runIndex, GrBatchFontCache*,
95 GrBatchTextStrike**, const SkGlyph&,
96 SkScalar sx, SkScalar sy, GrColor color,
97 GrFontScaler* scaler,
98 SkScalar textRatio, const SkMatrix& viewMatrix);
joshualitt0a42e682015-12-10 13:20:58 -080099};
100
101#endif