blob: 93a0c1f8f74ddd5091c302920e5e0f6b624084fa [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
Brian Salomonf856fd12016-12-16 14:24:34 -050015class GrAtlasGlyphCache;
joshualitt29677982015-12-11 06:08:59 -080016class GrAtlasTextBlob;
Brian Salomonf856fd12016-12-16 14:24:34 -050017class GrAtlasTextStrike;
joshualitt0a42e682015-12-10 13:20:58 -080018class GrClip;
19class GrContext;
Brian Osman11052242016-10-27 14:47:55 -040020class GrRenderTargetContext;
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,
Brian Salomonf856fd12016-12-16 14:24:34 -050038 GrAtlasGlyphCache*, const SkSurfaceProps&,
joshualitte76b4bb32015-12-28 07:23:58 -080039 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,
Brian Salomonf856fd12016-12-16 14:24:34 -050045 GrAtlasGlyphCache*, 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,
Brian Salomonf856fd12016-12-16 14:24:34 -050056 GrAtlasGlyphCache*, 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,
Brian Salomonf856fd12016-12-16 14:24:34 -050063 GrAtlasGlyphCache*, 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
Brian Osman11052242016-10-27 14:47:55 -040071 static void DrawTextAsPath(GrContext*, GrRenderTargetContext*, const GrClip& clip,
joshualitt29677982015-12-11 06:08:59 -080072 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,
Brian Osman11052242016-10-27 14:47:55 -040077 GrRenderTargetContext* rtc,
joshualitt29677982015-12-11 06:08:59 -080078 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
Brian Salomonf856fd12016-12-16 14:24:34 -050095 static void BmpAppendGlyph(GrAtlasTextBlob*, int runIndex, GrAtlasGlyphCache*,
96 GrAtlasTextStrike**, const SkGlyph&, int left, int top,
bsalomonc2878e22016-05-17 13:18:03 -070097 GrColor color, SkGlyphCache*);
joshualitt0d2199b2016-01-20 06:36:09 -080098
Brian Salomonf856fd12016-12-16 14:24:34 -050099 static bool DfAppendGlyph(GrAtlasTextBlob*, int runIndex, GrAtlasGlyphCache*,
100 GrAtlasTextStrike**, const SkGlyph&,
joshualitt0d2199b2016-01-20 06:36:09 -0800101 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