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