blob: 61e69d8db24acbd6d0c5b577f2330edfe60bd7df [file] [log] [blame]
Xavier Phane29cdaf2020-03-26 16:15:14 +00001/*
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
16class SkRRect;
17
18class 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 Freemane9663db2020-04-14 14:37:13 -070028 void setFontStyle(const SkSVGStringType&);
29 void setFontWeight(const SkSVGStringType&);
Xavier Phane29cdaf2020-03-26 16:15:14 +000030 void setText(const SkSVGStringType&);
31 void setTextAnchor(const SkSVGStringType&);
32
33 protected:
Florin Malitaf4403e72020-04-10 14:14:04 +000034 void onSetAttribute(SkSVGAttribute, const SkSVGValue&) override;
Xavier Phane29cdaf2020-03-26 16:15:14 +000035
36 void onDraw(SkCanvas*, const SkSVGLengthContext&, const SkPaint&,
37 SkPathFillType) const override;
38
39 SkPath onAsPath(const SkSVGRenderContext&) const override;
40
Tyler Freemane9663db2020-04-14 14:37:13 -070041 void loadFont();
42
Xavier Phane29cdaf2020-03-26 16:15:14 +000043 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 Freemane9663db2020-04-14 14:37:13 -070050 SkSVGStringType fFontFamily;
51 SkSVGStringType fFontStyle;
52 SkSVGStringType fFontWeight;
Xavier Phane29cdaf2020-03-26 16:15:14 +000053 SkTextUtils::Align fTextAlign = SkTextUtils::Align::kLeft_Align;
John Stiles7571f9e2020-09-02 22:42:33 -040054 using INHERITED = SkSVGShape;
Xavier Phane29cdaf2020-03-26 16:15:14 +000055};
56
57#endif // SkSVGText_DEFINED