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 * Jérôme Duval, jerome.duval@free.fr 8 * Axel Dörfler, axeld@pinc-software.de 9 * Stephan Aßmus <superstippi@gmx.de> 10 */ 11 #ifndef SERVER_FONT_H 12 #define SERVER_FONT_H 13 14 15 #include <Font.h> 16 #include <Rect.h> 17 18 #include "AppFontManager.h" 19 #include "FontFamily.h" 20 #include "FontManager.h" 21 #include "GlobalSubpixelSettings.h" 22 #include "Transformable.h" 23 24 class BShape; 25 class BString; 26 27 28 class ServerFont { 29 public: 30 ServerFont(); 31 ServerFont(FontStyle& style, 32 float size = 12.0, float rotation = 0.0, 33 float shear = 90.0, 34 float falseBoldWidth = 0.0, 35 uint16 flags = 0, 36 uint8 spacing = B_BITMAP_SPACING); 37 ServerFont(const ServerFont& font); 38 virtual ~ServerFont(); 39 40 ServerFont &operator=(const ServerFont& font); 41 bool operator==(const ServerFont& other) const; 42 43 font_direction Direction() const 44 { return fDirection; } 45 uint32 Encoding() const 46 { return fEncoding; } 47 uint32 Flags() const 48 { return fFlags; } 49 uint32 Spacing() const 50 { return fSpacing; } 51 float Shear() const 52 { return fShear; } 53 float Rotation() const 54 { return fRotation; } 55 float FalseBoldWidth() const 56 { return fFalseBoldWidth; } 57 float Size() const 58 { return fSize; } 59 uint16 Face() const 60 { return fFace; } 61 uint32 CountGlyphs() 62 { return fStyle->GlyphCount(); } 63 int32 CountTuned(); 64 65 font_file_format FileFormat(); 66 67 const char* Style() const; 68 const char* Family() const; 69 const char* Path() const 70 { return fStyle->Path(); } 71 72 void SetStyle(FontStyle* style); 73 status_t SetFamilyAndStyle(uint16 familyID, 74 uint16 styleID, 75 AppFontManager* fontManager = NULL); 76 status_t SetFamilyAndStyle(uint32 fontID, 77 AppFontManager* fontManager = NULL); 78 79 uint16 StyleID() const 80 { return fStyle->ID(); } 81 uint16 FamilyID() const 82 { return fStyle->Family()->ID(); } 83 uint32 GetFamilyAndStyle() const; 84 85 void SetDirection(font_direction dir) 86 { fDirection = dir; } 87 void SetEncoding(uint32 encoding) 88 { fEncoding = encoding; } 89 void SetFlags(uint32 value) 90 { fFlags = value; } 91 void SetSpacing(uint32 value) 92 { fSpacing = value; } 93 void SetShear(float value) 94 { fShear = value; } 95 void SetSize(float value); 96 97 void SetRotation(float value) 98 { fRotation = value; } 99 void SetFalseBoldWidth(float value) 100 { fFalseBoldWidth = value; } 101 status_t SetFace(uint16 face); 102 103 bool IsFixedWidth() const 104 { return fStyle->IsFixedWidth(); } 105 bool IsScalable() const 106 { return fStyle->IsScalable(); } 107 bool HasKerning() const 108 { return fStyle->HasKerning(); } 109 bool HasTuned() const 110 { return fStyle->HasTuned(); } 111 int32 TunedCount() const 112 { return fStyle->TunedCount(); } 113 uint16 GlyphCount() const 114 { return fStyle->GlyphCount(); } 115 uint16 CharMapCount() const 116 { return fStyle->CharMapCount(); } 117 inline bool Hinting() const; 118 119 status_t GetGlyphShapes(const char charArray[], 120 int32 numChars, BShape *shapeArray[]) const; 121 122 status_t GetHasGlyphs(const char charArray[], 123 int32 numBytes, int32 numChars, 124 bool hasArray[]) const; 125 126 status_t GetEdges(const char charArray[], int32 numBytes, 127 int32 numChars, edge_info edgeArray[]) 128 const; 129 130 status_t GetEscapements(const char charArray[], 131 int32 numBytes, int32 numChars, 132 escapement_delta delta, 133 BPoint escapementArray[], 134 BPoint offsetArray[]) const; 135 136 status_t GetEscapements(const char charArray[], 137 int32 numBytes, int32 numChars, 138 escapement_delta delta, 139 float widthArray[]) const; 140 141 status_t GetBoundingBoxes(const char charArray[], 142 int32 numBytes, int32 numChars, 143 BRect rectArray[], bool stringEscapement, 144 font_metric_mode mode, 145 escapement_delta delta, 146 bool asString); 147 148 status_t GetBoundingBoxesForStrings(char *charArray[], 149 size_t lengthArray[], int32 numStrings, 150 BRect rectArray[], font_metric_mode mode, 151 escapement_delta deltaArray[]); 152 153 float StringWidth(const char *string, 154 int32 numBytes, 155 const escapement_delta* delta = NULL) const; 156 157 bool Lock() const { return fStyle->Lock(); } 158 void Unlock() const { fStyle->Unlock(); } 159 160 // FT_Face GetFTFace() const 161 // { return fStyle->FreeTypeFace(); }; 162 163 BRect BoundingBox(); 164 void GetHeight(font_height& height) const; 165 166 void TruncateString(BString* inOut, 167 uint32 mode, float width) const; 168 169 Transformable EmbeddedTransformation() const; 170 status_t GetUnicodeBlocks(unicode_block &blocksForFont); 171 status_t IncludesUnicodeBlock(uint32 start, uint32 end, 172 bool &hasBlock); 173 174 void SetFontData(FT_Byte* location, uint32 size); 175 uint32 FontDataSize() const 176 { return fStyle->FontDataSize(); } 177 FT_Byte* FontData() const 178 { return fStyle->FontData(); } 179 180 protected: 181 friend class FontStyle; 182 183 FT_Face GetTransformedFace(bool rotate, 184 bool shear) const; 185 void PutTransformedFace(FT_Face face) const; 186 187 BReference<FontStyle> 188 fStyle; 189 float fSize; 190 float fRotation; 191 float fShear; 192 float fFalseBoldWidth; 193 BRect fBounds; 194 uint32 fFlags; 195 uint32 fSpacing; 196 font_direction fDirection; 197 uint16 fFace; 198 uint32 fEncoding; 199 }; 200 201 inline bool ServerFont::Hinting() const 202 { 203 switch (gDefaultHintingMode) { 204 case HINTING_MODE_OFF: 205 return false; 206 default: 207 case HINTING_MODE_ON: 208 return true; 209 case HINTING_MODE_MONOSPACED_ONLY: 210 return IsFixedWidth(); 211 } 212 } 213 214 #endif /* SERVER_FONT_H */ 215