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