blob: 7823473f771d09ee977e88a4e0605b246e46bf5a [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&,
brianosmana1e8f8d2016-04-08 06:47:54 -070041 GrColor, uint32_t scalerContextFlags, 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&,
brianosmana1e8f8d2016-04-08 06:47:54 -070047 GrColor, uint32_t scalerContextFlags, 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&,
brianosmana1e8f8d2016-04-08 06:47:54 -070058 const SkPaint& skPaint, GrColor color, uint32_t scalerContextFlags,
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&,
brianosmana1e8f8d2016-04-08 06:47:54 -070065 GrColor color, uint32_t scalerContextFlags,
66 const SkMatrix& viewMatrix,
joshualitt0d2199b2016-01-20 06:36:09 -080067 const char text[], size_t byteLength,
68 const SkScalar pos[], int scalarsPerPosition,
69 const SkPoint& offset);
70
joshualitt29677982015-12-11 06:08:59 -080071 // 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);
joshualitt8e84a1e2016-02-16 11:09:25 -080085
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
joshualitt29677982015-12-11 06:08:59 -080091private:
joshualitt0d2199b2016-01-20 06:36:09 -080092 static void InitDistanceFieldPaint(GrAtlasTextBlob* blob,
93 SkPaint* skPaint,
94 SkScalar* textRatio,
95 const SkMatrix& viewMatrix);
96
joshualitt29677982015-12-11 06:08:59 -080097 static void BmpAppendGlyph(GrAtlasTextBlob*, int runIndex, GrBatchFontCache*,
98 GrBatchTextStrike**, const SkGlyph&, int left, int top,
99 GrColor color, GrFontScaler*);
joshualitt0d2199b2016-01-20 06:36:09 -0800100
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);
joshualitt0a42e682015-12-10 13:20:58 -0800106};
107
108#endif