blob: c218ab7da19768288265e91fcc461a289244cfac [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"
brianosman32f77822016-04-07 06:25:45 -070012#include "SkPaint.h"
joshualitt0a42e682015-12-10 13:20:58 -080013#include "SkScalar.h"
14
joshualitt29677982015-12-11 06:08:59 -080015class GrAtlasTextBlob;
16class GrBatchFontCache;
17class GrBatchTextStrike;
joshualitt0a42e682015-12-10 13:20:58 -080018class GrClip;
19class GrContext;
20class GrDrawContext;
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;
joshualitt0a42e682015-12-10 13:20:58 -080025struct SkPoint;
joshualitt29677982015-12-11 06:08:59 -080026class SkGlyphCache;
joshualitt0a42e682015-12-10 13:20:58 -080027class 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 */
34class GrTextUtils {
35public:
joshualitt29677982015-12-11 06:08:59 -080036 // Functions for appending BMP text to GrAtlasTextBlob
37 static void DrawBmpText(GrAtlasTextBlob*, int runIndex,
joshualitte76b4bb32015-12-28 07:23:58 -080038 GrBatchFontCache*, const SkSurfaceProps&,
39 const SkPaint&,
brianosmana1e8f8d2016-04-08 06:47:54 -070040 GrColor, uint32_t scalerContextFlags, const SkMatrix& viewMatrix,
joshualitt29677982015-12-11 06:08:59 -080041 const char text[], size_t byteLength,
42 SkScalar x, SkScalar y);
joshualitt0a42e682015-12-10 13:20:58 -080043
joshualitt29677982015-12-11 06:08:59 -080044 static void DrawBmpPosText(GrAtlasTextBlob*, int runIndex,
joshualitte76b4bb32015-12-28 07:23:58 -080045 GrBatchFontCache*, const SkSurfaceProps&, const SkPaint&,
brianosmana1e8f8d2016-04-08 06:47:54 -070046 GrColor, uint32_t scalerContextFlags, const SkMatrix& viewMatrix,
joshualitt29677982015-12-11 06:08:59 -080047 const char text[], size_t byteLength,
48 const SkScalar pos[], int scalarsPerPosition,
49 const SkPoint& offset);
joshualitt0a42e682015-12-10 13:20:58 -080050
joshualitt0d2199b2016-01-20 06:36:09 -080051 // functions for appending distance field text
52 static bool CanDrawAsDistanceFields(const SkPaint& skPaint, const SkMatrix& viewMatrix,
53 const SkSurfaceProps& props, const GrShaderCaps& caps);
54
55 static void DrawDFText(GrAtlasTextBlob* blob, int runIndex,
56 GrBatchFontCache*, const SkSurfaceProps&,
brianosmana1e8f8d2016-04-08 06:47:54 -070057 const SkPaint& skPaint, GrColor color, uint32_t scalerContextFlags,
joshualitt0d2199b2016-01-20 06:36:09 -080058 const SkMatrix& viewMatrix,
59 const char text[], size_t byteLength,
60 SkScalar x, SkScalar y);
61
62 static void DrawDFPosText(GrAtlasTextBlob* blob, int runIndex,
63 GrBatchFontCache*, const SkSurfaceProps&, const SkPaint&,
brianosmana1e8f8d2016-04-08 06:47:54 -070064 GrColor color, uint32_t scalerContextFlags,
65 const SkMatrix& viewMatrix,
joshualitt0d2199b2016-01-20 06:36:09 -080066 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);
joshualitt8e84a1e2016-02-16 11:09:25 -080084
85 static bool ShouldDisableLCD(const SkPaint& paint);
86
joshualitt8e84a1e2016-02-16 11:09:25 -080087 static uint32_t FilterTextFlags(const SkSurfaceProps& surfaceProps, const SkPaint& paint);
88
joshualitt29677982015-12-11 06:08:59 -080089private:
joshualitt0d2199b2016-01-20 06:36:09 -080090 static void InitDistanceFieldPaint(GrAtlasTextBlob* blob,
91 SkPaint* skPaint,
92 SkScalar* textRatio,
93 const SkMatrix& viewMatrix);
94
joshualitt29677982015-12-11 06:08:59 -080095 static void BmpAppendGlyph(GrAtlasTextBlob*, int runIndex, GrBatchFontCache*,
96 GrBatchTextStrike**, const SkGlyph&, int left, int top,
bsalomonc2878e22016-05-17 13:18:03 -070097 GrColor color, SkGlyphCache*);
joshualitt0d2199b2016-01-20 06:36:09 -080098
99 static bool DfAppendGlyph(GrAtlasTextBlob*, int runIndex, GrBatchFontCache*,
100 GrBatchTextStrike**, const SkGlyph&,
101 SkScalar sx, SkScalar sy, GrColor color,
bsalomonc2878e22016-05-17 13:18:03 -0700102 SkGlyphCache* cache,
joshualitt0d2199b2016-01-20 06:36:09 -0800103 SkScalar textRatio, const SkMatrix& viewMatrix);
joshualitt0a42e682015-12-10 13:20:58 -0800104};
105
106#endif