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 <Referenceable.h> 20 #include <String.h> 21 22 #include <ft2build.h> 23 #include FT_FREETYPE_H 24 25 #include "AppFontManager.h" 26 27 28 struct node_ref; 29 class AppFontManager; 30 class FontFamily; 31 class ServerFont; 32 33 34 /*! 35 \class FontStyle FontStyle.h 36 \brief Object used to represent a font style 37 38 FontStyle objects help abstract a lot of the font engine details while 39 still offering plenty of information the style in question. 40 */ 41 class FontStyle : public BReferenceable { 42 public: 43 FontStyle(node_ref& nodeRef, const char* path, 44 FT_Face face); 45 virtual ~FontStyle(); 46 47 const node_ref& NodeRef() const { return fNodeRef; } 48 49 bool Lock(); 50 void Unlock(); 51 52 /*! 53 \fn bool FontStyle::IsFixedWidth(void) 54 \brief Determines whether the font's character width is fixed 55 \return true if fixed, false if not 56 */ 57 bool IsFixedWidth() const 58 { return FT_IS_FIXED_WIDTH(fFreeTypeFace); } 59 60 61 /* \fn bool FontStyle::IsFullAndHalfFixed() 62 \brief Determines whether the font has 2 different, fixed, widths. 63 \return false (for now) 64 */ 65 bool IsFullAndHalfFixed() const 66 { return fFullAndHalfFixed; }; 67 68 /*! 69 \fn bool FontStyle::IsScalable(void) 70 \brief Determines whether the font can be scaled to any size 71 \return true if scalable, false if not 72 */ 73 bool IsScalable() const 74 { return FT_IS_SCALABLE(fFreeTypeFace); } 75 /*! 76 \fn bool FontStyle::HasKerning(void) 77 \brief Determines whether the font has kerning information 78 \return true if kerning info is available, false if not 79 */ 80 bool HasKerning() const 81 { return FT_HAS_KERNING(fFreeTypeFace); } 82 /*! 83 \fn bool FontStyle::HasTuned(void) 84 \brief Determines whether the font contains strikes 85 \return true if it has strikes included, false if not 86 */ 87 bool HasTuned() const 88 { return FT_HAS_FIXED_SIZES(fFreeTypeFace); } 89 /*! 90 \fn bool FontStyle::TunedCount(void) 91 \brief Returns the number of strikes the style contains 92 \return The number of strikes the style contains 93 */ 94 int32 TunedCount() const 95 { return fFreeTypeFace->num_fixed_sizes; } 96 /*! 97 \fn bool FontStyle::GlyphCount(void) 98 \brief Returns the number of glyphs in the style 99 \return The number of glyphs the style contains 100 */ 101 uint16 GlyphCount() const 102 { return fFreeTypeFace->num_glyphs; } 103 /*! 104 \fn bool FontStyle::CharMapCount(void) 105 \brief Returns the number of character maps the style contains 106 \return The number of character maps the style contains 107 */ 108 uint16 CharMapCount() const 109 { return fFreeTypeFace->num_charmaps; } 110 111 const char* Name() const 112 { return fName.String(); } 113 FontFamily* Family() const 114 { return fFamily; } 115 uint16 ID() const 116 { return fID; } 117 uint32 Flags() const; 118 119 uint16 Face() const 120 { return fFace; } 121 uint16 PreservedFace(uint16) const; 122 123 const char* Path() const; 124 void UpdatePath(const node_ref& parentNodeRef); 125 126 void GetHeight(float size, font_height &heigth) const; 127 font_direction Direction() const 128 { return B_FONT_LEFT_TO_RIGHT; } 129 font_file_format FileFormat() const 130 { return B_TRUETYPE_WINDOWS; } 131 132 FT_Face FreeTypeFace() const 133 { return fFreeTypeFace; } 134 135 status_t UpdateFace(FT_Face face); 136 137 uint32 FontDataSize() const 138 { return fFontDataSize; } 139 140 void SetFontData(FT_Byte* location, uint32 size); 141 FT_Byte* FontData() const 142 { return fFontData; } 143 144 private: 145 friend class FontFamily; 146 uint16 _TranslateStyleToFace(const char *name) const; 147 void _SetFontFamily(FontFamily* family, uint16 id); 148 void _SetFontManager(AppFontManager* fontManager) 149 { fFontManager = fontManager; } 150 private: 151 FT_Face fFreeTypeFace; 152 BString fName; 153 BPath fPath; 154 node_ref fNodeRef; 155 156 FontFamily* fFamily; 157 uint16 fID; 158 159 BRect fBounds; 160 161 font_height fHeight; 162 uint16 fFace; 163 bool fFullAndHalfFixed; 164 165 FT_Byte* fFontData; 166 uint32 fFontDataSize; 167 AppFontManager* fFontManager; 168 }; 169 170 #endif // FONT_STYLE_H_ 171