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