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