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