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