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.PgMiscellaneous;
26 
27 private import core.stdc.stdio;
28 private import glib.Str;
29 private import glib.StringG;
30 private import gtkc.pango;
31 public  import gtkc.pangotypes;
32 
33 
34 public struct PgMiscellaneous
35 {
36 	/**
37 	 */
38 
39 	/**
40 	 * Do not use.  Does not do anything.
41 	 *
42 	 * Params:
43 	 *     key = Key to look up, in the form "SECTION/KEY".
44 	 *
45 	 * Return: %NULL
46 	 */
47 	public static string configKeyGet(string key)
48 	{
49 		return Str.toString(pango_config_key_get(Str.toStringz(key)));
50 	}
51 
52 	/**
53 	 * Do not use.  Does not do anything.
54 	 *
55 	 * Params:
56 	 *     key = Key to look up, in the form "SECTION/KEY".
57 	 *
58 	 * Return: %NULL
59 	 */
60 	public static string configKeyGetSystem(string key)
61 	{
62 		return Str.toString(pango_config_key_get_system(Str.toStringz(key)));
63 	}
64 
65 	/**
66 	 * Returns the name of the "pango" subdirectory of LIBDIR
67 	 * (which is set at compile time).
68 	 *
69 	 * Return: the Pango lib directory. The returned string should
70 	 *     not be freed.
71 	 */
72 	public static string getLibSubdirectory()
73 	{
74 		return Str.toString(pango_get_lib_subdirectory());
75 	}
76 
77 	/**
78 	 * Returns the name of the "pango" subdirectory of SYSCONFDIR
79 	 * (which is set at compile time).
80 	 *
81 	 * Return: the Pango sysconf directory. The returned string should
82 	 *     not be freed.
83 	 */
84 	public static string getSysconfSubdirectory()
85 	{
86 		return Str.toString(pango_get_sysconf_subdirectory());
87 	}
88 
89 	/**
90 	 * Checks @ch to see if it is a character that should not be
91 	 * normally rendered on the screen.  This includes all Unicode characters
92 	 * with "ZERO WIDTH" in their name, as well as <firstterm>bidi</firstterm> formatting characters, and
93 	 * a few other ones.  This is totally different from g_unichar_iszerowidth()
94 	 * and is at best misnamed.
95 	 *
96 	 * Params:
97 	 *     ch = a Unicode character
98 	 *
99 	 * Return: %TRUE if @ch is a zero-width character, %FALSE otherwise
100 	 *
101 	 * Since: 1.10
102 	 */
103 	public static bool isZeroWidth(dchar ch)
104 	{
105 		return pango_is_zero_width(ch) != 0;
106 	}
107 
108 	/**
109 	 * This will return the bidirectional embedding levels of the input paragraph
110 	 * as defined by the Unicode Bidirectional Algorithm available at:
111 	 *
112 	 * http://www.unicode.org/reports/tr9/
113 	 *
114 	 * If the input base direction is a weak direction, the direction of the
115 	 * characters in the text will determine the final resolved direction.
116 	 *
117 	 * Params:
118 	 *     text = the text to itemize.
119 	 *     length = the number of bytes (not characters) to process, or -1
120 	 *         if @text is nul-terminated and the length should be calculated.
121 	 *     pbaseDir = input base direction, and output resolved direction.
122 	 *
123 	 * Return: a newly allocated array of embedding levels, one item per
124 	 *     character (not byte), that should be freed using g_free.
125 	 *
126 	 * Since: 1.4
127 	 */
128 	public static ubyte* log2visGetEmbeddingLevels(string text, int length, PangoDirection* pbaseDir)
129 	{
130 		return pango_log2vis_get_embedding_levels(Str.toStringz(text), length, pbaseDir);
131 	}
132 
133 	/**
134 	 * Look up all user defined aliases for the alias @fontname.
135 	 * The resulting font family names will be stored in @families,
136 	 * and the number of families in @n_families.
137 	 *
138 	 * Deprecated: This function is not thread-safe.
139 	 *
140 	 * Params:
141 	 *     fontname = an ascii string
142 	 *     families = will be set to an array of font family names.
143 	 *         this array is owned by pango and should not be freed.
144 	 *     nFamilies = will be set to the length of the @families array.
145 	 */
146 	public static void lookupAliases(string fontname, out string[] families)
147 	{
148 		char** outfamilies = null;
149 		int nFamilies;
150 		
151 		pango_lookup_aliases(Str.toStringz(fontname), &outfamilies, &nFamilies);
152 		
153 		families = Str.toStringArray(outfamilies, nFamilies);
154 	}
155 
156 	/**
157 	 * Parses an enum type and stores the result in @value.
158 	 *
159 	 * If @str does not match the nick name of any of the possible values for the
160 	 * enum and is not an integer, %FALSE is returned, a warning is issued
161 	 * if @warn is %TRUE, and a
162 	 * string representing the list of possible values is stored in
163 	 * @possible_values.  The list is slash-separated, eg.
164 	 * "none/start/middle/end".  If failed and @possible_values is not %NULL,
165 	 * returned string should be freed using g_free().
166 	 *
167 	 * Params:
168 	 *     type = enum type to parse, eg. %PANGO_TYPE_ELLIPSIZE_MODE.
169 	 *     str = string to parse.  May be %NULL.
170 	 *     value = integer to store the result in, or %NULL.
171 	 *     warn = if %TRUE, issue a g_warning() on bad input.
172 	 *     possibleValues = place to store list of possible values on failure, or %NULL.
173 	 *
174 	 * Return: %TRUE if @str was successfully parsed.
175 	 *
176 	 * Since: 1.16
177 	 */
178 	public static bool parseEnum(GType type, string str, out int value, bool warn, out string possibleValues)
179 	{
180 		char* outpossibleValues = null;
181 		
182 		auto p = pango_parse_enum(type, Str.toStringz(str), &value, warn, &outpossibleValues) != 0;
183 		
184 		possibleValues = Str.toString(outpossibleValues);
185 		
186 		return p;
187 	}
188 
189 	/**
190 	 * Parses a font stretch. The allowed values are
191 	 * "ultra_condensed", "extra_condensed", "condensed",
192 	 * "semi_condensed", "normal", "semi_expanded", "expanded",
193 	 * "extra_expanded" and "ultra_expanded". Case variations are
194 	 * ignored and the '_' characters may be omitted.
195 	 *
196 	 * Params:
197 	 *     str = a string to parse.
198 	 *     stretch = a #PangoStretch to store the
199 	 *         result in.
200 	 *     warn = if %TRUE, issue a g_warning() on bad input.
201 	 *
202 	 * Return: %TRUE if @str was successfully parsed.
203 	 */
204 	public static bool parseStretch(string str, out PangoStretch stretch, bool warn)
205 	{
206 		return pango_parse_stretch(Str.toStringz(str), &stretch, warn) != 0;
207 	}
208 
209 	/**
210 	 * Parses a font style. The allowed values are "normal",
211 	 * "italic" and "oblique", case variations being
212 	 * ignored.
213 	 *
214 	 * Params:
215 	 *     str = a string to parse.
216 	 *     style = a #PangoStyle to store the result
217 	 *         in.
218 	 *     warn = if %TRUE, issue a g_warning() on bad input.
219 	 *
220 	 * Return: %TRUE if @str was successfully parsed.
221 	 */
222 	public static bool parseStyle(string str, out PangoStyle style, bool warn)
223 	{
224 		return pango_parse_style(Str.toStringz(str), &style, warn) != 0;
225 	}
226 
227 	/**
228 	 * Parses a font variant. The allowed values are "normal"
229 	 * and "smallcaps" or "small_caps", case variations being
230 	 * ignored.
231 	 *
232 	 * Params:
233 	 *     str = a string to parse.
234 	 *     variant = a #PangoVariant to store the
235 	 *         result in.
236 	 *     warn = if %TRUE, issue a g_warning() on bad input.
237 	 *
238 	 * Return: %TRUE if @str was successfully parsed.
239 	 */
240 	public static bool parseVariant(string str, out PangoVariant variant, bool warn)
241 	{
242 		return pango_parse_variant(Str.toStringz(str), &variant, warn) != 0;
243 	}
244 
245 	/**
246 	 * Parses a font weight. The allowed values are "heavy",
247 	 * "ultrabold", "bold", "normal", "light", "ultraleight"
248 	 * and integers. Case variations are ignored.
249 	 *
250 	 * Params:
251 	 *     str = a string to parse.
252 	 *     weight = a #PangoWeight to store the result
253 	 *         in.
254 	 *     warn = if %TRUE, issue a g_warning() on bad input.
255 	 *
256 	 * Return: %TRUE if @str was successfully parsed.
257 	 */
258 	public static bool parseWeight(string str, out PangoWeight weight, bool warn)
259 	{
260 		return pango_parse_weight(Str.toStringz(str), &weight, warn) != 0;
261 	}
262 
263 	/**
264 	 * Quantizes the thickness and position of a line, typically an
265 	 * underline or strikethrough, to whole device pixels, that is integer
266 	 * multiples of %PANGO_SCALE. The purpose of this function is to avoid
267 	 * such lines looking blurry.
268 	 *
269 	 * Care is taken to make sure @thickness is at least one pixel when this
270 	 * function returns, but returned @position may become zero as a result
271 	 * of rounding.
272 	 *
273 	 * Params:
274 	 *     thickness = pointer to the thickness of a line, in Pango units
275 	 *     position = corresponding position
276 	 *
277 	 * Since: 1.12
278 	 */
279 	public static void quantizeLineGeometry(ref int thickness, ref int position)
280 	{
281 		pango_quantize_line_geometry(&thickness, &position);
282 	}
283 
284 	/**
285 	 * Reads an entire line from a file into a buffer. Lines may
286 	 * be delimited with '\n', '\r', '\n\r', or '\r\n'. The delimiter
287 	 * is not written into the buffer. Text after a '#' character is treated as
288 	 * a comment and skipped. '\' can be used to escape a # character.
289 	 * '\' proceeding a line delimiter combines adjacent lines. A '\' proceeding
290 	 * any other character is ignored and written into the output buffer
291 	 * unmodified.
292 	 *
293 	 * Params:
294 	 *     stream = a stdio stream
295 	 *     str = #GString buffer into which to write the result
296 	 *
297 	 * Return: 0 if the stream was already at an %EOF character, otherwise
298 	 *     the number of lines read (this is useful for maintaining
299 	 *     a line number counter which doesn't combine lines with '\')
300 	 */
301 	public static int readLine(FILE* stream, out StringG str)
302 	{
303 		GString* outstr = new GString;
304 		
305 		auto p = pango_read_line(stream, outstr);
306 		
307 		str = new StringG(outstr);
308 		
309 		return p;
310 	}
311 
312 	/**
313 	 * Scans an integer.
314 	 * Leading white space is skipped.
315 	 *
316 	 * Params:
317 	 *     pos = in/out string position
318 	 *     output = an int into which to write the result
319 	 *
320 	 * Return: %FALSE if a parse error occurred.
321 	 */
322 	public static bool scanInt(ref string pos, out int output)
323 	{
324 		char* outpos = Str.toStringz(pos);
325 		
326 		auto p = pango_scan_int(&outpos, &output) != 0;
327 		
328 		pos = Str.toString(outpos);
329 		
330 		return p;
331 	}
332 
333 	/**
334 	 * Scans a string into a #GString buffer. The string may either
335 	 * be a sequence of non-white-space characters, or a quoted
336 	 * string with '"'. Instead a quoted string, '\"' represents
337 	 * a literal quote. Leading white space outside of quotes is skipped.
338 	 *
339 	 * Params:
340 	 *     pos = in/out string position
341 	 *     output = a #GString into which to write the result
342 	 *
343 	 * Return: %FALSE if a parse error occurred.
344 	 */
345 	public static bool scanString(ref string pos, out StringG output)
346 	{
347 		char* outpos = Str.toStringz(pos);
348 		GString* outoutput = new GString;
349 		
350 		auto p = pango_scan_string(&outpos, outoutput) != 0;
351 		
352 		pos = Str.toString(outpos);
353 		output = new StringG(outoutput);
354 		
355 		return p;
356 	}
357 
358 	/**
359 	 * Scans a word into a #GString buffer. A word consists
360 	 * of [A-Za-z_] followed by zero or more [A-Za-z_0-9]
361 	 * Leading white space is skipped.
362 	 *
363 	 * Params:
364 	 *     pos = in/out string position
365 	 *     output = a #GString into which to write the result
366 	 *
367 	 * Return: %FALSE if a parse error occurred.
368 	 */
369 	public static bool scanWord(ref string pos, out StringG output)
370 	{
371 		char* outpos = Str.toStringz(pos);
372 		GString* outoutput = new GString;
373 		
374 		auto p = pango_scan_word(&outpos, outoutput) != 0;
375 		
376 		pos = Str.toString(outpos);
377 		output = new StringG(outoutput);
378 		
379 		return p;
380 	}
381 
382 	/**
383 	 * Skips 0 or more characters of white space.
384 	 *
385 	 * Params:
386 	 *     pos = in/out string position
387 	 *
388 	 * Return: %FALSE if skipping the white space leaves
389 	 *     the position at a '\0' character.
390 	 */
391 	public static bool skipSpace(ref string pos)
392 	{
393 		char* outpos = Str.toStringz(pos);
394 		
395 		auto p = pango_skip_space(&outpos) != 0;
396 		
397 		pos = Str.toString(outpos);
398 		
399 		return p;
400 	}
401 
402 	/**
403 	 * Splits a %G_SEARCHPATH_SEPARATOR-separated list of files, stripping
404 	 * white space and substituting ~/ with $HOME/.
405 	 *
406 	 * Params:
407 	 *     str = a %G_SEARCHPATH_SEPARATOR separated list of filenames
408 	 *
409 	 * Return: a list of
410 	 *     strings to be freed with g_strfreev()
411 	 */
412 	public static string[] splitFileList(string str)
413 	{
414 		return Str.toStringArray(pango_split_file_list(Str.toStringz(str)));
415 	}
416 
417 	/**
418 	 * Trims leading and trailing whitespace from a string.
419 	 *
420 	 * Params:
421 	 *     str = a string
422 	 *
423 	 * Return: A newly-allocated string that must be freed with g_free()
424 	 */
425 	public static string trimString(string str)
426 	{
427 		return Str.toString(pango_trim_string(Str.toStringz(str)));
428 	}
429 }