~ubuntu-branches/ubuntu/precise/ipe/precise

« back to all changes in this revision

Viewing changes to src/include/ipecolor.h

  • Committer: Bazaar Package Importer
  • Author(s): Steve M. Robbins
  • Date: 2009-12-11 21:22:35 UTC
  • mfrom: (4.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20091211212235-5iio4nzpra64snab
Tags: 7.0.10-1
* New upstream.  Closes: #551192.
  - New build-depends: libcairo2-dev, liblua5.1-0-dev, gsfonts
  - patches/config.diff: Remove.  Upstream build system replaced.
  - Runtime lib package changed to libipe7.0.10 from libipe1c2a
  - Devel package renamed to libipe-dev (from libipe1-dev)
  - Package ipe depends on lua5.1 due to ipe-update-master.

* rules: Re-write to use dh.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// -*- C++ -*-
2
 
// --------------------------------------------------------------------
3
 
// Ipe object attributes (not just color!)
4
 
// --------------------------------------------------------------------
5
 
/*
6
 
 
7
 
    This file is part of the extensible drawing editor Ipe.
8
 
    Copyright (C) 1993-2007  Otfried Cheong
9
 
 
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.
14
 
 
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.
19
 
 
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.
24
 
 
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.
29
 
 
30
 
*/
31
 
 
32
 
#ifndef IPECOLOR_H
33
 
#define IPECOLOR_H
34
 
 
35
 
#include "ipebase.h"
36
 
#include "ipegeo.h"
37
 
 
38
 
// --------------------------------------------------------------------
39
 
 
40
 
class IpeAttribute {
41
 
  enum { ESymbolic = 0x80000000, EValue = 0x40000000, ENumeric = 0x20000000,
42
 
         EKindShift = 24, EKindMask = 0x1f000000,
43
 
         ENameMask = 0x00ffffff };
44
 
public:
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,
52
 
               EMaxKind };
53
 
 
54
 
  //! Default constructor creates null object.
55
 
  explicit IpeAttribute() : iName(0) { /* nothing */ }
56
 
 
57
 
  explicit IpeAttribute(TKind kind, bool symbolic, int index);
58
 
  explicit IpeAttribute(TKind kind, IpeFixed value);
59
 
 
60
 
  //! Is it symbolic?
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(); }
64
 
  //! Is it null?
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); }
73
 
  //! Is it void?
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(); }
77
 
  //! Is it solid?
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(); }
81
 
  //! Is it black?
82
 
  inline bool IsBlack() const { return (iName == 3); }
83
 
  //! Is it white?
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); }
90
 
 
91
 
  TKind Kind() const;
92
 
 
93
 
  //! Are two values equal (only compares index!)
94
 
  inline bool operator==(const IpeAttribute &rhs) const {
95
 
    return iName == rhs.iName; }
96
 
 
97
 
  //! Are two values different (only compares index!)
98
 
  inline bool operator!=(const IpeAttribute &rhs) const {
99
 
    return iName != rhs.iName; }
100
 
 
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); }
109
 
private:
110
 
  inline IpeAttribute(int index) : iName(index) { /* nothing */ }
111
 
private:
112
 
  int iName;
113
 
 
114
 
  friend class IpeStyleSheet;
115
 
};
116
 
 
117
 
/*! \var IpeKind
118
 
  \ingroup attr
119
 
  \brief Shortcut for IpeAttribute::TKind.
120
 
*/
121
 
typedef IpeAttribute::TKind IpeKind;
122
 
 
123
 
/*! \var IpeAttributeSeq
124
 
  \ingroup attr
125
 
  \brief A sequence of attribute values.
126
 
*/
127
 
typedef std::vector<IpeAttribute> IpeAttributeSeq;
128
 
 
129
 
class IpeColor {
130
 
public:
131
 
  //! Default constructor.
132
 
  IpeColor() { /* nothing */ }
133
 
  explicit IpeColor(double red, double green, double blue);
134
 
  void Save(IpeStream &stream) const;
135
 
  bool IsGray() const;
136
 
  bool operator==(const IpeColor &rhs) const;
137
 
public:
138
 
  double iRed, iGreen, iBlue;
139
 
};
140
 
 
141
 
//! Layout of an IpePage.
142
 
struct IpeLayout {
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.
152
 
  IpeVector iOrigin;
153
 
  //! Size of the frame (the drawing area).
154
 
  IpeVector iFrameSize;
155
 
  //! Paragraph skip (between textboxes).
156
 
  double iParagraphSkip;
157
 
};
158
 
 
159
 
//! A shading pattern for the paper background.
160
 
struct IpeShading {
161
 
  //! There are two types of shadings, along an axis or between two circles.
162
 
  enum TType { ENone = 0, EAxial = 2, ERadial = 3 };
163
 
 
164
 
  //! The type of shading: axial or radial.
165
 
  TType iType;
166
 
  //! The extreme colors of the shading.
167
 
  IpeColor iColor[2];
168
 
  //! The coordinates of the axis endpoints, or the two circle centers.
169
 
  IpeVector iV[2];
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.
173
 
  bool iExtend[2];
174
 
};
175
 
 
176
 
class IpeDashStyle {
177
 
public:
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;
183
 
public:
184
 
  //! The PDF representation of this dash style.
185
 
  IpeString iDash;
186
 
};
187
 
 
188
 
class IpeStrokeStyle {
189
 
public:
190
 
  //! Line join style.
191
 
  enum { EMiterJoin = 0, ERoundJoin, EBevelJoin };
192
 
  //! Line cap style.
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);
205
 
private:
206
 
  int iBits;
207
 
};
208
 
 
209
 
class IpeRepository {
210
 
public:
211
 
  IpeRepository();
212
 
 
213
 
  IpeString ToString(IpeAttribute index) const;
214
 
  IpeColor ToColor(IpeAttribute index) const;
215
 
  IpeFixed ToScalar(IpeAttribute index) const;
216
 
 
217
 
  IpeAttribute ToAttribute(const IpeColor &color);
218
 
  IpeAttribute ToAttribute(IpeKind kind, IpeFixed value);
219
 
 
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;
227
 
 
228
 
  IpeString String(IpeAttribute attr) const;
229
 
 
230
 
private:
231
 
  IpeAttribute ToSymbolic(IpeKind kind, IpeString name);
232
 
 
233
 
private:
234
 
  std::vector<IpeString> iStrings;
235
 
  std::vector<IpeColor> iColors;
236
 
};
237
 
 
238
 
// --------------------------------------------------------------------
239
 
 
240
 
inline IpeStream &operator<<(IpeStream &stream, const IpeColor &attr)
241
 
{
242
 
  attr.Save(stream); return stream;
243
 
}
244
 
 
245
 
// --------------------------------------------------------------------
246
 
#endif