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.PgFontDescription; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import glib.c.functions; 30 private import gobject.ObjectG; 31 private import gtkd.Loader; 32 private import pango.c.functions; 33 public import pango.c.types; 34 35 36 /** 37 * A `PangoFontDescription` describes a font in an implementation-independent 38 * manner. 39 * 40 * `PangoFontDescription` structures are used both to list what fonts are 41 * available on the system and also for specifying the characteristics of 42 * a font to load. 43 */ 44 public class PgFontDescription 45 { 46 /** the main Gtk struct */ 47 protected PangoFontDescription* pangoFontDescription; 48 protected bool ownedRef; 49 50 /** Get the main Gtk struct */ 51 public PangoFontDescription* getPgFontDescriptionStruct(bool transferOwnership = false) 52 { 53 if (transferOwnership) 54 ownedRef = false; 55 return pangoFontDescription; 56 } 57 58 /** the main Gtk struct as a void* */ 59 protected void* getStruct() 60 { 61 return cast(void*)pangoFontDescription; 62 } 63 64 /** 65 * Sets our main struct and passes it to the parent class. 66 */ 67 public this (PangoFontDescription* pangoFontDescription, bool ownedRef = false) 68 { 69 this.pangoFontDescription = pangoFontDescription; 70 this.ownedRef = ownedRef; 71 } 72 73 ~this () 74 { 75 if ( Linker.isLoaded(LIBRARY_PANGO) && ownedRef ) 76 pango_font_description_free(pangoFontDescription); 77 } 78 79 /** 80 * Creates a nwe font description and set the family nd the size 81 * Params: 82 * family = Family 83 * size = Size 84 */ 85 public this(string family, int size) 86 { 87 this(); 88 setFamily(family); 89 setSize(size * PANGO_SCALE); 90 } 91 92 /** 93 */ 94 95 /** */ 96 public static GType getType() 97 { 98 return pango_font_description_get_type(); 99 } 100 101 /** 102 * Creates a new font description structure with all fields unset. 103 * 104 * Returns: the newly allocated `PangoFontDescription`, which 105 * should be freed using [method@Pango.FontDescription.free]. 106 * 107 * Throws: ConstructionException GTK+ fails to create the object. 108 */ 109 public this() 110 { 111 auto __p = pango_font_description_new(); 112 113 if(__p is null) 114 { 115 throw new ConstructionException("null returned by new"); 116 } 117 118 this(cast(PangoFontDescription*) __p); 119 } 120 121 /** 122 * Determines if the style attributes of @new_match are a closer match 123 * for @desc than those of @old_match are, or if @old_match is %NULL, 124 * determines if @new_match is a match at all. 125 * 126 * Approximate matching is done for weight and style; other style attributes 127 * must match exactly. Style attributes are all attributes other than family 128 * and size-related attributes. Approximate matching for style considers 129 * %PANGO_STYLE_OBLIQUE and %PANGO_STYLE_ITALIC as matches, but not as good 130 * a match as when the styles are equal. 131 * 132 * Note that @old_match must match @desc. 133 * 134 * Params: 135 * oldMatch = a `PangoFontDescription`, or %NULL 136 * newMatch = a `PangoFontDescription` 137 * 138 * Returns: %TRUE if @new_match is a better match 139 */ 140 public bool betterMatch(PgFontDescription oldMatch, PgFontDescription newMatch) 141 { 142 return pango_font_description_better_match(pangoFontDescription, (oldMatch is null) ? null : oldMatch.getPgFontDescriptionStruct(), (newMatch is null) ? null : newMatch.getPgFontDescriptionStruct()) != 0; 143 } 144 145 /** 146 * Make a copy of a `PangoFontDescription`. 147 * 148 * Returns: the newly allocated `PangoFontDescription`, 149 * which should be freed with [method@Pango.FontDescription.free], 150 * or %NULL if @desc was %NULL. 151 */ 152 public PgFontDescription copy() 153 { 154 auto __p = pango_font_description_copy(pangoFontDescription); 155 156 if(__p is null) 157 { 158 return null; 159 } 160 161 return ObjectG.getDObject!(PgFontDescription)(cast(PangoFontDescription*) __p, true); 162 } 163 164 /** 165 * Make a copy of a `PangoFontDescription`, but don't duplicate 166 * allocated fields. 167 * 168 * This is like [method@Pango.FontDescription.copy], but only a shallow 169 * copy is made of the family name and other allocated fields. The result 170 * can only be used until @desc is modified or freed. This is meant 171 * to be used when the copy is only needed temporarily. 172 * 173 * Returns: the newly allocated `PangoFontDescription`, 174 * which should be freed with [method@Pango.FontDescription.free], 175 * or %NULL if @desc was %NULL. 176 */ 177 public PgFontDescription copyStatic() 178 { 179 auto __p = pango_font_description_copy_static(pangoFontDescription); 180 181 if(__p is null) 182 { 183 return null; 184 } 185 186 return ObjectG.getDObject!(PgFontDescription)(cast(PangoFontDescription*) __p, true); 187 } 188 189 /** 190 * Compares two font descriptions for equality. 191 * 192 * Two font descriptions are considered equal if the fonts they describe 193 * are provably identical. This means that their masks do not have to match, 194 * as long as other fields are all the same. (Two font descriptions may 195 * result in identical fonts being loaded, but still compare %FALSE.) 196 * 197 * Params: 198 * desc2 = another `PangoFontDescription` 199 * 200 * Returns: %TRUE if the two font descriptions are identical, 201 * %FALSE otherwise. 202 */ 203 public bool equal(PgFontDescription desc2) 204 { 205 return pango_font_description_equal(pangoFontDescription, (desc2 is null) ? null : desc2.getPgFontDescriptionStruct()) != 0; 206 } 207 208 /** 209 * Frees a font description. 210 */ 211 public void free() 212 { 213 pango_font_description_free(pangoFontDescription); 214 ownedRef = false; 215 } 216 217 /** 218 * Gets the family name field of a font description. 219 * 220 * See [method@Pango.FontDescription.set_family]. 221 * 222 * Returns: the family name field for the font 223 * description, or %NULL if not previously set. This has the same 224 * life-time as the font description itself and should not be freed. 225 */ 226 public string getFamily() 227 { 228 return Str.toString(pango_font_description_get_family(pangoFontDescription)); 229 } 230 231 /** 232 * Gets the gravity field of a font description. 233 * 234 * See [method@Pango.FontDescription.set_gravity]. 235 * 236 * Returns: the gravity field for the font description. 237 * Use [method@Pango.FontDescription.get_set_fields] to find out 238 * if the field was explicitly set or not. 239 * 240 * Since: 1.16 241 */ 242 public PangoGravity getGravity() 243 { 244 return pango_font_description_get_gravity(pangoFontDescription); 245 } 246 247 /** 248 * Determines which fields in a font description have been set. 249 * 250 * Returns: a bitmask with bits set corresponding to the 251 * fields in @desc that have been set. 252 */ 253 public PangoFontMask getSetFields() 254 { 255 return pango_font_description_get_set_fields(pangoFontDescription); 256 } 257 258 /** 259 * Gets the size field of a font description. 260 * 261 * See [method@Pango.FontDescription.set_size]. 262 * 263 * Returns: the size field for the font description in points 264 * or device units. You must call 265 * [method@Pango.FontDescription.get_size_is_absolute] to find out 266 * which is the case. Returns 0 if the size field has not previously 267 * been set or it has been set to 0 explicitly. 268 * Use [method@Pango.FontDescription.get_set_fields] to find out 269 * if the field was explicitly set or not. 270 */ 271 public int getSize() 272 { 273 return pango_font_description_get_size(pangoFontDescription); 274 } 275 276 /** 277 * Determines whether the size of the font is in points (not absolute) 278 * or device units (absolute). 279 * 280 * See [method@Pango.FontDescription.set_size] 281 * and [method@Pango.FontDescription.set_absolute_size]. 282 * 283 * Returns: whether the size for the font description is in 284 * points or device units. Use [method@Pango.FontDescription.get_set_fields] 285 * to find out if the size field of the font description was explicitly 286 * set or not. 287 * 288 * Since: 1.8 289 */ 290 public bool getSizeIsAbsolute() 291 { 292 return pango_font_description_get_size_is_absolute(pangoFontDescription) != 0; 293 } 294 295 /** 296 * Gets the stretch field of a font description. 297 * 298 * See [method@Pango.FontDescription.set_stretch]. 299 * 300 * Returns: the stretch field for the font description. 301 * Use [method@Pango.FontDescription.get_set_fields] to find 302 * out if the field was explicitly set or not. 303 */ 304 public PangoStretch getStretch() 305 { 306 return pango_font_description_get_stretch(pangoFontDescription); 307 } 308 309 /** 310 * Gets the style field of a `PangoFontDescription`. 311 * 312 * See [method@Pango.FontDescription.set_style]. 313 * 314 * Returns: the style field for the font description. 315 * Use [method@Pango.FontDescription.get_set_fields] to 316 * find out if the field was explicitly set or not. 317 */ 318 public PangoStyle getStyle() 319 { 320 return pango_font_description_get_style(pangoFontDescription); 321 } 322 323 /** 324 * Gets the variant field of a `PangoFontDescription`. 325 * 326 * See [method@Pango.FontDescription.set_variant]. 327 * 328 * Returns: the variant field for the font description. 329 * Use [method@Pango.FontDescription.get_set_fields] to find 330 * out if the field was explicitly set or not. 331 */ 332 public PangoVariant getVariant() 333 { 334 return pango_font_description_get_variant(pangoFontDescription); 335 } 336 337 /** 338 * Gets the variations field of a font description. 339 * 340 * See [method@Pango.FontDescription.set_variations]. 341 * 342 * Returns: the variations field for the font 343 * description, or %NULL if not previously set. This has the same 344 * life-time as the font description itself and should not be freed. 345 * 346 * Since: 1.42 347 */ 348 public string getVariations() 349 { 350 return Str.toString(pango_font_description_get_variations(pangoFontDescription)); 351 } 352 353 /** 354 * Gets the weight field of a font description. 355 * 356 * See [method@Pango.FontDescription.set_weight]. 357 * 358 * Returns: the weight field for the font description. 359 * Use [method@Pango.FontDescription.get_set_fields] to find 360 * out if the field was explicitly set or not. 361 */ 362 public PangoWeight getWeight() 363 { 364 return pango_font_description_get_weight(pangoFontDescription); 365 } 366 367 /** 368 * Computes a hash of a `PangoFontDescription` structure. 369 * 370 * This is suitable to be used, for example, as an argument 371 * to g_hash_table_new(). The hash value is independent of @desc->mask. 372 * 373 * Returns: the hash value. 374 */ 375 public uint hash() 376 { 377 return pango_font_description_hash(pangoFontDescription); 378 } 379 380 /** 381 * Merges the fields that are set in @desc_to_merge into the fields in 382 * @desc. 383 * 384 * If @replace_existing is %FALSE, only fields in @desc that 385 * are not already set are affected. If %TRUE, then fields that are 386 * already set will be replaced as well. 387 * 388 * If @desc_to_merge is %NULL, this function performs nothing. 389 * 390 * Params: 391 * descToMerge = the `PangoFontDescription` to merge from, 392 * or %NULL 393 * replaceExisting = if %TRUE, replace fields in @desc with the 394 * corresponding values from @desc_to_merge, even if they 395 * are already exist. 396 */ 397 public void merge(PgFontDescription descToMerge, bool replaceExisting) 398 { 399 pango_font_description_merge(pangoFontDescription, (descToMerge is null) ? null : descToMerge.getPgFontDescriptionStruct(), replaceExisting); 400 } 401 402 /** 403 * Merges the fields that are set in @desc_to_merge into the fields in 404 * @desc, without copying allocated fields. 405 * 406 * This is like [method@Pango.FontDescription.merge], but only a shallow copy 407 * is made of the family name and other allocated fields. @desc can only 408 * be used until @desc_to_merge is modified or freed. This is meant to 409 * be used when the merged font description is only needed temporarily. 410 * 411 * Params: 412 * descToMerge = the `PangoFontDescription` to merge from 413 * replaceExisting = if %TRUE, replace fields in @desc with the 414 * corresponding values from @desc_to_merge, even if they 415 * are already exist. 416 */ 417 public void mergeStatic(PgFontDescription descToMerge, bool replaceExisting) 418 { 419 pango_font_description_merge_static(pangoFontDescription, (descToMerge is null) ? null : descToMerge.getPgFontDescriptionStruct(), replaceExisting); 420 } 421 422 /** 423 * Sets the size field of a font description, in device units. 424 * 425 * This is mutually exclusive with [method@Pango.FontDescription.set_size] 426 * which sets the font size in points. 427 * 428 * Params: 429 * size = the new size, in Pango units. There are %PANGO_SCALE Pango units 430 * in one device unit. For an output backend where a device unit is a pixel, 431 * a @size value of 10 * PANGO_SCALE gives a 10 pixel font. 432 * 433 * Since: 1.8 434 */ 435 public void setAbsoluteSize(double size) 436 { 437 pango_font_description_set_absolute_size(pangoFontDescription, size); 438 } 439 440 /** 441 * Sets the family name field of a font description. 442 * 443 * The family 444 * name represents a family of related font styles, and will 445 * resolve to a particular `PangoFontFamily`. In some uses of 446 * `PangoFontDescription`, it is also possible to use a comma 447 * separated list of family names for this field. 448 * 449 * Params: 450 * family = a string representing the family name. 451 */ 452 public void setFamily(string family) 453 { 454 pango_font_description_set_family(pangoFontDescription, Str.toStringz(family)); 455 } 456 457 /** 458 * Sets the family name field of a font description, without copying the string. 459 * 460 * This is like [method@Pango.FontDescription.set_family], except that no 461 * copy of @family is made. The caller must make sure that the 462 * string passed in stays around until @desc has been freed or the 463 * name is set again. This function can be used if @family is a static 464 * string such as a C string literal, or if @desc is only needed temporarily. 465 * 466 * Params: 467 * family = a string representing the family name 468 */ 469 public void setFamilyStatic(string family) 470 { 471 pango_font_description_set_family_static(pangoFontDescription, Str.toStringz(family)); 472 } 473 474 /** 475 * Sets the gravity field of a font description. 476 * 477 * The gravity field 478 * specifies how the glyphs should be rotated. If @gravity is 479 * %PANGO_GRAVITY_AUTO, this actually unsets the gravity mask on 480 * the font description. 481 * 482 * This function is seldom useful to the user. Gravity should normally 483 * be set on a `PangoContext`. 484 * 485 * Params: 486 * gravity = the gravity for the font description. 487 * 488 * Since: 1.16 489 */ 490 public void setGravity(PangoGravity gravity) 491 { 492 pango_font_description_set_gravity(pangoFontDescription, gravity); 493 } 494 495 /** 496 * Sets the size field of a font description in fractional points. 497 * 498 * This is mutually exclusive with 499 * [method@Pango.FontDescription.set_absolute_size]. 500 * 501 * Params: 502 * size = the size of the font in points, scaled by %PANGO_SCALE. 503 * (That is, a @size value of 10 * PANGO_SCALE is a 10 point font. 504 * The conversion factor between points and device units depends on 505 * system configuration and the output device. For screen display, a 506 * logical DPI of 96 is common, in which case a 10 point font corresponds 507 * to a 10 * (96 / 72) = 13.3 pixel font. 508 * Use [method@Pango.FontDescription.set_absolute_size] if you need 509 * a particular size in device units. 510 */ 511 public void setSize(int size) 512 { 513 pango_font_description_set_size(pangoFontDescription, size); 514 } 515 516 /** 517 * Sets the stretch field of a font description. 518 * 519 * The [enum@Pango.Stretch] field specifies how narrow or 520 * wide the font should be. 521 * 522 * Params: 523 * stretch = the stretch for the font description 524 */ 525 public void setStretch(PangoStretch stretch) 526 { 527 pango_font_description_set_stretch(pangoFontDescription, stretch); 528 } 529 530 /** 531 * Sets the style field of a `PangoFontDescription`. 532 * 533 * The [enum@Pango.Style] enumeration describes whether the font is 534 * slanted and the manner in which it is slanted; it can be either 535 * #PANGO_STYLE_NORMAL, #PANGO_STYLE_ITALIC, or #PANGO_STYLE_OBLIQUE. 536 * 537 * Most fonts will either have a italic style or an oblique style, 538 * but not both, and font matching in Pango will match italic 539 * specifications with oblique fonts and vice-versa if an exact 540 * match is not found. 541 * 542 * Params: 543 * style = the style for the font description 544 */ 545 public void setStyle(PangoStyle style) 546 { 547 pango_font_description_set_style(pangoFontDescription, style); 548 } 549 550 /** 551 * Sets the variant field of a font description. 552 * 553 * The [enum@Pango.Variant] can either be %PANGO_VARIANT_NORMAL 554 * or %PANGO_VARIANT_SMALL_CAPS. 555 * 556 * Params: 557 * variant = the variant type for the font description. 558 */ 559 public void setVariant(PangoVariant variant) 560 { 561 pango_font_description_set_variant(pangoFontDescription, variant); 562 } 563 564 /** 565 * Sets the variations field of a font description. 566 * 567 * OpenType font variations allow to select a font instance by 568 * specifying values for a number of axes, such as width or weight. 569 * 570 * The format of the variations string is 571 * 572 * AXIS1=VALUE,AXIS2=VALUE... 573 * 574 * with each AXIS a 4 character tag that identifies a font axis, 575 * and each VALUE a floating point number. Unknown axes are ignored, 576 * and values are clamped to their allowed range. 577 * 578 * Pango does not currently have a way to find supported axes of 579 * a font. Both harfbuzz or freetype have API for this. 580 * 581 * Params: 582 * variations = a string representing the variations 583 * 584 * Since: 1.42 585 */ 586 public void setVariations(string variations) 587 { 588 pango_font_description_set_variations(pangoFontDescription, Str.toStringz(variations)); 589 } 590 591 /** 592 * Sets the variations field of a font description. 593 * 594 * This is like [method@Pango.FontDescription.set_variations], except 595 * that no copy of @variations is made. The caller must make sure that 596 * the string passed in stays around until @desc has been freed 597 * or the name is set again. This function can be used if 598 * @variations is a static string such as a C string literal, 599 * or if @desc is only needed temporarily. 600 * 601 * Params: 602 * variations = a string representing the variations 603 * 604 * Since: 1.42 605 */ 606 public void setVariationsStatic(string variations) 607 { 608 pango_font_description_set_variations_static(pangoFontDescription, Str.toStringz(variations)); 609 } 610 611 /** 612 * Sets the weight field of a font description. 613 * 614 * The weight field 615 * specifies how bold or light the font should be. In addition 616 * to the values of the [enum@Pango.Weight] enumeration, other 617 * intermediate numeric values are possible. 618 * 619 * Params: 620 * weight = the weight for the font description. 621 */ 622 public void setWeight(PangoWeight weight) 623 { 624 pango_font_description_set_weight(pangoFontDescription, weight); 625 } 626 627 /** 628 * Creates a filename representation of a font description. 629 * 630 * The filename is identical to the result from calling 631 * [method@Pango.FontDescription.to_string], but with underscores 632 * instead of characters that are untypical in filenames, and in 633 * lower case only. 634 * 635 * Returns: a new string that must be freed with g_free(). 636 */ 637 public string toFilename() 638 { 639 auto retStr = pango_font_description_to_filename(pangoFontDescription); 640 641 scope(exit) Str.freeString(retStr); 642 return Str.toString(retStr); 643 } 644 645 /** 646 * Creates a string representation of a font description. 647 * 648 * See [type_func@Pango.FontDescription.from_string] for a description 649 * of the format of the string representation. The family list in 650 * the string description will only have a terminating comma if 651 * the last word of the list is a valid style option. 652 * 653 * Returns: a new string that must be freed with g_free(). 654 */ 655 public override string toString() 656 { 657 auto retStr = pango_font_description_to_string(pangoFontDescription); 658 659 scope(exit) Str.freeString(retStr); 660 return Str.toString(retStr); 661 } 662 663 /** 664 * Unsets some of the fields in a `PangoFontDescription`. 665 * 666 * The unset fields will get back to their default values. 667 * 668 * Params: 669 * toUnset = bitmask of fields in the @desc to unset. 670 */ 671 public void unsetFields(PangoFontMask toUnset) 672 { 673 pango_font_description_unset_fields(pangoFontDescription, toUnset); 674 } 675 676 /** 677 * Creates a new font description from a string representation. 678 * 679 * The string must have the form 680 * 681 * "\[FAMILY-LIST] \[STYLE-OPTIONS] \[SIZE] \[VARIATIONS]", 682 * 683 * where FAMILY-LIST is a comma-separated list of families optionally 684 * terminated by a comma, STYLE_OPTIONS is a whitespace-separated list 685 * of words where each word describes one of style, variant, weight, 686 * stretch, or gravity, and SIZE is a decimal number (size in points) 687 * or optionally followed by the unit modifier "px" for absolute size. 688 * VARIATIONS is a comma-separated list of font variation 689 * specifications of the form "\@axis=value" (the = sign is optional). 690 * 691 * The following words are understood as styles: 692 * "Normal", "Roman", "Oblique", "Italic". 693 * 694 * The following words are understood as variants: 695 * "Small-Caps". 696 * 697 * The following words are understood as weights: 698 * "Thin", "Ultra-Light", "Extra-Light", "Light", "Semi-Light", 699 * "Demi-Light", "Book", "Regular", "Medium", "Semi-Bold", "Demi-Bold", 700 * "Bold", "Ultra-Bold", "Extra-Bold", "Heavy", "Black", "Ultra-Black", 701 * "Extra-Black". 702 * 703 * The following words are understood as stretch values: 704 * "Ultra-Condensed", "Extra-Condensed", "Condensed", "Semi-Condensed", 705 * "Semi-Expanded", "Expanded", "Extra-Expanded", "Ultra-Expanded". 706 * 707 * The following words are understood as gravity values: 708 * "Not-Rotated", "South", "Upside-Down", "North", "Rotated-Left", 709 * "East", "Rotated-Right", "West". 710 * 711 * Any one of the options may be absent. If FAMILY-LIST is absent, then 712 * the family_name field of the resulting font description will be 713 * initialized to %NULL. If STYLE-OPTIONS is missing, then all style 714 * options will be set to the default values. If SIZE is missing, the 715 * size in the resulting font description will be set to 0. 716 * 717 * A typical example: 718 * 719 * "Cantarell Italic Light 15 \@wght=200" 720 * 721 * Params: 722 * str = string representation of a font description. 723 * 724 * Returns: a new `PangoFontDescription`. 725 */ 726 public static PgFontDescription fromString(string str) 727 { 728 auto __p = pango_font_description_from_string(Str.toStringz(str)); 729 730 if(__p is null) 731 { 732 return null; 733 } 734 735 return ObjectG.getDObject!(PgFontDescription)(cast(PangoFontDescription*) __p, true); 736 } 737 }