Xavier Phan | e29cdaf | 2020-03-26 16:15:14 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 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 SkSVGText_DEFINED |
| 9 | #define SkSVGText_DEFINED |
| 10 | |
| 11 | #include "experimental/svg/model/SkSVGShape.h" |
| 12 | #include "experimental/svg/model/SkSVGTypes.h" |
| 13 | #include "include/core/SkFont.h" |
| 14 | #include "include/utils/SkTextUtils.h" |
| 15 | |
| 16 | class SkRRect; |
| 17 | |
| 18 | class SkSVGText final : public SkSVGShape { |
| 19 | public: |
| 20 | ~SkSVGText() override = default; |
| 21 | static sk_sp<SkSVGText> Make() { |
| 22 | return sk_sp<SkSVGText>(new SkSVGText()); } |
| 23 | |
| 24 | void setX(const SkSVGLength&); |
| 25 | void setY(const SkSVGLength&); |
| 26 | void setFontFamily(const SkSVGStringType&); |
| 27 | void setFontSize(const SkSVGLength&); |
Tyler Freeman | e9663db | 2020-04-14 14:37:13 -0700 | [diff] [blame] | 28 | void setFontStyle(const SkSVGStringType&); |
| 29 | void setFontWeight(const SkSVGStringType&); |
Xavier Phan | e29cdaf | 2020-03-26 16:15:14 +0000 | [diff] [blame] | 30 | void setText(const SkSVGStringType&); |
| 31 | void setTextAnchor(const SkSVGStringType&); |
| 32 | |
| 33 | protected: |
Florin Malita | f4403e7 | 2020-04-10 14:14:04 +0000 | [diff] [blame] | 34 | void onSetAttribute(SkSVGAttribute, const SkSVGValue&) override; |
Xavier Phan | e29cdaf | 2020-03-26 16:15:14 +0000 | [diff] [blame] | 35 | |
| 36 | void onDraw(SkCanvas*, const SkSVGLengthContext&, const SkPaint&, |
| 37 | SkPathFillType) const override; |
| 38 | |
| 39 | SkPath onAsPath(const SkSVGRenderContext&) const override; |
| 40 | |
Tyler Freeman | e9663db | 2020-04-14 14:37:13 -0700 | [diff] [blame] | 41 | void loadFont(); |
| 42 | |
Xavier Phan | e29cdaf | 2020-03-26 16:15:14 +0000 | [diff] [blame] | 43 | private: |
| 44 | SkSVGText(); |
| 45 | SkSVGLength fX = SkSVGLength(0); |
| 46 | SkSVGLength fY = SkSVGLength(0); |
| 47 | SkSVGStringType fText; |
| 48 | sk_sp<SkTypeface> fTypeface; |
| 49 | SkSVGLength fFontSize; |
Tyler Freeman | e9663db | 2020-04-14 14:37:13 -0700 | [diff] [blame] | 50 | SkSVGStringType fFontFamily; |
| 51 | SkSVGStringType fFontStyle; |
| 52 | SkSVGStringType fFontWeight; |
Xavier Phan | e29cdaf | 2020-03-26 16:15:14 +0000 | [diff] [blame] | 53 | SkTextUtils::Align fTextAlign = SkTextUtils::Align::kLeft_Align; |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 54 | using INHERITED = SkSVGShape; |
Xavier Phan | e29cdaf | 2020-03-26 16:15:14 +0000 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | #endif // SkSVGText_DEFINED |