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