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 gtkd.Loader;
31 private import pango.PgFont;
32 private import pango.c.functions;
33 public  import pango.c.types;
34 
35 
36 /**
37  * A `PangoGlyphString` is used to store strings of glyphs with geometry
38  * and visual attribute information.
39  * 
40  * The storage for the glyph information is owned by the structure
41  * 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 [method@Pango.GlyphString.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 [method@Pango.GlyphString.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.
126 	 *
127 	 * See the documentation for [method@Pango.Font.get_glyph_extents] for details
128 	 * about the interpretation of the rectangles.
129 	 *
130 	 * Examples of logical (red) and ink (green) rects:
131 	 *
132 	 * ![](rects1.png) ![](rects2.png)
133 	 *
134 	 * Params:
135 	 *     font = a `PangoFont`
136 	 *     inkRect = rectangle used to store the extents of the glyph string
137 	 *         as drawn or %NULL to indicate that the result is not needed.
138 	 *     logicalRect = rectangle used to store the logical extents of the
139 	 *         glyph string or %NULL to indicate that the result is not needed.
140 	 */
141 	public void extents(PgFont font, out PangoRectangle inkRect, out PangoRectangle logicalRect)
142 	{
143 		pango_glyph_string_extents(pangoGlyphString, (font is null) ? null : font.getPgFontStruct(), &inkRect, &logicalRect);
144 	}
145 
146 	/**
147 	 * Computes the extents of a sub-portion of a glyph string.
148 	 *
149 	 * The extents are relative to the start of the glyph string range
150 	 * (the origin of their coordinate system is at the start of the range,
151 	 * not at the start of the entire glyph string).
152 	 *
153 	 * Params:
154 	 *     start = start index
155 	 *     end = end index (the range is the set of bytes with
156 	 *         indices such that start <= index < end)
157 	 *     font = a `PangoFont`
158 	 *     inkRect = rectangle used to
159 	 *         store the extents of the glyph string range as drawn or
160 	 *         %NULL to indicate that the result is not needed.
161 	 *     logicalRect = rectangle used to
162 	 *         store the logical extents of the glyph string range or
163 	 *         %NULL to indicate that the result is not needed.
164 	 */
165 	public void extentsRange(int start, int end, PgFont font, out PangoRectangle inkRect, out PangoRectangle logicalRect)
166 	{
167 		pango_glyph_string_extents_range(pangoGlyphString, start, end, (font is null) ? null : font.getPgFontStruct(), &inkRect, &logicalRect);
168 	}
169 
170 	/**
171 	 * Free a glyph string and associated storage.
172 	 */
173 	public void free()
174 	{
175 		pango_glyph_string_free(pangoGlyphString);
176 		ownedRef = false;
177 	}
178 
179 	/**
180 	 * Given a `PangoGlyphString` and corresponding text, determine the width
181 	 * corresponding to each character.
182 	 *
183 	 * When multiple characters compose a single cluster, the width of the
184 	 * entire cluster is divided equally among the characters.
185 	 *
186 	 * See also [method@Pango.GlyphItem.get_logical_widths].
187 	 *
188 	 * Params:
189 	 *     text = the text corresponding to the glyphs
190 	 *     length = the length of @text, in bytes
191 	 *     embeddingLevel = the embedding level of the string
192 	 *     logicalWidths = an array whose length is the number of
193 	 *         characters in text (equal to g_utf8_strlen (text,
194 	 *         length) unless text has NUL bytes) to be filled in
195 	 *         with the resulting character widths.
196 	 */
197 	public void getLogicalWidths(string text, int length, int embeddingLevel, int[] logicalWidths)
198 	{
199 		pango_glyph_string_get_logical_widths(pangoGlyphString, Str.toStringz(text), length, embeddingLevel, logicalWidths.ptr);
200 	}
201 
202 	/**
203 	 * Computes the logical width of the glyph string.
204 	 *
205 	 * This can also be computed using [method@Pango.GlyphString.extents].
206 	 * However, since this only computes the width, it's much faster. This
207 	 * is in fact only a convenience function that computes the sum of
208 	 * @geometry.width for each glyph in the @glyphs.
209 	 *
210 	 * Returns: the logical width of the glyph string.
211 	 *
212 	 * Since: 1.14
213 	 */
214 	public int getWidth()
215 	{
216 		return pango_glyph_string_get_width(pangoGlyphString);
217 	}
218 
219 	/**
220 	 * Converts from character position to x position.
221 	 *
222 	 * The X position is measured from the left edge of the run.
223 	 * Character positions are computed by dividing up each cluster
224 	 * into equal portions.
225 	 *
226 	 * Params:
227 	 *     text = the text for the run
228 	 *     length = the number of bytes (not characters) in @text.
229 	 *     analysis = the analysis information return from [func@itemize]
230 	 *     index = the byte index within @text
231 	 *     trailing = whether we should compute the result for the beginning (%FALSE)
232 	 *         or end (%TRUE) of the character.
233 	 *     xPos = location to store result
234 	 */
235 	public void indexToX(string text, int length, PangoAnalysis* analysis, int index, bool trailing, out int xPos)
236 	{
237 		pango_glyph_string_index_to_x(pangoGlyphString, Str.toStringz(text), length, analysis, index, trailing, &xPos);
238 	}
239 
240 	/**
241 	 * Resize a glyph string to the given length.
242 	 *
243 	 * Params:
244 	 *     newLen = the new length of the string.
245 	 */
246 	public void setSize(int newLen)
247 	{
248 		pango_glyph_string_set_size(pangoGlyphString, newLen);
249 	}
250 
251 	/**
252 	 * Convert from x offset to character position.
253 	 *
254 	 * Character positions are computed by dividing up each cluster into
255 	 * equal portions. In scripts where positioning within a cluster is
256 	 * not allowed (such as Thai), the returned value may not be a valid
257 	 * cursor position; the caller must combine the result with the logical
258 	 * attributes for the text to compute the valid cursor position.
259 	 *
260 	 * Params:
261 	 *     text = the text for the run
262 	 *     length = the number of bytes (not characters) in text.
263 	 *     analysis = the analysis information return from [func@itemize]
264 	 *     xPos = the x offset (in Pango units)
265 	 *     index = location to store calculated byte index within @text
266 	 *     trailing = location to store a boolean indicating
267 	 *         whether the user clicked on the leading or trailing
268 	 *         edge of the character.
269 	 */
270 	public void xToIndex(string text, int length, PangoAnalysis* analysis, int xPos, out int index, out int trailing)
271 	{
272 		pango_glyph_string_x_to_index(pangoGlyphString, Str.toStringz(text), length, analysis, xPos, &index, &trailing);
273 	}
274 }