-
Notifications
You must be signed in to change notification settings - Fork 0
/
SVGElement.h
323 lines (257 loc) · 9 KB
/
SVGElement.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#ifndef _SVG_ELEMENT_H_
#define _SVG_ELEMENT_H_
#include <Archivable.h>
#include "SVGDefs.h"
#include "SVGState.h"
class BBitmap;
class BSVGView;
class BView;
class BWindow;
class BSVGElement : public BArchivable {
public:
BSVGElement();
BSVGElement(BSVGView *parent);
BSVGElement(BSVGView *parent, const BString &data);
virtual ~BSVGElement();
BSVGElement(BMessage *data);
static BArchivable *Instantiate(BMessage *data);
virtual status_t Archive(BMessage *data, bool deep = true) const;
virtual element_t Type() { return B_SVG_ELEMENT; };
virtual void SetHeaderData(const BString &data);
BString HeaderData();
virtual void SetFooterData(const BString &data);
BString FooterData();
virtual void RecreateData();
virtual void CollectData(BString &into, int32 indentlevel = 0);
virtual void CollectBounds(BRect &bounds, bool *first);
virtual void PromoteDownMember(void *member, void *setto);
virtual void SetVisible(bool visible);
bool Visible();
virtual void SetID(const char *id);
virtual void SetID(const BString &id);
BString ID();
void AddID(BString &to);
virtual void SetClass(const char *_class);
virtual void SetClass(const BString &_class);
BString Class();
virtual void SetLink(const char *link);
virtual void SetLink(const BString &link);
BString Link();
virtual void SetParent(BSVGView *parent);
BSVGView *Parent();
// attributes
virtual void HandleAttribute(attribute_s *attr);
virtual void HandleAttributes();
// called after filling in attributes
void AddAttribute(attribute_s *attr, bool handle = false);
void RemoveAttribute(attribute_s *attr);
attribute_s *RemoveAttributeAt(int32 index);
void ClearAttributes();
attribute_s *AttributeAt(int32 index);
int32 IndexOf(attribute_s *attr);
int32 CountAttributes();
attribute_s *FindAttributeByName(const BString &name);
attribute_s *FindAttributeByValue(const BString &value);
bool HasAttribute(const BString &name);
// elements
void OpenElement();
void CloseElement();
bool IsOpen();
void AddElement(BSVGElement *element, int32 index = -1);
int32 CountElements(bool deep = true);
BSVGElement *FindElement(const BString &id, uint32 of_type = 0, bool deep = true);
status_t FindElements(const BString &_class, ElementList &elements);
BSVGElement *FindParentElement(uint32 of_type = 0);
BSVGElement *ElementAt(int index, bool deep = true);
int32 IndexOf(BSVGElement *child, bool deep = true);
BSVGElement *RemoveElement(const BString &id, bool deep = true);
BSVGElement *RemoveElement(BSVGElement *element, bool deep = true);
BSVGElement *RemoveElementAt(int index, bool deep = true);
BSVGElement *RemoveSelf();
BSVGElement *LastElement();
BSVGElement *LastContainer();
BSVGElement *OpenContainer(BSVGElement *container = NULL);
BSVGElement *OpenContainer(SVGState *state = NULL);
void CloseContainer();
void SetParentElement(BSVGElement *parent);
BSVGElement *ParentElement();
// debug
void DumpTree(int indent = 0);
void PrintToStream();
virtual void PrepareRendering(SVGState *inherit = NULL);
virtual void Render(BView *view);
virtual void Render(BWindow *window);
virtual void Render(BBitmap *bitmap);
// must accept child views
virtual void RenderCommon();
// SVGState API
virtual status_t ResolveField(field_t field, void *result);
virtual void SetValue(field_t field, void *to);
virtual void GetValue(field_t field, void *result);
virtual void SetSource(field_t field, source_t to);
virtual source_t GetSource(field_t field);
virtual void UnsetField(field_t field);
virtual void SetOpacity(float opacity);
virtual void UnsetOpacity();
bool IsOpacitySet();
float Opacity();
virtual void SetFillServer(BString id);
virtual void SetFillServer(const char *id);
virtual void UnsetFillServer();
bool IsFillServerSet();
const char *FillServer();
virtual void SetFillColor(rgb_color color);
virtual void SetFillColor(uchar r, uchar g, uchar b);
virtual void UnsetFillColor();
bool IsFillColorSet();
rgb_color FillColor();
virtual void SetFillType(paint_t type);
virtual void UnsetFillType();
bool IsFillTypeSet();
paint_t FillType();
virtual void SetFillOpacity(float opacity);
virtual void UnsetFillOpacity();
bool IsFillOpacitySet();
float FillOpacity();
virtual void SetFillRule(rule_t rule);
virtual void UnsetFillRule();
bool IsFillRuleSet();
rule_t FillRule();
virtual void SetStrokeServer(BString id);
virtual void SetStrokeServer(const char *id);
virtual void UnsetStrokeServer();
bool IsStrokeServerSet();
const char *StrokeServer();
virtual void SetStrokeColor(rgb_color color);
void SetStrokeColor(uchar r, uchar g, uchar b);
virtual void UnsetStrokeColor();
bool IsStrokeColorSet();
rgb_color StrokeColor();
virtual void SetStrokeType(paint_t type);
virtual void UnsetStrokeType();
bool IsStrokeTypeSet();
paint_t StrokeType();
virtual void SetStrokeWidth(float width);
virtual void UnsetStrokeWidth();
bool IsStrokeWidthSet();
float StrokeWidth();
virtual void SetStrokeLineJoin(join_mode mode);
virtual void UnsetStrokeLineJoin();
bool IsStrokeLineJoinSet();
join_mode StrokeLineJoin();
virtual void SetStrokeLineCap(cap_mode mode);
virtual void UnsetStrokeLineCap();
bool IsStrokeLineCapSet();
cap_mode StrokeLineCap();
virtual void SetStrokeMiterLimit(float limit);
virtual void UnsetStrokeMiterLimit();
bool IsStrokeMiterLimitSet();
float StrokeMiterLimit();
virtual void SetStrokeOpacity(float opacity);
virtual void UnsetStrokeOpacity();
bool IsStrokeOpacitySet();
float StrokeOpacity();
virtual void SetStopColor(rgb_color color);
virtual void SetStopColor(uchar r, uchar g, uchar b);
virtual void UnsetStopColor();
bool IsStopColorSet();
rgb_color StopColor();
virtual void SetStopOpacity(float opacity);
virtual void UnsetStopOpacity();
bool IsStopOpacitySet();
float StopOpacity();
virtual void SetFontFamily(const char *family);
virtual void SetFontFamily(const BString &string);
virtual void UnsetFontFamily();
bool IsFontFamilySet();
const char *FontFamily();
virtual void SetFontSize(float size);
virtual void UnsetFontSize();
bool IsFontSizeSet();
float FontSize();
virtual void SetFontKerning(float kerning);
virtual void UnsetFontKerning();
bool IsFontKerningSet();
float FontKerning();
virtual void SetLetterSpacing(float spacing);
virtual void UnsetLetterSpacing();
bool IsLetterSpacingSet();
float LetterSpacing();
virtual void SetWordSpacing(float spacing);
virtual void UnsetWordSpacing();
bool IsWordSpacingSet();
float WordSpacing();
virtual void SetFontDecoration(decoration_t decoration);
virtual void UnsetFontDecoration();
bool IsFontDecorationSet();
decoration_t FontDecoration();
virtual void SetTextAnchor(anchor_t anchor);
virtual void UnsetTextAnchor();
bool IsTextAnchorSet();
anchor_t TextAnchor();
virtual void SetStartOffset(float offset);
virtual void UnsetStartOffset();
bool IsStartOffsetSet();
float StartOffset();
virtual void SetTransformation(Matrix2D &transformation);
virtual void UnsetTransformation();
bool IsTransformationSet();
Matrix2D Transformation();
virtual void SetCurrentColor(rgb_color color);
void SetCurrentColor(uchar r, uchar g, uchar b);
virtual void UnsetCurrentColor();
bool IsCurrentColorSet();
rgb_color CurrentColor();
virtual void SetViewPort(BRect viewport);
virtual void UnsetViewPort();
bool IsViewPortSet();
BRect ViewPort();
// end SVGState API
virtual void SetState(const SVGState &state);
SVGState *State();
virtual void SetRenderState(const SVGState &state);
SVGState *RenderState();
private:
friend class BSVGDocument;
friend class BSVGRoot;
friend class BSVGGroup;
friend class BSVGDefs;
friend class BSVGPattern;
friend class BSVGUse;
friend class BSVGPath;
friend class BSVGRect;
friend class BSVGEllipse;
friend class BSVGCircle;
friend class BSVGLine;
friend class BSVGPolyline;
friend class BSVGPolygon;
friend class BSVGText;
friend class BSVGTextSpan;
friend class BSVGTextPath;
friend class BSVGString;
friend class BSVGGradient;
friend class BSVGLinearGradient;
friend class BSVGRadialGradient;
friend class BSVGStop;
friend class BSVGPaintServer;
friend class BSVGView;
int32 ElementAtInternal(int32 index, BSVGElement *&result);
bool IndexOfInternal(BSVGElement *child, int32 *result);
BString fHeaderData; // element begin
BString fFooterData; // eventual closing element
BString fID;
BString fClass;
BString fLink;
resolve_t fStatus;
AttributeList fAttributes;
AttributeList fAttributeNames;
AttributeList fAttributeValues;
SVGState fState;
SVGState fRenderState; // temporary state for rendering
BSVGView *fParent; // were we are getting gradients from...
BSVGElement *fParentElement;
ElementList fElements;
bool fVisible;
bool fOpen;
};
#endif