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.PgFontDescription;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import gobject.ObjectG;
30 private import gtkc.pango;
31 public  import gtkc.pangotypes;
32 
33 
34 /**
35  * The #PangoFontDescription structure represents the description
36  * of an ideal font. These structures are used both to list
37  * what fonts are available on the system and also for specifying
38  * the characteristics of a font to load.
39  */
40 public class PgFontDescription
41 {
42 	/** the main Gtk struct */
43 	protected PangoFontDescription* pangoFontDescription;
44 
45 	/** Get the main Gtk struct */
46 	public PangoFontDescription* getPgFontDescriptionStruct()
47 	{
48 		return pangoFontDescription;
49 	}
50 
51 	/** the main Gtk struct as a void* */
52 	protected void* getStruct()
53 	{
54 		return cast(void*)pangoFontDescription;
55 	}
56 
57 	/**
58 	 * Sets our main struct and passes it to the parent class.
59 	 */
60 	public this (PangoFontDescription* pangoFontDescription)
61 	{
62 		this.pangoFontDescription = pangoFontDescription;
63 	}
64 
65 	/**
66 	 * Creates a nwe font description and set the family nd the size
67 	 * Params:
68 	 *  family = Family
69 	 *  size = Size
70 	 */
71 	public this(string family, int size)
72 	{
73 		this();
74 		setFamily(family);
75 		setSize(size * PANGO_SCALE);
76 	}
77 
78 	/**
79 	 */
80 
81 	public static GType getType()
82 	{
83 		return pango_font_description_get_type();
84 	}
85 
86 	/**
87 	 * Creates a new font description structure with all fields unset.
88 	 *
89 	 * Return: the newly allocated #PangoFontDescription, which
90 	 *     should be freed using pango_font_description_free().
91 	 *
92 	 * Throws: ConstructionException GTK+ fails to create the object.
93 	 */
94 	public this()
95 	{
96 		auto p = pango_font_description_new();
97 		
98 		if(p is null)
99 		{
100 			throw new ConstructionException("null returned by new");
101 		}
102 		
103 		this(cast(PangoFontDescription*) p);
104 	}
105 
106 	/**
107 	 * Determines if the style attributes of @new_match are a closer match
108 	 * for @desc than those of @old_match are, or if @old_match is %NULL,
109 	 * determines if @new_match is a match at all.
110 	 * Approximate matching is done for
111 	 * weight and style; other style attributes must match exactly.
112 	 * Style attributes are all attributes other than family and size-related
113 	 * attributes.  Approximate matching for style considers PANGO_STYLE_OBLIQUE
114 	 * and PANGO_STYLE_ITALIC as matches, but not as good a match as when the
115 	 * styles are equal.
116 	 *
117 	 * Note that @old_match must match @desc.
118 	 *
119 	 * Params:
120 	 *     oldMatch = a #PangoFontDescription, or %NULL
121 	 *     newMatch = a #PangoFontDescription
122 	 *
123 	 * Return: %TRUE if @new_match is a better match
124 	 */
125 	public bool betterMatch(PgFontDescription oldMatch, PgFontDescription newMatch)
126 	{
127 		return pango_font_description_better_match(pangoFontDescription, (oldMatch is null) ? null : oldMatch.getPgFontDescriptionStruct(), (newMatch is null) ? null : newMatch.getPgFontDescriptionStruct()) != 0;
128 	}
129 
130 	/**
131 	 * Make a copy of a #PangoFontDescription.
132 	 *
133 	 * Return: the newly allocated #PangoFontDescription, which should
134 	 *     be freed with pango_font_description_free(), or %NULL
135 	 *     if @desc was %NULL.
136 	 */
137 	public PgFontDescription copy()
138 	{
139 		auto p = pango_font_description_copy(pangoFontDescription);
140 		
141 		if(p is null)
142 		{
143 			return null;
144 		}
145 		
146 		return ObjectG.getDObject!(PgFontDescription)(cast(PangoFontDescription*) p);
147 	}
148 
149 	/**
150 	 * Like pango_font_description_copy(), but only a shallow copy is made
151 	 * of the family name and other allocated fields. The result can only
152 	 * be used until @desc is modified or freed. This is meant to be used
153 	 * when the copy is only needed temporarily.
154 	 *
155 	 * Return: the newly allocated #PangoFontDescription, which should
156 	 *     be freed with pango_font_description_free(), or %NULL
157 	 *     if @desc was %NULL.
158 	 */
159 	public PgFontDescription copyStatic()
160 	{
161 		auto p = pango_font_description_copy_static(pangoFontDescription);
162 		
163 		if(p is null)
164 		{
165 			return null;
166 		}
167 		
168 		return ObjectG.getDObject!(PgFontDescription)(cast(PangoFontDescription*) p);
169 	}
170 
171 	/**
172 	 * Compares two font descriptions for equality. Two font descriptions
173 	 * are considered equal if the fonts they describe are provably identical.
174 	 * This means that their masks do not have to match, as long as other fields
175 	 * are all the same. (Two font descriptions may result in identical fonts
176 	 * being loaded, but still compare %FALSE.)
177 	 *
178 	 * Params:
179 	 *     desc2 = another #PangoFontDescription
180 	 *
181 	 * Return: %TRUE if the two font descriptions are identical,
182 	 *     %FALSE otherwise.
183 	 */
184 	public bool equal(PgFontDescription desc2)
185 	{
186 		return pango_font_description_equal(pangoFontDescription, (desc2 is null) ? null : desc2.getPgFontDescriptionStruct()) != 0;
187 	}
188 
189 	/**
190 	 * Frees a font description.
191 	 */
192 	public void free()
193 	{
194 		pango_font_description_free(pangoFontDescription);
195 	}
196 
197 	/**
198 	 * Gets the family name field of a font description. See
199 	 * pango_font_description_set_family().
200 	 *
201 	 * Return: the family name field for the font description, or
202 	 *     %NULL if not previously set.  This has the same life-time
203 	 *     as the font description itself and should not be freed.
204 	 */
205 	public string getFamily()
206 	{
207 		return Str.toString(pango_font_description_get_family(pangoFontDescription));
208 	}
209 
210 	/**
211 	 * Gets the gravity field of a font description. See
212 	 * pango_font_description_set_gravity().
213 	 *
214 	 * Return: the gravity field for the font description. Use
215 	 *     pango_font_description_get_set_fields() to find out if
216 	 *     the field was explicitly set or not.
217 	 *
218 	 * Since: 1.16
219 	 */
220 	public PangoGravity getGravity()
221 	{
222 		return pango_font_description_get_gravity(pangoFontDescription);
223 	}
224 
225 	/**
226 	 * Determines which fields in a font description have been set.
227 	 *
228 	 * Return: a bitmask with bits set corresponding to the
229 	 *     fields in @desc that have been set.
230 	 */
231 	public PangoFontMask getSetFields()
232 	{
233 		return pango_font_description_get_set_fields(pangoFontDescription);
234 	}
235 
236 	/**
237 	 * Gets the size field of a font description.
238 	 * See pango_font_description_set_size().
239 	 *
240 	 * Return: the size field for the font description in points or device units.
241 	 *     You must call pango_font_description_get_size_is_absolute()
242 	 *     to find out which is the case. Returns 0 if the size field has not
243 	 *     previously been set or it has been set to 0 explicitly.
244 	 *     Use pango_font_description_get_set_fields() to
245 	 *     find out if the field was explicitly set or not.
246 	 */
247 	public int getSize()
248 	{
249 		return pango_font_description_get_size(pangoFontDescription);
250 	}
251 
252 	/**
253 	 * Determines whether the size of the font is in points (not absolute) or device units (absolute).
254 	 * See pango_font_description_set_size() and pango_font_description_set_absolute_size().
255 	 *
256 	 * Return: whether the size for the font description is in
257 	 *     points or device units.  Use pango_font_description_get_set_fields() to
258 	 *     find out if the size field of the font description was explicitly set or not.
259 	 *
260 	 * Since: 1.8
261 	 */
262 	public bool getSizeIsAbsolute()
263 	{
264 		return pango_font_description_get_size_is_absolute(pangoFontDescription) != 0;
265 	}
266 
267 	/**
268 	 * Gets the stretch field of a font description.
269 	 * See pango_font_description_set_stretch().
270 	 *
271 	 * Return: the stretch field for the font description. Use
272 	 *     pango_font_description_get_set_fields() to find out if
273 	 *     the field was explicitly set or not.
274 	 */
275 	public PangoStretch getStretch()
276 	{
277 		return pango_font_description_get_stretch(pangoFontDescription);
278 	}
279 
280 	/**
281 	 * Gets the style field of a #PangoFontDescription. See
282 	 * pango_font_description_set_style().
283 	 *
284 	 * Return: the style field for the font description.
285 	 *     Use pango_font_description_get_set_fields() to find out if
286 	 *     the field was explicitly set or not.
287 	 */
288 	public PangoStyle getStyle()
289 	{
290 		return pango_font_description_get_style(pangoFontDescription);
291 	}
292 
293 	/**
294 	 * Gets the variant field of a #PangoFontDescription. See
295 	 * pango_font_description_set_variant().
296 	 *
297 	 * Return: the variant field for the font description. Use
298 	 *     pango_font_description_get_set_fields() to find out if
299 	 *     the field was explicitly set or not.
300 	 */
301 	public PangoVariant getVariant()
302 	{
303 		return pango_font_description_get_variant(pangoFontDescription);
304 	}
305 
306 	/**
307 	 * Gets the weight field of a font description. See
308 	 * pango_font_description_set_weight().
309 	 *
310 	 * Return: the weight field for the font description. Use
311 	 *     pango_font_description_get_set_fields() to find out if
312 	 *     the field was explicitly set or not.
313 	 */
314 	public PangoWeight getWeight()
315 	{
316 		return pango_font_description_get_weight(pangoFontDescription);
317 	}
318 
319 	/**
320 	 * Computes a hash of a #PangoFontDescription structure suitable
321 	 * to be used, for example, as an argument to g_hash_table_new().
322 	 * The hash value is independent of @desc->mask.
323 	 *
324 	 * Return: the hash value.
325 	 */
326 	public uint hash()
327 	{
328 		return pango_font_description_hash(pangoFontDescription);
329 	}
330 
331 	/**
332 	 * Merges the fields that are set in @desc_to_merge into the fields in
333 	 * @desc.  If @replace_existing is %FALSE, only fields in @desc that
334 	 * are not already set are affected. If %TRUE, then fields that are
335 	 * already set will be replaced as well.
336 	 *
337 	 * If @desc_to_merge is %NULL, this function performs nothing.
338 	 *
339 	 * Params:
340 	 *     descToMerge = the #PangoFontDescription to merge from, or %NULL
341 	 *     replaceExisting = if %TRUE, replace fields in @desc with the
342 	 *         corresponding values from @desc_to_merge, even if they
343 	 *         are already exist.
344 	 */
345 	public void merge(PgFontDescription descToMerge, bool replaceExisting)
346 	{
347 		pango_font_description_merge(pangoFontDescription, (descToMerge is null) ? null : descToMerge.getPgFontDescriptionStruct(), replaceExisting);
348 	}
349 
350 	/**
351 	 * Like pango_font_description_merge(), but only a shallow copy is made
352 	 * of the family name and other allocated fields. @desc can only be
353 	 * used until @desc_to_merge is modified or freed. This is meant
354 	 * to be used when the merged font description is only needed temporarily.
355 	 *
356 	 * Params:
357 	 *     descToMerge = the #PangoFontDescription to merge from
358 	 *     replaceExisting = if %TRUE, replace fields in @desc with the
359 	 *         corresponding values from @desc_to_merge, even if they
360 	 *         are already exist.
361 	 */
362 	public void mergeStatic(PgFontDescription descToMerge, bool replaceExisting)
363 	{
364 		pango_font_description_merge_static(pangoFontDescription, (descToMerge is null) ? null : descToMerge.getPgFontDescriptionStruct(), replaceExisting);
365 	}
366 
367 	/**
368 	 * Sets the size field of a font description, in device units. This is mutually
369 	 * exclusive with pango_font_description_set_size() which sets the font size
370 	 * in points.
371 	 *
372 	 * Params:
373 	 *     size = the new size, in Pango units. There are %PANGO_SCALE Pango units in one
374 	 *         device unit. For an output backend where a device unit is a pixel, a @size
375 	 *         value of 10 * PANGO_SCALE gives a 10 pixel font.
376 	 *
377 	 * Since: 1.8
378 	 */
379 	public void setAbsoluteSize(double size)
380 	{
381 		pango_font_description_set_absolute_size(pangoFontDescription, size);
382 	}
383 
384 	/**
385 	 * Sets the family name field of a font description. The family
386 	 * name represents a family of related font styles, and will
387 	 * resolve to a particular #PangoFontFamily. In some uses of
388 	 * #PangoFontDescription, it is also possible to use a comma
389 	 * separated list of family names for this field.
390 	 *
391 	 * Params:
392 	 *     family = a string representing the family name.
393 	 */
394 	public void setFamily(string family)
395 	{
396 		pango_font_description_set_family(pangoFontDescription, Str.toStringz(family));
397 	}
398 
399 	/**
400 	 * Like pango_font_description_set_family(), except that no
401 	 * copy of @family is made. The caller must make sure that the
402 	 * string passed in stays around until @desc has been freed
403 	 * or the name is set again. This function can be used if
404 	 * @family is a static string such as a C string literal, or
405 	 * if @desc is only needed temporarily.
406 	 *
407 	 * Params:
408 	 *     family = a string representing the family name.
409 	 */
410 	public void setFamilyStatic(string family)
411 	{
412 		pango_font_description_set_family_static(pangoFontDescription, Str.toStringz(family));
413 	}
414 
415 	/**
416 	 * Sets the gravity field of a font description. The gravity field
417 	 * specifies how the glyphs should be rotated.  If @gravity is
418 	 * %PANGO_GRAVITY_AUTO, this actually unsets the gravity mask on
419 	 * the font description.
420 	 *
421 	 * This function is seldom useful to the user.  Gravity should normally
422 	 * be set on a #PangoContext.
423 	 *
424 	 * Params:
425 	 *     gravity = the gravity for the font description.
426 	 *
427 	 * Since: 1.16
428 	 */
429 	public void setGravity(PangoGravity gravity)
430 	{
431 		pango_font_description_set_gravity(pangoFontDescription, gravity);
432 	}
433 
434 	/**
435 	 * Sets the size field of a font description in fractional points. This is mutually
436 	 * exclusive with pango_font_description_set_absolute_size().
437 	 *
438 	 * Params:
439 	 *     size = the size of the font in points, scaled by PANGO_SCALE. (That is,
440 	 *         a @size value of 10 * PANGO_SCALE is a 10 point font. The conversion
441 	 *         factor between points and device units depends on system configuration
442 	 *         and the output device. For screen display, a logical DPI of 96 is
443 	 *         common, in which case a 10 point font corresponds to a 10 * (96 / 72) = 13.3
444 	 *         pixel font. Use pango_font_description_set_absolute_size() if you need
445 	 *         a particular size in device units.
446 	 */
447 	public void setSize(int size)
448 	{
449 		pango_font_description_set_size(pangoFontDescription, size);
450 	}
451 
452 	/**
453 	 * Sets the stretch field of a font description. The stretch field
454 	 * specifies how narrow or wide the font should be.
455 	 *
456 	 * Params:
457 	 *     stretch = the stretch for the font description
458 	 */
459 	public void setStretch(PangoStretch stretch)
460 	{
461 		pango_font_description_set_stretch(pangoFontDescription, stretch);
462 	}
463 
464 	/**
465 	 * Sets the style field of a #PangoFontDescription. The
466 	 * #PangoStyle enumeration describes whether the font is slanted and
467 	 * the manner in which it is slanted; it can be either
468 	 * #PANGO_STYLE_NORMAL, #PANGO_STYLE_ITALIC, or #PANGO_STYLE_OBLIQUE.
469 	 * Most fonts will either have a italic style or an oblique
470 	 * style, but not both, and font matching in Pango will
471 	 * match italic specifications with oblique fonts and vice-versa
472 	 * if an exact match is not found.
473 	 *
474 	 * Params:
475 	 *     style = the style for the font description
476 	 */
477 	public void setStyle(PangoStyle style)
478 	{
479 		pango_font_description_set_style(pangoFontDescription, style);
480 	}
481 
482 	/**
483 	 * Sets the variant field of a font description. The #PangoVariant
484 	 * can either be %PANGO_VARIANT_NORMAL or %PANGO_VARIANT_SMALL_CAPS.
485 	 *
486 	 * Params:
487 	 *     variant = the variant type for the font description.
488 	 */
489 	public void setVariant(PangoVariant variant)
490 	{
491 		pango_font_description_set_variant(pangoFontDescription, variant);
492 	}
493 
494 	/**
495 	 * Sets the weight field of a font description. The weight field
496 	 * specifies how bold or light the font should be. In addition
497 	 * to the values of the #PangoWeight enumeration, other intermediate
498 	 * numeric values are possible.
499 	 *
500 	 * Params:
501 	 *     weight = the weight for the font description.
502 	 */
503 	public void setWeight(PangoWeight weight)
504 	{
505 		pango_font_description_set_weight(pangoFontDescription, weight);
506 	}
507 
508 	/**
509 	 * Creates a filename representation of a font description. The
510 	 * filename is identical to the result from calling
511 	 * pango_font_description_to_string(), but with underscores instead of
512 	 * characters that are untypical in filenames, and in lower case only.
513 	 *
514 	 * Return: a new string that must be freed with g_free().
515 	 */
516 	public string toFilename()
517 	{
518 		return Str.toString(pango_font_description_to_filename(pangoFontDescription));
519 	}
520 
521 	/**
522 	 * Creates a string representation of a font description. See
523 	 * pango_font_description_from_string() for a description of the
524 	 * format of the string representation. The family list in the
525 	 * string description will only have a terminating comma if the
526 	 * last word of the list is a valid style option.
527 	 *
528 	 * Return: a new string that must be freed with g_free().
529 	 */
530 	public override string toString()
531 	{
532 		return Str.toString(pango_font_description_to_string(pangoFontDescription));
533 	}
534 
535 	/**
536 	 * Unsets some of the fields in a #PangoFontDescription.  The unset
537 	 * fields will get back to their default values.
538 	 *
539 	 * Params:
540 	 *     toUnset = bitmask of fields in the @desc to unset.
541 	 */
542 	public void unsetFields(PangoFontMask toUnset)
543 	{
544 		pango_font_description_unset_fields(pangoFontDescription, toUnset);
545 	}
546 
547 	/**
548 	 * Creates a new font description from a string representation in the
549 	 * form "[FAMILY-LIST] [STYLE-OPTIONS] [SIZE]", where FAMILY-LIST is a
550 	 * comma separated list of families optionally terminated by a comma,
551 	 * STYLE_OPTIONS is a whitespace separated list of words where each WORD
552 	 * describes one of style, variant, weight, stretch, or gravity, and SIZE
553 	 * is a decimal number (size in points) or optionally followed by the
554 	 * unit modifier "px" for absolute size. Any one of the options may
555 	 * be absent.  If FAMILY-LIST is absent, then the family_name field of
556 	 * the resulting font description will be initialized to %NULL.  If
557 	 * STYLE-OPTIONS is missing, then all style options will be set to the
558 	 * default values. If SIZE is missing, the size in the resulting font
559 	 * description will be set to 0.
560 	 *
561 	 * Params:
562 	 *     str = string representation of a font description.
563 	 *
564 	 * Return: a new #PangoFontDescription.
565 	 */
566 	public static PgFontDescription fromString(string str)
567 	{
568 		auto p = pango_font_description_from_string(Str.toStringz(str));
569 		
570 		if(p is null)
571 		{
572 			return null;
573 		}
574 		
575 		return ObjectG.getDObject!(PgFontDescription)(cast(PangoFontDescription*) p);
576 	}
577 }