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 font fallback attribute. 161 * 162 * If fallback is disabled, characters will only be used from the 163 * closest matching font on the system. No fallback will be done to 164 * other fonts on the system that might contain the characters in the 165 * text. 166 * 167 * Params: 168 * enableFallback = %TRUE if we should fall back on other fonts 169 * for characters the active font is missing. 170 * 171 * Return: the newly allocated #PangoAttribute, 172 * which should be freed with pango_attribute_destroy(). 173 * 174 * Since: 1.4 175 */ 176 public static PgAttribute fallbackNew(bool enableFallback) 177 { 178 auto p = pango_attr_fallback_new(enableFallback); 179 180 if(p is null) 181 { 182 return null; 183 } 184 185 return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p); 186 } 187 188 /** 189 * Create a new font family attribute. 190 * 191 * Params: 192 * family = the family or comma separated list of families 193 * 194 * Return: the newly allocated #PangoAttribute, 195 * which should be freed with pango_attribute_destroy(). 196 */ 197 public static PgAttribute familyNew(string family) 198 { 199 auto p = pango_attr_family_new(Str.toStringz(family)); 200 201 if(p is null) 202 { 203 return null; 204 } 205 206 return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p); 207 } 208 209 /** 210 * Create a new foreground color attribute. 211 * 212 * Params: 213 * red = the red value (ranging from 0 to 65535) 214 * green = the green value 215 * blue = the blue value 216 * 217 * Return: the newly allocated #PangoAttribute, 218 * which should be freed with pango_attribute_destroy(). 219 */ 220 public static PgAttribute foregroundNew(ushort red, ushort green, ushort blue) 221 { 222 auto p = pango_attr_foreground_new(red, green, blue); 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 gravity hint attribute. 234 * 235 * Params: 236 * hint = the gravity hint value. 237 * 238 * Return: the newly allocated #PangoAttribute, 239 * which should be freed with pango_attribute_destroy(). 240 * 241 * Since: 1.16 242 */ 243 public static PgAttribute gravityHintNew(PangoGravityHint hint) 244 { 245 auto p = pango_attr_gravity_hint_new(hint); 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 gravity attribute. 257 * 258 * Params: 259 * gravity = the gravity value; should not be %PANGO_GRAVITY_AUTO. 260 * 261 * Return: the newly allocated #PangoAttribute, 262 * which should be freed with pango_attribute_destroy(). 263 * 264 * Since: 1.16 265 */ 266 public static PgAttribute gravityNew(PangoGravity gravity) 267 { 268 auto p = pango_attr_gravity_new(gravity); 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 letter-spacing attribute. 280 * 281 * Params: 282 * letterSpacing = amount of extra space to add between graphemes 283 * of the text, in Pango units. 284 * 285 * Return: the newly allocated #PangoAttribute, 286 * which should be freed with pango_attribute_destroy(). 287 * 288 * Since: 1.6 289 */ 290 public static PgAttribute letterSpacingNew(int letterSpacing) 291 { 292 auto p = pango_attr_letter_spacing_new(letterSpacing); 293 294 if(p is null) 295 { 296 return null; 297 } 298 299 return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p); 300 } 301 302 /** 303 * Create a new baseline displacement attribute. 304 * 305 * Params: 306 * rise = the amount that the text should be displaced vertically, 307 * in Pango units. Positive values displace the text upwards. 308 * 309 * Return: the newly allocated #PangoAttribute, 310 * which should be freed with pango_attribute_destroy(). 311 */ 312 public static PgAttribute riseNew(int rise) 313 { 314 auto p = pango_attr_rise_new(rise); 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 font size scale attribute. The base font for the 326 * affected text will have its size multiplied by @scale_factor. 327 * 328 * Params: 329 * scaleFactor = factor to scale the font 330 * 331 * Return: the newly allocated #PangoAttribute, 332 * which should be freed with pango_attribute_destroy(). 333 */ 334 public static PgAttribute scaleNew(double scaleFactor) 335 { 336 auto p = pango_attr_scale_new(scaleFactor); 337 338 if(p is null) 339 { 340 return null; 341 } 342 343 return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p); 344 } 345 346 /** 347 * Create a new font stretch attribute 348 * 349 * Params: 350 * stretch = the stretch 351 * 352 * Return: the newly allocated #PangoAttribute, 353 * which should be freed with pango_attribute_destroy(). 354 */ 355 public static PgAttribute stretchNew(PangoStretch stretch) 356 { 357 auto p = pango_attr_stretch_new(stretch); 358 359 if(p is null) 360 { 361 return null; 362 } 363 364 return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p); 365 } 366 367 /** 368 * Create a new strikethrough color attribute. This attribute 369 * modifies the color of strikethrough lines. If not set, strikethrough 370 * lines will use the foreground color. 371 * 372 * Params: 373 * red = the red value (ranging from 0 to 65535) 374 * green = the green value 375 * blue = the blue value 376 * 377 * Return: the newly allocated #PangoAttribute, 378 * which should be freed with pango_attribute_destroy(). 379 * 380 * Since: 1.8 381 */ 382 public static PgAttribute strikethroughColorNew(ushort red, ushort green, ushort blue) 383 { 384 auto p = pango_attr_strikethrough_color_new(red, green, blue); 385 386 if(p is null) 387 { 388 return null; 389 } 390 391 return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p); 392 } 393 394 /** 395 * Create a new strike-through attribute. 396 * 397 * Params: 398 * strikethrough = %TRUE if the text should be struck-through. 399 * 400 * Return: the newly allocated #PangoAttribute, 401 * which should be freed with pango_attribute_destroy(). 402 */ 403 public static PgAttribute strikethroughNew(bool strikethrough) 404 { 405 auto p = pango_attr_strikethrough_new(strikethrough); 406 407 if(p is null) 408 { 409 return null; 410 } 411 412 return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p); 413 } 414 415 /** 416 * Create a new font slant style attribute. 417 * 418 * Params: 419 * style = the slant style 420 * 421 * Return: the newly allocated #PangoAttribute, 422 * which should be freed with pango_attribute_destroy(). 423 */ 424 public static PgAttribute styleNew(PangoStyle style) 425 { 426 auto p = pango_attr_style_new(style); 427 428 if(p is null) 429 { 430 return null; 431 } 432 433 return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p); 434 } 435 436 /** 437 * Fetches the attribute type name passed in when registering the type using 438 * pango_attr_type_register(). 439 * 440 * The returned value is an interned string (see g_intern_string() for what 441 * that means) that should not be modified or freed. 442 * 443 * Params: 444 * type = an attribute type ID to fetch the name for 445 * 446 * Return: the type ID name (which may be %NULL), or %NULL if @type is 447 * a built-in Pango attribute type or invalid. 448 * 449 * Since: 1.22 450 */ 451 public static string typeGetName(PangoAttrType type) 452 { 453 return Str.toString(pango_attr_type_get_name(type)); 454 } 455 456 /** 457 * Allocate a new attribute type ID. The attribute type name can be accessed 458 * later by using pango_attr_type_get_name(). 459 * 460 * Params: 461 * name = an identifier for the type 462 * 463 * Return: the new type ID. 464 */ 465 public static PangoAttrType typeRegister(string name) 466 { 467 return pango_attr_type_register(Str.toStringz(name)); 468 } 469 470 /** 471 * Create a new underline color attribute. This attribute 472 * modifies the color of underlines. If not set, underlines 473 * will use the foreground color. 474 * 475 * Params: 476 * red = the red value (ranging from 0 to 65535) 477 * green = the green value 478 * blue = the blue value 479 * 480 * Return: the newly allocated #PangoAttribute, 481 * which should be freed with pango_attribute_destroy(). 482 * 483 * Since: 1.8 484 */ 485 public static PgAttribute underlineColorNew(ushort red, ushort green, ushort blue) 486 { 487 auto p = pango_attr_underline_color_new(red, green, blue); 488 489 if(p is null) 490 { 491 return null; 492 } 493 494 return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p); 495 } 496 497 /** 498 * Create a new underline-style attribute. 499 * 500 * Params: 501 * underline = the underline style. 502 * 503 * Return: the newly allocated #PangoAttribute, 504 * which should be freed with pango_attribute_destroy(). 505 */ 506 public static PgAttribute underlineNew(PangoUnderline underline) 507 { 508 auto p = pango_attr_underline_new(underline); 509 510 if(p is null) 511 { 512 return null; 513 } 514 515 return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p); 516 } 517 518 /** 519 * Create a new font variant attribute (normal or small caps) 520 * 521 * Params: 522 * variant = the variant 523 * 524 * Return: the newly allocated #PangoAttribute, 525 * which should be freed with pango_attribute_destroy(). 526 */ 527 public static PgAttribute variantNew(PangoVariant variant) 528 { 529 auto p = pango_attr_variant_new(variant); 530 531 if(p is null) 532 { 533 return null; 534 } 535 536 return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p); 537 } 538 539 /** 540 * Create a new font weight attribute. 541 * 542 * Params: 543 * weight = the weight 544 * 545 * Return: the newly allocated #PangoAttribute, 546 * which should be freed with pango_attribute_destroy(). 547 */ 548 public static PgAttribute weightNew(PangoWeight weight) 549 { 550 auto p = pango_attr_weight_new(weight); 551 552 if(p is null) 553 { 554 return null; 555 } 556 557 return ObjectG.getDObject!(PgAttribute)(cast(PangoAttribute*) p); 558 } 559 560 /** 561 * After feeding a pango markup parser some data with g_markup_parse_context_parse(), 562 * use this function to get the list of pango attributes and text out of the 563 * markup. This function will not free @context, use g_markup_parse_context_free() 564 * to do so. 565 * 566 * Params: 567 * context = A valid parse context that was returned from pango_markup_parser_new() 568 * attrList = address of return location for a #PangoAttrList, or %NULL 569 * text = address of return location for text with tags stripped, or %NULL 570 * accelChar = address of return location for accelerator char, or %NULL 571 * 572 * Return: %FALSE if @error is set, otherwise %TRUE 573 * 574 * Since: 1.31.0 575 * 576 * Throws: GException on failure. 577 */ 578 public static bool markupParserFinish(SimpleXML context, out PgAttributeList attrList, out string text, out dchar accelChar) 579 { 580 PangoAttrList* outattrList = null; 581 char* outtext = null; 582 GError* err = null; 583 584 auto p = pango_markup_parser_finish((context is null) ? null : context.getSimpleXMLStruct(), &outattrList, &outtext, &accelChar, &err) != 0; 585 586 if (err !is null) 587 { 588 throw new GException( new ErrorG(err) ); 589 } 590 591 attrList = ObjectG.getDObject!(PgAttributeList)(outattrList); 592 text = Str.toString(outtext); 593 594 return p; 595 } 596 597 /** 598 * Parses marked-up text (see 599 * <link linkend="PangoMarkupFormat">markup format</link>) to create 600 * a plain-text string and an attribute list. 601 * 602 * If @accel_marker is nonzero, the given character will mark the 603 * character following it as an accelerator. For example, @accel_marker 604 * might be an ampersand or underscore. All characters marked 605 * as an accelerator will receive a %PANGO_UNDERLINE_LOW attribute, 606 * and the first character so marked will be returned in @accel_char, 607 * when calling finish(). Two @accel_marker characters following each 608 * other produce a single literal @accel_marker character. 609 * 610 * To feed markup to the parser, use g_markup_parse_context_parse() 611 * on the returned #GMarkupParseContext. When done with feeding markup 612 * to the parser, use pango_markup_parser_finish() to get the data out 613 * of it, and then use g_markup_parse_context_free() to free it. 614 * 615 * This function is designed for applications that read pango markup 616 * from streams. To simply parse a string containing pango markup, 617 * the simpler pango_parse_markup() API is recommended instead. 618 * 619 * Params: 620 * accelMarker = character that precedes an accelerator, or 0 for none 621 * 622 * Return: a #GMarkupParseContext that should be 623 * destroyed with g_markup_parse_context_free(). 624 * 625 * Since: 1.31.0 626 */ 627 public static SimpleXML markupParserNew(dchar accelMarker) 628 { 629 auto p = pango_markup_parser_new(accelMarker); 630 631 if(p is null) 632 { 633 return null; 634 } 635 636 return new SimpleXML(cast(GMarkupParseContext*) p); 637 } 638 639 /** 640 * Parses marked-up text (see 641 * <link linkend="PangoMarkupFormat">markup format</link>) to create 642 * a plain-text string and an attribute list. 643 * 644 * If @accel_marker is nonzero, the given character will mark the 645 * character following it as an accelerator. For example, @accel_marker 646 * might be an ampersand or underscore. All characters marked 647 * as an accelerator will receive a %PANGO_UNDERLINE_LOW attribute, 648 * and the first character so marked will be returned in @accel_char. 649 * Two @accel_marker characters following each other produce a single 650 * literal @accel_marker character. 651 * 652 * To parse a stream of pango markup incrementally, use pango_markup_parser_new(). 653 * 654 * If any error happens, none of the output arguments are touched except 655 * for @error. 656 * 657 * Params: 658 * markupText = markup to parse (see <link linkend="PangoMarkupFormat">markup format</link>) 659 * length = length of @markup_text, or -1 if nul-terminated 660 * accelMarker = character that precedes an accelerator, or 0 for none 661 * attrList = address of return location for a #PangoAttrList, or %NULL 662 * text = address of return location for text with tags stripped, or %NULL 663 * accelChar = address of return location for accelerator char, or %NULL 664 * 665 * Return: %FALSE if @error is set, otherwise %TRUE 666 * 667 * Throws: GException on failure. 668 */ 669 public static bool parseMarkup(string markupText, int length, dchar accelMarker, out PgAttributeList attrList, out string text, out dchar accelChar) 670 { 671 PangoAttrList* outattrList = null; 672 char* outtext = null; 673 GError* err = null; 674 675 auto p = pango_parse_markup(Str.toStringz(markupText), length, accelMarker, &outattrList, &outtext, &accelChar, &err) != 0; 676 677 if (err !is null) 678 { 679 throw new GException( new ErrorG(err) ); 680 } 681 682 attrList = ObjectG.getDObject!(PgAttributeList)(outattrList); 683 text = Str.toString(outtext); 684 685 return p; 686 } 687 }