blob: 55716cd3f05c42f8a6318eae6643eb1970222768 [file] [log] [blame]
Florin Malitab3418102020-10-15 18:10:29 -04001/*
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 Malita39fe8c82020-10-20 10:43:03 -040013#include "modules/svg/include/SkSVGTransformableNode.h"
Florin Malitab3418102020-10-15 18:10:29 -040014#include "modules/svg/include/SkSVGTypes.h"
15
16class SkRRect;
17
Florin Malita39fe8c82020-10-20 10:43:03 -040018class SkSVGText final : public SkSVGTransformableNode {
Florin Malitab3418102020-10-15 18:10:29 -040019 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 Malitab3418102020-10-15 18:10:29 -040026 void setText(const SkSVGStringType&);
27 void setTextAnchor(const SkSVGStringType&);
28
29 protected:
30 void onSetAttribute(SkSVGAttribute, const SkSVGValue&) override;
31
Florin Malita39fe8c82020-10-20 10:43:03 -040032 void onRender(const SkSVGRenderContext&) const override;
33 void appendChild(sk_sp<SkSVGNode>) override;
Florin Malitab3418102020-10-15 18:10:29 -040034
35 SkPath onAsPath(const SkSVGRenderContext&) const override;
36
37 void loadFont();
38
39 private:
40 SkSVGText();
Florin Malita39fe8c82020-10-20 10:43:03 -040041
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 Malitab3418102020-10-15 18:10:29 -040048 SkTextUtils::Align fTextAlign = SkTextUtils::Align::kLeft_Align;
Florin Malita39fe8c82020-10-20 10:43:03 -040049
50 using INHERITED = SkSVGTransformableNode;
Florin Malitab3418102020-10-15 18:10:29 -040051};
52
53#endif // SkSVGText_DEFINED