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