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