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 gobject.ObjectG;
28 private import gtkc.pango;
29 public  import gtkc.pangotypes;
30 
31 
32 /**
33  * The #PangoLayoutLine structure represents one of the lines resulting
34  * from laying out a paragraph via #PangoLayout. #PangoLayoutLine
35  * structures are obtained by calling pango_layout_get_line() and
36  * are only valid until the text, attributes, or settings of the
37  * parent #PangoLayout are modified.
38  * 
39  * Routines for rendering PangoLayout objects are provided in
40  * code specific to each rendering system.
41  */
42 public class PgLayoutLine
43 {
44 	/** the main Gtk struct */
45 	protected PangoLayoutLine* pangoLayoutLine;
46 
47 	/** Get the main Gtk struct */
48 	public PangoLayoutLine* getPgLayoutLineStruct()
49 	{
50 		return pangoLayoutLine;
51 	}
52 
53 	/** the main Gtk struct as a void* */
54 	protected void* getStruct()
55 	{
56 		return cast(void*)pangoLayoutLine;
57 	}
58 
59 	/**
60 	 * Sets our main struct and passes it to the parent class.
61 	 */
62 	public this (PangoLayoutLine* pangoLayoutLine)
63 	{
64 		this.pangoLayoutLine = pangoLayoutLine;
65 	}
66 
67 	/**
68 	 */
69 
70 	public static GType getType()
71 	{
72 		return pango_layout_line_get_type();
73 	}
74 
75 	/**
76 	 * Computes the logical and ink extents of a layout line. See
77 	 * pango_font_get_glyph_extents() for details about the interpretation
78 	 * of the rectangles.
79 	 *
80 	 * Params:
81 	 *     inkRect = rectangle used to store the extents of
82 	 *         the glyph string as drawn, or %NULL
83 	 *     logicalRect = rectangle used to store the logical
84 	 *         extents of the glyph string, or %NULL
85 	 */
86 	public void getExtents(out PangoRectangle inkRect, out PangoRectangle logicalRect)
87 	{
88 		pango_layout_line_get_extents(pangoLayoutLine, &inkRect, &logicalRect);
89 	}
90 
91 	/**
92 	 * Computes the logical and ink extents of @layout_line in device units.
93 	 * This function just calls pango_layout_line_get_extents() followed by
94 	 * two pango_extents_to_pixels() calls, rounding @ink_rect and @logical_rect
95 	 * such that the rounded rectangles fully contain the unrounded one (that is,
96 	 * passes them as first argument to pango_extents_to_pixels()).
97 	 *
98 	 * Params:
99 	 *     inkRect = rectangle used to store the extents of
100 	 *         the glyph string as drawn, or %NULL
101 	 *     logicalRect = rectangle used to store the logical
102 	 *         extents of the glyph string, or %NULL
103 	 */
104 	public void getPixelExtents(out PangoRectangle inkRect, out PangoRectangle logicalRect)
105 	{
106 		pango_layout_line_get_pixel_extents(pangoLayoutLine, &inkRect, &logicalRect);
107 	}
108 
109 	/**
110 	 * Gets a list of visual ranges corresponding to a given logical range.
111 	 * This list is not necessarily minimal - there may be consecutive
112 	 * ranges which are adjacent. The ranges will be sorted from left to
113 	 * right. The ranges are with respect to the left edge of the entire
114 	 * layout, not with respect to the line.
115 	 *
116 	 * Params:
117 	 *     startIndex = Start byte index of the logical range. If this value
118 	 *         is less than the start index for the line, then
119 	 *         the first range will extend all the way to the leading
120 	 *         edge of the layout. Otherwise it will start at the
121 	 *         leading edge of the first character.
122 	 *     endIndex = Ending byte index of the logical range. If this value
123 	 *         is greater than the end index for the line, then
124 	 *         the last range will extend all the way to the trailing
125 	 *         edge of the layout. Otherwise, it will end at the
126 	 *         trailing edge of the last character.
127 	 *     ranges = location to store a pointer to an array of ranges.
128 	 *         The array will be of length <literal>2*n_ranges</literal>,
129 	 *         with each range starting at <literal>(*ranges)[2*n]</literal>
130 	 *         and of width <literal>(*ranges)[2*n + 1] - (*ranges)[2*n]</literal>.
131 	 *         This array must be freed with g_free(). The coordinates are relative
132 	 *         to the layout and are in Pango units.
133 	 *     nRanges = The number of ranges stored in @ranges.
134 	 */
135 	public void getXRanges(int startIndex, int endIndex, out int[] ranges)
136 	{
137 		int* outranges = null;
138 		int nRanges;
139 		
140 		pango_layout_line_get_x_ranges(pangoLayoutLine, startIndex, endIndex, &outranges, &nRanges);
141 		
142 		ranges = outranges[0 .. nRanges];
143 	}
144 
145 	/**
146 	 * Converts an index within a line to a X position.
147 	 *
148 	 * Params:
149 	 *     index = byte offset of a grapheme within the layout
150 	 *     trailing = an integer indicating the edge of the grapheme to retrieve
151 	 *         the position of. If > 0, the trailing edge of the grapheme,
152 	 *         if 0, the leading of the grapheme.
153 	 *     xPos = location to store the x_offset (in Pango unit)
154 	 */
155 	public void indexToX(int index, bool trailing, out int xPos)
156 	{
157 		pango_layout_line_index_to_x(pangoLayoutLine, index, trailing, &xPos);
158 	}
159 
160 	/**
161 	 * Increase the reference count of a #PangoLayoutLine by one.
162 	 *
163 	 * Return: the line passed in.
164 	 *
165 	 * Since: 1.10
166 	 */
167 	public PgLayoutLine doref()
168 	{
169 		auto p = pango_layout_line_ref(pangoLayoutLine);
170 		
171 		if(p is null)
172 		{
173 			return null;
174 		}
175 		
176 		return ObjectG.getDObject!(PgLayoutLine)(cast(PangoLayoutLine*) p);
177 	}
178 
179 	/**
180 	 * Decrease the reference count of a #PangoLayoutLine by one.
181 	 * If the result is zero, the line and all associated memory
182 	 * will be freed.
183 	 */
184 	public void unref()
185 	{
186 		pango_layout_line_unref(pangoLayoutLine);
187 	}
188 
189 	/**
190 	 * Converts from x offset to the byte index of the corresponding
191 	 * character within the text of the layout. If @x_pos is outside the line,
192 	 * @index_ and @trailing will point to the very first or very last position
193 	 * in the line. This determination is based on the resolved direction
194 	 * of the paragraph; for example, if the resolved direction is
195 	 * right-to-left, then an X position to the right of the line (after it)
196 	 * results in 0 being stored in @index_ and @trailing. An X position to the
197 	 * left of the line results in @index_ pointing to the (logical) last
198 	 * grapheme in the line and @trailing being set to the number of characters
199 	 * in that grapheme. The reverse is true for a left-to-right line.
200 	 *
201 	 * Params:
202 	 *     xPos = the X offset (in Pango units)
203 	 *         from the left edge of the line.
204 	 *     index = location to store calculated byte index for
205 	 *         the grapheme in which the user clicked.
206 	 *     trailing = location to store an integer indicating where
207 	 *         in the grapheme the user clicked. It will either
208 	 *         be zero, or the number of characters in the
209 	 *         grapheme. 0 represents the leading edge of the grapheme.
210 	 *
211 	 * Return: %FALSE if @x_pos was outside the line, %TRUE if inside
212 	 */
213 	public bool xToIndex(int xPos, out int index, out int trailing)
214 	{
215 		return pango_layout_line_x_to_index(pangoLayoutLine, xPos, &index, &trailing) != 0;
216 	}
217 }