1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module pango.PgLayoutIter;
26 
27 private import gobject.ObjectG;
28 public  import gtkc.pangotypes;
29 private import gtkd.Loader;
30 private import pango.PgLayout;
31 private import pango.PgLayoutLine;
32 private import pango.c.functions;
33 public  import pango.c.types;
34 
35 
36 /**
37  * A #PangoLayoutIter structure can be used to
38  * iterate over the visual extents of a #PangoLayout.
39  * 
40  * The #PangoLayoutIter structure is opaque, and
41  * has no user-visible fields.
42  */
43 public class PgLayoutIter
44 {
45 	/** the main Gtk struct */
46 	protected PangoLayoutIter* pangoLayoutIter;
47 	protected bool ownedRef;
48 
49 	/** Get the main Gtk struct */
50 	public PangoLayoutIter* getPgLayoutIterStruct(bool transferOwnership = false)
51 	{
52 		if (transferOwnership)
53 			ownedRef = false;
54 		return pangoLayoutIter;
55 	}
56 
57 	/** the main Gtk struct as a void* */
58 	protected void* getStruct()
59 	{
60 		return cast(void*)pangoLayoutIter;
61 	}
62 
63 	/**
64 	 * Sets our main struct and passes it to the parent class.
65 	 */
66 	public this (PangoLayoutIter* pangoLayoutIter, bool ownedRef = false)
67 	{
68 		this.pangoLayoutIter = pangoLayoutIter;
69 		this.ownedRef = ownedRef;
70 	}
71 
72 	~this ()
73 	{
74 		if ( Linker.isLoaded(LIBRARY_PANGO) && ownedRef )
75 			pango_layout_iter_free(pangoLayoutIter);
76 	}
77 
78 
79 	/** */
80 	public static GType getType()
81 	{
82 		return pango_layout_iter_get_type();
83 	}
84 
85 	/**
86 	 * Determines whether @iter is on the last line of the layout.
87 	 *
88 	 * Returns: %TRUE if @iter is on the last line.
89 	 */
90 	public bool atLastLine()
91 	{
92 		return pango_layout_iter_at_last_line(pangoLayoutIter) != 0;
93 	}
94 
95 	/**
96 	 * Copies a #PangoLayoutIter.
97 	 *
98 	 * Returns: the newly allocated #PangoLayoutIter,
99 	 *     which should be freed with pango_layout_iter_free(),
100 	 *     or %NULL if @iter was %NULL.
101 	 *
102 	 * Since: 1.20
103 	 */
104 	public PgLayoutIter copy()
105 	{
106 		auto p = pango_layout_iter_copy(pangoLayoutIter);
107 
108 		if(p is null)
109 		{
110 			return null;
111 		}
112 
113 		return ObjectG.getDObject!(PgLayoutIter)(cast(PangoLayoutIter*) p, true);
114 	}
115 
116 	/**
117 	 * Frees an iterator that's no longer in use.
118 	 */
119 	public void free()
120 	{
121 		pango_layout_iter_free(pangoLayoutIter);
122 		ownedRef = false;
123 	}
124 
125 	/**
126 	 * Gets the Y position of the current line's baseline, in layout
127 	 * coordinates (origin at top left of the entire layout).
128 	 *
129 	 * Returns: baseline of current line.
130 	 */
131 	public int getBaseline()
132 	{
133 		return pango_layout_iter_get_baseline(pangoLayoutIter);
134 	}
135 
136 	/**
137 	 * Gets the extents of the current character, in layout coordinates
138 	 * (origin is the top left of the entire layout). Only logical extents
139 	 * can sensibly be obtained for characters; ink extents make sense only
140 	 * down to the level of clusters.
141 	 *
142 	 * Params:
143 	 *     logicalRect = rectangle to fill with
144 	 *         logical extents
145 	 */
146 	public void getCharExtents(out PangoRectangle logicalRect)
147 	{
148 		pango_layout_iter_get_char_extents(pangoLayoutIter, &logicalRect);
149 	}
150 
151 	/**
152 	 * Gets the extents of the current cluster, in layout coordinates
153 	 * (origin is the top left of the entire layout).
154 	 *
155 	 * Params:
156 	 *     inkRect = rectangle to fill with ink extents, or %NULL
157 	 *     logicalRect = rectangle to fill with logical extents, or %NULL
158 	 */
159 	public void getClusterExtents(out PangoRectangle inkRect, out PangoRectangle logicalRect)
160 	{
161 		pango_layout_iter_get_cluster_extents(pangoLayoutIter, &inkRect, &logicalRect);
162 	}
163 
164 	/**
165 	 * Gets the current byte index. Note that iterating forward by char
166 	 * moves in visual order, not logical order, so indexes may not be
167 	 * sequential. Also, the index may be equal to the length of the text
168 	 * in the layout, if on the %NULL run (see pango_layout_iter_get_run()).
169 	 *
170 	 * Returns: current byte index.
171 	 */
172 	public int getIndex()
173 	{
174 		return pango_layout_iter_get_index(pangoLayoutIter);
175 	}
176 
177 	/**
178 	 * Gets the layout associated with a #PangoLayoutIter.
179 	 *
180 	 * Returns: the layout associated with @iter.
181 	 *
182 	 * Since: 1.20
183 	 */
184 	public PgLayout getLayout()
185 	{
186 		auto p = pango_layout_iter_get_layout(pangoLayoutIter);
187 
188 		if(p is null)
189 		{
190 			return null;
191 		}
192 
193 		return ObjectG.getDObject!(PgLayout)(cast(PangoLayout*) p);
194 	}
195 
196 	/**
197 	 * Obtains the extents of the #PangoLayout being iterated
198 	 * over. @ink_rect or @logical_rect can be %NULL if you
199 	 * aren't interested in them.
200 	 *
201 	 * Params:
202 	 *     inkRect = rectangle to fill with ink extents,
203 	 *         or %NULL
204 	 *     logicalRect = rectangle to fill with logical
205 	 *         extents, or %NULL
206 	 */
207 	public void getLayoutExtents(out PangoRectangle inkRect, out PangoRectangle logicalRect)
208 	{
209 		pango_layout_iter_get_layout_extents(pangoLayoutIter, &inkRect, &logicalRect);
210 	}
211 
212 	/**
213 	 * Gets the current line.
214 	 *
215 	 * Use the faster pango_layout_iter_get_line_readonly() if you do not plan
216 	 * to modify the contents of the line (glyphs, glyph widths, etc.).
217 	 *
218 	 * Returns: the current line.
219 	 */
220 	public PgLayoutLine getLine()
221 	{
222 		auto p = pango_layout_iter_get_line(pangoLayoutIter);
223 
224 		if(p is null)
225 		{
226 			return null;
227 		}
228 
229 		return ObjectG.getDObject!(PgLayoutLine)(cast(PangoLayoutLine*) p, true);
230 	}
231 
232 	/**
233 	 * Obtains the extents of the current line. @ink_rect or @logical_rect
234 	 * can be %NULL if you aren't interested in them. Extents are in layout
235 	 * coordinates (origin is the top-left corner of the entire
236 	 * #PangoLayout).  Thus the extents returned by this function will be
237 	 * the same width/height but not at the same x/y as the extents
238 	 * returned from pango_layout_line_get_extents().
239 	 *
240 	 * Params:
241 	 *     inkRect = rectangle to fill with ink extents, or %NULL
242 	 *     logicalRect = rectangle to fill with logical extents, or %NULL
243 	 */
244 	public void getLineExtents(out PangoRectangle inkRect, out PangoRectangle logicalRect)
245 	{
246 		pango_layout_iter_get_line_extents(pangoLayoutIter, &inkRect, &logicalRect);
247 	}
248 
249 	/**
250 	 * Gets the current line for read-only access.
251 	 *
252 	 * This is a faster alternative to pango_layout_iter_get_line(),
253 	 * but the user is not expected
254 	 * to modify the contents of the line (glyphs, glyph widths, etc.).
255 	 *
256 	 * Returns: the current line, that should not be
257 	 *     modified.
258 	 *
259 	 * Since: 1.16
260 	 */
261 	public PgLayoutLine getLineReadonly()
262 	{
263 		auto p = pango_layout_iter_get_line_readonly(pangoLayoutIter);
264 
265 		if(p is null)
266 		{
267 			return null;
268 		}
269 
270 		return ObjectG.getDObject!(PgLayoutLine)(cast(PangoLayoutLine*) p);
271 	}
272 
273 	/**
274 	 * Divides the vertical space in the #PangoLayout being iterated over
275 	 * between the lines in the layout, and returns the space belonging to
276 	 * the current line.  A line's range includes the line's logical
277 	 * extents, plus half of the spacing above and below the line, if
278 	 * pango_layout_set_spacing() has been called to set layout spacing.
279 	 * The Y positions are in layout coordinates (origin at top left of the
280 	 * entire layout).
281 	 *
282 	 * Params:
283 	 *     y0 = start of line, or %NULL
284 	 *     y1 = end of line, or %NULL
285 	 */
286 	public void getLineYrange(out int y0, out int y1)
287 	{
288 		pango_layout_iter_get_line_yrange(pangoLayoutIter, &y0, &y1);
289 	}
290 
291 	/**
292 	 * Gets the current run. When iterating by run, at the end of each
293 	 * line, there's a position with a %NULL run, so this function can return
294 	 * %NULL. The %NULL run at the end of each line ensures that all lines have
295 	 * at least one run, even lines consisting of only a newline.
296 	 *
297 	 * Use the faster pango_layout_iter_get_run_readonly() if you do not plan
298 	 * to modify the contents of the run (glyphs, glyph widths, etc.).
299 	 *
300 	 * Returns: the current run.
301 	 */
302 	public PangoLayoutRun* getRun()
303 	{
304 		return pango_layout_iter_get_run(pangoLayoutIter);
305 	}
306 
307 	/**
308 	 * Gets the extents of the current run in layout coordinates
309 	 * (origin is the top left of the entire layout).
310 	 *
311 	 * Params:
312 	 *     inkRect = rectangle to fill with ink extents, or %NULL
313 	 *     logicalRect = rectangle to fill with logical extents, or %NULL
314 	 */
315 	public void getRunExtents(out PangoRectangle inkRect, out PangoRectangle logicalRect)
316 	{
317 		pango_layout_iter_get_run_extents(pangoLayoutIter, &inkRect, &logicalRect);
318 	}
319 
320 	/**
321 	 * Gets the current run. When iterating by run, at the end of each
322 	 * line, there's a position with a %NULL run, so this function can return
323 	 * %NULL. The %NULL run at the end of each line ensures that all lines have
324 	 * at least one run, even lines consisting of only a newline.
325 	 *
326 	 * This is a faster alternative to pango_layout_iter_get_run(),
327 	 * but the user is not expected
328 	 * to modify the contents of the run (glyphs, glyph widths, etc.).
329 	 *
330 	 * Returns: the current run, that
331 	 *     should not be modified.
332 	 *
333 	 * Since: 1.16
334 	 */
335 	public PangoLayoutRun* getRunReadonly()
336 	{
337 		return pango_layout_iter_get_run_readonly(pangoLayoutIter);
338 	}
339 
340 	/**
341 	 * Moves @iter forward to the next character in visual order. If @iter was already at
342 	 * the end of the layout, returns %FALSE.
343 	 *
344 	 * Returns: whether motion was possible.
345 	 */
346 	public bool nextChar()
347 	{
348 		return pango_layout_iter_next_char(pangoLayoutIter) != 0;
349 	}
350 
351 	/**
352 	 * Moves @iter forward to the next cluster in visual order. If @iter
353 	 * was already at the end of the layout, returns %FALSE.
354 	 *
355 	 * Returns: whether motion was possible.
356 	 */
357 	public bool nextCluster()
358 	{
359 		return pango_layout_iter_next_cluster(pangoLayoutIter) != 0;
360 	}
361 
362 	/**
363 	 * Moves @iter forward to the start of the next line. If @iter is
364 	 * already on the last line, returns %FALSE.
365 	 *
366 	 * Returns: whether motion was possible.
367 	 */
368 	public bool nextLine()
369 	{
370 		return pango_layout_iter_next_line(pangoLayoutIter) != 0;
371 	}
372 
373 	/**
374 	 * Moves @iter forward to the next run in visual order. If @iter was
375 	 * already at the end of the layout, returns %FALSE.
376 	 *
377 	 * Returns: whether motion was possible.
378 	 */
379 	public bool nextRun()
380 	{
381 		return pango_layout_iter_next_run(pangoLayoutIter) != 0;
382 	}
383 }