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.PgLanguage; 26 27 private import glib.Str; 28 private import glib.c.functions; 29 private import gobject.ObjectG; 30 private import pango.c.functions; 31 public import pango.c.types; 32 33 34 /** 35 * The `PangoLanguage` structure is used to 36 * represent a language. 37 * 38 * `PangoLanguage` pointers can be efficiently 39 * copied and compared with each other. 40 */ 41 public class PgLanguage 42 { 43 /** the main Gtk struct */ 44 protected PangoLanguage* pangoLanguage; 45 protected bool ownedRef; 46 47 /** Get the main Gtk struct */ 48 public PangoLanguage* getPgLanguageStruct(bool transferOwnership = false) 49 { 50 if (transferOwnership) 51 ownedRef = false; 52 return pangoLanguage; 53 } 54 55 /** the main Gtk struct as a void* */ 56 protected void* getStruct() 57 { 58 return cast(void*)pangoLanguage; 59 } 60 61 /** 62 * Sets our main struct and passes it to the parent class. 63 */ 64 public this (PangoLanguage* pangoLanguage, bool ownedRef = false) 65 { 66 this.pangoLanguage = pangoLanguage; 67 this.ownedRef = ownedRef; 68 } 69 70 71 /** */ 72 public static GType getType() 73 { 74 return pango_language_get_type(); 75 } 76 77 /** 78 * Get a string that is representative of the characters needed to 79 * render a particular language. 80 * 81 * The sample text may be a pangram, but is not necessarily. It is chosen 82 * to be demonstrative of normal text in the language, as well as exposing 83 * font feature requirements unique to the language. It is suitable for use 84 * as sample text in a font selection dialog. 85 * 86 * If @language is %NULL, the default language as found by 87 * [type_func@Pango.Language.get_default] is used. 88 * 89 * If Pango does not have a sample string for @language, the classic 90 * "The quick brown fox..." is returned. This can be detected by 91 * comparing the returned pointer value to that returned for (non-existent) 92 * language code "xx". That is, compare to: 93 * 94 * ``` 95 * pango_language_get_sample_string (pango_language_from_string ("xx")) 96 * ``` 97 * 98 * Returns: the sample string. This value is owned by Pango 99 * and should not be freed. 100 */ 101 public string getSampleString() 102 { 103 return Str.toString(pango_language_get_sample_string(pangoLanguage)); 104 } 105 106 /** 107 * Determines the scripts used to to write @language. 108 * 109 * If nothing is known about the language tag @language, 110 * or if @language is %NULL, then %NULL is returned. 111 * The list of scripts returned starts with the script that the 112 * language uses most and continues to the one it uses least. 113 * 114 * The value @num_script points at will be set to the number 115 * of scripts in the returned array (or zero if %NULL is returned). 116 * 117 * Most languages use only one script for writing, but there are 118 * some that use two (Latin and Cyrillic for example), and a few 119 * use three (Japanese for example). Applications should not make 120 * any assumptions on the maximum number of scripts returned 121 * though, except that it is positive if the return value is not 122 * %NULL, and it is a small number. 123 * 124 * The [method@Pango.Language.includes_script] function uses this function 125 * internally. 126 * 127 * Note: while the return value is declared as `PangoScript`, the 128 * returned values are from the `GUnicodeScript` enumeration, which 129 * may have more values. Callers need to handle unknown values. 130 * 131 * Returns: An array of 132 * `PangoScript` values, with the number of entries in the array 133 * stored in @num_scripts, or %NULL if Pango does not have any 134 * information about this particular language tag (also the case 135 * if @language is %NULL). The returned array is owned by Pango 136 * and should not be modified or freed. 137 * 138 * Since: 1.22 139 */ 140 public PangoScript[] getScripts() 141 { 142 int numScripts; 143 144 auto __p = pango_language_get_scripts(pangoLanguage, &numScripts); 145 146 return __p[0 .. numScripts]; 147 } 148 149 /** 150 * Determines if @script is one of the scripts used to 151 * write @language. The returned value is conservative; 152 * if nothing is known about the language tag @language, 153 * %TRUE will be returned, since, as far as Pango knows, 154 * @script might be used to write @language. 155 * 156 * This routine is used in Pango's itemization process when 157 * determining if a supplied language tag is relevant to 158 * a particular section of text. It probably is not useful 159 * for applications in most circumstances. 160 * 161 * This function uses [method@Pango.Language.get_scripts] internally. 162 * 163 * Params: 164 * script = a `PangoScript` 165 * 166 * Returns: %TRUE if @script is one of the scripts used 167 * to write @language or if nothing is known about @language 168 * (including the case that @language is %NULL), %FALSE otherwise. 169 * 170 * Since: 1.4 171 */ 172 public bool includesScript(PangoScript script) 173 { 174 return pango_language_includes_script(pangoLanguage, script) != 0; 175 } 176 177 /** 178 * Checks if a language tag matches one of the elements in a list of 179 * language ranges. 180 * 181 * A language tag is considered to match a range 182 * in the list if the range is '*', the range is exactly the tag, 183 * or the range is a prefix of the tag, and the character after it 184 * in the tag is '-'. 185 * 186 * Params: 187 * rangeList = a list of language ranges, separated by ';', ':', 188 * ',', or space characters. 189 * Each element must either be '*', or a RFC 3066 language range 190 * canonicalized as by [type_func@Pango.Language.from_string] 191 * 192 * Returns: %TRUE if a match was found. 193 */ 194 public bool matches(string rangeList) 195 { 196 return pango_language_matches(pangoLanguage, Str.toStringz(rangeList)) != 0; 197 } 198 199 /** 200 * Gets the RFC-3066 format string representing the given language tag. 201 * 202 * Returns: a string representing the language tag. This is owned by 203 * Pango and should not be freed. 204 */ 205 public override string toString() 206 { 207 return Str.toString(pango_language_to_string(pangoLanguage)); 208 } 209 210 /** 211 * Convert a language tag to a `PangoLanguage`. 212 * 213 * The language tag must be in a RFC-3066 format. `PangoLanguage` pointers 214 * can be efficiently copied (copy the pointer) and compared with other 215 * language tags (compare the pointer.) 216 * 217 * This function first canonicalizes the string by converting it to 218 * lowercase, mapping '_' to '-', and stripping all characters other 219 * than letters and '-'. 220 * 221 * Use [type_func@Pango.Language.get_default] if you want to get the `PangoLanguage` 222 * for the current locale of the process. 223 * 224 * Params: 225 * language = a string representing a language tag, or %NULL 226 * 227 * Returns: an opaque pointer to a 228 * `PangoLanguage` structure, or %NULL if @language was %NULL. The 229 * returned pointer will be valid forever after, and should not be freed. 230 */ 231 public static PgLanguage fromString(string language) 232 { 233 auto __p = pango_language_from_string(Str.toStringz(language)); 234 235 if(__p is null) 236 { 237 return null; 238 } 239 240 return ObjectG.getDObject!(PgLanguage)(cast(PangoLanguage*) __p); 241 } 242 243 /** 244 * Returns the `PangoLanguage` for the current locale of the process. 245 * 246 * On Unix systems, this is the return value is derived from 247 * `setlocale (LC_CTYPE, NULL)`, and the user can 248 * affect this through the environment variables LC_ALL, LC_CTYPE or 249 * LANG (checked in that order). The locale string typically is in 250 * the form lang_COUNTRY, where lang is an ISO-639 language code, and 251 * COUNTRY is an ISO-3166 country code. For instance, sv_FI for 252 * Swedish as written in Finland or pt_BR for Portuguese as written in 253 * Brazil. 254 * 255 * On Windows, the C library does not use any such environment 256 * variables, and setting them won't affect the behavior of functions 257 * like ctime(). The user sets the locale through the Regional Options 258 * in the Control Panel. The C library (in the setlocale() function) 259 * does not use country and language codes, but country and language 260 * names spelled out in English. 261 * However, this function does check the above environment 262 * variables, and does return a Unix-style locale string based on 263 * either said environment variables or the thread's current locale. 264 * 265 * Your application should call `setlocale(LC_ALL, "")` for the user 266 * settings to take effect. GTK does this in its initialization 267 * functions automatically (by calling gtk_set_locale()). 268 * See the setlocale() manpage for more details. 269 * 270 * Note that the default language can change over the life of an application. 271 * 272 * Returns: the default language as a 273 * `PangoLanguage`, must not be freed. 274 * 275 * Since: 1.16 276 */ 277 public static PgLanguage getDefault() 278 { 279 auto __p = pango_language_get_default(); 280 281 if(__p is null) 282 { 283 return null; 284 } 285 286 return ObjectG.getDObject!(PgLanguage)(cast(PangoLanguage*) __p); 287 } 288 289 /** 290 * Returns the list of languages that the user prefers. 291 * 292 * The list is specified by the `PANGO_LANGUAGE` or `LANGUAGE` environment 293 * variables, in order of preference. Note that this list does not necessarily 294 * include the language returned by [type_func@Pango.Language.get_default]. 295 * 296 * When choosing language-specific resources, such as the sample 297 * text returned by [method@Pango.Language.get_sample_string], you should 298 * first try the default language, followed by the languages returned 299 * by this function. 300 * 301 * Returns: a %NULL-terminated array of 302 * `PangoLanguage`* 303 * 304 * Since: 1.48 305 */ 306 public static PgLanguage getPreferred() 307 { 308 auto __p = pango_language_get_preferred(); 309 310 if(__p is null) 311 { 312 return null; 313 } 314 315 return ObjectG.getDObject!(PgLanguage)(cast(PangoLanguage*) __p); 316 } 317 }