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