| 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 |
|
| 11 |
#include "include/core/SkFont.h" |
| 12 |
#include "include/core/SkFontTypes.h" |
| 13 |
#include "include/core/SkPath.h" |
| 14 |
#include "include/core/SkPoint.h" |
| 15 |
#include "include/core/SkRect.h" |
| 16 |
#include "include/core/SkRefCnt.h" |
| 17 |
#include "include/core/SkScalar.h" |
| 18 |
#include "include/core/SkString.h" |
| 19 |
#include "include/utils/SkTextUtils.h" |
| 20 |
#include "modules/sksg/include/SkSGGeometryNode.h" |
| 21 |
#include "modules/sksg/include/SkSGNode.h" |
| 22 |
|
| 23 |
class SkCanvas; |
| 24 |
class SkMatrix; |
| 25 |
class SkPaint; |
| 26 |
class SkTextBlob; |
| 27 |
class SkTypeface; |
| 28 |
|
| 29 |
namespace sksg { |
| 30 |
class InvalidationController; |
| 31 |
|
| 32 |
/** |
| 33 |
* Concrete Geometry node, wrapping a (shaped) SkTextBlob. |
| 34 |
*/ |
| 35 |
class Text final : public GeometryNode { |
| 36 |
public: |
| 37 |
static sk_sp<Text> Make(sk_sp<SkTypeface> tf, const SkString& text); |
| 38 |
~Text() override; |
| 39 |
|
| 40 |
SG_ATTRIBUTE(Typeface, sk_sp<SkTypeface> , fTypeface) |
| 41 |
SG_ATTRIBUTE(Text , SkString , fText ) |
| 42 |
SG_ATTRIBUTE(Position, SkPoint , fPosition) |
| 43 |
SG_ATTRIBUTE(Size , SkScalar , fSize ) |
| 44 |
SG_ATTRIBUTE(ScaleX , SkScalar , fScaleX ) |
| 45 |
SG_ATTRIBUTE(SkewX , SkScalar , fSkewX ) |
| 46 |
SG_ATTRIBUTE(Align , SkTextUtils::Align, fAlign ) |
| 47 |
SG_ATTRIBUTE(Edging , SkFont::Edging , fEdging ) |
| 48 |
SG_ATTRIBUTE(Hinting , SkFontHinting , fHinting ) |
| 49 |
|
| 50 |
// TODO: add shaping functionality. |
| 51 |
|
| 52 |
protected: |
| 53 |
void onClip(SkCanvas*, bool antiAlias) const override; |
| 54 |
void onDraw(SkCanvas*, const SkPaint&) const override; |
| 55 |
bool onContains(const SkPoint&) const override; |
| 56 |
|
| 57 |
SkRect onRevalidate(InvalidationController*, const SkMatrix&) override; |
| 58 |
SkPath onAsPath() const override; |
| 59 |
|
| 60 |
private: |
| 61 |
Text(sk_sp<SkTypeface>, const SkString&); |
| 62 |
|
| 63 |
SkPoint alignedPosition(SkScalar advance) const; |
| 64 |
|
| 65 |
sk_sp<SkTypeface> fTypeface; |
| 66 |
SkString fText; |
| 67 |
SkPoint fPosition = SkPoint::Make(0, 0); |
| 68 |
SkScalar fSize = 12; |
| 69 |
SkScalar fScaleX = 1; |
| 70 |
SkScalar fSkewX = 0; |
| 71 |
SkTextUtils::Align fAlign = SkTextUtils::kLeft_Align; |
| 72 |
SkFont::Edging fEdging = SkFont::Edging::kAntiAlias; |
| 73 |
SkFontHinting fHinting = SkFontHinting::kNormal; |
| 74 |
|
| 75 |
sk_sp<SkTextBlob> fBlob; // cached text blob |
| 76 |
|
| 77 |
using INHERITED = GeometryNode; |
| 78 |
}; |
| 79 |
|
| 80 |
} // namespace sksg |
| 81 |
|
| 82 |
#endif // SkSGText_DEFINED |