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