summaryrefslogtreecommitdiffstats
path: root/ksvg/impl/SVGStylableImpl.h
blob: 50a375685b65622c4be03325eea4fc755ddc9de8 (plain)
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
324
325
326
327
/*
    Copyright (C) 2001-2003 KSVG Team
    This file is part of the KDE project

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#ifndef SVGStylableImpl_H
#define SVGStylableImpl_H

#include <tqstring.h>
#include <tqstringlist.h>

#include <dom/dom_string.h>

#include "ksvg_lookup.h"

class TQRect;

// from libart, but now no dependency
typedef enum
{
  PATH_STROKE_JOIN_MITER,
  PATH_STROKE_JOIN_ROUND,
  PATH_STROKE_JOIN_BEVEL
} PathStrokeJoinType;

typedef enum
{
  PATH_STROKE_CAP_BUTT,
  PATH_STROKE_CAP_ROUND,
  PATH_STROKE_CAP_SQUARE
} PathStrokeCapType;

#define SVG_STYLE_FLAG_NONE							0x0000000000000ULL
#define SVG_STYLE_FLAG_BASELINE_SHIFT				0x0000000000001ULL
#define SVG_STYLE_FLAG_CLIP_PATH					0x0000000000002ULL
#define SVG_STYLE_FLAG_CLIP_RULE					0x0000000000004ULL
#define SVG_STYLE_FLAG_COLOR						0x0000000000008ULL
#define SVG_STYLE_FLAG_COLOR_INTERPOLATION			0x0000000000010ULL
#define SVG_STYLE_FLAG_COLOR_INTERPOLATION_FILTERS	0x0000000000020ULL
#define SVG_STYLE_FLAG_COLOR_PROFILE				0x0000000000040ULL
#define SVG_STYLE_FLAG_COLOR_RENDERING				0x0000000000080ULL
#define SVG_STYLE_FLAG_CURSOR						0x0000000000100ULL
#define SVG_STYLE_FLAG_DIRECTION					0x0000000000200ULL
#define SVG_STYLE_FLAG_DISPLAY						0x0000000000400ULL
#define SVG_STYLE_FLAG_FILL							0x0000000000800ULL
#define SVG_STYLE_FLAG_FILL_OPACITY					0x0000000001000ULL
#define SVG_STYLE_FLAG_FILL_RULE					0x0000000002000ULL
#define SVG_STYLE_FLAG_FONT_FAMILY					0x0000000004000ULL
#define SVG_STYLE_FLAG_FONT_SIZE					0x0000000008000ULL
#define SVG_STYLE_FLAG_FONT_SIZE_ADJUST				0x0000000010000ULL
#define SVG_STYLE_FLAG_FONT_STRETCH					0x0000000020000ULL
#define SVG_STYLE_FLAG_FONT_STYLE					0x0000000040000ULL
#define SVG_STYLE_FLAG_FONT_VARIANT					0x0000000080000ULL
#define SVG_STYLE_FLAG_FONT_WEIGHT					0x0000000100000ULL
#define SVG_STYLE_FLAG_GLYPH_ORIENTATION_HORIZONTAL	0x0000000200000ULL
#define SVG_STYLE_FLAG_GLYPH_ORIENTATION_VERTICAL	0x0000000400000ULL
#define SVG_STYLE_FLAG_IMAGE_RENDERING				0x0000000800000ULL
#define SVG_STYLE_FLAG_KERNING						0x0000001000000ULL
#define SVG_STYLE_FLAG_LETTER_SPACING				0x0000002000000ULL
#define SVG_STYLE_FLAG_MARKER						0x0000004000000ULL
#define SVG_STYLE_FLAG_MARKER_END					0x0000008000000ULL
#define SVG_STYLE_FLAG_MARKER_MID					0x0000010000000ULL
#define SVG_STYLE_FLAG_MARKER_START					0x0000020000000ULL
#define SVG_STYLE_FLAG_OPACITY						0x0000040000000ULL
#define SVG_STYLE_FLAG_POINTER_EVENTS				0x0000080000000ULL
#define SVG_STYLE_FLAG_SHAPE_RENDERING				0x0000100000000ULL
#define SVG_STYLE_FLAG_STOP							0x0000200000000ULL
#define SVG_STYLE_FLAG_STROKE_DASH_ARRAY			0x0000400000000ULL
#define SVG_STYLE_FLAG_STROKE_DASH_OFFSET			0x0000800000000ULL
#define SVG_STYLE_FLAG_STROKE_LINE_CAP				0x0001000000000ULL
#define SVG_STYLE_FLAG_STROKE_LINE_JOIN				0x0002000000000ULL
#define SVG_STYLE_FLAG_STROKE_MITER_LIMIT			0x0004000000000ULL
#define SVG_STYLE_FLAG_STROKE_OPACITY				0x0008000000000ULL
#define SVG_STYLE_FLAG_STROKE						0x0010000000000ULL
#define SVG_STYLE_FLAG_STROKE_WIDTH					0x0020000000000ULL
#define SVG_STYLE_FLAG_TEXT_ANCHOR					0x0040000000000ULL
#define SVG_STYLE_FLAG_TEXT_DECORATION				0x0080000000000ULL
#define SVG_STYLE_FLAG_TEXT_DIRECTION				0x0100000000000ULL
#define SVG_STYLE_FLAG_TEXT_RENDERING				0x0200000000000ULL
#define SVG_STYLE_FLAG_TEXT_UNICODE_BIDI			0x0400000000000ULL
#define SVG_STYLE_FLAG_TEXT_WRITING_MODE			0x0800000000000ULL
#define SVG_STYLE_FLAG_VISIBILITY					0x1000000000000ULL
#define SVG_STYLE_FLAG_WORD_SPACING					0x2000000000000ULL
#define SVG_STYLE_FLAG_OVERFLOW						0x4000000000000ULL
#define SVG_STYLE_FLAG_MASK								0x0008000000000000ULL

//?#define SVG_STYLE_FLAG_MASK_INHERIT				0x0010000000000000ULL

// Helper macros
#define STYLE_GET(Return, Name, Member) \
protected:\
 Return Member;\
public:\
Return get ##Name () const { return Member; }

#define STYLE_GET_OPTIM(Return, Name, Member, Optim) \
protected:\
 Return Member : Optim;\
public:\
Return get ##Name () const { return Member; }

#define STYLE_HAS(Name, Member) \
bool has##Name () { return ! Member .isEmpty(); }

namespace KSVG
{

enum ECursor
{
	CURSOR_AUTO,
	CURSOR_CROSSHAIR,
	CURSOR_DEFAULT,
	CURSOR_POINTER,
	CURSOR_MOVE,
	CURSOR_E_RESIZE,
	CURSOR_NE_RESIZE,
	CURSOR_N_RESIZE,
	CURSOR_NW_RESIZE,
	CURSOR_SE_RESIZE,
	CURSOR_SW_RESIZE,
	CURSOR_S_RESIZE,
	CURSOR_W_RESIZE,
	CURSOR_TEXT,
	CURSOR_WAIT,
	CURSOR_HELP
};

enum ETextDirection
{
	LTR, RTL
};

enum ETextDecoration
{
	TDNONE = 0, UNDERLINE = 1, OVERLINE = 2, LINE_THROUGH = 4
};

enum ETextAnchor
{
	TASTART, TAMIDDLE, TAEND
};

enum EUnicodeBidi
{
	UBNORMAL, EMBED, OVERRIDE, INHERIT
};

enum EFontStyle
{
	FSNORMAL, ITALIC, OBLIQUE
};

enum ETextWritingMode
{
	LR, RL, TB
};

enum EWindRule
{
	RULE_NONZERO,
	RULE_EVENODD
};

enum EPointerEvents
{
	PE_NONE,
	PE_STROKE,
	PE_FILL,
	PE_PAINTED,
	PE_VISIBLE,
	PE_VISIBLE_STROKE,
	PE_VISIBLE_FILL,
	PE_VISIBLE_PAINTED,
	PE_ALL,
	PE_INHERIT
};

enum EColorInterpolation
{
	CI_SRGB,
	CI_LINEARRGB
};

class SVGColorImpl;
class SVGPaintImpl;
class SVGLengthImpl;
class SVGAnimatedLengthImpl;
class SVGAnimatedLengthListImpl;
class SVGMatrixImpl;
class SVGStringListImpl;
class SVGElementImpl;
class SVGStylableImpl
{
public:
	SVGStylableImpl(SVGElementImpl *object);
	virtual ~SVGStylableImpl();
	
	static void setColor(const TQString &, SVGColorImpl *);

	STYLE_GET(SVGAnimatedLengthImpl *, DashOffset, m_dashOffset)
	STYLE_GET(SVGAnimatedLengthListImpl *, DashArray, m_dashArray)
	STYLE_GET(SVGPaintImpl *, StrokeColor, m_strokeColor)
	STYLE_GET(SVGPaintImpl *, FillColor, m_fillColor)
	STYLE_GET(SVGColorImpl *, StopColor, m_stopColor)
	STYLE_GET(SVGColorImpl *, Color, m_color)
	STYLE_GET(SVGAnimatedLengthImpl *, StrokeWidth, m_strokeWidth)
	STYLE_GET(SVGStringListImpl *, FontFamily, m_fontFamily);
	STYLE_GET(float, FontSize, m_fontSize)
	STYLE_GET(TQString, LetterSpacing, m_letterSpacing)
	STYLE_GET(TQString, WordSpacing, m_wordSpacing)
	STYLE_GET(TQString, FontWeight, m_fontWeight)
	STYLE_GET(TQString, ClipPath, m_clipPath)
	STYLE_GET(TQString, Mask, m_mask)
	STYLE_GET(TQString, StartMarker, m_startMarker)
	STYLE_GET(TQString, MidMarker, m_midMarker)
	STYLE_GET(TQString, EndMarker, m_endMarker)
	STYLE_GET(TQString, BaselineShift, m_baselineShift)
	STYLE_GET(TQString, GlyphOrientationVertical, m_glyphOrientationVertical)
	STYLE_GET(TQString, GlyphOrientationHorizontal, m_glyphOrientationHorizontal)
	STYLE_GET(float, Opacity, m_opacity)
	STYLE_GET(float, FillOpacity, m_fillOpacity)
	STYLE_GET(float, StrokeOpacity, m_strokeOpacity)
	STYLE_GET(unsigned int, StrokeMiterlimit, m_strokeMiterlimit)

	STYLE_GET_OPTIM(EPointerEvents, PointerEvents, m_pointerEvents, 4) 
	STYLE_GET_OPTIM(ECursor, Cursor, m_cursor, 4) 
	STYLE_GET_OPTIM(EWindRule, FillRule, m_fillRule, 1)
	STYLE_GET_OPTIM(EWindRule, ClipRule, m_clipRule, 1)
	STYLE_GET_OPTIM(PathStrokeCapType, CapStyle, m_capStyle, 2)
	STYLE_GET_OPTIM(PathStrokeJoinType, JoinStyle, m_joinStyle, 2)
	STYLE_GET_OPTIM(ETextDirection, TextDirection, m_textDirection, 1)
	STYLE_GET_OPTIM(unsigned int, TextDecoration, m_textDecoration, 3)
	STYLE_GET_OPTIM(ETextAnchor, TextAnchor, m_textAnchor, 2)
	STYLE_GET_OPTIM(EUnicodeBidi, TextUnicodeBidi, m_textUnicodeBidi, 2)
	STYLE_GET_OPTIM(ETextWritingMode, TextWritingMode, m_textWritingMode, 2)
	STYLE_GET_OPTIM(EFontStyle, FontStyle, m_fontStyle, 2)
	STYLE_GET_OPTIM(bool, Overflow, m_overflow, 1)
	STYLE_GET_OPTIM(bool, Visible, m_visible, 1)
	STYLE_GET_OPTIM(bool, Display, m_display, 1)
	STYLE_GET_OPTIM(EColorInterpolation, ColorInterpolation, m_colorInterpolation, 1)
	
	STYLE_HAS(ClipPath, m_clipPath)
	STYLE_HAS(Mask, m_mask)
	STYLE_HAS(StartMarker, m_startMarker)
	STYLE_HAS(MidMarker, m_midMarker)
	STYLE_HAS(EndMarker, m_endMarker)

	// Special "set" cases
	void setStartMarker(const TQString &);
	void setMidMarker(const TQString &);
	void setEndMarker(const TQString &);
	void setMarkers(const TQString &);

	// Special "has" cases
	bool hasMarkers() const;

	// Special "is" cases
	bool isStroked() const;
	bool isFilled() const;

	// Function which sets default values
	void processStyle();
	
	// Special virtual functions
	virtual void setClip(const TQString &clip);
	virtual TQRect clip();

protected:
	float fontSizeForText(const TQString &);

	SVGElementImpl *m_object;

private:
	void setPaint(const TQString &, SVGPaintImpl *);
	TQString extractUrlId(const TQString& string);

	unsigned long long m_flags;

public:
	KSVG_GET
	KSVG_PUT

	enum
	{
		// Properties
		ClassName, Style,
		StrokeWidth, StrokeMiterlimit, StrokeLineCap, StrokeLineJoin,
	 	Stroke, Fill, Color, StopColor, FontSize, FontFamily, FontWeight,
		FontStyle, TextDecoration, TextAnchor, Direction, WritingMode,
		UnicodeBidi, Opacity, FillOpacity, StrokeOpacity, ClipPath,
		MarkerStart, MarkerMid, MarkerEnd, Marker, Cursor, Display,
		Overflow, Clip, Visibility, FillRule, ClipRule,
		StrokeDashOffset, StrokeDashArray, ColorProfile, BaselineShift,
		LetterSpacing, WordSpacing, PointerEvents,
		GlyphOrientationVertical, GlyphOrientationHorizontal,
		ColorInterpolation, Mask,
		// Functions
		GetStyle
	};

	KJS::Value getValueProperty(KJS::ExecState *exec, int token) const;
	void putValueProperty(KJS::ExecState *exec, int token, const KJS::Value &value, int attr);
};

}

KSVG_DEFINE_PROTOTYPE(SVGStylableImplProto)
KSVG_IMPLEMENT_PROTOFUNC(SVGStylableImplProtoFunc, SVGStylableImpl)

#endif

// vim:ts=4:noet