1/* 2 * Copyright 2013 Haiku Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * John Scipione, jscipione@gmail.com 7 * 8 * Corresponds to: 9 * headers/os/interface/Font.h hrev45178 10 * src/kits/interface/Font.cpp hrev45178 11 */ 12 13 14/*! 15 \file Font.h 16 \ingroup interface 17 \ingroup libbe 18 \brief BFont class definition, unicode_block class definition, and 19 font-related struct and enum definitions. 20*/ 21 22 23/*! 24 \var B_CHAR_SPACING 25 26 Position each character without adjustment. Best mode for printing. 27*/ 28 29 30/*! 31 \var B_STRING_SPACING 32 33 Optimizes the position of each character within it's space. Collisions 34 are unlikely but characters may touch each other. Best mode to use when 35 the screen needs to match what appears on the printed page. 36*/ 37 38 39/*! 40 \var B_BITMAP_SPACING 41 42 The widths of the characters are chosen so that they never collide and 43 rarely touch. Best mode for drawing small amounts of text. 44*/ 45 46 47/*! 48 \var B_FIXED_SPACING 49 50 Positions characters at a constant width. Best mode for fixed-width fonts. 51*/ 52 53 54/*! 55 \enum font_direction 56 \ingroup interface 57 58 Determines the direction of the text rendered by the font, 59 left-to-right or right-to-left. 60*/ 61 62 63/*! 64 \var font_direction B_FONT_LEFT_TO_RIGHT 65 66 Left to right. 67*/ 68 69/*! 70 \var font_direction B_FONT_RIGHT_TO_LEFT 71 72 Right to left. 73*/ 74 75 76/*! 77 \var B_DISABLE_ANTIALIASING 78 79 Disable antialiasing. Used by BFont::Flags() and BFont::SetFlags(). 80*/ 81 82 83/*! 84 \var B_FORCE_ANTIALIASING 85 86 Force antialiasing. Used by BFont::Flags() and BFont::SetFlags(). 87*/ 88 89 90/*! 91 \var B_TRUNCATE_END 92 93 Truncate from the end of the string. 94*/ 95 96 97/*! 98 \var B_TRUNCATE_BEGINNING 99 100 Truncate from the beginning of the string. 101*/ 102 103 104/*! 105 \var B_TRUNCATE_MIDDLE 106 107 Truncate from the middle of the string. 108*/ 109 110 111/*! 112 \var B_TRUNCATE_SMART 113 114 Truncate while keeping each string unique. 115*/ 116 117 118/*! 119 \var B_UNICODE_UTF8 120 121 UTF-8 font encoding. 122*/ 123 124 125/*! 126 \var B_ISO_8859_1 127 128 ISO 8859-1 aka Latin 1 "Western European" font encoding. 129*/ 130 131 132/*! 133 \var B_ISO_8859_2 134 135 ISO 8859-2 aka Latin 2 "Eastern European" font encoding. 136*/ 137 138 139/*! 140 \var B_ISO_8859_3 141 142 ISO 8859-3 aka Latin 3 "South European" font encoding. 143*/ 144 145 146/*! 147 \var B_ISO_8859_4 148 149 ISO 8859-4 aka Latin 4 "Northern European" font encoding. 150*/ 151 152 153/*! 154 \var B_ISO_8859_5 155 156 ISO 8859-5 "Latin/Cyrillic" font encoding. 157*/ 158 159 160/*! 161 \var B_ISO_8859_6 162 163 ISO 8859-6 "Latin/Arabic" font encoding. 164*/ 165 166 167/*! 168 \var B_ISO_8859_7 169 170 ISO 8859-7 "Latin/Greek" font encoding. 171*/ 172 173 174/*! 175 \var B_ISO_8859_8 176 177 ISO 8859-8 "Latin/Hebrew" font encoding. 178*/ 179 180 181/*! 182 \var B_ISO_8859_9 183 184 ISO 8859-9 aka Latin 5 "Latin/Turkish" font encoding. 185*/ 186 187 188/*! 189 \var B_ISO_8859_10 190 191 ISO 8859-10 aka Latin 6 "Nordic" font encoding. 192*/ 193 194 195/*! 196 \var B_MACINTOSH_ROMAN 197 198 Macintosh Roman font encoding. 199*/ 200 201 202/*! 203 \var B_HAS_TUNED_FONT 204 205 Flags for get_font_family() and get_font_style() 206*/ 207 208 209/*! 210 \var B_IS_FIXED 211 212 flags for get_font_family() and get_font_style() 213*/ 214 215 216/*! 217 \var B_ITALIC_FACE 218 219 Italic font face flag. 220*/ 221 222 223/*! 224 \var B_UNDERSCORE_FACE 225 226 Underscore font face flag. 227*/ 228 229 230/*! 231 \var B_NEGATIVE_FACE 232 233 Negative font face flag. 234*/ 235 236 237/*! 238 \var B_OUTLINED_FACE 239 240 Outline font face flag. 241*/ 242 243 244/*! 245 \var B_STRIKEOUT_FACE 246 247 Strikeout font face flag. 248*/ 249 250 251/*! 252 \var B_BOLD_FACE 253 254 Bold font face flag. 255*/ 256 257 258/*! 259 \var B_REGULAR_FACE 260 261 Regular font face flag. 262*/ 263 264 265/*! 266 \var B_CONDENSED_FACE 267 268 Condensed font face flag. Not in BeOS 5. 269*/ 270 271 272/*! 273 \var B_LIGHT_FACE 274 275 Light font face flag. Not in BeOS 5. 276*/ 277 278 279/*! 280 \var B_HEAVY_FACE 281 282 Heavy font face flag. Not in BeOS 5. 283*/ 284 285 286/*! 287 \enum font_metric_mode 288 289 Font metric mode, screen or printing. 290*/ 291 292/*! 293 \var font_metric_mode B_SCREEN_METRIC 294 295 Screen font metric mode. 296*/ 297 298/*! 299 \var font_metric_mode B_PRINTING_METRIC 300 301 Printing font metric mode. 302*/ 303 304 305/*! 306 \enum font_file_format 307 \ingroup interface 308 309 Font file format, TrueType™ or PostScript™ Type1. 310 311 \see BFont::FileFormat() 312*/ 313 314/*! 315 \var font_file_format B_TRUETYPE_WINDOWS 316 317 TrueType™ font file format. 318*/ 319 320/*! 321 \var font_file_format B_POSTSCRIPT_TYPE1_WINDOWS 322 323 PostScript™ Type1 font file format. 324*/ 325 326 327/*! 328 \class unicode_block 329 \ingroup interface 330 \ingroup libbe 331 \brief Describes the blocks of Unicode characters supported by a font. 332 333 \see BFont::Blocks() 334*/ 335 336 337/*! 338 \fn unicode_block::unicode_block() 339 \brief Construct a \c unicode_block and set block data to 0. 340 341 You must initialize the block data before before using this object. 342*/ 343 344 345/*! 346 \fn unicode_block::unicode_block(uint64 block2, uint64 block1) 347 \brief Construct a \c unicode_block object and initialize it with the 348 supplied Unicode block range. 349 350 \param block2 End block. 351 \param block1 Begin block. 352*/ 353 354 355/*! 356 \fn bool unicode_block::Includes(const unicode_block& block) const 357 \brief Determines if \a block is a subset of the \c unicode_block object. 358 359 \param block The Unicode block to check. 360 361 \returns Whether or not \a block is a subset of the \c unicode_block 362 object. 363 \retval true \a block is a subset of the current \c unicode_block. 364 \retval false \a block is NOT a subset of the current \c unicode_block. 365*/ 366 367 368/*! 369 \name Assignment operators 370*/ 371 372 373//! @{ 374 375 376/*! 377 \fn unicode_block unicode_block::operator&(const unicode_block& block) const 378 \brief Creates a new \c unicode_block object that is the intersection of 379 \a block and the \c unicode_block object. 380 381 \param block The Unicode block to intersect with. 382 383 \returns The intersection of \a block and the \c unicode_block object. 384*/ 385 386 387/*! 388 \fn unicode_block unicode_block::operator|(const unicode_block& block) const 389 \brief Creates a new \c unicode_block object that is the union of \a block 390 and the \c unicode_block object. 391 392 \param block The Unicode block to form a union with. 393 394 \returns The union of \a block and the \c unicode_block object. 395*/ 396 397 398/*! 399 \fn unicode_block& unicode_block::operator=(const unicode_block& block) 400 \brief Copies \a block data into the left-hand side object. 401 402 \param block The unicode block to copy from. 403 404 \returns A copy of \a block. 405*/ 406 407 408//! @} 409 410 411/*! 412 \name Comparison operators 413*/ 414 415 416//! @{ 417 418 419/*! 420 \fn bool unicode_block::operator==(const unicode_block& block) const 421 \brief Determines if the block object are exactly equal. 422 423 \param block The unicode block to compare against. 424 425 \returns \c true if the block object are exactly equal, \c false 426 otherwise. 427*/ 428 429 430/*! 431 \fn bool unicode_block::operator!=(const unicode_block& block) const 432 \brief Determines if the block object are not equal. 433 434 \param block The unicode block to compare against. 435 436 \returns \c true if the block object are NOT equal, \c false 437 if the block objects are exactly equal. 438*/ 439 440 441//! @} 442 443 444/*! 445 \struct edge_info 446 \ingroup interface 447 \ingroup libbe 448 \brief The distance that a character outline is inset from its escapement 449 boundaries. 450 451 Edge values, like escapements, need to be multiplied by the font size to 452 get the correct value for the font. 453 454 \see BFont::GetEdges() 455*/ 456 457 458/*! 459 \var edge_info::left 460 461 The distance that the character outline is inset from the left 462 escapement boundary. 463*/ 464 465 466/*! 467 \var edge_info::right 468 469 The distance that the character outline is inset from the right 470 escapement boundary. 471*/ 472 473 474/*! 475 \struct font_height 476 \ingroup interface 477 \ingroup libbe 478 \brief The amount of vertical space surrounding a character. 479 480 \see BFont::GetHeight() 481*/ 482 483 484/*! 485 \var font_height::ascent 486 487 The distance characters can ascend above the baseline. 488*/ 489 490 491/*! 492 \var font_height::descent 493 494 The distance characters can descend below the baseline. 495*/ 496 497 498/*! 499 \var font_height::leading 500 501 The distance between lines, descent above to ascent below. 502*/ 503 504 505/*! 506 \struct escapement_delta 507 \ingroup interface 508 \ingroup libbe 509 \brief A struct that allows you to specify extra horizontal space to surround 510 each character with. 511 512 Escapements need to be multiplied by the font size to get the correct 513 value for the font. 514 515 \see BFont::GetEscapements() 516*/ 517 518 519/*! 520 \var escapement_delta::nonspace 521 522 The amount of horizontal space to surround a visible glyph character with. 523*/ 524 525 526/*! 527 \var escapement_delta::space 528 529 The amount of horizontal space to surround a whitespace character with, for 530 example \c B_TAB or \c B_SPACE. 531*/ 532 533 534/*! 535 \struct font_cache_info 536 \ingroup interface 537 \ingroup libbe 538 \brief Font cache parameters. 539*/ 540 541 542/*! 543 \var font_cache_info::sheared_font_penalty 544 545 Sheared font penalty. 546*/ 547 548 549/*! 550 \var font_cache_info::rotated_font_penalty 551 552 Rotated font penalty. 553*/ 554 555 556/*! 557 \var font_cache_info::oversize_threshold 558 559 Oversize threshold. 560*/ 561 562 563/*! 564 \var font_cache_info::oversize_penalty 565 566 Oversize penalty. 567*/ 568 569/*! 570 \var font_cache_info::cache_size 571 572 Cache size. 573*/ 574 575 576/*! 577 \var font_cache_info::spacing_size_threshold 578 579 Spacing size threshold. 580*/ 581 582 583/*! 584 \struct tuned_font_info 585 \ingroup interface 586 \ingroup libbe 587 \brief Tuning information of fonts used to make it look better when 588 displayed on-screen. 589 590 \see BFont::GetTunedInfo() 591 \see BFont::CountTuned() 592*/ 593 594 595/*! 596 \var tuned_font_info::size 597 598 Font size. 599*/ 600 601 602/*! 603 \var tuned_font_info::shear 604 605 Font shear. 606*/ 607 608 609/*! 610 \var tuned_font_info::rotation 611 612 Font rotation. 613*/ 614 615 616/*! 617 \var tuned_font_info::flags 618 619 Font flags. 620*/ 621 622/*! 623 \var tuned_font_info::face 624 625 Font face. 626*/ 627 628 629/*! 630 \fn int32 count_font_families() 631 \brief Gets the number of installed font families 632 633 \return The number of installed font families 634*/ 635 636 637/*! 638 \fn int32 count_font_styles(font_family family) 639 \brief Gets the number of styles available for a font family. 640 641 \return The number of styles available for a font family. 642*/ 643 644 645/*! 646 \fn status_t get_font_family(int32 index, font_family *_name, 647 uint32 *_flags) 648 \brief Retrieves the family name at the specified index. 649 650 \param index Unique font identifier code. 651 \param _name font_family String to receive the name of the family. 652 \param _flags if non-<tt>NULL</tt>, the values of the flags \c IS_FIXED 653 and \c B_HAS_TUNED_FONT are returned. 654 655 \return A status code, \c B_OK on success or an error code. 656 \retval B_BAD_VALUE \a _name is \c NULL. 657 \retval B_ERROR \a index does not correspond to a font family. 658*/ 659 660 661/*! 662 \fn status_t get_font_style(font_family family, int32 index, 663 font_style *_name, uint32 *_flags) 664 \brief Retrieves the family name at the specified index. 665 666 \param family The font family. 667 \param index Unique font identifier code. 668 \param _name string to receive the name of the family. 669 \param _flags if non-<tt>NULL</tt>, the values of the flags \c IS_FIXED 670 and \c B_HAS_TUNED_FONT are returned 671 672 \return A status code, \c B_OK on success or an error code. 673 \retval B_ERROR \a index does not correspond to a font style. 674*/ 675 676 677/*! 678 \fn status_t get_font_style(font_family family, int32 index, 679 font_style *_name, uint16 *_face, uint32 *_flags) 680 \brief Retrieves the family name at the specified index. 681 682 The face value returned by this function is not very reliable. At the same 683 time, the value returned should be fairly reliable, returning the proper 684 flag for 90%-99% of font names. 685 686 \param family The font family. 687 \param index Unique font identifier code. 688 \param _name String to receive the name of the family. 689 \param _face recipient of font face value, such as \c B_REGULAR_FACE. 690 \param _flags if non-<tt>NULL</tt>, the values of the flags \c IS_FIXED 691 and \c B_HAS_TUNED_FONT are returned. 692 693 \return A status code, \c B_OK on success or an error code. 694 \retval B_ERROR \a index does not correspond to a font style. 695*/ 696 697 698/*! 699 \fn bool update_font_families(bool checkOnly) 700 \brief Updates the font families list. 701 702 \param checkOnly Parameter is ignored. 703 704 \return \c true if the font list has changed, \c false if not. 705*/ 706 707 708/*! 709 \class BFont 710 \ingroup interface 711 \ingroup libbe 712 \brief Represents a typeface including it's family, style and size. 713 714 The Interface Kit provides three prebuilt BFont objects which can be used 715 but not modified. 716 - \c const BFont* \c be_plain_font A plain font used by many controls. 717 - \c const BFont* \c be_bold_font A bold font used by titles. 718 - \c const BFont* \c be_fixed_font A fixed-width font. 719 720 A BFont object does nothing on it's own but is used in combination with 721 a view or control. Here is an example of creating a BFont object from a 722 system font and assigning it to a view: 723 724\code 725 BFont font(be_plain_font); 726 font.SetSize(12.0); 727 font.SetEncoding(B_ISO_8859_1); 728 view->SetFont(&font); 729\endcode 730 731 You may also create a BFont object from a view, modify it and reassign it 732 back to the view like this: 733 734\code 735 BFont font; 736 view->GetFont(&font); 737 font.SetFace(B_ITALIC_FACE); 738 font.SetSpacing(B_CHAR_SPACING); 739 myView->SetFont(&font); 740\endcode 741 742 You can change the way a font renders with the SetFamilyAndStyle(), 743 SetFamilyAndFace(), SetSize(), SetShear(), SetRotation(), 744 SetFalseBoldWidth(), SetSpacing(), SetEncoding(), SetFace(), and 745 SetFlags() methods. 746 747 More information about the space taken up by a font can be determined 748 by querying a BFont object using the following methods: 749 StringWidth(), GetStringWidths() GetEscapements(), GetEdges(), 750 GetHeight(), BoundingBox() GetBoundingBoxesAsGlyphs(), 751 GetBoundingBoxesAsString(), and GetBoundingBoxesForStrings(). 752 753 You can also perform intelligent string truncation with the 754 TruncateString() and GetTruncatedStrings() methods. 755*/ 756 757 758/*! 759 \fn BFont::BFont() 760 \brief Creates a BFont object initialized to \c be_plain_font. 761 762 \see BView::GetFont() 763*/ 764 765 766/*! 767 \fn BFont::BFont(const BFont &font) 768 \brief Creates and initializes a BFont object from another BFont object. 769 770 \param font The BFont object to initialize from. 771*/ 772 773 774/*! 775 \fn BFont::BFont(const BFont *font) 776 \brief Creates and initializes a BFont object from a pointer to a BFont 777 object. 778 779 \param font The pointer to a BFont object to initialize from. 780*/ 781 782 783/*! 784 \fn BFont::BFont(const BFont *font) 785 \brief Creates and initializes a BFont object from a pointer to a BFont 786 object. 787 788 \param font The pointer to a BFont object to initialize from. 789*/ 790 791 792/*! 793 \fn status_t BFont::SetFamilyAndStyle(const font_family family, 794 const font_style style) 795 \brief Sets the font's family and style all at once. 796 797 \param family Font family to set. 798 \param style Font style to set. 799 800 \returns A status code, \c B_OK on success or an error code. 801 \retval B_BAD_VALUE \a family is \c NULL and \a style is \c NULL. 802 \retval B_NAME_NOT_FOUND Family or style do not exist. 803*/ 804 805 806/*! 807 \fn void BFont::SetFamilyAndStyle(uint32 code) 808 \brief Sets the font's family and style from a font identifier. 809 810 \param code Unique font identifier obtained from the server. 811*/ 812 813 814/*! 815 \fn status_t BFont::SetFamilyAndFace(const font_family family, uint16 face) 816 \brief Sets the font's family and face all at once. 817 818 \param family Font family to set. 819 \param face Font face to set. 820 821 \note To comply with the BeBook, this function will only set valid values, 822 i.e. passing a nonexistent family will cause only the face to be set. 823 Additionally, if a particular face does not exist in a family, the 824 closest match will be chosen. 825 826 \returns A status code, \c B_OK on success or an error code. 827 \retval B_ERROR Family does not exists or face has an invalid value. 828*/ 829 830 831/*! 832 \fn void BFont::SetSize(float size) 833 \brief Sets the font size. 834 835 \param size The point size to set the font to. 836*/ 837 838 839/*! 840 \fn void BFont::SetShear(float shear) 841 \brief Sets the angle in degrees relative to the baseline. 842 843 The default shear is 90.0° measured counterclockwise. The shear 844 range is from 45.0° to 135.0°. 845 846 \param shear The shear in degrees to set the font to. 847*/ 848 849 850/*! 851 \fn void BFont::SetRotation(float rotation) 852 \brief Sets the font rotation from the baseline in degrees. 853 854 The default baseline is 0° and rotates counterclockwise. Rotation is not 855 supported by BTextView. 856 857 \param rotation The rotation in degrees to set the font to. 858*/ 859 860 861/*! 862 \fn void BFont::SetFalseBoldWidth(float width) 863 \brief Sets the false bold width. 864 865 \param width The false bold width to set. 866*/ 867 868 869/*! 870 \fn void BFont::SetSpacing(uint8 spacing) 871 \brief Sets how characters are horizontally spaced relative to each other. 872 873 - \c B_CHAR_SPACING Position each character without adjustment. Best mode 874 for printing. Characters may collide or overlap at small font sizes. 875 - \c B_STRING_SPACING Optimizes the position of each character within it's 876 space. Collisions are unlikely but characters may touch each other. 877 Best mode to use when the screen needs to match what appears on the 878 printed page. Adding new characters requires the entire string to 879 be redrawn. 880 - \c B_BITMAP_SPACING The widths of the characters are chosen so that they 881 never collide and rarely touch. Best mode for drawing small amounts 882 of text. Character widths are integral values. Spacing on screen will 883 not match spacing used by \c B_CHAR_SPACING mode for printing. 884 - \c B_FIXED_SPACING Positions characters at a constant width. Must be 885 used with fixed-width fonts otherwise \c B_CHAR_SPACING mode is used. 886 All characters have an identical integral escapement. 887 888 \c B_STRING_SPACING and \c B_BITMAP_SPACING modes are relevant only for 889 font sizes from 7.0pt to 18.0pt, above and below that range 890 \c B_CHAR_SPACING produces nicer results. \c B_CHAR_SPACING is also always 891 used for rotated or sheared text and when antialiasing is disabled. 892 893 \param spacing The spacing mode to set. 894 895 \see BView::DrawString() 896 \see GetEscapements() 897*/ 898 899 900/*! 901 \fn void BFont::SetEncoding(uint8 encoding) 902 \brief Sets the character encoding of the font for example 903 \c B_UNICODE_UTF8 or \c B_ISO_8859_1. 904 905 The following character encodings are supported: 906 - \c B_UNICODE_UTF8 907 - \c B_ISO_8859_1 aka Latin 1 aka "Western European". 908 - \c B_ISO_8859_2 aka Latin 2 aka "Eastern European". 909 - \c B_ISO_8859_3 aka Latin 3 aka "South European". 910 - \c B_ISO_8859_4 aka Latin 4 aka "Northern European". 911 - \c B_ISO_8859_5 aka "Latin/Cyrillic". 912 - \c B_ISO_8859_6 aka "Latin/Arabic". 913 - \c B_ISO_8859_7 aka "Latin/Greek". 914 - \c B_ISO_8859_8 aka "Latin/Hebrew". 915 - \c B_ISO_8859_9 aka Latin 5 aka "Latin/Turkish". 916 - \c B_ISO_8859_10 aka Latin 6 aka "Nordic". 917 - \c B_MACINTOSH_ROMAN 918 919 UTF-8 is the standard encoding used by classes in the Interface Kit. It 920 is part of the Unicode® standard and allows Haiku to represent characters 921 from all over the world while maintaining backwards compatibility with 922 7-bit ASCII codes. 923 924 Each of the encodings extend the ASCII codes and differ from each other 925 only when the highest bit is set to 1, in other words, the value is 926 greater than 127. Furthermore each of the encodings except for UTF-8 927 are represented by a single byte and consequently encompass a limited set 928 of characters. Most of the encodings are in the ISO/IEC 8859 family of 929 character codes with the notable exception of Macintosh Roman which is 930 the standard encoding used by the classic Mac OS®. 931 932 If the value of the first byte of a UTF-8 character is greater than 127 933 it indicates that the character is a multibyte character and therefore you 934 must look at the next byte (and possibly the third byte, or rarely even 935 forth byte) to get the whole character. 936 937 Setting the character encoding on a view determines how BView::DrawString() 938 interprets the values passed to it and also how BView::KeyDown() interprets 939 the values representing the keys that the user presses. 940 941 \param encoding The character encoding to set the font to. 942*/ 943 944 945/*! 946 \fn void BFont::SetFace(uint16 face) 947 \brief Sets the font face according to the flags set by \a face. 948 949 The following font face flags are supported: 950 - \c B_ITALIC_FACE Characters are slanted to the right. 951 - \c B_UNDERSCORE_FACE Characters are underlined. 952 - \c B_NEGATIVE_FACE High and low colors are reversed when drawing 953 characters. 954 - \c B_OUTLINED_FACE Characters are drawn hollowed out. 955 - \c B_STRIKEOUT_FACE A horizontal line is drawn through their middle. 956 - \c B_BOLD_FACE Characters are bold. 957 - \c B_REGULAR_FACE Characters are drawn normally. 958 - \c B_CONDENSED_FACE Characters are drawn condensed. Not in BeOS 5. 959 - \c B_LIGHT_FACE Characters are drawn thiner than normal. Not in BeOS 5. 960 - \c B_HEAVY_FACE Characters are drawn heavier than normal. Not in BeOS 5. 961 962 \param face The bitmap of font face flags to set. 963*/ 964 965 966/*! 967 \fn void BFont::SetFlags(uint32 flags) 968 \brief Sets font flags controlling antialiasing. 969 970 The following flags are supported: 971 - \c B_DISABLE_ANTIALIASING Disable antialiasing. 972 - \c B_FORCE_ANTIALIASING Force antialiasing. 973 974 \param flags The bitmap of flags to set. 975*/ 976 977 978/*! 979 \fn void BFont::GetFamilyAndStyle(font_family *family, 980 font_style *style) const 981 \brief Writes out the name of the font family and/or font style. 982 983 This method may be called with either \a family or \a style set to 984 \c NULL in order to get one or the other. 985 986 \param family A font_family pointer to be filled out. 987 \param style A font_style pointer to be filled out. 988*/ 989 990 991/*! 992 \fn uint32 BFont::FamilyAndStyle() const 993 \brief Gets the code of the font family and style combination. 994 995 \returns The family and style combination encoded as a unique integer. 996 997 \see SetFamilyAndStyle(uint32 code) 998*/ 999 1000 1001/*! 1002 \fn float BFont::Size() const 1003 \brief Gets the font size. 1004 1005 \returns The font size in points. 1006 1007 \see SetSize() 1008*/ 1009 1010 1011/*! 1012 \fn float BFont::Shear() const 1013 \brief Gets the font shear. 1014 1015 \returns The font shear as an angle from 45.0° to 135.0°. 1016 1017 \see SetShear() 1018*/ 1019 1020 1021/*! 1022 \fn float BFont::Rotation() const 1023 \brief Gets the font rotation. 1024 1025 \returns The font rotation as an angle in degrees. 1026 1027 \see SetRotation() 1028*/ 1029 1030 1031/*! 1032 \fn float BFont::FalseBoldWidth() const 1033 \brief Gets the width of the font as if it were bold. 1034 1035 \returns The font width of the bold font variety. 1036 1037 \see SetFalseBoldWidth() 1038*/ 1039 1040 1041/*! 1042 \fn uint8 BFont::Spacing() const 1043 \brief Gets the spacing constant. 1044 1045 \returns The spacing constant. 1046 1047 \see SetSpacing() 1048*/ 1049 1050 1051/*! 1052 \fn uint8 BFont::Encoding() const 1053 \brief Gets the character encoding constant. 1054 1055 \returns The character encoding constant. 1056 1057 \see SetEncoding() 1058*/ 1059 1060 1061/*! 1062 \fn uint16 BFont::Face() const 1063 \brief Gets the font face flags bitmap. 1064 1065 \returns The font face flags bitmap. 1066 1067 \see SetFace() 1068*/ 1069 1070 1071/*! 1072 \fn uint32 BFont::Flags() const 1073 \brief Gets the antialiasing flags. 1074 1075 \returns The antialiasing flags. 1076 1077 \see SetFlags() 1078*/ 1079 1080 1081/*! 1082 \fn font_direction BFont::Direction() const 1083 \brief Gets the font direction, left-to-right or right-to left. 1084 1085 \returns The font direction. 1086*/ 1087 1088 1089/*! 1090 \fn bool BFont::IsFixed() const 1091 \brief Gets whether or not the font is fixed width. 1092 1093 \returns \c true if the font is fixed width, \c false otherwise. 1094*/ 1095 1096 1097/*! 1098 \fn bool BFont::IsFullAndHalfFixed() const 1099 \brief Returns whether or not the font is fixed-width and contains both 1100 full and half-width characters. 1101 1102 \note This was left unimplemented as of R5. It is a way to work with both 1103 Kanji and Roman characters in the same fixed-width font. 1104*/ 1105 1106 1107/*! 1108 \fn BRect BFont::BoundingBox() const 1109 \brief Gets a BRect that encloses the font text. 1110 1111 \returns A BRect that encloses the font text. 1112*/ 1113 1114 1115/*! 1116 \fn unicode_block BFont::Blocks() const 1117 \brief Gets a \c unicode_block object that identifies the Unicode blocks 1118 supported by this font face and family. 1119 1120 \attention Currently unimplemented, returns an empty \a unicode_block 1121 object. 1122 1123 \returns A \c unicode_block object containing supported Unicode blocks. 1124*/ 1125 1126 1127/*! 1128 \fn font_file_format BFont::FileFormat() const 1129 \brief Gets whether the font is a TrueType™ or PostScript™ Type1 font. 1130 1131 \returns A \c font_file_format struct containing the font file format. 1132*/ 1133 1134 1135/*! 1136 \fn int32 BFont::CountTuned() const 1137 \brief Gets the number of tuned fonts for the font family and style. 1138 1139 \returns The number of tuned fonts. 1140*/ 1141 1142 1143/*! 1144 \fn void BFont::GetTunedInfo(int32 index, tuned_font_info *info) const 1145 \brief Writes information about the tuned font at \a index into \a info. 1146 1147 The index begins at 0 and counts tuned fonts for current font family and 1148 style only. 1149 1150 \param index The index of desired tuned font. 1151 \param info The \a turned_font_info struct to be filled out. 1152*/ 1153 1154 1155/*! 1156 \fn void BFont::TruncateString(BString *inOut, uint32 mode, 1157 float width) const 1158 \brief Truncates \a inOut to be no longer than \a width using the 1159 supplied truncation \a mode. 1160 1161 The following truncation modes are supported: 1162 - \c B_TRUNCATE_BEGINNING Truncate from the beginning of the string. 1163 - \c B_TRUNCATE_MIDDLE Truncate from the middle of the string. 1164 - \c B_TRUNCATE_END Truncate from the end of the string. 1165 - \c B_TRUNCATE_SMART Truncate from anywhere, but do so so that each 1166 string is made unique after being truncated. 1167 1168 \param inOut The BString to truncate. 1169 \param mode Truncation mode to use. 1170 \param width The maximum width to truncate to. 1171*/ 1172 1173 1174/*! 1175 \fn void BFont::GetTruncatedStrings(const char *stringArray[], 1176 int32 numStrings, uint32 mode, float width, 1177 BString resultArray[]) const 1178 \brief Write truncated BString objects to \a resultArray given source 1179 BString objects in \a stringArray. 1180 1181 The following truncation modes are supported: 1182 - \c B_TRUNCATE_BEGINNING Truncate from the beginning of the string. 1183 - \c B_TRUNCATE_MIDDLE Truncate from the middle of the string. 1184 - \c B_TRUNCATE_END Truncate from the end of the string. 1185 - \c B_TRUNCATE_SMART Truncate from anywhere, but do so so that each 1186 string is made unique after being truncated. 1187 1188 \param stringArray The source string array. 1189 \param numStrings The number of strings in \a stringArray. 1190 \param mode Truncation mode to use. 1191 \param width The maximum width to truncate to. 1192 \param resultArray The destination string array. 1193*/ 1194 1195 1196/*! 1197 \fn void BFont::GetTruncatedStrings(const char *stringArray[], 1198 int32 numStrings, uint32 mode, float width, char *resultArray[]) const 1199 \brief Write truncated strings to \a resultArray given source 1200 BString objects in \a stringArray. 1201 1202 \a resultArray is an array of pointers to string buffers which should be 1203 allocated ahead of time and should be at least 3 bytes longer than the 1204 matching input string. The 3 extra bytes provide enough room for the 1205 truncated output given that GetTruncatedStrings() truncates only a 1206 single-byte character from the input string and replaces it with an 1207 ellipsis character (which takes three bytes for the UTF-8 encoding), 1208 and adds a \c NUL-terminator. 1209 1210 The following truncation modes are supported: 1211 - \c B_TRUNCATE_BEGINNING Truncate from the beginning of the string. 1212 - \c B_TRUNCATE_MIDDLE Truncate from the middle of the string. 1213 - \c B_TRUNCATE_END Truncate from the end of the string. 1214 - \c B_TRUNCATE_SMART Truncate from anywhere, but do so so that each 1215 string is made unique after being truncated. 1216 1217 \param stringArray The source string array. 1218 \param numStrings The number of strings in \a stringArray. 1219 \param mode Truncation mode to use. 1220 \param width The maximum width to truncate to. 1221 \param resultArray The destination string array. 1222*/ 1223 1224 1225/*! 1226 \fn float BFont::StringWidth(const char *string) const 1227 \brief Determines the amount of space required to draw \a string in the 1228 current font. 1229 1230 \param string The source string. 1231 1232 \returns The width required to draw the string. 1233*/ 1234 1235 1236/*! 1237 \fn float BFont::StringWidth(const char *string, int32 length) const 1238 \brief Determines the amount of space required to draw \a string in the 1239 current font up to \a length characters. 1240 1241 \param string The source string. 1242 \param length The number of characters in \a string to consider. 1243 1244 \returns The width required to draw the string. 1245*/ 1246 1247 1248/*! 1249 \fn void BFont::GetStringWidths(const char *stringArray[], 1250 const int32 lengthArray[], int32 numStrings, float widthArray[]) const 1251 \brief Determines the amount of space required to draw each string in 1252 \a stringArray and writes the result in \a widthArray. 1253 1254 \param stringArray The source string array. 1255 \param lengthArray The number of characters to consider for each string in 1256 \a stringArray 1257 \param numStrings The number of strings in \a stringArray. 1258 \param widthArray The destination array to put the widths required to draw 1259 each string. 1260*/ 1261 1262 1263/*! 1264 \fn void BFont::GetEscapements(const char charArray[], int32 numChars, 1265 float escapementArray[]) const 1266 \brief Determines the escapements for each char in \a charArray and writes 1267 the result in \a escapementArray. 1268 1269 \param charArray The source character array. 1270 \param numChars The number of characters to consider in \a charArray. 1271 \param escapementArray The destination array to put the escapements. 1272*/ 1273 1274 1275/*! 1276 \fn void BFont::GetEscapements(const char charArray[], int32 numChars, 1277 escapement_delta *delta, float escapementArray[]) const 1278 \brief Determines the escapements for each char in \a charArray and writes 1279 the result in \a escapementArray with consideration to the horizontal 1280 space provided by the escapement \a delta. 1281 1282 The escapement_delta structure contains the following values: 1283 - \c nonspace The amount of horizontal space to surround a visible glyph 1284 character with. 1285 - \c space The amount of horizontal space to surround a whitespace character 1286 with, for example \c B_TAB or \c B_SPACE. 1287 1288 \param charArray The source character array. 1289 \param numChars The number of characters to consider in \a charArray. 1290 \param delta The escapement_delta structure to use. 1291 \param escapementArray The destination array to put the escapements. 1292*/ 1293 1294 1295/*! 1296 \fn void BFont::GetEscapements(const char charArray[], int32 numChars, 1297 escapement_delta *delta, BPoint escapementArray[]) const 1298 \brief Determines the escapements for each char in \a charArray and writes 1299 the result in \a escapementArray as an array of BPoint objects 1300 with consideration to the horizontal space provided by the escapement 1301 \a delta. 1302 1303 The escapement_delta structure contains the following values: 1304 - \c nonspace The amount of horizontal space to surround a visible glyph 1305 character with. 1306 - \c space The amount of horizontal space to surround a whitespace character 1307 with, for example \c B_TAB or \c B_SPACE. 1308 1309 \param charArray The source character array. 1310 \param numChars The number of characters to consider in \a charArray. 1311 \param delta The escapement_delta structure to use. 1312 \param escapementArray The destination array of escapements as BPoint 1313 objects. 1314*/ 1315 1316 1317/*! 1318 \fn void BFont::GetEscapements(const char charArray[], int32 numChars, 1319 escapement_delta *delta, BPoint escapementArray[], 1320 BPoint offsetArray[]) const 1321 \brief Determines the escapements for each char in \a charArray and writes 1322 the result in \a escapementArray as an array of BPoint objects 1323 with consideration to the horizontal space provided by the escapement 1324 \a delta and writes the offsets to \a offsetArray. 1325 1326 The escapement_delta structure contains the following values: 1327 - \c nonspace The amount of horizontal space to surround a visible glyph 1328 character with. 1329 - \c space The amount of horizontal space to surround a whitespace character 1330 with, for example \c B_TAB or \c B_SPACE. 1331 1332 \param charArray The source character array. 1333 \param numChars The number of characters to consider in \a charArray. 1334 \param delta The escapement_delta structure to use. 1335 \param escapementArray The destination array of escapements as BPoint 1336 objects. 1337 \param offsetArray The destination array of offsets as BPoint objects. 1338*/ 1339 1340 1341/*! 1342 \fn void BFont::GetEdges(const char charArray[], int32 numChars, 1343 edge_info edgeArray[]) const 1344 \brief Determines the edge information for each character in \a charArray 1345 and writes the result in \a edgeArray. 1346 1347 The \c edge_info struct contains the following values: 1348 - \c left The distance that the character outline is inset from the left 1349 escapement boundary. 1350 - \c right The distance that the character outline is inset from the 1351 right escapement boundary. 1352 1353 \param charArray The source character array. 1354 \param numChars The number of characters to consider in \a charArray. 1355 \param edgeArray The destination array of \c edge_info structs. 1356*/ 1357 1358 1359/*! 1360 \fn void BFont::GetHeight(font_height *_height) const 1361 \brief Fills out the \c font_height struct with the amount of vertical 1362 space surrounding a character. 1363 1364 The \c font_height struct contains the following values: 1365 - \c ascent The distance characters can ascend above the baseline. 1366 - \c descent The distance characters can descend below the baseline. 1367 - \c leading The distance between lines, descent above to ascent below. 1368 1369 \param _height The \c font_height struct to fill out. 1370*/ 1371 1372 1373/*! 1374 \fn void BFont::GetBoundingBoxesAsGlyphs(const char charArray[], 1375 int32 numChars, font_metric_mode mode, BRect boundingBoxArray[]) const 1376 \brief Writes an array of BRect objects to \a boundingBoxArray 1377 representing the bounding rectangles of each character in 1378 \a charArray. 1379 1380 Each BRect object corresponds to the glyph of one character. 1381 1382 The \c font_metric_mode should contain one of the following values: 1383 - \c B_SCREEN_METRIC The bounding boxes should use the screen metric. 1384 - \c B_PRINTING_METRIC The bounding boxes should use the print metric. 1385 1386 \param charArray The source character array. 1387 \param numChars The number of characters to consider in \a charArray. 1388 \param mode The \c font_metric_mode to use, screen or printing. 1389 \param boundingBoxArray The destination array of BRect bounding boxes. 1390*/ 1391 1392 1393/*! 1394 \fn void BFont::GetBoundingBoxesAsString(const char charArray[], 1395 int32 numChars, font_metric_mode mode, escapement_delta *delta, 1396 BRect boundingBoxArray[]) const 1397 \brief Writes an array of BRect objects to \a boundingBoxArray representing 1398 the bounding rectangles of each character in \a charArray with 1399 consideration to the horizontal space provided by the escapement 1400 \a delta. 1401 1402 Each BRect object corresponds to the glyph of one character. 1403 1404 The \c font_metric_mode should contain one of the following values: 1405 - \c B_SCREEN_METRIC The bounding boxes should use the screen metric. 1406 - \c B_PRINTING_METRIC The bounding boxes should use the print metric. 1407 1408 The provided escapement \a delta is applied as part of the bounding box 1409 calculations. This lets you specify a character spacing is looser or 1410 tighter than normal. 1411 1412 The escapement_delta structure contains the following values: 1413 - \c nonspace The amount of horizontal space to surround a visible glyph 1414 character with. 1415 - \c space The amount of horizontal space to surround a whitespace character 1416 with, for example \c B_TAB or \c B_SPACE. 1417 1418 \param charArray The source character array. 1419 \param numChars The number of characters to consider in \a charArray. 1420 \param mode The \c font_metric_mode to use, screen or printing. 1421 \param delta The escapement_delta structure to use. 1422 \param boundingBoxArray The destination array of BRect bounding boxes. 1423*/ 1424 1425 1426/*! 1427 \fn void BFont::GetBoundingBoxesForStrings(const char *stringArray[], 1428 int32 numStrings, font_metric_mode mode, escapement_delta deltas[], 1429 BRect boundingBoxArray[]) const 1430 \brief Writes an array of BRect objects to \a boundingBoxArray representing 1431 the bounding rectangles of each string in \a stringArray with 1432 consideration to the horizontal space provided by the escapement 1433 \a deltas. 1434 1435 Each BRect object corresponds to the bounding box of the entire string. 1436 1437 The \c font_metric_mode should contain one of the following values: 1438 - \c B_SCREEN_METRIC The bounding boxes should use the screen metric. 1439 - \c B_PRINTING_METRIC The bounding boxes should use the print metric. 1440 1441 The provided escapement \a deltas are applied as part of the bounding box 1442 calculations. This lets you specify a character spacing is looser or tighter 1443 than normal. 1444 1445 The escapement_delta structure contains the following values: 1446 - \c nonspace The amount of horizontal space to surround a visible glyph 1447 character with. 1448 - \c space The amount of horizontal space to surround a whitespace character 1449 with, for example \c B_TAB or \c B_SPACE. 1450 1451 \param stringArray The source string array. 1452 \param numStrings The number of strings to consider in \a stringArray. 1453 \param mode The \c font_metric_mode to use, screen or printing. 1454 \param deltas The array of escapement_delta structures to use. 1455 \param boundingBoxArray The destination array of BRect bounding boxes. 1456*/ 1457 1458 1459/*! 1460 void BFont::GetGlyphShapes(const char charArray[], int32 numChars, 1461 BShape *glyphShapeArray[]) const 1462 \brief Writes an array of BShape objects to \a glyphShapeArray 1463 representing the glyph shapes of each character in 1464 \a charArray. 1465 1466 Each BShape object corresponds to the glyph of one character. 1467 1468 \param charArray The source character array. 1469 \param numChars The number of characters to consider in \a charArray. 1470 \param glyphShapeArray The destination array of BShape glyphs. 1471*/ 1472 1473 1474/*! 1475 void BFont::GetHasGlyphs(const char charArray[], int32 numChars, 1476 bool hasArray[]) const 1477 \brief Fills out \a hasArray with whether or not each characters in 1478 \a charArray has a glyph for the font. 1479 1480 \c true is written in \a hasArray if the character has a glyph in the 1481 current font and \c false is written in \a hasArray if the character 1482 does NOT have a glyph in the current font. 1483 1484 \param charArray The source character array. 1485 \param numChars The number of characters to consider in \a charArray. 1486 \param hasArray The destination array of booleans. 1487*/ 1488 1489 1490/*! 1491 BFont& BFont::operator=(const BFont &font) 1492 \brief Assignment overload method. 1493 1494 \param font The BFont object to assign from. 1495*/ 1496 1497 1498/*! 1499 bool BFont::operator==(const BFont &font) const 1500 \brief Equality comparison overload method. 1501 1502 \param font The BFont object to compare the current font to. 1503 1504 \returns \c true if the fonts objects are identical, \c false otherwise. 1505*/ 1506 1507 1508/*! 1509 bool BFont::operator!=(const BFont &font) const 1510 \brief Inequality comparison overload method. 1511 1512 \param font The BFont object to compare the current font to. 1513 1514 \returns \c true if the fonts objects are NOT identical, \c true 1515 otherwise. 1516*/ 1517 1518 1519/*! 1520 void BFont::PrintToStream() const 1521 \brief Writes information about the font to \c stdout. 1522 1523 printf("BFont { %s (%d), %s (%d) 0x%x %f/%f %fpt (%f %f %f), %d }\n", 1524 family, fFamilyID, style, fStyleID, fFace, fShear, fRotation, fSize, 1525 fHeight.ascent, fHeight.descent, fHeight.leading, fEncoding); 1526*/ 1527