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