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 "FontFamily.h" 19 #include "Transformable.h" 20 21 class BShape; 22 class BString; 23 24 25 class ServerFont { 26 public: 27 ServerFont(); 28 ServerFont(FontStyle& style, 29 float size = 12.0, 30 float rotation = 0.0, 31 float shear = 90.0, 32 float falseBoldWidth = 0.0, 33 uint16 flags = 0, 34 uint8 spacing = B_CHAR_SPACING); 35 ServerFont(const ServerFont& font); 36 virtual ~ServerFont(); 37 38 ServerFont &operator=(const ServerFont& font); 39 40 font_direction Direction() const 41 { return fDirection; } 42 uint32 Encoding() const 43 { return fEncoding; } 44 uint32 Flags() const 45 { return fFlags; } 46 uint32 Spacing() const 47 { return fSpacing; } 48 float Shear() const 49 { return fShear; } 50 float Rotation() const 51 { return fRotation; } 52 float FalseBoldWidth() const 53 { return fFalseBoldWidth; } 54 float Size() const 55 { return fSize; } 56 uint16 Face() const 57 { return fFace; } 58 uint32 CountGlyphs() 59 { return fStyle->GlyphCount(); } 60 int32 CountTuned(); 61 62 font_file_format FileFormat(); 63 64 const char* Style() const; 65 const char* Family() const; 66 const char* Path() const 67 { return fStyle->Path(); } 68 69 void SetStyle(FontStyle* style); 70 status_t SetFamilyAndStyle(uint16 familyID, 71 uint16 styleID); 72 status_t SetFamilyAndStyle(uint32 fontID); 73 74 uint16 StyleID() const 75 { return fStyle->ID(); } 76 uint16 FamilyID() const 77 { return fStyle->Family()->ID(); } 78 uint32 GetFamilyAndStyle() const; 79 80 void SetDirection(font_direction dir) 81 { fDirection = dir; } 82 void SetEncoding(uint32 encoding) 83 { fEncoding = encoding; } 84 void SetFlags(uint32 value) 85 { fFlags = value; } 86 void SetSpacing(uint32 value) 87 { fSpacing = value; } 88 void SetShear(float value) 89 { fShear = value; } 90 void SetSize(float value) 91 { fSize = value; } 92 void SetRotation(float value) 93 { fRotation = value; } 94 void SetFalseBoldWidth(float value) 95 { fFalseBoldWidth = value; } 96 status_t SetFace(uint16 face); 97 98 bool IsFixedWidth() const 99 { return fStyle->IsFixedWidth(); } 100 bool IsScalable() const 101 { return fStyle->IsScalable(); } 102 bool HasKerning() const 103 { return fStyle->HasKerning(); } 104 bool HasTuned() const 105 { return fStyle->HasTuned(); } 106 int32 TunedCount() const 107 { return fStyle->TunedCount(); } 108 uint16 GlyphCount() const 109 { return fStyle->GlyphCount(); } 110 uint16 CharMapCount() const 111 { return fStyle->CharMapCount(); } 112 113 114 FT_Face GetTransformedFace(bool rotate, 115 bool shear) const; 116 void PutTransformedFace(FT_Face face) const; 117 118 status_t GetGlyphShapes(const char charArray[], 119 int32 numChars, BShape *shapeArray[]) const; 120 121 status_t GetHasGlyphs(const char charArray[], 122 int32 numBytes, bool hasArray[]) const; 123 124 status_t GetEdges(const char charArray[], int32 numBytes, 125 edge_info edgeArray[]) const; 126 127 status_t GetEscapements(const char charArray[], 128 int32 numBytes, int32 numChars, 129 escapement_delta delta, 130 BPoint escapementArray[], 131 BPoint offsetArray[]) const; 132 133 status_t GetEscapements(const char charArray[], 134 int32 numBytes, int32 numChars, 135 escapement_delta delta, 136 float widthArray[]) const; 137 138 status_t GetBoundingBoxes(const char charArray[], 139 int32 numBytes, BRect rectArray[], 140 bool stringEscapement, 141 font_metric_mode mode, 142 escapement_delta delta, 143 bool asString); 144 145 status_t GetBoundingBoxesForStrings(char *charArray[], 146 int32 lengthArray[], int32 numStrings, 147 BRect rectArray[], font_metric_mode mode, 148 escapement_delta deltaArray[]); 149 150 float StringWidth(const char *string, 151 int32 numBytes, 152 const escapement_delta* delta = NULL) const; 153 154 bool Lock() const { return fStyle->Lock(); } 155 void Unlock() const { fStyle->Unlock(); } 156 157 // FT_Face GetFTFace() const 158 // { return fStyle->FreeTypeFace(); }; 159 160 BRect BoundingBox(); 161 void GetHeight(font_height& height) const; 162 163 void TruncateString(BString* inOut, 164 uint32 mode, 165 float width) const; 166 167 Transformable EmbeddedTransformation() const; 168 169 protected: 170 friend class FontStyle; 171 172 FontStyle* fStyle; 173 float fSize; 174 float fRotation; 175 float fShear; 176 float fFalseBoldWidth; 177 BRect fBounds; 178 uint32 fFlags; 179 uint32 fSpacing; 180 font_direction fDirection; 181 uint16 fFace; 182 uint32 fEncoding; 183 }; 184 185 #endif /* SERVER_FONT_H */ 186