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
Direction()43 font_direction Direction() const
44 { return fDirection; }
Encoding()45 uint32 Encoding() const
46 { return fEncoding; }
Flags()47 uint32 Flags() const
48 { return fFlags; }
Spacing()49 uint32 Spacing() const
50 { return fSpacing; }
Shear()51 float Shear() const
52 { return fShear; }
Rotation()53 float Rotation() const
54 { return fRotation; }
FalseBoldWidth()55 float FalseBoldWidth() const
56 { return fFalseBoldWidth; }
Size()57 float Size() const
58 { return fSize; }
Face()59 uint16 Face() const
60 { return fFace; }
CountGlyphs()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;
Path()69 const char* Path() const
70 { return fStyle->Path(); }
FaceIndex()71 long FaceIndex() const
72 { return fStyle->FreeTypeFace()->face_index; }
73
74 void SetStyle(FontStyle* style);
75 status_t SetFamilyAndStyle(uint16 familyID,
76 uint16 styleID,
77 AppFontManager* fontManager = NULL);
78 status_t SetFamilyAndStyle(uint32 fontID,
79 AppFontManager* fontManager = NULL);
80
StyleID()81 uint16 StyleID() const
82 { return fStyle->ID(); }
FamilyID()83 uint16 FamilyID() const
84 { return fStyle->Family()->ID(); }
85 uint32 GetFamilyAndStyle() const;
86
SetDirection(font_direction dir)87 void SetDirection(font_direction dir)
88 { fDirection = dir; }
SetEncoding(uint32 encoding)89 void SetEncoding(uint32 encoding)
90 { fEncoding = encoding; }
SetFlags(uint32 value)91 void SetFlags(uint32 value)
92 { fFlags = value; }
SetSpacing(uint32 value)93 void SetSpacing(uint32 value)
94 { fSpacing = value; }
SetShear(float value)95 void SetShear(float value)
96 { fShear = value; }
97 void SetSize(float value);
98
SetRotation(float value)99 void SetRotation(float value)
100 { fRotation = value; }
SetFalseBoldWidth(float value)101 void SetFalseBoldWidth(float value)
102 { fFalseBoldWidth = value; }
103 status_t SetFace(uint16 face);
104
IsFixedWidth()105 bool IsFixedWidth() const
106 { return fStyle->IsFixedWidth(); }
IsScalable()107 bool IsScalable() const
108 { return fStyle->IsScalable(); }
HasKerning()109 bool HasKerning() const
110 { return fStyle->HasKerning(); }
HasTuned()111 bool HasTuned() const
112 { return fStyle->HasTuned(); }
TunedCount()113 int32 TunedCount() const
114 { return fStyle->TunedCount(); }
GlyphCount()115 uint16 GlyphCount() const
116 { return fStyle->GlyphCount(); }
CharMapCount()117 uint16 CharMapCount() const
118 { return fStyle->CharMapCount(); }
119 inline bool Hinting() const;
120
121 status_t GetGlyphShapes(const char charArray[],
122 int32 numChars, BShape *shapeArray[]) const;
123
124 status_t GetHasGlyphs(const char charArray[],
125 int32 numBytes, int32 numChars,
126 bool hasArray[], bool useFallbacks) const;
127
128 status_t GetEdges(const char charArray[], int32 numBytes,
129 int32 numChars, edge_info edgeArray[])
130 const;
131
132 status_t GetEscapements(const char charArray[],
133 int32 numBytes, int32 numChars,
134 escapement_delta delta,
135 BPoint escapementArray[],
136 BPoint offsetArray[]) const;
137
138 status_t GetEscapements(const char charArray[],
139 int32 numBytes, int32 numChars,
140 escapement_delta delta,
141 float widthArray[]) const;
142
143 status_t GetBoundingBoxes(const char charArray[],
144 int32 numBytes, int32 numChars,
145 BRect rectArray[], bool stringEscapement,
146 font_metric_mode mode,
147 escapement_delta delta,
148 bool asString);
149
150 status_t GetBoundingBoxesForStrings(char *charArray[],
151 size_t lengthArray[], int32 numStrings,
152 BRect rectArray[], font_metric_mode mode,
153 escapement_delta deltaArray[]);
154
155 float StringWidth(const char *string,
156 int32 numBytes,
157 const escapement_delta* delta = NULL) const;
158
Lock()159 bool Lock() const { return fStyle->Lock(); }
Unlock()160 void Unlock() const { fStyle->Unlock(); }
161
162 // FT_Face GetFTFace() const
163 // { return fStyle->FreeTypeFace(); };
164
165 BRect BoundingBox();
166 void GetHeight(font_height& height) const;
167
168 void TruncateString(BString* inOut,
169 uint32 mode, float width) const;
170
171 Transformable EmbeddedTransformation() const;
172 status_t GetUnicodeBlocks(unicode_block &blocksForFont);
173 status_t IncludesUnicodeBlock(uint32 start, uint32 end,
174 bool &hasBlock);
175
Manager()176 FontManager* Manager() const
177 { return fStyle->Manager(); }
178
179 void SetFontData(FT_Byte* location, uint32 size);
FontDataSize()180 uint32 FontDataSize() const
181 { return fStyle->FontDataSize(); }
FontData()182 FT_Byte* FontData() const
183 { return fStyle->FontData(); }
184
185 protected:
186 friend class FontStyle;
187
188 FT_Face GetTransformedFace(bool rotate,
189 bool shear) const;
190 void PutTransformedFace(FT_Face face) const;
191
192 BReference<FontStyle>
193 fStyle;
194 float fSize;
195 float fRotation;
196 float fShear;
197 float fFalseBoldWidth;
198 BRect fBounds;
199 uint32 fFlags;
200 uint32 fSpacing;
201 font_direction fDirection;
202 uint16 fFace;
203 uint32 fEncoding;
204 };
205
Hinting()206 inline bool ServerFont::Hinting() const
207 {
208 switch (gDefaultHintingMode) {
209 case HINTING_MODE_OFF:
210 return false;
211 default:
212 case HINTING_MODE_ON:
213 return true;
214 case HINTING_MODE_MONOSPACED_ONLY:
215 return IsFixedWidth();
216 }
217 }
218
219 #endif /* SERVER_FONT_H */
220