1 /* 2 * Copyright 2005-2007, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _FONT_H_ 6 #define _FONT_H_ 7 8 9 #include <SupportDefs.h> 10 #include <InterfaceDefs.h> 11 12 class BPoint; 13 14 15 #define B_FONT_FAMILY_LENGTH 63 16 #define B_FONT_STYLE_LENGTH 63 17 typedef char font_family[B_FONT_FAMILY_LENGTH + 1]; 18 typedef char font_style[B_FONT_STYLE_LENGTH + 1]; 19 20 // font spacing 21 enum { 22 B_CHAR_SPACING = 0, 23 B_STRING_SPACING = 1, 24 B_BITMAP_SPACING = 2, 25 B_FIXED_SPACING = 3 26 }; 27 28 enum font_direction { 29 B_FONT_LEFT_TO_RIGHT = 0, 30 B_FONT_RIGHT_TO_LEFT = 1 31 }; 32 33 // font flags 34 enum { 35 B_DISABLE_ANTIALIASING = 0x00000001, 36 B_FORCE_ANTIALIASING = 0x00000002 37 }; 38 39 // truncation modes 40 enum { 41 B_TRUNCATE_END = 0, 42 B_TRUNCATE_BEGINNING = 1, 43 B_TRUNCATE_MIDDLE = 2, 44 B_TRUNCATE_SMART = 3 45 }; 46 47 // font encodings 48 enum { 49 B_UNICODE_UTF8 = 0, 50 B_ISO_8859_1 = 1, 51 B_ISO_8859_2 = 2, 52 B_ISO_8859_3 = 3, 53 B_ISO_8859_4 = 4, 54 B_ISO_8859_5 = 5, 55 B_ISO_8859_6 = 6, 56 B_ISO_8859_7 = 7, 57 B_ISO_8859_8 = 8, 58 B_ISO_8859_9 = 9, 59 B_ISO_8859_10 = 10, 60 B_MACINTOSH_ROMAN = 11 61 }; 62 63 // flags for get_font_family() and get_font_style() 64 enum { 65 B_HAS_TUNED_FONT = 0x0001, 66 B_IS_FIXED = 0x0002 67 }; 68 69 // font face flags 70 enum { 71 B_ITALIC_FACE = 0x0001, 72 B_UNDERSCORE_FACE = 0x0002, 73 B_NEGATIVE_FACE = 0x0004, 74 B_OUTLINED_FACE = 0x0008, 75 B_STRIKEOUT_FACE = 0x0010, 76 B_BOLD_FACE = 0x0020, 77 B_REGULAR_FACE = 0x0040, 78 // new in Haiku: 79 B_CONDENSED_FACE = 0x0080, 80 B_LIGHT_FACE = 0x0100, 81 B_HEAVY_FACE = 0x0200, 82 }; 83 84 enum font_metric_mode { 85 B_SCREEN_METRIC = 0, 86 B_PRINTING_METRIC = 1 87 }; 88 89 enum font_file_format { 90 B_TRUETYPE_WINDOWS = 0, 91 B_POSTSCRIPT_TYPE1_WINDOWS = 1 92 }; 93 94 class unicode_block { 95 public: 96 inline unicode_block(); 97 inline unicode_block(uint64 block2, uint64 block1); 98 99 inline bool Includes(const unicode_block &block) const; 100 inline unicode_block operator&(const unicode_block &block) const; 101 inline unicode_block operator|(const unicode_block &block) const; 102 inline unicode_block &operator=(const unicode_block &block); 103 inline bool operator==(const unicode_block &block) const; 104 inline bool operator!=(const unicode_block &block) const; 105 106 private: 107 uint64 fData[2]; 108 }; 109 110 struct edge_info { 111 float left; 112 float right; 113 }; 114 115 struct font_height { 116 float ascent; 117 float descent; 118 float leading; 119 }; 120 121 struct escapement_delta { 122 float nonspace; 123 float space; 124 }; 125 126 struct font_cache_info { 127 int32 sheared_font_penalty; 128 int32 rotated_font_penalty; 129 float oversize_threshold; 130 int32 oversize_penalty; 131 int32 cache_size; 132 float spacing_size_threshold; 133 }; 134 135 struct tuned_font_info { 136 float size; 137 float shear; 138 float rotation; 139 uint32 flags; 140 uint16 face; 141 }; 142 143 class BShape; 144 class BString; 145 class BFontPrivate; 146 147 148 class BFont { 149 public: 150 BFont(); 151 BFont(const BFont &font); 152 BFont(const BFont *font); 153 154 status_t SetFamilyAndStyle(const font_family family, 155 const font_style style); 156 void SetFamilyAndStyle(uint32 code); 157 status_t SetFamilyAndFace(const font_family family, uint16 face); 158 159 void SetSize(float size); 160 void SetShear(float shear); 161 void SetRotation(float rotation); 162 void SetFalseBoldWidth(float width); 163 void SetSpacing(uint8 spacing); 164 void SetEncoding(uint8 encoding); 165 void SetFace(uint16 face); 166 void SetFlags(uint32 flags); 167 168 void GetFamilyAndStyle(font_family *family, 169 font_style *style) const; 170 uint32 FamilyAndStyle() const; 171 float Size() const; 172 float Shear() const; 173 float Rotation() const; 174 float FalseBoldWidth() const; 175 uint8 Spacing() const; 176 uint8 Encoding() const; 177 uint16 Face() const; 178 uint32 Flags() const; 179 180 font_direction Direction() const; 181 bool IsFixed() const; 182 bool IsFullAndHalfFixed() const; 183 BRect BoundingBox() const; 184 unicode_block Blocks() const; 185 font_file_format FileFormat() const; 186 187 int32 CountTuned() const; 188 void GetTunedInfo(int32 index, tuned_font_info *info) const; 189 190 void TruncateString(BString* inOut, uint32 mode, 191 float width) const; 192 void GetTruncatedStrings(const char *stringArray[], 193 int32 numStrings, uint32 mode, float width, 194 BString resultArray[]) const; 195 void GetTruncatedStrings(const char *stringArray[], 196 int32 numStrings, uint32 mode, float width, 197 char *resultArray[]) const; 198 199 float StringWidth(const char *string) const; 200 float StringWidth(const char *string, int32 length) const; 201 void GetStringWidths(const char *stringArray[], 202 const int32 lengthArray[], int32 numStrings, 203 float widthArray[]) const; 204 205 void GetEscapements(const char charArray[], int32 numChars, 206 float escapementArray[]) const; 207 void GetEscapements(const char charArray[], int32 numChars, 208 escapement_delta *delta, float escapementArray[]) const; 209 void GetEscapements(const char charArray[], int32 numChars, 210 escapement_delta *delta, BPoint escapementArray[]) const; 211 void GetEscapements(const char charArray[], int32 numChars, 212 escapement_delta *delta, BPoint escapementArray[], 213 BPoint offsetArray[]) const; 214 215 void GetEdges(const char charArray[], int32 numBytes, 216 edge_info edgeArray[]) const; 217 void GetHeight(font_height *height) const; 218 219 void GetBoundingBoxesAsGlyphs(const char charArray[], 220 int32 numChars, font_metric_mode mode, 221 BRect boundingBoxArray[]) const; 222 void GetBoundingBoxesAsString(const char charArray[], 223 int32 numChars, font_metric_mode mode, 224 escapement_delta *delta, BRect boundingBoxArray[]) const; 225 void GetBoundingBoxesForStrings(const char *stringArray[], 226 int32 numStrings, font_metric_mode mode, 227 escapement_delta deltas[], 228 BRect boundingBoxArray[]) const; 229 230 void GetGlyphShapes(const char charArray[], int32 numChars, 231 BShape *glyphShapeArray[]) const; 232 233 void GetHasGlyphs(const char charArray[], int32 numChars, 234 bool hasArray[]) const; 235 236 BFont& operator=(const BFont &font); 237 bool operator==(const BFont &font) const; 238 bool operator!=(const BFont &font) const; 239 240 void PrintToStream() const; 241 242 private: 243 friend void _init_global_fonts_(); 244 245 uint16 fFamilyID; 246 uint16 fStyleID; 247 float fSize; 248 float fShear; 249 float fRotation; 250 float fFalseBoldWidth; 251 uint8 fSpacing; 252 uint8 fEncoding; 253 uint16 fFace; 254 uint32 fFlags; 255 mutable font_height fHeight; 256 mutable uint32 fExtraFlags; 257 uint32 _reserved[1]; 258 259 void _GetExtraFlags() const; 260 void _GetBoundingBoxes(const char charArray[], 261 int32 numChars, font_metric_mode mode, 262 bool string_escapement, escapement_delta *delta, 263 BRect boundingBoxArray[], bool asString) const; 264 }; 265 266 267 // BFont related declarations 268 269 extern const BFont *be_plain_font; 270 extern const BFont *be_bold_font; 271 extern const BFont *be_fixed_font; 272 273 int32 count_font_families(void); 274 status_t get_font_family(int32 index, font_family *name, uint32 *flags = NULL); 275 276 int32 count_font_styles(font_family name); 277 status_t get_font_style(font_family family, int32 index, font_style *name, 278 uint32 *flags = NULL); 279 status_t get_font_style(font_family family, int32 index, font_style *name, 280 uint16 *face, uint32 *flags = NULL); 281 bool update_font_families(bool checkOnly); 282 283 284 // unicode_block inlines 285 286 unicode_block::unicode_block() 287 { 288 fData[0] = fData[1] = 0LL; 289 } 290 291 unicode_block::unicode_block(uint64 block2, uint64 block1) 292 { 293 fData[0] = block1; 294 fData[1] = block2; 295 } 296 297 bool 298 unicode_block::Includes(const unicode_block &block) const 299 { 300 return (fData[0] & block.fData[0]) == block.fData[0] 301 && (fData[1] & block.fData[1]) == block.fData[1]; 302 } 303 304 unicode_block 305 unicode_block::operator&(const unicode_block &block) const 306 { 307 unicode_block result; 308 result.fData[0] = fData[0] & block.fData[0]; 309 result.fData[1] = fData[1] & block.fData[1]; 310 311 return result; 312 } 313 314 unicode_block 315 unicode_block::operator|(const unicode_block &block) const 316 { 317 unicode_block result; 318 result.fData[0] = fData[0] | block.fData[0]; 319 result.fData[1] = fData[1] | block.fData[1]; 320 321 return result; 322 } 323 324 unicode_block & 325 unicode_block::operator=(const unicode_block &block) 326 { 327 fData[0] = block.fData[0]; 328 fData[1] = block.fData[1]; 329 return *this; 330 } 331 332 bool 333 unicode_block::operator==(const unicode_block &block) const 334 { 335 return fData[0] == block.fData[0] && fData[1] == block.fData[1]; 336 } 337 338 bool 339 unicode_block::operator!=(const unicode_block &block) const 340 { 341 return fData[0] != block.fData[0] || fData[1] != block.fData[1]; 342 } 343 344 #endif /* _FONT_H_ */ 345