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