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