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