blob: c5c29ad86f6f20a9eceb588015f1364888127786 [file] [log] [blame]
kkinnunenc6cb56f2014-06-24 00:12:27 -07001/*
2 * Copyright 2014 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 GrStencilAndCoverTextContext_DEFINED
9#define GrStencilAndCoverTextContext_DEFINED
10
11#include "GrTextContext.h"
cdaltonb2808cd2014-07-25 14:13:57 -070012#include "GrDrawTarget.h"
kkinnunen50b58e62015-05-18 23:02:07 -070013#include "GrStrokeInfo.h"
kkinnunenc6cb56f2014-06-24 00:12:27 -070014
15class GrTextStrike;
16class GrPath;
cdalton855d83f2014-09-18 13:51:53 -070017class GrPathRange;
robertphillipsfcf78292015-06-19 11:49:52 -070018class SkSurfaceProps;
kkinnunenc6cb56f2014-06-24 00:12:27 -070019
20/*
21 * This class implements text rendering using stencil and cover path rendering
22 * (by the means of GrDrawTarget::drawPath).
23 * This class exposes the functionality through GrTextContext interface.
24 */
25class GrStencilAndCoverTextContext : public GrTextContext {
26public:
robertphillipsf6703fa2015-09-01 05:36:47 -070027 static GrStencilAndCoverTextContext* Create(GrContext*, const SkSurfaceProps&);
jvanverth8c27a182014-10-14 08:45:50 -070028
kkinnunenc6cb56f2014-06-24 00:12:27 -070029 virtual ~GrStencilAndCoverTextContext();
30
kkinnunenc6cb56f2014-06-24 00:12:27 -070031private:
robertphillipsf6703fa2015-09-01 05:36:47 -070032 GrStencilAndCoverTextContext(GrContext*, const SkSurfaceProps&);
jvanverth8c27a182014-10-14 08:45:50 -070033
cdaltone68f7362015-03-25 14:02:37 -070034 bool canDraw(const GrRenderTarget*, const GrClip&, const GrPaint&,
mtklein36352bf2015-03-25 18:17:31 -070035 const SkPaint&, const SkMatrix& viewMatrix) override;
jvanverth8c27a182014-10-14 08:45:50 -070036
robertphillipsf6703fa2015-09-01 05:36:47 -070037 void onDrawText(GrDrawContext*, GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
cdaltone68f7362015-03-25 14:02:37 -070038 const SkMatrix& viewMatrix,
39 const char text[], size_t byteLength,
mtklein36352bf2015-03-25 18:17:31 -070040 SkScalar x, SkScalar y, const SkIRect& regionClipBounds) override;
robertphillipsf6703fa2015-09-01 05:36:47 -070041 void onDrawPosText(GrDrawContext*, GrRenderTarget*,
42 const GrClip&, const GrPaint&, const SkPaint&,
cdaltone68f7362015-03-25 14:02:37 -070043 const SkMatrix& viewMatrix,
44 const char text[], size_t byteLength,
45 const SkScalar pos[], int scalarsPerPosition,
mtklein36352bf2015-03-25 18:17:31 -070046 const SkPoint& offset, const SkIRect& regionClipBounds) override;
jvanverth8c27a182014-10-14 08:45:50 -070047
cdalton3bd909a2015-10-05 14:57:20 -070048 class TextRun {
49 public:
50 TextRun(const SkPaint& fontAndStroke);
51 ~TextRun();
52
53 void setText(const char text[], size_t byteLength, SkScalar x, SkScalar y,
54 GrContext*, const SkSurfaceProps*);
55
56 void setPosText(const char text[], size_t byteLength,
57 const SkScalar pos[], int scalarsPerPosition, const SkPoint& offset,
58 GrContext*, const SkSurfaceProps*);
59
60 void draw(GrDrawContext*, GrRenderTarget*, const GrClip&, const GrPaint&, const SkMatrix&,
61 const SkIRect& regionClipBounds, GrTextContext* fallbackTextContext,
62 const SkPaint& originalSkPaint) const;
63
64 private:
65 GrPathRange* createGlyphs(GrContext*, SkGlyphCache*);
66
67 void appendGlyph(const SkGlyph&, const SkPoint&);
68
69 GrStrokeInfo fStroke;
70 SkPaint fFont;
71 SkScalar fTextRatio;
72 float fTextInverseRatio;
73 SkMatrix fLocalMatrix;
74 bool fUsingRawGlyphPaths;
75 SkAutoTUnref<GrPathRangeDraw> fDraw;
76 SkSTArray<32, uint16_t, true> fFallbackIndices;
77 SkSTArray<32, SkPoint, true> fFallbackPositions;
78 };
kkinnunenc6cb56f2014-06-24 00:12:27 -070079
bsalomon1fcc01c2015-09-09 09:48:06 -070080 typedef GrTextContext INHERITED;
kkinnunenc6cb56f2014-06-24 00:12:27 -070081};
82
83#endif