Magick++  6.9.3
Geometry.h
Go to the documentation of this file.
1 // This may look like C code, but it is really -*- C++ -*-
2 //
3 // Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002
4 // Copyright Dirk Lemstra 2014
5 //
6 // Geometry Definition
7 //
8 // Representation of an ImageMagick geometry specification
9 // X11 geometry specification plus hints
10 
11 #if !defined (Magick_Geometry_header)
12 #define Magick_Geometry_header
13 
14 #include "Magick++/Include.h"
15 #include <string>
16 
17 namespace Magick
18 {
20 
21  // Compare two Geometry objects regardless of LHS/RHS
22  MagickPPExport int operator ==
23  (const Magick::Geometry& left_,const Magick::Geometry& right_);
24  MagickPPExport int operator !=
25  (const Magick::Geometry& left_,const Magick::Geometry& right_);
26  MagickPPExport int operator >
27  (const Magick::Geometry& left_,const Magick::Geometry& right_);
28  MagickPPExport int operator <
29  (const Magick::Geometry& left_,const Magick::Geometry& right_);
30  MagickPPExport int operator >=
31  (const Magick::Geometry& left_,const Magick::Geometry& right_);
32  MagickPPExport int operator <=
33  (const Magick::Geometry& left_,const Magick::Geometry& right_);
34 
36  {
37  public:
38 
39  // Default constructor
40  Geometry();
41 
42  // Construct Geometry from specified string
43  Geometry(const char *geometry_);
44 
45  // Copy constructor
46  Geometry(const Geometry &geometry_);
47 
48  // Construct Geometry from specified string
49  Geometry(const std::string &geometry_);
50 
51  // Construct Geometry from specified dimensions
52  Geometry(size_t width_,size_t height_,::ssize_t xOff_=0,
53  ::ssize_t yOff_=0,bool xNegative_=false,bool yNegative_=false);
54 
55  // Destructor
56  ~Geometry(void);
57 
58  // Set via geometry string
59  const Geometry& operator=(const char *geometry_);
60 
61  // Assignment operator
62  Geometry& operator=(const Geometry& Geometry_);
63 
64  // Set via geometry string
65  const Geometry& operator=(const std::string &geometry_ );
66 
67  // Return geometry string
68  operator std::string() const;
69 
70  // Resize without preserving aspect ratio (!)
71  void aspect(bool aspect_);
72  bool aspect(void) const;
73 
74  // Resize the image based on the smallest fitting dimension (^)
75  void fillArea(bool fillArea_);
76  bool fillArea(void) const;
77 
78  // Resize if image is greater than size (>)
79  void greater(bool greater_);
80  bool greater(void) const;
81 
82  // Height
83  void height(size_t height_);
84  size_t height(void) const;
85 
86  // Does object contain valid geometry?
87  void isValid(bool isValid_);
88  bool isValid(void) const;
89 
90  // Resize if image is less than size (<)
91  void less(bool less_);
92  bool less(void) const;
93 
94  // Resize using a pixel area count limit (@)
95  void limitPixels(bool limitPixels_);
96  bool limitPixels(void) const;
97 
98  // Width and height are expressed as percentages
99  void percent(bool percent_);
100  bool percent(void) const;
101 
102  // Width
103  void width(size_t width_);
104  size_t width(void) const;
105 
106  // Sign of X offset negative? (X origin at right)
107  void xNegative(bool xNegative_);
108  bool xNegative(void) const;
109 
110  // X offset from origin
111  void xOff(::ssize_t xOff_);
112  ::ssize_t xOff(void) const;
113 
114  // Sign of Y offset negative? (Y origin at bottom)
115  void yNegative(bool yNegative_);
116  bool yNegative(void) const;
117 
118  // Y offset from origin
119  void yOff(::ssize_t yOff_);
120  ::ssize_t yOff(void) const;
121 
122  //
123  // Public methods below this point are for Magick++ use only.
124  //
125 
126  // Construct from RectangleInfo
127  Geometry(const MagickCore::RectangleInfo &rectangle_);
128 
129  // Set via RectangleInfo
130  const Geometry& operator=(const MagickCore::RectangleInfo &rectangle_);
131 
132  // Return an ImageMagick RectangleInfo struct
133  operator MagickCore::RectangleInfo() const;
134 
135  private:
136  size_t _width;
137  size_t _height;
138  ::ssize_t _xOff;
139  ::ssize_t _yOff;
140  bool _xNegative;
141  bool _yNegative;
142  bool _isValid;
143  bool _percent; // Interpret width & height as percentages (%)
144  bool _aspect; // Force exact size (!)
145  bool _greater; // Resize only if larger than geometry (>)
146  bool _less; // Resize only if smaller than geometry (<)
147  bool _fillArea; // Resize the image based on the smallest fitting dimension (^)
148  bool _limitPixels; // Resize using a pixel area count limit (@)
149  };
150 
152 
153  // Compare two Offset objects
154  MagickPPExport int operator ==
155  (const Magick::Offset& left_,const Magick::Offset& right_);
156  MagickPPExport int operator !=
157  (const Magick::Offset& left_,const Magick::Offset& right_);
158 
160  {
161  public:
162 
163  // Default constructor
164  Offset();
165 
166  // Construct Offset from specified string
167  Offset(const char *offset_);
168 
169  // Copy constructor
170  Offset(const Offset &offset_);
171 
172  // Construct Offset from specified string
173  Offset(const std::string &offset_);
174 
175  // Construct Offset from specified x and y
176  Offset(ssize_t x_,ssize_t y_);
177 
178  // Destructor
179  ~Offset(void);
180 
181  // Set via offset string
182  const Offset& operator=(const char *offset_);
183 
184  // Assignment operator
185  Offset& operator=(const Offset& offset_);
186 
187  // Set via offset string
188  const Offset& operator=(const std::string &offset_);
189 
190  // X offset from origin
191  ssize_t x(void) const;
192 
193  // Y offset from origin
194  ssize_t y(void) const;
195 
196  //
197  // Public methods below this point are for Magick++ use only.
198  //
199 
200  // Return an ImageMagick OffsetInfo struct
201  operator MagickCore::OffsetInfo() const;
202 
203  private:
204  ssize_t _x;
205  ssize_t _y;
206  };
207 } // namespace Magick
208 
209 //
210 // Inlines
211 //
212 
213 inline void Magick::Geometry::aspect(bool aspect_)
214 {
215  _aspect=aspect_;
216 }
217 
218 inline bool Magick::Geometry::aspect(void) const
219 {
220  return(_aspect);
221 }
222 
223 inline void Magick::Geometry::fillArea(bool fillArea_)
224 {
225  _fillArea=fillArea_;
226 }
227 
228 inline bool Magick::Geometry::fillArea(void) const
229 {
230  return(_fillArea);
231 }
232 
233 inline void Magick::Geometry::greater(bool greater_)
234 {
235  _greater=greater_;
236 }
237 
238 inline bool Magick::Geometry::greater(void) const
239 {
240  return(_greater);
241 }
242 
243 inline void Magick::Geometry::height(size_t height_)
244 {
245  _height=height_;
246 }
247 
248 inline size_t Magick::Geometry::height(void) const
249 {
250  return(_height);
251 }
252 
253 inline void Magick::Geometry::isValid(bool isValid_)
254 {
255  _isValid=isValid_;
256 }
257 
258 inline bool Magick::Geometry::isValid(void) const
259 {
260  return(_isValid);
261 }
262 
263 inline void Magick::Geometry::less(bool less_)
264 {
265  _less=less_;
266 }
267 
268 inline bool Magick::Geometry::less(void) const
269 {
270  return(_less);
271 }
272 
273 inline void Magick::Geometry::limitPixels(bool limitPixels_)
274 {
275  _limitPixels=limitPixels_;
276 }
277 
278 inline bool Magick::Geometry::limitPixels(void) const
279 {
280  return(_limitPixels);
281 }
282 
283 inline void Magick::Geometry::width(size_t width_)
284 {
285  _width=width_;
286  isValid(true);
287 }
288 
289 inline void Magick::Geometry::percent(bool percent_)
290 {
291  _percent = percent_;
292 }
293 
294 inline bool Magick::Geometry::percent(void) const
295 {
296  return(_percent);
297 }
298 
299 inline size_t Magick::Geometry::width(void) const
300 {
301  return(_width);
302 }
303 
304 inline void Magick::Geometry::xNegative(bool xNegative_)
305 {
306  _xNegative=xNegative_;
307 }
308 
309 inline bool Magick::Geometry::xNegative(void) const
310 {
311  return(_xNegative);
312 }
313 
314 inline void Magick::Geometry::xOff(::ssize_t xOff_)
315 {
316  _xOff=xOff_;
317 }
318 
319 inline ::ssize_t Magick::Geometry::xOff(void) const
320 {
321  return(_xOff);
322 }
323 
324 inline void Magick::Geometry::yNegative(bool yNegative_)
325 {
326  _yNegative=yNegative_;
327 }
328 
329 inline bool Magick::Geometry::yNegative(void) const
330 {
331  return(_yNegative);
332 }
333 
334 inline void Magick::Geometry::yOff(::ssize_t yOff_)
335 {
336  _yOff=yOff_;
337 }
338 
339 inline ::ssize_t Magick::Geometry::yOff(void) const
340 {
341  return(_yOff);
342 }
343 
344 #endif // Magick_Geometry_header
bool limitPixels(void) const
Definition: Geometry.h:278
class MagickPPExport Offset
Definition: Geometry.h:151
size_t width(void) const
Definition: Geometry.h:299
bool yNegative(void) const
Definition: Geometry.h:329
size_t height(void) const
Definition: Geometry.h:248
bool percent(void) const
Definition: Geometry.h:294
#define MagickPPExport
Definition: Include.h:261
class MagickPPExport Geometry
Definition: Geometry.h:19
bool aspect(void) const
Definition: Geometry.h:218
bool less(void) const
Definition: Geometry.h:268
bool isValid(void) const
Definition: Geometry.h:258
bool greater(void) const
Definition: Geometry.h:238
::ssize_t yOff(void) const
Definition: Geometry.h:339
::ssize_t xOff(void) const
Definition: Geometry.h:319
bool xNegative(void) const
Definition: Geometry.h:309
bool fillArea(void) const
Definition: Geometry.h:228