1 /* 2 * Copyright 2001-2008, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * DarkWyrm <bpmagic@columbus.rr.com> 7 * Axel Dörfler, axeld@pinc-software.de 8 */ 9 #ifndef FONT_STYLE_H_ 10 #define FONT_STYLE_H_ 11 12 13 #include <Font.h> 14 #include <Locker.h> 15 #include <Node.h> 16 #include <ObjectList.h> 17 #include <Path.h> 18 #include <Rect.h> 19 #include <String.h> 20 21 #include <ft2build.h> 22 #include FT_FREETYPE_H 23 #include "ReferenceCounting.h" 24 #include "HashTable.h" 25 26 27 struct node_ref; 28 class FontFamily; 29 class ServerFont; 30 31 32 class FontKey : public Hashable { 33 public: 34 FontKey(uint16 familyID, uint16 styleID) 35 : fHash(familyID | (styleID << 16UL)) 36 { 37 } 38 virtual ~FontKey() {}; 39 40 virtual uint32 Hash() const 41 { return fHash; } 42 virtual bool CompareTo(Hashable& other) const 43 { return fHash == other.Hash(); } 44 45 private: 46 uint32 fHash; 47 }; 48 49 50 /*! 51 \class FontStyle FontStyle.h 52 \brief Object used to represent a font style 53 54 FontStyle objects help abstract a lot of the font engine details while 55 still offering plenty of information the style in question. 56 */ 57 class FontStyle : public ReferenceCounting, public Hashable { 58 public: 59 FontStyle(node_ref& nodeRef, const char* path, 60 FT_Face face); 61 virtual ~FontStyle(); 62 63 virtual uint32 Hash() const; 64 virtual bool CompareTo(Hashable& other) const; 65 66 const node_ref& NodeRef() const { return fNodeRef; } 67 68 bool Lock(); 69 void Unlock(); 70 71 /*! 72 \fn bool FontStyle::IsFixedWidth(void) 73 \brief Determines whether the font's character width is fixed 74 \return true if fixed, false if not 75 */ 76 bool IsFixedWidth() const 77 { return FT_IS_FIXED_WIDTH(fFreeTypeFace); } 78 79 80 /* \fn bool FontStyle::IsFullAndHalfFixed() 81 \brief Determines whether the font has 2 different, fixed, widths. 82 \return false (for now) 83 */ 84 bool IsFullAndHalfFixed() const 85 { return false; }; 86 87 /*! 88 \fn bool FontStyle::IsScalable(void) 89 \brief Determines whether the font can be scaled to any size 90 \return true if scalable, false if not 91 */ 92 bool IsScalable() const 93 { return FT_IS_SCALABLE(fFreeTypeFace); } 94 /*! 95 \fn bool FontStyle::HasKerning(void) 96 \brief Determines whether the font has kerning information 97 \return true if kerning info is available, false if not 98 */ 99 bool HasKerning() const 100 { return FT_HAS_KERNING(fFreeTypeFace); } 101 /*! 102 \fn bool FontStyle::HasTuned(void) 103 \brief Determines whether the font contains strikes 104 \return true if it has strikes included, false if not 105 */ 106 bool HasTuned() const 107 { return FT_HAS_FIXED_SIZES(fFreeTypeFace); } 108 /*! 109 \fn bool FontStyle::TunedCount(void) 110 \brief Returns the number of strikes the style contains 111 \return The number of strikes the style contains 112 */ 113 int32 TunedCount() const 114 { return fFreeTypeFace->num_fixed_sizes; } 115 /*! 116 \fn bool FontStyle::GlyphCount(void) 117 \brief Returns the number of glyphs in the style 118 \return The number of glyphs the style contains 119 */ 120 uint16 GlyphCount() const 121 { return fFreeTypeFace->num_glyphs; } 122 /*! 123 \fn bool FontStyle::CharMapCount(void) 124 \brief Returns the number of character maps the style contains 125 \return The number of character maps the style contains 126 */ 127 uint16 CharMapCount() const 128 { return fFreeTypeFace->num_charmaps; } 129 130 const char* Name() const 131 { return fName.String(); } 132 FontFamily* Family() const 133 { return fFamily; } 134 uint16 ID() const 135 { return fID; } 136 uint32 Flags() const; 137 138 uint16 Face() const 139 { return fFace; } 140 uint16 PreservedFace(uint16) const; 141 142 const char* Path() const; 143 void UpdatePath(const node_ref& parentNodeRef); 144 145 void GetHeight(float size, font_height &heigth) const; 146 font_direction Direction() const 147 { return B_FONT_LEFT_TO_RIGHT; } 148 font_file_format FileFormat() const 149 { return B_TRUETYPE_WINDOWS; } 150 151 FT_Face FreeTypeFace() const 152 { return fFreeTypeFace; } 153 154 status_t UpdateFace(FT_Face face); 155 156 private: 157 friend class FontFamily; 158 uint16 _TranslateStyleToFace(const char *name) const; 159 void _SetFontFamily(FontFamily* family, uint16 id); 160 161 private: 162 FT_Face fFreeTypeFace; 163 BString fName; 164 BPath fPath; 165 node_ref fNodeRef; 166 167 FontFamily* fFamily; 168 uint16 fID; 169 170 BRect fBounds; 171 172 font_height fHeight; 173 uint16 fFace; 174 }; 175 176 #endif // FONT_STYLE_H_ 177