skia_safe/modules/svg/
text.rs1use super::{DebugAttributes, Iri, Length, NodeSubtype, XmlSpace};
2use crate::{impl_default_make, interop, prelude::*, scalar};
3use skia_bindings as sb;
4
5type TextContainer = RCHandle<sb::SkSVGTextContainer>;
6
7impl NodeSubtype for sb::SkSVGTextContainer {
8 type Base = sb::SkSVGContainer;
9}
10
11impl DebugAttributes for TextContainer {
12 const NAME: &'static str = "TextContainer";
13
14 fn _dbg(&self, builder: &mut std::fmt::DebugStruct) {
15 self.as_base()._dbg(
16 builder
17 .field("x", &self.x())
18 .field("y", &self.y())
19 .field("dx", &self.dx())
20 .field("dy", &self.dy())
21 .field("rotate", &self.rotate())
22 .field("xml_space", &self.xml_space()),
23 );
24 }
25}
26
27impl TextContainer {
28 pub fn x(&self) -> &[Length] {
29 unsafe {
30 safer::from_raw_parts(
31 Length::from_native_ptr(sb::C_SkSVGTextContainer_getX(self.native())),
32 sb::C_SkSVGTextContainer_getXCount(self.native()),
33 )
34 }
35 }
36
37 pub fn y(&self) -> &[Length] {
38 unsafe {
39 safer::from_raw_parts(
40 Length::from_native_ptr(sb::C_SkSVGTextContainer_getY(self.native())),
41 sb::C_SkSVGTextContainer_getYCount(self.native()),
42 )
43 }
44 }
45
46 pub fn dx(&self) -> &[Length] {
47 unsafe {
48 safer::from_raw_parts(
49 Length::from_native_ptr(sb::C_SkSVGTextContainer_getDx(self.native())),
50 sb::C_SkSVGTextContainer_getDxCount(self.native()),
51 )
52 }
53 }
54
55 pub fn dy(&self) -> &[Length] {
56 unsafe {
57 safer::from_raw_parts(
58 Length::from_native_ptr(sb::C_SkSVGTextContainer_getDy(self.native())),
59 sb::C_SkSVGTextContainer_getDyCount(self.native()),
60 )
61 }
62 }
63
64 pub fn rotate(&self) -> &[scalar] {
65 unsafe {
66 safer::from_raw_parts(sb::C_SkSVGTextContainer_getRotate(self.native()), {
67 sb::C_SkSVGTextContainer_getRotateCount(self.native())
68 })
69 }
70 }
71
72 skia_svg_macros::attrs! {
73 SkSVGTextContainer => {
74 xml_space: XmlSpace [get(value) => value, set(value) => value]
75 }
76 }
77}
78
79pub type Text = RCHandle<sb::SkSVGText>;
80
81impl NodeSubtype for sb::SkSVGText {
82 type Base = sb::SkSVGTextContainer;
83}
84
85impl_default_make!(Text, sb::C_SkSVGText_Make);
86
87impl DebugAttributes for Text {
88 const NAME: &'static str = "Text";
89
90 fn _dbg(&self, builder: &mut std::fmt::DebugStruct) {
91 self.as_base()._dbg(builder);
92 }
93}
94
95pub type TSpan = RCHandle<sb::SkSVGTSpan>;
96
97impl NodeSubtype for sb::SkSVGTSpan {
98 type Base = sb::SkSVGTextContainer;
99}
100
101impl_default_make!(TSpan, sb::C_SkSVGTSpan_Make);
102
103impl DebugAttributes for TSpan {
104 const NAME: &'static str = "TSpan";
105
106 fn _dbg(&self, builder: &mut std::fmt::DebugStruct) {
107 self.as_base()._dbg(builder);
108 }
109}
110
111pub type TextLiteral = RCHandle<sb::SkSVGTextLiteral>;
112
113impl NodeSubtype for sb::SkSVGTextLiteral {
114 type Base = sb::SkSVGTransformableNode;
115}
116
117impl_default_make!(TextLiteral, sb::C_SkSVGTextLiteral_Make);
118
119impl DebugAttributes for TextLiteral {
120 const NAME: &'static str = "TextLiteral";
121
122 fn _dbg(&self, builder: &mut std::fmt::DebugStruct) {
123 self.as_base()._dbg(builder.field("text", &self.text()));
124 }
125}
126
127impl TextLiteral {
128 skia_svg_macros::attrs! {
129 SkSVGTextLiteral => {
130 text: str [
131 get(value) => interop::String::from_native_ref(value).as_str(),
132 set(&value) => interop::String::from_str(value).into_native()
133 ]
134 }
135 }
136}
137
138pub type TextPath = RCHandle<sb::SkSVGTextPath>;
139
140impl NodeSubtype for sb::SkSVGTextPath {
141 type Base = sb::SkSVGTextContainer;
142}
143
144impl_default_make!(TextPath, sb::C_SkSVGTextPath_Make);
145
146impl DebugAttributes for TextPath {
147 const NAME: &'static str = "TextPath";
148
149 fn _dbg(&self, builder: &mut std::fmt::DebugStruct) {
150 self.as_base()._dbg(
151 builder
152 .field("href", &self.href())
153 .field("start_offset", &self.start_offset()),
154 );
155 }
156}
157
158impl TextPath {
159 skia_svg_macros::attrs! {
160 SkSVGTextPath => {
161 href: Iri [get(value) => Iri::from_native_ref(value), set(value) => value.into_native()],
162 start_offset: Length [get(value) => Length::from_native_ref(value), set(value) => value.into_native()]
163 }
164 }
165}