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