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