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