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