Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [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 "include/core/SkFont.h" |
| 12 | #include "include/utils/SkTextUtils.h" |
Florin Malita | 39fe8c8 | 2020-10-20 10:43:03 -0400 | [diff] [blame^] | 13 | #include "modules/svg/include/SkSVGTransformableNode.h" |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 14 | #include "modules/svg/include/SkSVGTypes.h" |
| 15 | |
| 16 | class SkRRect; |
| 17 | |
Florin Malita | 39fe8c8 | 2020-10-20 10:43:03 -0400 | [diff] [blame^] | 18 | class SkSVGText final : public SkSVGTransformableNode { |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 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&); |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 26 | void setText(const SkSVGStringType&); |
| 27 | void setTextAnchor(const SkSVGStringType&); |
| 28 | |
| 29 | protected: |
| 30 | void onSetAttribute(SkSVGAttribute, const SkSVGValue&) override; |
| 31 | |
Florin Malita | 39fe8c8 | 2020-10-20 10:43:03 -0400 | [diff] [blame^] | 32 | void onRender(const SkSVGRenderContext&) const override; |
| 33 | void appendChild(sk_sp<SkSVGNode>) override; |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 34 | |
| 35 | SkPath onAsPath(const SkSVGRenderContext&) const override; |
| 36 | |
| 37 | void loadFont(); |
| 38 | |
| 39 | private: |
| 40 | SkSVGText(); |
Florin Malita | 39fe8c8 | 2020-10-20 10:43:03 -0400 | [diff] [blame^] | 41 | |
| 42 | SkFont resolveFont(const SkSVGRenderContext&) const; |
| 43 | |
| 44 | SkSVGLength fX = SkSVGLength(0); |
| 45 | SkSVGLength fY = SkSVGLength(0); |
| 46 | SkSVGStringType fText; |
| 47 | sk_sp<SkTypeface> fTypeface; |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 48 | SkTextUtils::Align fTextAlign = SkTextUtils::Align::kLeft_Align; |
Florin Malita | 39fe8c8 | 2020-10-20 10:43:03 -0400 | [diff] [blame^] | 49 | |
| 50 | using INHERITED = SkSVGTransformableNode; |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | #endif // SkSVGText_DEFINED |