1/* Copyright (C) 2002 The gtkmm Development Team
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free
15 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 */
17
18#include <pango/pango-types.h>
19
20_DEFS(pangomm,pango)
21
22namespace Pango
23{
24
25/** A Pango::Rectangle represents a rectangle.
26 * It is frequently used to represent the logical or ink extents of a single glyph or section of text.
27 * The coordinate system for each rectangle has its origin at the base line and the horizontal
28 * origin of the character with increasing coordinates extending to the right and down.
29 * get_ascent(), get_descent(), get_lbearing(), and get_rbearing() can be used to convert
30 * from the extents rectangle to more traditional font metrics.
31 * The units of rectangles usually are in 1/Pango::SCALE of a device unit.
32 */
33class Rectangle
34{
35  _CLASS_GENERIC(Rectangle, PangoRectangle)
36
37public:
38  Rectangle();
39  Rectangle(int x, int y, int width, int height);
40  explicit Rectangle(const PangoRectangle* src);
41
42  /** Sets the X coordinate of the left side of the rectangle.
43   * @param x The new X coordinate.
44   */
45  void set_x(int x)        { gobject_.x = x; }
46
47  /** Sets the Y coordinate of the top side of the rectangle.
48   * @param y The new Y coordinate.
49   */
50  void set_y(int y)        { gobject_.y = y; }
51
52  /** Sets the width of the rectangle.
53   * @param w The new width.
54   */
55  void set_width(int w)    { gobject_.width = w; }
56
57  /** Sets the height of the rectangle.
58   * @param h The new height.
59   */
60  void set_height(int h)   { gobject_.height = h; }
61
62  /** Gets the X coordinate of the left side of the rectangle.
63   * @return The X coordinate.
64   */
65  int get_x() const        { return gobject_.x; }
66
67  /** Gets the Y coordinate of the top side of the rectangle.
68   * @return The Y coordinate.
69   */
70  int get_y() const        { return gobject_.y; }
71
72  /** Gets the width of the rectangle.
73   * @return The width.
74   */
75  int get_width() const    { return gobject_.width; }
76
77  /** Gets the height of the rectangle.
78   * @return The height.
79   */
80  int get_height() const   { return gobject_.height; }
81
82  /** Extracts the ascent from a Pango::Rectangle representing glyph extents.
83   * The ascent is the distance from the baseline to the highest point of the character.
84   * This is positive if the glyph ascends above the baseline.
85   * @return The ascent of the character.
86   */
87  int get_ascent() const   { return PANGO_ASCENT(*gobj()); }
88
89  /** Extracts the descent from a Pango::Rectangle representing glyph extents.
90   * The descent is the distance from the baseline to the lowest point of the character.
91   * This is positive if the glyph descends below the baseline.
92   * @return The descent of the character.
93   */
94  int get_descent() const  { return PANGO_DESCENT(*gobj()); }
95
96  /** Extracts the left bearing from a Pango::Rectangle representing glyph extents.
97   * The left bearing is the distance from the horizontal origin to the farthest left point of the character.
98   * This is positive for characters drawn completely to the right of the glyph origin.
99   * @return The left bearing of the character.
100   */
101  int get_lbearing() const { return PANGO_LBEARING(*gobj()); }
102
103  /** Extracts the right bearing from a Pango::Rectangle representing glyph extents.
104   * The right bearing is the distance from the horizontal origin to the farthest right point of the character.
105   * This is positive except for characters drawn completely to the left of the horizontal origin.
106   * @return The right bearing of the character.
107   */
108  int get_rbearing() const { return PANGO_RBEARING(*gobj()); }
109
110  /** Checks for equality of two Pango::Rectangles.
111   * @param rhs The Pango::Rectangle to compare with.
112   * @return true if @a rhs is equal with the rectangle.
113   */
114  bool equal(const Rectangle& rhs) const;
115
116  /// Provides access to the underlying C GObject.
117  PangoRectangle*       gobj()       { return &gobject_; }
118  /// Provides access to the underlying C GObject.
119  const PangoRectangle* gobj() const { return &gobject_; }
120
121protected:
122  PangoRectangle gobject_;
123};
124
125/** @relates Pango::Rectangle */
126inline bool operator==(const Rectangle& lhs, const Rectangle& rhs)
127  { return lhs.equal(rhs); }
128
129/** @relates Pango::Rectangle */
130inline bool operator!=(const Rectangle& lhs, const Rectangle& rhs)
131  { return !lhs.equal(rhs); }
132
133} /* namespace Pango */
134
135
136namespace Glib
137{
138
139/** @relates Pango::Rectangle */
140Pango::Rectangle& wrap(PangoRectangle* object);
141
142/** @relates Pango::Rectangle */
143const Pango::Rectangle& wrap(const PangoRectangle* object);
144
145} /* namespace Glib */
146