summaryrefslogtreecommitdiff
path: root/libs/gtkmm2/pango/pangomm/layoutline.cc
blob: f3ff3724614de75f90856b58231442bdd4f2f36b (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
// Generated by gtkmmproc -- DO NOT MODIFY!

#include <pangomm/layoutline.h>
#include <pangomm/private/layoutline_p.h>

// -*- c++ -*-
/* $Id$ */

/*
 *
 * Copyright 1998-2002 The gtkmm Development Team
 *
 * 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; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <pangomm/layout.h>

namespace Pango {

Rectangle LayoutLine::get_ink_extents() const
{
  Rectangle ink_rect;
  pango_layout_line_get_extents(const_cast<PangoLayoutLine*>(gobj()), ink_rect.gobj(), 0);
  return ink_rect;
}

Rectangle LayoutLine::get_logical_extents() const
{
  Rectangle logical_rect;
  pango_layout_line_get_extents(const_cast<PangoLayoutLine*>(gobj()), 0, logical_rect.gobj());
  return logical_rect;
}

Rectangle LayoutLine::get_pixel_ink_extents() const
{
  Rectangle ink_rect;
  pango_layout_line_get_pixel_extents(const_cast<PangoLayoutLine*>(gobj()), ink_rect.gobj(), 0);
  return ink_rect;
}

Rectangle LayoutLine::get_pixel_logical_extents() const
{
  Rectangle logical_rect;
  pango_layout_line_get_pixel_extents(const_cast<PangoLayoutLine*>(gobj()), 0, logical_rect.gobj());
  return logical_rect;
}

int LayoutLine::index_to_x(int index, bool trailing) const
{
  int x_pos;
  pango_layout_line_index_to_x(const_cast<PangoLayoutLine*>(gobj()), index, trailing, &x_pos);
  return x_pos;
}

Glib::ArrayHandle<std::pair<int,int> > LayoutLine::get_x_ranges(int start_index, int end_index) const
{
  int* ranges = 0;
  int n_ranges = 0;
  pango_layout_line_get_x_ranges(const_cast<PangoLayoutLine*>(gobj()), start_index, end_index, &ranges, &n_ranges);
  return Glib::ArrayHandle<std::pair<int,int> >(reinterpret_cast<std::pair<int,int>*>(ranges), n_ranges, Glib::OWNERSHIP_SHALLOW);
}

} /* namespace Pango */


namespace
{
} // anonymous namespace


/* Why reinterpret_cast<LayoutLine*>(gobject) is needed:
 *
 * A LayoutLine instance is in fact always a PangoLayoutLine instance.
 * Unfortunately, PangoLayoutLine cannot be a member of LayoutLine,
 * because it is an opaque struct.  Also, the C interface does not provide
 * any hooks to install a destroy notification handler, thus we cannot
 * wrap it dynamically either.
 *
 * The cast works because LayoutLine does not have any member data, and
 * it is impossible to derive from it.  This is ensured by not implementing
 * the (protected) default constructor.  The ctor is protected rather than
 * private just to avoid a compile warning.
 */

namespace Glib
{

Glib::RefPtr<Pango::LayoutLine> wrap(PangoLayoutLine* object, bool take_copy)
{
  if(take_copy && object)
    pango_layout_line_ref(object);

  // See the comment at the top of this file, if you want to know why the cast works.
  return Glib::RefPtr<Pango::LayoutLine>(reinterpret_cast<Pango::LayoutLine*>(object));
}

} // namespace Glib


namespace Pango
{


void LayoutLine::reference() const
{
  // See the comment at the top of this file, if you want to know why the cast works.
  pango_layout_line_ref(reinterpret_cast<PangoLayoutLine*>(const_cast<LayoutLine*>(this)));
}

void LayoutLine::unreference() const
{
  // See the comment at the top of this file, if you want to know why the cast works.
  pango_layout_line_unref(reinterpret_cast<PangoLayoutLine*>(const_cast<LayoutLine*>(this)));
}

PangoLayoutLine* LayoutLine::gobj()
{
  // See the comment at the top of this file, if you want to know why the cast works.
  return reinterpret_cast<PangoLayoutLine*>(this);
}

const PangoLayoutLine* LayoutLine::gobj() const
{
  // See the comment at the top of this file, if you want to know why the cast works.
  return reinterpret_cast<const PangoLayoutLine*>(this);
}

PangoLayoutLine* LayoutLine::gobj_copy() const
{
  // See the comment at the top of this file, if you want to know why the cast works.
  PangoLayoutLine *const gobject = reinterpret_cast<PangoLayoutLine*>(const_cast<LayoutLine*>(this));
  pango_layout_line_ref(gobject);
  return gobject;
}


bool LayoutLine::x_to_index(int x_pos, int& index, int& trailing) const
{
  return pango_layout_line_x_to_index(const_cast<PangoLayoutLine*>(gobj()), x_pos, &index, &trailing);
}

void LayoutLine::get_extents(Rectangle& ink_rect, Rectangle& logical_rect) const
{
  pango_layout_line_get_extents(const_cast<PangoLayoutLine*>(gobj()), (ink_rect).gobj(), (logical_rect).gobj());
}

void LayoutLine::get_pixel_extents(Rectangle& ink_rect, Rectangle& logical_rect) const
{
  pango_layout_line_get_pixel_extents(const_cast<PangoLayoutLine*>(gobj()), (ink_rect).gobj(), (logical_rect).gobj());
}

Glib::RefPtr<Pango::Layout> LayoutLine::get_layout()
{
  Glib::RefPtr<Pango::Layout> ref_ptr(Glib::wrap(gobj()->layout));

  if(ref_ptr)
    ref_ptr->reference();

  return ref_ptr;
}

Glib::RefPtr<const Pango::Layout> LayoutLine::get_layout() const
{
  Glib::RefPtr<const Pango::Layout> ref_ptr(Glib::wrap(gobj()->layout));

  if(ref_ptr)
    ref_ptr->reference();

  return ref_ptr;
}

int LayoutLine::get_length() const
{
  return gobj()->length;
}

int LayoutLine::get_start_index() const
{
  return gobj()->start_index;
}


} // namespace Pango