Home | History | Annotate | Download | only in geometry
      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 "SkSGGeometryNode.h"
     12 
     13 #include "SkPaintDefaults.h"
     14 #include "SkPoint.h"
     15 #include "SkString.h"
     16 
     17 class SkCanvas;
     18 class SkPaint;
     19 class SkTextBlob;
     20 class SkTypeface;
     21 
     22 namespace sksg {
     23 
     24 /**
     25  * Concrete Geometry node, wrapping a (shaped) SkTextBlob.
     26  */
     27 class Text final : public GeometryNode {
     28 public:
     29     static sk_sp<Text> Make(sk_sp<SkTypeface> tf, const SkString& text);
     30     ~Text() override;
     31 
     32     SG_ATTRIBUTE(Text    , SkString      , fText    )
     33     SG_ATTRIBUTE(Flags   , uint32_t      , fFlags   )
     34     SG_ATTRIBUTE(Position, SkPoint       , fPosition)
     35     SG_ATTRIBUTE(Size    , SkScalar      , fSize    )
     36     SG_ATTRIBUTE(ScaleX  , SkScalar      , fScaleX  )
     37     SG_ATTRIBUTE(SkewX   , SkScalar      , fSkewX   )
     38     SG_ATTRIBUTE(Align   , SkPaint::Align, fAlign   )
     39 
     40     // TODO: add shaping functionality.
     41 
     42 protected:
     43     void onClip(SkCanvas*, bool antiAlias) const override;
     44     void onDraw(SkCanvas*, const SkPaint&) const override;
     45 
     46     SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
     47     SkPath onAsPath() const override;
     48 
     49 private:
     50     explicit Text(sk_sp<SkTypeface>, const SkString&);
     51 
     52     const sk_sp<SkTypeface> fTypeface;
     53     SkString                fText;
     54     uint32_t                fFlags    = SkPaintDefaults_Flags;
     55     SkPoint                 fPosition = SkPoint::Make(0, 0);
     56     SkScalar                fSize     = SkPaintDefaults_TextSize;
     57     SkScalar                fScaleX   = 1;
     58     SkScalar                fSkewX    = 0;
     59     SkPaint::Align          fAlign    = SkPaint::kLeft_Align;
     60     SkPaint::Hinting        fHinting  = SkPaintDefaults_Hinting;
     61 
     62     sk_sp<SkTextBlob> fBlob; // cached text blob
     63 
     64     using INHERITED = GeometryNode;
     65 };
     66 
     67 } // namespace sksg
     68 
     69 #endif // SkSGText_DEFINED
     70