• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2010 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 GrTextContext_DEFINED
9 #define GrTextContext_DEFINED
10 
11 #include "GrGlyph.h"
12 #include "GrPaint.h"
13 #include "SkDeviceProperties.h"
14 
15 #include "SkPostConfig.h"
16 
17 class GrContext;
18 class GrDrawTarget;
19 class GrFontScaler;
20 
21 /*
22  * This class wraps the state for a single text render
23  */
24 class GrTextContext {
25 public:
~GrTextContext()26     virtual ~GrTextContext() {}
27     virtual void drawText(const GrPaint&, const SkPaint&, const char text[], size_t byteLength,
28                           SkScalar x, SkScalar y) = 0;
29     virtual void drawPosText(const GrPaint&, const SkPaint&,
30                              const char text[], size_t byteLength,
31                              const SkScalar pos[], SkScalar constY,
32                              int scalarsPerPosition) = 0;
33 
34     virtual bool canDraw(const SkPaint& paint) = 0;
35 
36 protected:
37     GrTextContext(GrContext*, const SkDeviceProperties&);
38 
39     static GrFontScaler* GetGrFontScaler(SkGlyphCache* cache);
40     static void MeasureText(SkGlyphCache* cache, SkDrawCacheProc glyphCacheProc,
41                             const char text[], size_t byteLength, SkVector* stopVector);
42 
43     void init(const GrPaint&, const SkPaint&);
finish()44     void finish() { fDrawTarget = NULL; }
45 
46     GrContext*         fContext;
47     SkDeviceProperties fDeviceProperties;
48 
49     GrDrawTarget*      fDrawTarget;
50     SkIRect            fClipRect;
51     GrPaint            fPaint;
52     SkPaint            fSkPaint;
53 };
54 
55 #endif
56