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.PgGlyphString;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import gobject.ObjectG;
30 private import gtkc.pango;
31 public  import gtkc.pangotypes;
32 private import pango.PgFont;
33 
34 
35 /**
36  * The #PangoGlyphString structure is used to store strings
37  * of glyphs with geometry and visual attribute information.
38  * The storage for the glyph information is owned
39  * by the structure which simplifies memory management.
40  */
41 public class PgGlyphString
42 {
43 	/** the main Gtk struct */
44 	protected PangoGlyphString* pangoGlyphString;
45 	protected bool ownedRef;
46 
47 	/** Get the main Gtk struct */
48 	public PangoGlyphString* getPgGlyphStringStruct()
49 	{
50 		return pangoGlyphString;
51 	}
52 
53 	/** the main Gtk struct as a void* */
54 	protected void* getStruct()
55 	{
56 		return cast(void*)pangoGlyphString;
57 	}
58 
59 	/**
60 	 * Sets our main struct and passes it to the parent class.
61 	 */
62 	public this (PangoGlyphString* pangoGlyphString, bool ownedRef = false)
63 	{
64 		this.pangoGlyphString = pangoGlyphString;
65 		this.ownedRef = ownedRef;
66 	}
67 
68 
69 	/** */
70 	public static GType getType()
71 	{
72 		return pango_glyph_string_get_type();
73 	}
74 
75 	/**
76 	 * Create a new #PangoGlyphString.
77 	 *
78 	 * Return: the newly allocated #PangoGlyphString, which
79 	 *     should be freed with pango_glyph_string_free().
80 	 *
81 	 * Throws: ConstructionException GTK+ fails to create the object.
82 	 */
83 	public this()
84 	{
85 		auto p = pango_glyph_string_new();
86 		
87 		if(p is null)
88 		{
89 			throw new ConstructionException("null returned by new");
90 		}
91 		
92 		this(cast(PangoGlyphString*) p);
93 	}
94 
95 	/**
96 	 * Copy a glyph string and associated storage.
97 	 *
98 	 * Return: the newly allocated #PangoGlyphString,
99 	 *     which should be freed with pango_glyph_string_free(),
100 	 *     or %NULL if @string was %NULL.
101 	 */
102 	public PgGlyphString copy()
103 	{
104 		auto p = pango_glyph_string_copy(pangoGlyphString);
105 		
106 		if(p is null)
107 		{
108 			return null;
109 		}
110 		
111 		return ObjectG.getDObject!(PgGlyphString)(cast(PangoGlyphString*) p, true);
112 	}
113 
114 	/**
115 	 * Compute the logical and ink extents of a glyph string. See the documentation
116 	 * for pango_font_get_glyph_extents() for details about the interpretation
117 	 * of the rectangles.
118 	 *
119 	 * Params:
120 	 *     font = a #PangoFont
121 	 *     inkRect = rectangle used to store the extents of the glyph string
122 	 *         as drawn or %NULL to indicate that the result is not needed.
123 	 *     logicalRect = rectangle used to store the logical extents of the
124 	 *         glyph string or %NULL to indicate that the result is not needed.
125 	 */
126 	public void extents(PgFont font, out PangoRectangle inkRect, out PangoRectangle logicalRect)
127 	{
128 		pango_glyph_string_extents(pangoGlyphString, (font is null) ? null : font.getPgFontStruct(), &inkRect, &logicalRect);
129 	}
130 
131 	/**
132 	 * Computes the extents of a sub-portion of a glyph string. The extents are
133 	 * relative to the start of the glyph string range (the origin of their
134 	 * coordinate system is at the start of the range, not at the start of the entire
135 	 * glyph string).
136 	 *
137 	 * Params:
138 	 *     start = start index
139 	 *     end = end index (the range is the set of bytes with
140 	 *         indices such that start <= index < end)
141 	 *     font = a #PangoFont
142 	 *     inkRect = rectangle used to
143 	 *         store the extents of the glyph string range as drawn or
144 	 *         %NULL to indicate that the result is not needed.
145 	 *     logicalRect = rectangle used to
146 	 *         store the logical extents of the glyph string range or
147 	 *         %NULL to indicate that the result is not needed.
148 	 */
149 	public void extentsRange(int start, int end, PgFont font, out PangoRectangle inkRect, out PangoRectangle logicalRect)
150 	{
151 		pango_glyph_string_extents_range(pangoGlyphString, start, end, (font is null) ? null : font.getPgFontStruct(), &inkRect, &logicalRect);
152 	}
153 
154 	/**
155 	 * Free a glyph string and associated storage.
156 	 */
157 	public void free()
158 	{
159 		pango_glyph_string_free(pangoGlyphString);
160 	}
161 
162 	/**
163 	 * Given a #PangoGlyphString resulting from pango_shape() and the corresponding
164 	 * text, determine the screen width corresponding to each character. When
165 	 * multiple characters compose a single cluster, the width of the entire
166 	 * cluster is divided equally among the characters.
167 	 *
168 	 * See also pango_glyph_item_get_logical_widths().
169 	 *
170 	 * Params:
171 	 *     text = the text corresponding to the glyphs
172 	 *     length = the length of @text, in bytes
173 	 *     embeddingLevel = the embedding level of the string
174 	 *     logicalWidths = an array whose length is the number of
175 	 *         characters in text (equal to g_utf8_strlen (text,
176 	 *         length) unless text has NUL bytes) to be filled in
177 	 *         with the resulting character widths.
178 	 */
179 	public void getLogicalWidths(string text, int length, int embeddingLevel, int[] logicalWidths)
180 	{
181 		pango_glyph_string_get_logical_widths(pangoGlyphString, Str.toStringz(text), length, embeddingLevel, logicalWidths.ptr);
182 	}
183 
184 	/**
185 	 * Computes the logical width of the glyph string as can also be computed
186 	 * using pango_glyph_string_extents().  However, since this only computes the
187 	 * width, it's much faster.  This is in fact only a convenience function that
188 	 * computes the sum of geometry.width for each glyph in the @glyphs.
189 	 *
190 	 * Return: the logical width of the glyph string.
191 	 *
192 	 * Since: 1.14
193 	 */
194 	public int getWidth()
195 	{
196 		return pango_glyph_string_get_width(pangoGlyphString);
197 	}
198 
199 	/**
200 	 * Converts from character position to x position. (X position
201 	 * is measured from the left edge of the run). Character positions
202 	 * are computed by dividing up each cluster into equal portions.
203 	 *
204 	 * Params:
205 	 *     text = the text for the run
206 	 *     length = the number of bytes (not characters) in @text.
207 	 *     analysis = the analysis information return from pango_itemize()
208 	 *     index = the byte index within @text
209 	 *     trailing = whether we should compute the result for the beginning (%FALSE)
210 	 *         or end (%TRUE) of the character.
211 	 *     xPos = location to store result
212 	 */
213 	public void indexToX(string text, int length, PangoAnalysis* analysis, int index, bool trailing, out int xPos)
214 	{
215 		pango_glyph_string_index_to_x(pangoGlyphString, Str.toStringz(text), length, analysis, index, trailing, &xPos);
216 	}
217 
218 	/**
219 	 * Resize a glyph string to the given length.
220 	 *
221 	 * Params:
222 	 *     newLen = the new length of the string.
223 	 */
224 	public void setSize(int newLen)
225 	{
226 		pango_glyph_string_set_size(pangoGlyphString, newLen);
227 	}
228 
229 	/**
230 	 * Convert from x offset to character position. Character positions
231 	 * are computed by dividing up each cluster into equal portions.
232 	 * In scripts where positioning within a cluster is not allowed
233 	 * (such as Thai), the returned value may not be a valid cursor
234 	 * position; the caller must combine the result with the logical
235 	 * attributes for the text to compute the valid cursor position.
236 	 *
237 	 * Params:
238 	 *     text = the text for the run
239 	 *     length = the number of bytes (not characters) in text.
240 	 *     analysis = the analysis information return from pango_itemize()
241 	 *     xPos = the x offset (in Pango units)
242 	 *     index = location to store calculated byte index within @text
243 	 *     trailing = location to store a boolean indicating
244 	 *         whether the user clicked on the leading or trailing
245 	 *         edge of the character.
246 	 */
247 	public void xToIndex(string text, int length, PangoAnalysis* analysis, int xPos, out int index, out int trailing)
248 	{
249 		pango_glyph_string_x_to_index(pangoGlyphString, Str.toStringz(text), length, analysis, xPos, &index, &trailing);
250 	}
251 }