blob: 52b3ab4c54f60d5db6ef917562b4089cda4094ef [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;
joshualitt29677982015-12-11 06:08:59 -080021class GrFontScaler;
joshualitt0d2199b2016-01-20 06:36:09 -080022class GrShaderCaps;
joshualitt29677982015-12-11 06:08:59 -080023class SkGlyph;
joshualitt0a42e682015-12-10 13:20:58 -080024class SkMatrix;
25struct SkIRect;
joshualitt0a42e682015-12-10 13:20:58 -080026struct 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&,
brianosman32f77822016-04-07 06:25:45 -070041 GrColor, SkPaint::FakeGamma, const SkMatrix& viewMatrix,
joshualitt29677982015-12-11 06:08:59 -080042 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&,
brianosman32f77822016-04-07 06:25:45 -070047 GrColor, SkPaint::FakeGamma, const SkMatrix& viewMatrix,
joshualitt29677982015-12-11 06:08:59 -080048 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&,
brianosman32f77822016-04-07 06:25:45 -070058 const SkPaint& skPaint, GrColor color, SkPaint::FakeGamma,
joshualitt0d2199b2016-01-20 06:36:09 -080059 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&,
brianosman32f77822016-04-07 06:25:45 -070065 GrColor color, SkPaint::FakeGamma, 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
87 static GrFontScaler* GetGrFontScaler(SkGlyphCache* cache);
88 static uint32_t FilterTextFlags(const SkSurfaceProps& surfaceProps, const SkPaint& paint);
89
joshualitt29677982015-12-11 06:08:59 -080090private:
joshualitt0d2199b2016-01-20 06:36:09 -080091 static void InitDistanceFieldPaint(GrAtlasTextBlob* blob,
92 SkPaint* skPaint,
93 SkScalar* textRatio,
94 const SkMatrix& viewMatrix);
95
joshualitt29677982015-12-11 06:08:59 -080096 static void BmpAppendGlyph(GrAtlasTextBlob*, int runIndex, GrBatchFontCache*,
97 GrBatchTextStrike**, const SkGlyph&, int left, int top,
98 GrColor color, GrFontScaler*);
joshualitt0d2199b2016-01-20 06:36:09 -080099
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);
joshualitt0a42e682015-12-10 13:20:58 -0800105};
106
107#endif