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.PgAttribute;
26 
27 private import glib.ErrorG;
28 private import glib.GException;
29 private import glib.SimpleXML;
30 private import glib.Str;
31 private import gobject.ObjectG;
32 public  import gtkc.pangotypes;
33 private import pango.PgAttributeList;
34 private import pango.c.functions;
35 public  import pango.c.types;
36 
37 
38 /**
39  * The #PangoAttribute structure represents the common portions of all
40  * attributes. Particular types of attributes include this structure
41  * as their initial portion. The common portion of the attribute holds
42  * the range to which the value in the type-specific part of the attribute
43  * applies and should be initialized using pango_attribute_init().
44  * By default an attribute will have an all-inclusive range of [0,%G_MAXUINT].
45  */
46 public class PgAttribute
47 {
48 	/** the main Gtk struct */
49 	protected PangoAttribute* pangoAttribute;
50 	protected bool ownedRef;
51 
52 	/** Get the main Gtk struct */
53 	public PangoAttribute* getPgAttributeStruct(bool transferOwnership = false)
54 	{
55 		if (transferOwnership)
56 			ownedRef = false;
57 		return pangoAttribute;
58 	}
59 
60 	/** the main Gtk struct as a void* */
61 	protected void* getStruct()
62 	{
63 		return cast(void*)pangoAttribute;
64 	}
65 
66 	/**
67 	 * Sets our main struct and passes it to the parent class.
68 	 */
69 	public this (PangoAttribute* pangoAttribute, bool ownedRef = false)
70 	{
71 		this.pangoAttribute = pangoAttribute;
72 		this.ownedRef = ownedRef;
73 	}
74 
75 
76 	/**
77 	 * Make a copy of an attribute.
78 	 *
79 	 * Returns: the newly allocated #PangoAttribute,
80 	 *     which should be freed with pango_attribute_destroy().
81 	 */
82 	public PgAttribute copy()
83 	{
84 		auto p = pango_attribute_copy(pangoAttribute);
85 
86 		if(p is null)
87 		{
88 			return null;
89 		}
90 
91 		return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p, true);
92 	}
93 
94 	/**
95 	 * Destroy a #PangoAttribute and free all associated memory.
96 	 */
97 	public void destroy()
98 	{
99 		pango_attribute_destroy(pangoAttribute);
100 	}
101 
102 	/**
103 	 * Compare two attributes for equality. This compares only the
104 	 * actual value of the two attributes and not the ranges that the
105 	 * attributes apply to.
106 	 *
107 	 * Params:
108 	 *     attr2 = another #PangoAttribute
109 	 *
110 	 * Returns: %TRUE if the two attributes have the same value.
111 	 */
112 	public bool equal(PgAttribute attr2)
113 	{
114 		return pango_attribute_equal(pangoAttribute, (attr2 is null) ? null : attr2.getPgAttributeStruct()) != 0;
115 	}
116 
117 	/**
118 	 * Initializes @attr's klass to @klass,
119 	 * it's start_index to %PANGO_ATTR_INDEX_FROM_TEXT_BEGINNING
120 	 * and end_index to %PANGO_ATTR_INDEX_TO_TEXT_END
121 	 * such that the attribute applies
122 	 * to the entire text by default.
123 	 *
124 	 * Params:
125 	 *     klass = a #PangoAttrClass
126 	 *
127 	 * Since: 1.20
128 	 */
129 	public void init(PangoAttrClass* klass)
130 	{
131 		pango_attribute_init(pangoAttribute, klass);
132 	}
133 
134 	/**
135 	 * Create a new background color attribute.
136 	 *
137 	 * Params:
138 	 *     red = the red value (ranging from 0 to 65535)
139 	 *     green = the green value
140 	 *     blue = the blue value
141 	 *
142 	 * Returns: the newly allocated #PangoAttribute,
143 	 *     which should be freed with pango_attribute_destroy().
144 	 */
145 	public static PgAttribute backgroundNew(ushort red, ushort green, ushort blue)
146 	{
147 		auto p = pango_attr_background_new(red, green, blue);
148 
149 		if(p is null)
150 		{
151 			return null;
152 		}
153 
154 		return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p, true);
155 	}
156 
157 	/**
158 	 * Create a new background alpha attribute.
159 	 *
160 	 * Params:
161 	 *     alpha = the alpha value, between 1 and 65536
162 	 *
163 	 * Returns: the new allocated #PangoAttribute,
164 	 *     which should be freed with pango_attribute_destroy().
165 	 *
166 	 * Since: 1.38
167 	 */
168 	public static PgAttribute backgroundAlphaNew(ushort alpha)
169 	{
170 		auto p = pango_attr_background_alpha_new(alpha);
171 
172 		if(p is null)
173 		{
174 			return null;
175 		}
176 
177 		return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p, true);
178 	}
179 
180 	/**
181 	 * Create a new font fallback attribute.
182 	 *
183 	 * If fallback is disabled, characters will only be used from the
184 	 * closest matching font on the system. No fallback will be done to
185 	 * other fonts on the system that might contain the characters in the
186 	 * text.
187 	 *
188 	 * Params:
189 	 *     enableFallback = %TRUE if we should fall back on other fonts
190 	 *         for characters the active font is missing.
191 	 *
192 	 * Returns: the newly allocated #PangoAttribute,
193 	 *     which should be freed with pango_attribute_destroy().
194 	 *
195 	 * Since: 1.4
196 	 */
197 	public static PgAttribute fallbackNew(bool enableFallback)
198 	{
199 		auto p = pango_attr_fallback_new(enableFallback);
200 
201 		if(p is null)
202 		{
203 			return null;
204 		}
205 
206 		return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p, true);
207 	}
208 
209 	/**
210 	 * Create a new font family attribute.
211 	 *
212 	 * Params:
213 	 *     family = the family or comma separated list of families
214 	 *
215 	 * Returns: the newly allocated #PangoAttribute,
216 	 *     which should be freed with pango_attribute_destroy().
217 	 */
218 	public static PgAttribute familyNew(string family)
219 	{
220 		auto p = pango_attr_family_new(Str.toStringz(family));
221 
222 		if(p is null)
223 		{
224 			return null;
225 		}
226 
227 		return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p, true);
228 	}
229 
230 	/**
231 	 * Create a new foreground color attribute.
232 	 *
233 	 * Params:
234 	 *     red = the red value (ranging from 0 to 65535)
235 	 *     green = the green value
236 	 *     blue = the blue value
237 	 *
238 	 * Returns: the newly allocated #PangoAttribute,
239 	 *     which should be freed with pango_attribute_destroy().
240 	 */
241 	public static PgAttribute foregroundNew(ushort red, ushort green, ushort blue)
242 	{
243 		auto p = pango_attr_foreground_new(red, green, blue);
244 
245 		if(p is null)
246 		{
247 			return null;
248 		}
249 
250 		return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p, true);
251 	}
252 
253 	/**
254 	 * Create a new foreground alpha attribute.
255 	 *
256 	 * Params:
257 	 *     alpha = the alpha value, between 1 and 65536
258 	 *
259 	 * Returns: the new allocated #PangoAttribute,
260 	 *     which should be freed with pango_attribute_destroy().
261 	 *
262 	 * Since: 1.38
263 	 */
264 	public static PgAttribute foregroundAlphaNew(ushort alpha)
265 	{
266 		auto p = pango_attr_foreground_alpha_new(alpha);
267 
268 		if(p is null)
269 		{
270 			return null;
271 		}
272 
273 		return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p, true);
274 	}
275 
276 	/**
277 	 * Create a new gravity hint attribute.
278 	 *
279 	 * Params:
280 	 *     hint = the gravity hint value.
281 	 *
282 	 * Returns: the newly allocated #PangoAttribute,
283 	 *     which should be freed with pango_attribute_destroy().
284 	 *
285 	 * Since: 1.16
286 	 */
287 	public static PgAttribute gravityHintNew(PangoGravityHint hint)
288 	{
289 		auto p = pango_attr_gravity_hint_new(hint);
290 
291 		if(p is null)
292 		{
293 			return null;
294 		}
295 
296 		return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p, true);
297 	}
298 
299 	/**
300 	 * Create a new gravity attribute.
301 	 *
302 	 * Params:
303 	 *     gravity = the gravity value; should not be %PANGO_GRAVITY_AUTO.
304 	 *
305 	 * Returns: the newly allocated #PangoAttribute,
306 	 *     which should be freed with pango_attribute_destroy().
307 	 *
308 	 * Since: 1.16
309 	 */
310 	public static PgAttribute gravityNew(PangoGravity gravity)
311 	{
312 		auto p = pango_attr_gravity_new(gravity);
313 
314 		if(p is null)
315 		{
316 			return null;
317 		}
318 
319 		return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p, true);
320 	}
321 
322 	/**
323 	 * Create a new letter-spacing attribute.
324 	 *
325 	 * Params:
326 	 *     letterSpacing = amount of extra space to add between graphemes
327 	 *         of the text, in Pango units.
328 	 *
329 	 * Returns: the newly allocated #PangoAttribute,
330 	 *     which should be freed with pango_attribute_destroy().
331 	 *
332 	 * Since: 1.6
333 	 */
334 	public static PgAttribute letterSpacingNew(int letterSpacing)
335 	{
336 		auto p = pango_attr_letter_spacing_new(letterSpacing);
337 
338 		if(p is null)
339 		{
340 			return null;
341 		}
342 
343 		return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p, true);
344 	}
345 
346 	/**
347 	 * Create a new baseline displacement attribute.
348 	 *
349 	 * Params:
350 	 *     rise = the amount that the text should be displaced vertically,
351 	 *         in Pango units. Positive values displace the text upwards.
352 	 *
353 	 * Returns: the newly allocated #PangoAttribute,
354 	 *     which should be freed with pango_attribute_destroy().
355 	 */
356 	public static PgAttribute riseNew(int rise)
357 	{
358 		auto p = pango_attr_rise_new(rise);
359 
360 		if(p is null)
361 		{
362 			return null;
363 		}
364 
365 		return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p, true);
366 	}
367 
368 	/**
369 	 * Create a new font size scale attribute. The base font for the
370 	 * affected text will have its size multiplied by @scale_factor.
371 	 *
372 	 * Params:
373 	 *     scaleFactor = factor to scale the font
374 	 *
375 	 * Returns: the newly allocated #PangoAttribute,
376 	 *     which should be freed with pango_attribute_destroy().
377 	 */
378 	public static PgAttribute scaleNew(double scaleFactor)
379 	{
380 		auto p = pango_attr_scale_new(scaleFactor);
381 
382 		if(p is null)
383 		{
384 			return null;
385 		}
386 
387 		return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p, true);
388 	}
389 
390 	/**
391 	 * Create a new font stretch attribute
392 	 *
393 	 * Params:
394 	 *     stretch = the stretch
395 	 *
396 	 * Returns: the newly allocated #PangoAttribute,
397 	 *     which should be freed with pango_attribute_destroy().
398 	 */
399 	public static PgAttribute stretchNew(PangoStretch stretch)
400 	{
401 		auto p = pango_attr_stretch_new(stretch);
402 
403 		if(p is null)
404 		{
405 			return null;
406 		}
407 
408 		return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p, true);
409 	}
410 
411 	/**
412 	 * Create a new strikethrough color attribute. This attribute
413 	 * modifies the color of strikethrough lines. If not set, strikethrough
414 	 * lines will use the foreground color.
415 	 *
416 	 * Params:
417 	 *     red = the red value (ranging from 0 to 65535)
418 	 *     green = the green value
419 	 *     blue = the blue value
420 	 *
421 	 * Returns: the newly allocated #PangoAttribute,
422 	 *     which should be freed with pango_attribute_destroy().
423 	 *
424 	 * Since: 1.8
425 	 */
426 	public static PgAttribute strikethroughColorNew(ushort red, ushort green, ushort blue)
427 	{
428 		auto p = pango_attr_strikethrough_color_new(red, green, blue);
429 
430 		if(p is null)
431 		{
432 			return null;
433 		}
434 
435 		return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p, true);
436 	}
437 
438 	/**
439 	 * Create a new strike-through attribute.
440 	 *
441 	 * Params:
442 	 *     strikethrough = %TRUE if the text should be struck-through.
443 	 *
444 	 * Returns: the newly allocated #PangoAttribute,
445 	 *     which should be freed with pango_attribute_destroy().
446 	 */
447 	public static PgAttribute strikethroughNew(bool strikethrough)
448 	{
449 		auto p = pango_attr_strikethrough_new(strikethrough);
450 
451 		if(p is null)
452 		{
453 			return null;
454 		}
455 
456 		return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p, true);
457 	}
458 
459 	/**
460 	 * Create a new font slant style attribute.
461 	 *
462 	 * Params:
463 	 *     style = the slant style
464 	 *
465 	 * Returns: the newly allocated #PangoAttribute,
466 	 *     which should be freed with pango_attribute_destroy().
467 	 */
468 	public static PgAttribute styleNew(PangoStyle style)
469 	{
470 		auto p = pango_attr_style_new(style);
471 
472 		if(p is null)
473 		{
474 			return null;
475 		}
476 
477 		return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p, true);
478 	}
479 
480 	/**
481 	 * Fetches the attribute type name passed in when registering the type using
482 	 * pango_attr_type_register().
483 	 *
484 	 * The returned value is an interned string (see g_intern_string() for what
485 	 * that means) that should not be modified or freed.
486 	 *
487 	 * Params:
488 	 *     type = an attribute type ID to fetch the name for
489 	 *
490 	 * Returns: the type ID name (which may be %NULL), or
491 	 *     %NULL if @type is a built-in Pango attribute type or invalid.
492 	 *
493 	 * Since: 1.22
494 	 */
495 	public static string typeGetName(PangoAttrType type)
496 	{
497 		return Str.toString(pango_attr_type_get_name(type));
498 	}
499 
500 	/**
501 	 * Allocate a new attribute type ID.  The attribute type name can be accessed
502 	 * later by using pango_attr_type_get_name().
503 	 *
504 	 * Params:
505 	 *     name = an identifier for the type
506 	 *
507 	 * Returns: the new type ID.
508 	 */
509 	public static PangoAttrType typeRegister(string name)
510 	{
511 		return pango_attr_type_register(Str.toStringz(name));
512 	}
513 
514 	/**
515 	 * Create a new underline color attribute. This attribute
516 	 * modifies the color of underlines. If not set, underlines
517 	 * will use the foreground color.
518 	 *
519 	 * Params:
520 	 *     red = the red value (ranging from 0 to 65535)
521 	 *     green = the green value
522 	 *     blue = the blue value
523 	 *
524 	 * Returns: the newly allocated #PangoAttribute,
525 	 *     which should be freed with pango_attribute_destroy().
526 	 *
527 	 * Since: 1.8
528 	 */
529 	public static PgAttribute underlineColorNew(ushort red, ushort green, ushort blue)
530 	{
531 		auto p = pango_attr_underline_color_new(red, green, blue);
532 
533 		if(p is null)
534 		{
535 			return null;
536 		}
537 
538 		return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p, true);
539 	}
540 
541 	/**
542 	 * Create a new underline-style attribute.
543 	 *
544 	 * Params:
545 	 *     underline = the underline style.
546 	 *
547 	 * Returns: the newly allocated #PangoAttribute,
548 	 *     which should be freed with pango_attribute_destroy().
549 	 */
550 	public static PgAttribute underlineNew(PangoUnderline underline)
551 	{
552 		auto p = pango_attr_underline_new(underline);
553 
554 		if(p is null)
555 		{
556 			return null;
557 		}
558 
559 		return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p, true);
560 	}
561 
562 	/**
563 	 * Create a new font variant attribute (normal or small caps)
564 	 *
565 	 * Params:
566 	 *     variant = the variant
567 	 *
568 	 * Returns: the newly allocated #PangoAttribute,
569 	 *     which should be freed with pango_attribute_destroy().
570 	 */
571 	public static PgAttribute variantNew(PangoVariant variant)
572 	{
573 		auto p = pango_attr_variant_new(variant);
574 
575 		if(p is null)
576 		{
577 			return null;
578 		}
579 
580 		return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p, true);
581 	}
582 
583 	/**
584 	 * Create a new font weight attribute.
585 	 *
586 	 * Params:
587 	 *     weight = the weight
588 	 *
589 	 * Returns: the newly allocated #PangoAttribute,
590 	 *     which should be freed with pango_attribute_destroy().
591 	 */
592 	public static PgAttribute weightNew(PangoWeight weight)
593 	{
594 		auto p = pango_attr_weight_new(weight);
595 
596 		if(p is null)
597 		{
598 			return null;
599 		}
600 
601 		return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p, true);
602 	}
603 
604 	/**
605 	 * After feeding a pango markup parser some data with g_markup_parse_context_parse(),
606 	 * use this function to get the list of pango attributes and text out of the
607 	 * markup. This function will not free @context, use g_markup_parse_context_free()
608 	 * to do so.
609 	 *
610 	 * Params:
611 	 *     context = A valid parse context that was returned from pango_markup_parser_new()
612 	 *     attrList = address of return location for a #PangoAttrList, or %NULL
613 	 *     text = address of return location for text with tags stripped, or %NULL
614 	 *     accelChar = address of return location for accelerator char, or %NULL
615 	 *
616 	 * Returns: %FALSE if @error is set, otherwise %TRUE
617 	 *
618 	 * Since: 1.31.0
619 	 *
620 	 * Throws: GException on failure.
621 	 */
622 	public static bool markupParserFinish(SimpleXML context, out PgAttributeList attrList, out string text, out dchar accelChar)
623 	{
624 		PangoAttrList* outattrList = null;
625 		char* outtext = null;
626 		GError* err = null;
627 
628 		auto p = pango_markup_parser_finish((context is null) ? null : context.getSimpleXMLStruct(), &outattrList, &outtext, &accelChar, &err) != 0;
629 
630 		if (err !is null)
631 		{
632 			throw new GException( new ErrorG(err) );
633 		}
634 
635 		attrList = ObjectG.getDObject!(PgAttributeList)(outattrList);
636 		text = Str.toString(outtext);
637 
638 		return p;
639 	}
640 
641 	/**
642 	 * Parses marked-up text (see
643 	 * <link linkend="PangoMarkupFormat">markup format</link>) to create
644 	 * a plain-text string and an attribute list.
645 	 *
646 	 * If @accel_marker is nonzero, the given character will mark the
647 	 * character following it as an accelerator. For example, @accel_marker
648 	 * might be an ampersand or underscore. All characters marked
649 	 * as an accelerator will receive a %PANGO_UNDERLINE_LOW attribute,
650 	 * and the first character so marked will be returned in @accel_char,
651 	 * when calling finish(). Two @accel_marker characters following each
652 	 * other produce a single literal @accel_marker character.
653 	 *
654 	 * To feed markup to the parser, use g_markup_parse_context_parse()
655 	 * on the returned #GMarkupParseContext. When done with feeding markup
656 	 * to the parser, use pango_markup_parser_finish() to get the data out
657 	 * of it, and then use g_markup_parse_context_free() to free it.
658 	 *
659 	 * This function is designed for applications that read pango markup
660 	 * from streams. To simply parse a string containing pango markup,
661 	 * the simpler pango_parse_markup() API is recommended instead.
662 	 *
663 	 * Params:
664 	 *     accelMarker = character that precedes an accelerator, or 0 for none
665 	 *
666 	 * Returns: a #GMarkupParseContext that should be
667 	 *     destroyed with g_markup_parse_context_free().
668 	 *
669 	 * Since: 1.31.0
670 	 */
671 	public static SimpleXML markupParserNew(dchar accelMarker)
672 	{
673 		auto p = pango_markup_parser_new(accelMarker);
674 
675 		if(p is null)
676 		{
677 			return null;
678 		}
679 
680 		return new SimpleXML(cast(GMarkupParseContext*) p);
681 	}
682 
683 	/**
684 	 * Parses marked-up text (see
685 	 * <link linkend="PangoMarkupFormat">markup format</link>) to create
686 	 * a plain-text string and an attribute list.
687 	 *
688 	 * If @accel_marker is nonzero, the given character will mark the
689 	 * character following it as an accelerator. For example, @accel_marker
690 	 * might be an ampersand or underscore. All characters marked
691 	 * as an accelerator will receive a %PANGO_UNDERLINE_LOW attribute,
692 	 * and the first character so marked will be returned in @accel_char.
693 	 * Two @accel_marker characters following each other produce a single
694 	 * literal @accel_marker character.
695 	 *
696 	 * To parse a stream of pango markup incrementally, use pango_markup_parser_new().
697 	 *
698 	 * If any error happens, none of the output arguments are touched except
699 	 * for @error.
700 	 *
701 	 * Params:
702 	 *     markupText = markup to parse (see <link linkend="PangoMarkupFormat">markup format</link>)
703 	 *     length = length of @markup_text, or -1 if nul-terminated
704 	 *     accelMarker = character that precedes an accelerator, or 0 for none
705 	 *     attrList = address of return location for a #PangoAttrList, or %NULL
706 	 *     text = address of return location for text with tags stripped, or %NULL
707 	 *     accelChar = address of return location for accelerator char, or %NULL
708 	 *
709 	 * Returns: %FALSE if @error is set, otherwise %TRUE
710 	 *
711 	 * Throws: GException on failure.
712 	 */
713 	public static bool parseMarkup(string markupText, int length, dchar accelMarker, out PgAttributeList attrList, out string text, out dchar accelChar)
714 	{
715 		PangoAttrList* outattrList = null;
716 		char* outtext = null;
717 		GError* err = null;
718 
719 		auto p = pango_parse_markup(Str.toStringz(markupText), length, accelMarker, &outattrList, &outtext, &accelChar, &err) != 0;
720 
721 		if (err !is null)
722 		{
723 			throw new GException( new ErrorG(err) );
724 		}
725 
726 		attrList = ObjectG.getDObject!(PgAttributeList)(outattrList);
727 		text = Str.toString(outtext);
728 
729 		return p;
730 	}
731 }