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