Coverage Report

Created: 2024-09-14 07:19

/src/skia/modules/svg/include/SkSVGText.h
Line
Count
Source (jump to first uncovered line)
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/SkPath.h"
12
#include "include/core/SkRect.h"
13
#include "include/core/SkRefCnt.h"
14
#include "include/private/base/SkAPI.h"
15
#include "modules/svg/include/SkSVGNode.h"
16
#include "modules/svg/include/SkSVGTransformableNode.h"
17
#include "modules/svg/include/SkSVGTypes.h"
18
19
#include <vector>
20
21
class SkSVGRenderContext;
22
class SK_API SkSVGTextContext;
23
24
// Base class for text-rendering nodes.
25
class SkSVGTextFragment : public SkSVGTransformableNode {
26
public:
27
    void renderText(const SkSVGRenderContext&, SkSVGTextContext*, SkSVGXmlSpace) const;
28
29
protected:
30
5.04k
    explicit SkSVGTextFragment(SkSVGTag t) : INHERITED(t) {}
31
32
    virtual void onShapeText(const SkSVGRenderContext&, SkSVGTextContext*, SkSVGXmlSpace) const = 0;
33
34
    // Text nodes other than the root <text> element are not rendered directly.
35
2.75k
    void onRender(const SkSVGRenderContext&) const override {}
36
37
private:
38
    SkPath onAsPath(const SkSVGRenderContext&) const override;
39
40
    using INHERITED = SkSVGTransformableNode;
41
};
42
43
// Base class for nestable text containers (<text>, <tspan>, etc).
44
class SkSVGTextContainer : public SkSVGTextFragment {
45
public:
46
    SVG_ATTR(X, std::vector<SkSVGLength>, {})
47
    SVG_ATTR(Y, std::vector<SkSVGLength>, {})
48
    SVG_ATTR(Dx, std::vector<SkSVGLength>, {})
49
    SVG_ATTR(Dy, std::vector<SkSVGLength>, {})
50
    SVG_ATTR(Rotate, std::vector<SkSVGNumberType>, {})
51
52
    SVG_ATTR(XmlSpace, SkSVGXmlSpace, SkSVGXmlSpace::kDefault)
53
54
    void appendChild(sk_sp<SkSVGNode>) final;
55
56
protected:
57
1.27k
    explicit SkSVGTextContainer(SkSVGTag t) : INHERITED(t) {}
58
59
    void onShapeText(const SkSVGRenderContext&, SkSVGTextContext*, SkSVGXmlSpace) const override;
60
61
    bool parseAndSetAttribute(const char*, const char*) override;
62
63
private:
64
    std::vector<sk_sp<SkSVGTextFragment>> fChildren;
65
66
    using INHERITED = SkSVGTextFragment;
67
};
68
69
class SkSVGText final : public SkSVGTextContainer {
70
public:
71
1.27k
    static sk_sp<SkSVGText> Make() { return sk_sp<SkSVGText>(new SkSVGText()); }
72
73
private:
74
1.27k
    SkSVGText() : INHERITED(SkSVGTag::kText) {}
75
76
    void onRender(const SkSVGRenderContext&) const override;
77
78
    SkRect onObjectBoundingBox(const SkSVGRenderContext&) const override;
79
    SkPath onAsPath(const SkSVGRenderContext&) const override;
80
81
    using INHERITED = SkSVGTextContainer;
82
};
83
84
class SkSVGTSpan final : public SkSVGTextContainer {
85
public:
86
4
    static sk_sp<SkSVGTSpan> Make() { return sk_sp<SkSVGTSpan>(new SkSVGTSpan()); }
87
88
private:
89
4
    SkSVGTSpan() : INHERITED(SkSVGTag::kTSpan) {}
90
91
    using INHERITED = SkSVGTextContainer;
92
};
93
94
class SkSVGTextLiteral final : public SkSVGTextFragment {
95
public:
96
3.76k
    static sk_sp<SkSVGTextLiteral> Make() {
97
3.76k
        return sk_sp<SkSVGTextLiteral>(new SkSVGTextLiteral());
98
3.76k
    }
99
100
    SVG_ATTR(Text, SkSVGStringType, SkSVGStringType())
101
102
private:
103
3.76k
    SkSVGTextLiteral() : INHERITED(SkSVGTag::kTextLiteral) {}
104
105
    void onShapeText(const SkSVGRenderContext&, SkSVGTextContext*, SkSVGXmlSpace) const override;
106
107
0
    void appendChild(sk_sp<SkSVGNode>) override {}
108
109
    using INHERITED = SkSVGTextFragment;
110
};
111
112
class SkSVGTextPath final : public SkSVGTextContainer {
113
public:
114
0
    static sk_sp<SkSVGTextPath> Make() { return sk_sp<SkSVGTextPath>(new SkSVGTextPath()); }
115
116
    SVG_ATTR(Href       , SkSVGIRI   , {}  )
117
    SVG_ATTR(StartOffset, SkSVGLength, SkSVGLength(0))
118
119
private:
120
0
    SkSVGTextPath() : INHERITED(SkSVGTag::kTextPath) {}
121
122
    void onShapeText(const SkSVGRenderContext&, SkSVGTextContext*, SkSVGXmlSpace) const override;
123
    bool parseAndSetAttribute(const char*, const char*) override;
124
125
    using INHERITED = SkSVGTextContainer;
126
};
127
128
#endif  // SkSVGText_DEFINED