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