2
// --------------------------------------------------------------------
3
// Ipe object attributes (not just color!)
4
// --------------------------------------------------------------------
7
This file is part of the extensible drawing editor Ipe.
8
Copyright (C) 1993-2007 Otfried Cheong
10
Ipe is free software; you can redistribute it and/or modify it
11
under the terms of the GNU General Public License as published by
12
the Free Software Foundation; either version 2 of the License, or
13
(at your option) any later version.
15
As a special exception, you have permission to link Ipe with the
16
CGAL library and distribute executables, as long as you follow the
17
requirements of the Gnu General Public License in regard to all of
18
the software in the executable aside from CGAL.
20
Ipe is distributed in the hope that it will be useful, but WITHOUT
21
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
23
License for more details.
25
You should have received a copy of the GNU General Public License
26
along with Ipe; if not, you can find it at
27
"http://www.gnu.org/copyleft/gpl.html", or write to the Free
28
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
38
// --------------------------------------------------------------------
41
enum { ESymbolic = 0x80000000, EValue = 0x40000000, ENumeric = 0x20000000,
42
EKindShift = 24, EKindMask = 0x1f000000,
43
ENameMask = 0x00ffffff };
45
//! The different kinds of attributes.
46
// Attributes 0 .. ETemplate are stored in style sheet,
47
enum TKind { ELineWidth = 0, EMarkSize, EArrowSize,
48
EGridSize, EAngleSize, ETextStretch,
49
EDashStyle, ETextSize,
50
EColor, ETextStyle, ETemplate,
51
ELineCap, ELineJoin, EWindRule,
54
//! Default constructor creates null object.
55
explicit IpeAttribute() : iName(0) { /* nothing */ }
57
explicit IpeAttribute(TKind kind, bool symbolic, int index);
58
explicit IpeAttribute(TKind kind, IpeFixed value);
61
inline int IsSymbolic() const { return iName & ESymbolic; }
62
//! In bool expressions, attribute is false iff it is null.
63
inline operator bool() const { return !IsNull(); }
65
inline bool IsNull() const { return iName == 0; }
66
/*! Is it absolute (including the special values \c void, \c solid,
67
\c black, or \c white)? */
68
inline bool IsAbsolute() const { return iName && !(iName & ESymbolic); }
69
//! Is it an (absolute) value (either numeric or in IpeRepository)?
70
inline int IsValue() const { return (iName & EValue); }
71
//! Is it a numeric value?
72
inline int IsNumeric() const { return (iName & ENumeric); }
74
inline bool IsVoid() const { return (iName == 1); }
75
//! Is it null or void (null is interpreted as void when drawing)?
76
inline bool IsNullOrVoid() const { return IsNull() || IsVoid(); }
78
inline bool IsSolid() const { return (iName == 2); }
79
//! Is it null or solid (null is interpreted as solid when drawing)?
80
inline bool IsNullOrSolid() const { return IsNull() || IsSolid(); }
82
inline bool IsBlack() const { return (iName == 3); }
84
inline bool IsWhite() const { return (iName == 4); }
85
//! Return index into IpeRepository.
86
inline int Index() const { return iName & ENameMask; }
87
//! Return value of absolute numeric argument.
88
inline IpeFixed Number() const {
89
return IpeFixed::FromInternal(iName & ENameMask); }
93
//! Are two values equal (only compares index!)
94
inline bool operator==(const IpeAttribute &rhs) const {
95
return iName == rhs.iName; }
97
//! Are two values different (only compares index!)
98
inline bool operator!=(const IpeAttribute &rhs) const {
99
return iName != rhs.iName; }
101
//! Create void color or pen.
102
inline static IpeAttribute Void() { return IpeAttribute(1); }
103
//! Create solid dash style.
104
inline static IpeAttribute Solid() { return IpeAttribute(2); }
105
//! Create black color.
106
inline static IpeAttribute Black() { return IpeAttribute(3); }
107
//! Create white color.
108
inline static IpeAttribute White() { return IpeAttribute(4); }
110
inline IpeAttribute(int index) : iName(index) { /* nothing */ }
114
friend class IpeStyleSheet;
119
\brief Shortcut for IpeAttribute::TKind.
121
typedef IpeAttribute::TKind IpeKind;
123
/*! \var IpeAttributeSeq
125
\brief A sequence of attribute values.
127
typedef std::vector<IpeAttribute> IpeAttributeSeq;
131
//! Default constructor.
132
IpeColor() { /* nothing */ }
133
explicit IpeColor(double red, double green, double blue);
134
void Save(IpeStream &stream) const;
136
bool operator==(const IpeColor &rhs) const;
138
double iRed, iGreen, iBlue;
141
//! Layout of an IpePage.
143
//! Create null layout.
144
IpeLayout() { iPaperSize.iX = -1.0; }
145
//! Is this an undefined (null) layout?
146
bool isNull() const { return iPaperSize.iX < 0.0; }
147
//! Return rectangle describing the paper.
148
IpeRect paper() const { return IpeRect(-iOrigin, iPaperSize - iOrigin); }
149
//! Dimensions of the media.
150
IpeVector iPaperSize;
151
//! Origin of the Ipe coordinate system relative to the paper.
153
//! Size of the frame (the drawing area).
154
IpeVector iFrameSize;
155
//! Paragraph skip (between textboxes).
156
double iParagraphSkip;
159
//! A shading pattern for the paper background.
161
//! There are two types of shadings, along an axis or between two circles.
162
enum TType { ENone = 0, EAxial = 2, ERadial = 3 };
164
//! The type of shading: axial or radial.
166
//! The extreme colors of the shading.
168
//! The coordinates of the axis endpoints, or the two circle centers.
170
//! The radii of the two circles (not used for axial shadings).
171
IpeScalar iRadius[2];
172
//! Whether to extend the shading beyond the endpoints.
178
//! Default constructor creates solid style.
179
IpeDashStyle() { /* nothing */ }
180
//! Construct dash style with given PDF representation.
181
explicit IpeDashStyle(IpeString str);
182
bool operator==(const IpeDashStyle &rhs) const;
184
//! The PDF representation of this dash style.
188
class IpeStrokeStyle {
191
enum { EMiterJoin = 0, ERoundJoin, EBevelJoin };
193
enum { EButtCap = 0, ERoundCap, ESquareCap };
194
//! Constructor creates all null attributes.
195
IpeStrokeStyle() : iBits(0) { /* nothing */ }
196
IpeAttribute Join() const;
197
IpeAttribute Cap() const;
198
IpeAttribute WindRule() const;
199
void SetJoin(int val);
200
void SetCap(int val);
201
void SetWindRule(int val);
202
void SetJoin(IpeAttribute val);
203
void SetCap(IpeAttribute val);
204
void SetWindRule(IpeAttribute val);
209
class IpeRepository {
213
IpeString ToString(IpeAttribute index) const;
214
IpeColor ToColor(IpeAttribute index) const;
215
IpeFixed ToScalar(IpeAttribute index) const;
217
IpeAttribute ToAttribute(const IpeColor &color);
218
IpeAttribute ToAttribute(IpeKind kind, IpeFixed value);
220
IpeAttribute MakeColor(IpeString str);
221
IpeAttribute MakeString(IpeKind kind, IpeString str);
222
IpeAttribute MakeDashStyle(IpeString str);
223
IpeAttribute MakeTextSize(IpeString str);
224
IpeAttribute MakeScalar(IpeKind kind, IpeString str);
225
IpeAttribute MakeSymbol(IpeKind kind, IpeString str);
226
IpeAttribute GetSymbol(IpeKind kind, IpeString str) const;
228
IpeString String(IpeAttribute attr) const;
231
IpeAttribute ToSymbolic(IpeKind kind, IpeString name);
234
std::vector<IpeString> iStrings;
235
std::vector<IpeColor> iColors;
238
// --------------------------------------------------------------------
240
inline IpeStream &operator<<(IpeStream &stream, const IpeColor &attr)
242
attr.Save(stream); return stream;
245
// --------------------------------------------------------------------