Skia
2D Graphics Library
SkSGText.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018 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 SkSGText_DEFINED
9 #define SkSGText_DEFINED
10 
12 
13 #include "include/core/SkFont.h"
14 #include "include/core/SkPoint.h"
15 #include "include/core/SkString.h"
17 #include "include/utils/SkTextUtils.h"
18 
19 class SkCanvas;
20 class SkPaint;
21 class SkTypeface;
22 
23 namespace sksg {
24 
28 class Text final : public GeometryNode {
29 public:
30  static sk_sp<Text> Make(sk_sp<SkTypeface> tf, const SkString& text);
31  ~Text() override;
32 
33  SG_ATTRIBUTE(Typeface, sk_sp<SkTypeface> , fTypeface)
34  SG_ATTRIBUTE(Text , SkString , fText )
35  SG_ATTRIBUTE(Position, SkPoint , fPosition)
36  SG_ATTRIBUTE(Size , SkScalar , fSize )
37  SG_ATTRIBUTE(ScaleX , SkScalar , fScaleX )
38  SG_ATTRIBUTE(SkewX , SkScalar , fSkewX )
39  SG_ATTRIBUTE(Align , SkTextUtils::Align, fAlign )
40  SG_ATTRIBUTE(Edging , SkFont::Edging , fEdging )
41  SG_ATTRIBUTE(Hinting , SkFontHinting , fHinting )
42 
43  // TODO: add shaping functionality.
44 
45 protected:
46  void onClip(SkCanvas*, bool antiAlias) const override;
47  void onDraw(SkCanvas*, const SkPaint&) const override;
48  bool onContains(const SkPoint&) const override;
49 
51  SkPath onAsPath() const override;
52 
53 private:
55 
56  SkPoint alignedPosition(SkScalar advance) const;
57 
58  sk_sp<SkTypeface> fTypeface;
59  SkString fText;
60  SkPoint fPosition = SkPoint::Make(0, 0);
61  SkScalar fSize = 12;
62  SkScalar fScaleX = 1;
63  SkScalar fSkewX = 0;
64  SkTextUtils::Align fAlign = SkTextUtils::kLeft_Align;
67 
68  sk_sp<SkTextBlob> fBlob; // cached text blob
69 
70  using INHERITED = GeometryNode;
71 };
72 
73 } // namespace sksg
74 
75 #endif // SkSGText_DEFINED
SkFontHinting
Definition: SkFontTypes.h:18
@ kNormal
glyph outlines modified to improve constrast
#define SG_ATTRIBUTE(attr_name, attr_type, attr_container)
Definition: SkSGNode.h:99
float SkScalar
Definition: SkScalar.h:14
SkCanvas provides an interface for drawing, and how the drawing is clipped and transformed.
Definition: SkCanvas.h:99
Edging
Whether edge pixels draw opaque or with partial transparency.
Definition: SkFont.h:40
@ kAntiAlias
may have transparent pixels on glyph edges
SkMatrix holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:53
SkPaint controls options applied when drawing.
Definition: SkPaint.h:44
SkPath contain geometry.
Definition: SkPath.h:58
Light weight class for managing strings.
Definition: SkString.h:118
The SkTypeface class specifies the typeface and intrinsic style of a font.
Definition: SkTypeface.h:52
Shared pointer class to wrap classes that support a ref()/unref() interface.
Definition: SkRefCnt.h:220
Base class for nodes which provide 'geometry' (as opposed to paint) for drawing.
Definition: SkSGGeometryNode.h:25
Receiver for invalidation events.
Definition: SkSGInvalidationController.h:25
Base class for all scene graph nodes.
Definition: SkSGNode.h:32
Concrete Geometry node, wrapping a (shaped) SkTextBlob.
Definition: SkSGText.h:28
~Text() override
bool onContains(const SkPoint &) const override
SkPath onAsPath() const override
SkRect onRevalidate(InvalidationController *, const SkMatrix &) override
void onDraw(SkCanvas *, const SkPaint &) const override
void onClip(SkCanvas *, bool antiAlias) const override
static sk_sp< Text > Make(sk_sp< SkTypeface > tf, const SkString &text)
sk_sp< SkDrawLooper > SK_API Make(SkColor4f color, SkColorSpace *cs, SkScalar sigma, SkScalar dx, SkScalar dy)
Definition: Skottie.h:30
SkRect holds four float coordinates describing the upper and lower bounds of a rectangle.
Definition: SkRect.h:582