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