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