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