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