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