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 glib.c.functions; 32 private import gobject.ObjectG; 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. 41 * 42 * Particular types of attributes include this structure as their initial 43 * portion. The common portion of the attribute holds the range to which 44 * the value in the type-specific part of the attribute applies and should 45 * be initialized using [method@Pango.Attribute.init]. By default, an attribute 46 * will have an all-inclusive range of [0,%G_MAXUINT]. 47 */ 48 public class PgAttribute 49 { 50 /** the main Gtk struct */ 51 protected PangoAttribute* pangoAttribute; 52 protected bool ownedRef; 53 54 /** Get the main Gtk struct */ 55 public PangoAttribute* getPgAttributeStruct(bool transferOwnership = false) 56 { 57 if (transferOwnership) 58 ownedRef = false; 59 return pangoAttribute; 60 } 61 62 /** the main Gtk struct as a void* */ 63 protected void* getStruct() 64 { 65 return cast(void*)pangoAttribute; 66 } 67 68 /** 69 * Sets our main struct and passes it to the parent class. 70 */ 71 public this (PangoAttribute* pangoAttribute, bool ownedRef = false) 72 { 73 this.pangoAttribute = pangoAttribute; 74 this.ownedRef = ownedRef; 75 } 76 77 78 /** */ 79 public static GType getType() 80 { 81 return pango_attribute_get_type(); 82 } 83 84 /** 85 * Make a copy of an attribute. 86 * 87 * Returns: the newly allocated `PangoAttribute`, 88 * which should be freed with [method@Pango.Attribute.destroy]. 89 */ 90 public PgAttribute copy() 91 { 92 auto __p = pango_attribute_copy(pangoAttribute); 93 94 if(__p is null) 95 { 96 return null; 97 } 98 99 return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) __p, true); 100 } 101 102 /** 103 * Destroy a `PangoAttribute` and free all associated memory. 104 */ 105 public void destroy() 106 { 107 pango_attribute_destroy(pangoAttribute); 108 } 109 110 /** 111 * Compare two attributes for equality. This compares only the 112 * actual value of the two attributes and not the ranges that the 113 * attributes apply to. 114 * 115 * Params: 116 * attr2 = another `PangoAttribute` 117 * 118 * Returns: %TRUE if the two attributes have the same value. 119 */ 120 public bool equal(PgAttribute attr2) 121 { 122 return pango_attribute_equal(pangoAttribute, (attr2 is null) ? null : attr2.getPgAttributeStruct()) != 0; 123 } 124 125 /** 126 * Initializes @attr's klass to @klass, it's start_index to 127 * %PANGO_ATTR_INDEX_FROM_TEXT_BEGINNING and end_index to 128 * %PANGO_ATTR_INDEX_TO_TEXT_END 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 [method@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 newly allocated `PangoAttribute`, 171 * which should be freed with [method@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 [method@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 [method@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 [method@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 newly allocated `PangoAttribute`, 267 * which should be freed with [method@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 [method@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 [method@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 [method@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 [method@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. 377 * 378 * The base font for the affected text will have its size multiplied 379 * by @scale_factor. 380 * 381 * Params: 382 * scaleFactor = factor to scale the font 383 * 384 * Returns: the newly allocated `PangoAttribute`, 385 * which should be freed with [method@Pango.Attribute.destroy]. 386 */ 387 public static PgAttribute scaleNew(double scaleFactor) 388 { 389 auto __p = pango_attr_scale_new(scaleFactor); 390 391 if(__p is null) 392 { 393 return null; 394 } 395 396 return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) __p, true); 397 } 398 399 /** 400 * Create a new font stretch attribute. 401 * 402 * Params: 403 * stretch = the stretch 404 * 405 * Returns: the newly allocated `PangoAttribute`, 406 * which should be freed with [method@Pango.Attribute.destroy]. 407 */ 408 public static PgAttribute stretchNew(PangoStretch stretch) 409 { 410 auto __p = pango_attr_stretch_new(stretch); 411 412 if(__p is null) 413 { 414 return null; 415 } 416 417 return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) __p, true); 418 } 419 420 /** 421 * Create a new strikethrough color attribute. 422 * 423 * This attribute modifies the color of strikethrough lines. If not set, 424 * strikethrough lines will use the foreground color. 425 * 426 * Params: 427 * red = the red value (ranging from 0 to 65535) 428 * green = the green value 429 * blue = the blue value 430 * 431 * Returns: the newly allocated `PangoAttribute`, 432 * which should be freed with [method@Pango.Attribute.destroy]. 433 * 434 * Since: 1.8 435 */ 436 public static PgAttribute strikethroughColorNew(ushort red, ushort green, ushort blue) 437 { 438 auto __p = pango_attr_strikethrough_color_new(red, green, blue); 439 440 if(__p is null) 441 { 442 return null; 443 } 444 445 return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) __p, true); 446 } 447 448 /** 449 * Create a new strike-through attribute. 450 * 451 * Params: 452 * strikethrough = %TRUE if the text should be struck-through. 453 * 454 * Returns: the newly allocated `PangoAttribute`, 455 * which should be freed with [method@Pango.Attribute.destroy]. 456 */ 457 public static PgAttribute strikethroughNew(bool strikethrough) 458 { 459 auto __p = pango_attr_strikethrough_new(strikethrough); 460 461 if(__p is null) 462 { 463 return null; 464 } 465 466 return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) __p, true); 467 } 468 469 /** 470 * Create a new font slant style attribute. 471 * 472 * Params: 473 * style = the slant style 474 * 475 * Returns: the newly allocated `PangoAttribute`, 476 * which should be freed with [method@Pango.Attribute.destroy]. 477 */ 478 public static PgAttribute styleNew(PangoStyle style) 479 { 480 auto __p = pango_attr_style_new(style); 481 482 if(__p is null) 483 { 484 return null; 485 } 486 487 return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) __p, true); 488 } 489 490 /** 491 * Fetches the attribute type name. 492 * 493 * The attribute type name is the string passed in when registering the type 494 * using [type_func@attr_type_register]. 495 * 496 * The returned value is an interned string (see g_intern_string() for what 497 * that means) that should not be modified or freed. 498 * 499 * Params: 500 * type = an attribute type ID to fetch the name for 501 * 502 * Returns: the type ID name (which may be %NULL), or 503 * %NULL if @type is a built-in Pango attribute type or invalid. 504 * 505 * Since: 1.22 506 */ 507 public static string typeGetName(PangoAttrType type) 508 { 509 return Str.toString(pango_attr_type_get_name(type)); 510 } 511 512 /** 513 * Allocate a new attribute type ID. 514 * 515 * The attribute type name can be accessed later by using [type_func@Pango.AttrType.get_name]. 516 * 517 * Params: 518 * name = an identifier for the type 519 * 520 * Returns: the new type ID. 521 */ 522 public static PangoAttrType typeRegister(string name) 523 { 524 return pango_attr_type_register(Str.toStringz(name)); 525 } 526 527 /** 528 * Create a new underline color attribute. 529 * 530 * This attribute modifies the color of underlines. If not set, underlines 531 * will use the foreground color. 532 * 533 * Params: 534 * red = the red value (ranging from 0 to 65535) 535 * green = the green value 536 * blue = the blue value 537 * 538 * Returns: the newly allocated `PangoAttribute`, 539 * which should be freed with [method@Pango.Attribute.destroy]. 540 * 541 * Since: 1.8 542 */ 543 public static PgAttribute underlineColorNew(ushort red, ushort green, ushort blue) 544 { 545 auto __p = pango_attr_underline_color_new(red, green, blue); 546 547 if(__p is null) 548 { 549 return null; 550 } 551 552 return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) __p, true); 553 } 554 555 /** 556 * Create a new underline-style attribute. 557 * 558 * Params: 559 * underline = the underline style. 560 * 561 * Returns: the newly allocated `PangoAttribute`, 562 * which should be freed with [method@Pango.Attribute.destroy]. 563 */ 564 public static PgAttribute underlineNew(PangoUnderline underline) 565 { 566 auto __p = pango_attr_underline_new(underline); 567 568 if(__p is null) 569 { 570 return null; 571 } 572 573 return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) __p, true); 574 } 575 576 /** 577 * Create a new font variant attribute (normal or small caps). 578 * 579 * Params: 580 * variant = the variant 581 * 582 * Returns: the newly allocated `PangoAttribute`, 583 * which should be freed with [method@Pango.Attribute.destroy]. 584 */ 585 public static PgAttribute variantNew(PangoVariant variant) 586 { 587 auto __p = pango_attr_variant_new(variant); 588 589 if(__p is null) 590 { 591 return null; 592 } 593 594 return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) __p, true); 595 } 596 597 /** 598 * Create a new font weight attribute. 599 * 600 * Params: 601 * weight = the weight 602 * 603 * Returns: the newly allocated `PangoAttribute`, 604 * which should be freed with [method@Pango.Attribute.destroy]. 605 */ 606 public static PgAttribute weightNew(PangoWeight weight) 607 { 608 auto __p = pango_attr_weight_new(weight); 609 610 if(__p is null) 611 { 612 return null; 613 } 614 615 return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) __p, true); 616 } 617 618 /** 619 * Finishes parsing markup. 620 * 621 * After feeding a Pango markup parser some data with g_markup_parse_context_parse(), 622 * use this function to get the list of attributes and text out of the 623 * markup. This function will not free @context, use g_markup_parse_context_free() 624 * to do so. 625 * 626 * Params: 627 * context = A valid parse context that was returned from [func@markup_parser_new] 628 * attrList = address of return location for a `PangoAttrList`, or %NULL 629 * text = address of return location for text with tags stripped, or %NULL 630 * accelChar = address of return location for accelerator char, or %NULL 631 * 632 * Returns: %FALSE if @error is set, otherwise %TRUE 633 * 634 * Since: 1.31.0 635 * 636 * Throws: GException on failure. 637 */ 638 public static bool markupParserFinish(SimpleXML context, out PgAttributeList attrList, out string text, out dchar accelChar) 639 { 640 PangoAttrList* outattrList = null; 641 char* outtext = null; 642 GError* err = null; 643 644 auto __p = pango_markup_parser_finish((context is null) ? null : context.getSimpleXMLStruct(), &outattrList, &outtext, &accelChar, &err) != 0; 645 646 if (err !is null) 647 { 648 throw new GException( new ErrorG(err) ); 649 } 650 651 attrList = ObjectG.getDObject!(PgAttributeList)(outattrList); 652 text = Str.toString(outtext); 653 654 return __p; 655 } 656 657 /** 658 * Incrementally parses marked-up text to create a plain-text string 659 * and an attribute list. 660 * 661 * See the [Pango Markup](pango_markup.html) docs for details about the 662 * supported markup. 663 * 664 * If @accel_marker is nonzero, the given character will mark the 665 * character following it as an accelerator. For example, @accel_marker 666 * might be an ampersand or underscore. All characters marked 667 * as an accelerator will receive a %PANGO_UNDERLINE_LOW attribute, 668 * and the first character so marked will be returned in @accel_char, 669 * when calling [func@markup_parser_finish]. Two @accel_marker characters 670 * following each other produce a single literal @accel_marker character. 671 * 672 * To feed markup to the parser, use g_markup_parse_context_parse() 673 * on the returned `GMarkupParseContext`. When done with feeding markup 674 * to the parser, use [func@markup_parser_finish] to get the data out 675 * of it, and then use g_markup_parse_context_free() to free it. 676 * 677 * This function is designed for applications that read Pango markup 678 * from streams. To simply parse a string containing Pango markup, 679 * the [func@parse_markup] API is recommended instead. 680 * 681 * Params: 682 * accelMarker = character that precedes an accelerator, or 0 for none 683 * 684 * Returns: a `GMarkupParseContext` that should be 685 * destroyed with g_markup_parse_context_free(). 686 * 687 * Since: 1.31.0 688 */ 689 public static SimpleXML markupParserNew(dchar accelMarker) 690 { 691 auto __p = pango_markup_parser_new(accelMarker); 692 693 if(__p is null) 694 { 695 return null; 696 } 697 698 return new SimpleXML(cast(GMarkupParseContext*) __p); 699 } 700 701 /** 702 * Parses marked-up text to create a plain-text string and an attribute list. 703 * 704 * See the [Pango Markup](pango_markup.html) docs for details about the 705 * supported markup. 706 * 707 * If @accel_marker is nonzero, the given character will mark the 708 * character following it as an accelerator. For example, @accel_marker 709 * might be an ampersand or underscore. All characters marked 710 * as an accelerator will receive a %PANGO_UNDERLINE_LOW attribute, 711 * and the first character so marked will be returned in @accel_char. 712 * Two @accel_marker characters following each other produce a single 713 * literal @accel_marker character. 714 * 715 * To parse a stream of pango markup incrementally, use [func@markup_parser_new]. 716 * 717 * If any error happens, none of the output arguments are touched except 718 * for @error. 719 * 720 * Params: 721 * markupText = markup to parse (see the Pango Markup docs) 722 * length = length of @markup_text, or -1 if nul-terminated 723 * accelMarker = character that precedes an accelerator, or 0 for none 724 * attrList = address of return location for a `PangoAttrList`, or %NULL 725 * text = address of return location for text with tags stripped, or %NULL 726 * accelChar = address of return location for accelerator char, or %NULL 727 * 728 * Returns: %FALSE if @error is set, otherwise %TRUE 729 * 730 * Throws: GException on failure. 731 */ 732 public static bool parseMarkup(string markupText, int length, dchar accelMarker, out PgAttributeList attrList, out string text, out dchar accelChar) 733 { 734 PangoAttrList* outattrList = null; 735 char* outtext = null; 736 GError* err = null; 737 738 auto __p = pango_parse_markup(Str.toStringz(markupText), length, accelMarker, &outattrList, &outtext, &accelChar, &err) != 0; 739 740 if (err !is null) 741 { 742 throw new GException( new ErrorG(err) ); 743 } 744 745 attrList = ObjectG.getDObject!(PgAttributeList)(outattrList); 746 text = Str.toString(outtext); 747 748 return __p; 749 } 750 }