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