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