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