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