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