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" |
| 13 | #include "modules/svg/include/SkSVGShape.h" |
| 14 | #include "modules/svg/include/SkSVGTypes.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&); |
| 28 | void setFontStyle(const SkSVGStringType&); |
| 29 | void setFontWeight(const SkSVGStringType&); |
| 30 | void setText(const SkSVGStringType&); |
| 31 | void setTextAnchor(const SkSVGStringType&); |
| 32 | |
| 33 | protected: |
| 34 | void onSetAttribute(SkSVGAttribute, const SkSVGValue&) override; |
| 35 | |
| 36 | void onDraw(SkCanvas*, const SkSVGLengthContext&, const SkPaint&, |
| 37 | SkPathFillType) const override; |
| 38 | |
| 39 | SkPath onAsPath(const SkSVGRenderContext&) const override; |
| 40 | |
| 41 | void loadFont(); |
| 42 | |
| 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; |
| 50 | SkSVGStringType fFontFamily; |
| 51 | SkSVGStringType fFontStyle; |
| 52 | SkSVGStringType fFontWeight; |
| 53 | SkTextUtils::Align fTextAlign = SkTextUtils::Align::kLeft_Align; |
| 54 | using INHERITED = SkSVGShape; |
| 55 | }; |
| 56 | |
| 57 | #endif // SkSVGText_DEFINED |