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.PgLayoutLine;
26 
27 private import glib.ListSG;
28 private import glib.MemorySlice;
29 private import gobject.ObjectG;
30 public  import gtkc.pangotypes;
31 private import gtkd.Loader;
32 private import pango.PgLayout;
33 private import pango.c.functions;
34 public  import pango.c.types;
35 
36 
37 /**
38  * The #PangoLayoutLine structure represents one of the lines resulting
39  * from laying out a paragraph via #PangoLayout. #PangoLayoutLine
40  * structures are obtained by calling pango_layout_get_line() and
41  * are only valid until the text, attributes, or settings of the
42  * parent #PangoLayout are modified.
43  * 
44  * Routines for rendering PangoLayout objects are provided in
45  * code specific to each rendering system.
46  */
47 public final class PgLayoutLine
48 {
49 	/** the main Gtk struct */
50 	protected PangoLayoutLine* pangoLayoutLine;
51 	protected bool ownedRef;
52 
53 	/** Get the main Gtk struct */
54 	public PangoLayoutLine* getPgLayoutLineStruct(bool transferOwnership = false)
55 	{
56 		if (transferOwnership)
57 			ownedRef = false;
58 		return pangoLayoutLine;
59 	}
60 
61 	/** the main Gtk struct as a void* */
62 	protected void* getStruct()
63 	{
64 		return cast(void*)pangoLayoutLine;
65 	}
66 
67 	/**
68 	 * Sets our main struct and passes it to the parent class.
69 	 */
70 	public this (PangoLayoutLine* pangoLayoutLine, bool ownedRef = false)
71 	{
72 		this.pangoLayoutLine = pangoLayoutLine;
73 		this.ownedRef = ownedRef;
74 	}
75 
76 	~this ()
77 	{
78 		if ( Linker.isLoaded(LIBRARY_PANGO) && ownedRef )
79 			pango_layout_line_unref(pangoLayoutLine);
80 	}
81 
82 
83 	/**
84 	 * the layout this line belongs to, might be %NULL
85 	 */
86 	public @property PgLayout layout()
87 	{
88 		return ObjectG.getDObject!(PgLayout)(pangoLayoutLine.layout, false);
89 	}
90 
91 	/** Ditto */
92 	public @property void layout(PgLayout value)
93 	{
94 		pangoLayoutLine.layout = value.getPgLayoutStruct();
95 	}
96 
97 	/**
98 	 * start of line as byte index into layout->text
99 	 */
100 	public @property int startIndex()
101 	{
102 		return pangoLayoutLine.startIndex;
103 	}
104 
105 	/** Ditto */
106 	public @property void startIndex(int value)
107 	{
108 		pangoLayoutLine.startIndex = value;
109 	}
110 
111 	/**
112 	 * length of line in bytes
113 	 */
114 	public @property int length()
115 	{
116 		return pangoLayoutLine.length;
117 	}
118 
119 	/** Ditto */
120 	public @property void length(int value)
121 	{
122 		pangoLayoutLine.length = value;
123 	}
124 
125 	/**
126 	 * list of runs in the
127 	 * line, from left to right
128 	 */
129 	public @property ListSG runs()
130 	{
131 		return new ListSG(pangoLayoutLine.runs, false);
132 	}
133 
134 	/** Ditto */
135 	public @property void runs(ListSG value)
136 	{
137 		pangoLayoutLine.runs = value.getListSGStruct();
138 	}
139 
140 	/**
141 	 * #TRUE if this is the first line of the paragraph
142 	 */
143 	public @property uint isParagraphStart()
144 	{
145 		return pangoLayoutLine.isParagraphStart;
146 	}
147 
148 	/** Ditto */
149 	public @property void isParagraphStart(uint value)
150 	{
151 		pangoLayoutLine.isParagraphStart = value;
152 	}
153 
154 	/**
155 	 * #Resolved PangoDirection of line
156 	 */
157 	public @property uint resolvedDir()
158 	{
159 		return pangoLayoutLine.resolvedDir;
160 	}
161 
162 	/** Ditto */
163 	public @property void resolvedDir(uint value)
164 	{
165 		pangoLayoutLine.resolvedDir = value;
166 	}
167 
168 	/** */
169 	public static GType getType()
170 	{
171 		return pango_layout_line_get_type();
172 	}
173 
174 	/**
175 	 * Computes the logical and ink extents of a layout line. See
176 	 * pango_font_get_glyph_extents() for details about the interpretation
177 	 * of the rectangles.
178 	 *
179 	 * Params:
180 	 *     inkRect = rectangle used to store the extents of
181 	 *         the glyph string as drawn, or %NULL
182 	 *     logicalRect = rectangle used to store the logical
183 	 *         extents of the glyph string, or %NULL
184 	 */
185 	public void getExtents(out PangoRectangle inkRect, out PangoRectangle logicalRect)
186 	{
187 		pango_layout_line_get_extents(pangoLayoutLine, &inkRect, &logicalRect);
188 	}
189 
190 	/**
191 	 * Computes the logical and ink extents of @layout_line in device units.
192 	 * This function just calls pango_layout_line_get_extents() followed by
193 	 * two pango_extents_to_pixels() calls, rounding @ink_rect and @logical_rect
194 	 * such that the rounded rectangles fully contain the unrounded one (that is,
195 	 * passes them as first argument to pango_extents_to_pixels()).
196 	 *
197 	 * Params:
198 	 *     inkRect = rectangle used to store the extents of
199 	 *         the glyph string as drawn, or %NULL
200 	 *     logicalRect = rectangle used to store the logical
201 	 *         extents of the glyph string, or %NULL
202 	 */
203 	public void getPixelExtents(out PangoRectangle inkRect, out PangoRectangle logicalRect)
204 	{
205 		pango_layout_line_get_pixel_extents(pangoLayoutLine, &inkRect, &logicalRect);
206 	}
207 
208 	/**
209 	 * Gets a list of visual ranges corresponding to a given logical range.
210 	 * This list is not necessarily minimal - there may be consecutive
211 	 * ranges which are adjacent. The ranges will be sorted from left to
212 	 * right. The ranges are with respect to the left edge of the entire
213 	 * layout, not with respect to the line.
214 	 *
215 	 * Params:
216 	 *     startIndex = Start byte index of the logical range. If this value
217 	 *         is less than the start index for the line, then
218 	 *         the first range will extend all the way to the leading
219 	 *         edge of the layout. Otherwise it will start at the
220 	 *         leading edge of the first character.
221 	 *     endIndex = Ending byte index of the logical range. If this value
222 	 *         is greater than the end index for the line, then
223 	 *         the last range will extend all the way to the trailing
224 	 *         edge of the layout. Otherwise, it will end at the
225 	 *         trailing edge of the last character.
226 	 *     ranges = location to store a pointer to an array of ranges.
227 	 *         The array will be of length <literal>2*n_ranges</literal>,
228 	 *         with each range starting at <literal>(*ranges)[2*n]</literal>
229 	 *         and of width <literal>(*ranges)[2*n + 1] - (*ranges)[2*n]</literal>.
230 	 *         This array must be freed with g_free(). The coordinates are relative
231 	 *         to the layout and are in Pango units.
232 	 */
233 	public void getXRanges(int startIndex, int endIndex, out int[] ranges)
234 	{
235 		int* outranges = null;
236 		int nRanges;
237 
238 		pango_layout_line_get_x_ranges(pangoLayoutLine, startIndex, endIndex, &outranges, &nRanges);
239 
240 		ranges = outranges[0 .. nRanges];
241 	}
242 
243 	/**
244 	 * Converts an index within a line to a X position.
245 	 *
246 	 * Params:
247 	 *     index = byte offset of a grapheme within the layout
248 	 *     trailing = an integer indicating the edge of the grapheme to retrieve
249 	 *         the position of. If > 0, the trailing edge of the grapheme,
250 	 *         if 0, the leading of the grapheme.
251 	 *     xPos = location to store the x_offset (in Pango unit)
252 	 */
253 	public void indexToX(int index, bool trailing, out int xPos)
254 	{
255 		pango_layout_line_index_to_x(pangoLayoutLine, index, trailing, &xPos);
256 	}
257 
258 	alias doref = ref_;
259 	/**
260 	 * Increase the reference count of a #PangoLayoutLine by one.
261 	 *
262 	 * Returns: the line passed in.
263 	 *
264 	 * Since: 1.10
265 	 */
266 	public PgLayoutLine ref_()
267 	{
268 		auto p = pango_layout_line_ref(pangoLayoutLine);
269 
270 		if(p is null)
271 		{
272 			return null;
273 		}
274 
275 		return ObjectG.getDObject!(PgLayoutLine)(cast(PangoLayoutLine*) p, true);
276 	}
277 
278 	/**
279 	 * Decrease the reference count of a #PangoLayoutLine by one.
280 	 * If the result is zero, the line and all associated memory
281 	 * will be freed.
282 	 */
283 	public void unref()
284 	{
285 		pango_layout_line_unref(pangoLayoutLine);
286 	}
287 
288 	/**
289 	 * Converts from x offset to the byte index of the corresponding
290 	 * character within the text of the layout. If @x_pos is outside the line,
291 	 * @index_ and @trailing will point to the very first or very last position
292 	 * in the line. This determination is based on the resolved direction
293 	 * of the paragraph; for example, if the resolved direction is
294 	 * right-to-left, then an X position to the right of the line (after it)
295 	 * results in 0 being stored in @index_ and @trailing. An X position to the
296 	 * left of the line results in @index_ pointing to the (logical) last
297 	 * grapheme in the line and @trailing being set to the number of characters
298 	 * in that grapheme. The reverse is true for a left-to-right line.
299 	 *
300 	 * Params:
301 	 *     xPos = the X offset (in Pango units)
302 	 *         from the left edge of the line.
303 	 *     index = location to store calculated byte index for
304 	 *         the grapheme in which the user clicked.
305 	 *     trailing = location to store an integer indicating where
306 	 *         in the grapheme the user clicked. It will either
307 	 *         be zero, or the number of characters in the
308 	 *         grapheme. 0 represents the leading edge of the grapheme.
309 	 *
310 	 * Returns: %FALSE if @x_pos was outside the line, %TRUE if inside
311 	 */
312 	public bool xToIndex(int xPos, out int index, out int trailing)
313 	{
314 		return pango_layout_line_x_to_index(pangoLayoutLine, xPos, &index, &trailing) != 0;
315 	}
316 }