1 #include <Rect.h> 2 #include <stdio.h> 3 #include "Font.h" 4 5 class BFontPrivate 6 { 7 public: 8 BFontPrivate(void); 9 BFontPrivate &operator=(const BFontPrivate &fontdata); 10 11 BRect fBox; 12 font_family fFamily; 13 font_style fStyle; 14 bool fFixed; 15 font_file_format fFormat; 16 font_direction fDirection; 17 int32 fPrivateFlags; 18 }; 19 20 BFontPrivate::BFontPrivate(void) 21 { 22 fBox=BRect(0,0,0,0); 23 fFixed=false; 24 fFormat=B_TRUETYPE_WINDOWS; 25 fDirection=B_FONT_LEFT_TO_RIGHT; 26 } 27 28 BFontPrivate & BFontPrivate::operator=(const BFontPrivate &fontdata) 29 { 30 fBox=fontdata.fBox; 31 *fFamily=*(fontdata.fFamily); 32 *fStyle=*(fontdata.fStyle); 33 fFixed=fontdata.fFixed; 34 fFormat=fontdata.fFormat; 35 fDirection=fontdata.fDirection; 36 return *this; 37 } 38 39 40 BFont::BFont(void) 41 { 42 private_data=new BFontPrivate(); 43 if(be_plain_font) 44 { 45 fFamilyID=be_plain_font->fFamilyID; 46 fStyleID=be_plain_font->fStyleID; 47 fSize=be_plain_font->fSize; 48 fShear=be_plain_font->fShear; 49 fRotation=be_plain_font->fRotation; 50 fSpacing=be_plain_font->fSpacing; 51 fEncoding=be_plain_font->fEncoding; 52 fFace=be_plain_font->fFace; 53 fHeight=be_plain_font->fHeight; 54 private_data->fPrivateFlags=be_plain_font->private_data->fPrivateFlags; 55 } 56 else 57 { 58 fFamilyID=0; 59 fStyleID=0; 60 fSize=0.0; 61 fShear=90.0; 62 fRotation=0.0; 63 fSpacing=B_CHAR_SPACING; 64 fEncoding=B_UNICODE_UTF8; 65 fFace=B_REGULAR_FACE; 66 fHeight.ascent=0.0; 67 fHeight.descent=0.0; 68 fHeight.leading=0.0; 69 private_data->fPrivateFlags=0; 70 } 71 } 72 73 BFont::BFont(const BFont &font) 74 { 75 private_data=new BFontPrivate(); 76 fFamilyID=font.fFamilyID; 77 fStyleID=font.fStyleID; 78 fSize=font.fSize; 79 fShear=font.fShear; 80 fRotation=font.fRotation; 81 fSpacing=font.fSpacing; 82 fEncoding=font.fEncoding; 83 fFace=font.fFace; 84 fHeight=font.fHeight; 85 private_data->fPrivateFlags=font.private_data->fPrivateFlags; 86 } 87 88 BFont::BFont(const BFont *font) 89 { 90 private_data=new BFontPrivate(); 91 if(font) 92 { 93 fFamilyID=font->fFamilyID; 94 fStyleID=font->fStyleID; 95 fSize=font->fSize; 96 fShear=font->fShear; 97 fRotation=font->fRotation; 98 fSpacing=font->fSpacing; 99 fEncoding=font->fEncoding; 100 fFace=font->fFace; 101 fHeight=font->fHeight; 102 private_data->fPrivateFlags=font->private_data->fPrivateFlags; 103 } 104 else 105 { 106 if(be_plain_font) 107 { 108 fFamilyID=be_plain_font->fFamilyID; 109 fStyleID=be_plain_font->fStyleID; 110 fSize=be_plain_font->fSize; 111 fShear=be_plain_font->fShear; 112 fRotation=be_plain_font->fRotation; 113 fSpacing=be_plain_font->fSpacing; 114 fEncoding=be_plain_font->fEncoding; 115 fFace=be_plain_font->fFace; 116 fHeight=be_plain_font->fHeight; 117 private_data->fPrivateFlags=be_plain_font->private_data->fPrivateFlags; 118 } 119 else 120 { 121 fFamilyID=0; 122 fStyleID=0; 123 fSize=0.0; 124 fShear=90.0; 125 fRotation=0.0; 126 fSpacing=B_CHAR_SPACING; 127 fEncoding=B_UNICODE_UTF8; 128 fFace=B_REGULAR_FACE; 129 fHeight.ascent=0.0; 130 fHeight.descent=0.0; 131 fHeight.leading=0.0; 132 private_data->fPrivateFlags=0; 133 } 134 } 135 136 } 137 138 /* XXX TODO: R5 doesn't have a destructor, so we get linking errors when objects compiled with old headers with the new library 139 (but now we leak memory here) 140 BFont::~BFont(void) 141 { 142 delete private_data; 143 } 144 */ 145 146 status_t BFont::SetFamilyAndStyle(const font_family family, const font_style style) 147 { 148 // TODO: implement 149 // TODO: find out what codes are returned by this function. Be Book says this returns nothing 150 151 // Query server for the appropriate family and style IDs and then return the 152 // appropriate value 153 return B_ERROR; 154 } 155 156 void BFont::SetFamilyAndStyle(uint32 code) 157 { 158 fStyleID=code & 0xFFFF; 159 fFamilyID=(code & 0xFFFF0000) >> 16; 160 } 161 162 status_t BFont::SetFamilyAndFace(const font_family family, uint16 face) 163 { 164 // TODO: find out what codes are returned by this function. Be Book says this returns nothing 165 fFace=face; 166 167 // TODO: finish this function by adding the app_server Family query protocol code 168 if(family) 169 { 170 // Query server for family id for the specified family 171 } 172 173 return B_OK; 174 } 175 176 void BFont::SetSize(float size) 177 { 178 fSize=size; 179 } 180 181 void BFont::SetShear(float shear) 182 { 183 fShear=shear; 184 } 185 186 void BFont::SetRotation(float rotation) 187 { 188 fRotation=rotation; 189 } 190 191 void BFont::SetSpacing(uint8 spacing) 192 { 193 fSpacing=spacing; 194 } 195 196 void BFont::SetEncoding(uint8 encoding) 197 { 198 fEncoding=encoding; 199 } 200 201 void BFont::SetFace(uint16 face) 202 { 203 fFace=face; 204 } 205 206 void BFont::SetFlags(uint32 flags) 207 { 208 fFlags=flags; 209 } 210 211 void BFont::GetFamilyAndStyle(font_family *family, font_style *style) const 212 { 213 // TODO: implement 214 215 // Query server for the names of this stuff given the family and style IDs kept internally 216 } 217 218 uint32 BFont::FamilyAndStyle(void) const 219 { 220 uint32 token; 221 token=(fFamilyID << 16) | fStyleID; 222 return 0L; 223 } 224 225 float BFont::Size(void) const 226 { 227 return fSize; 228 } 229 230 float BFont::Shear(void) const 231 { 232 return fShear; 233 } 234 235 float BFont::Rotation(void) const 236 { 237 return fRotation; 238 } 239 240 uint8 BFont::Spacing(void) const 241 { 242 return fSpacing; 243 } 244 245 uint8 BFont::Encoding(void) const 246 { 247 return fEncoding; 248 } 249 250 uint16 BFont::Face(void) const 251 { 252 return fFace; 253 } 254 255 uint32 BFont::Flags(void) const 256 { 257 return fFlags; 258 } 259 260 font_direction BFont::Direction(void) const 261 { 262 return B_FONT_LEFT_TO_RIGHT; 263 } 264 265 bool BFont::IsFixed(void) const 266 { 267 // TODO: query server for whether this bad boy is fixed-width 268 269 return false; 270 } 271 272 bool BFont::IsFullAndHalfFixed(void) const 273 { 274 return false; 275 } 276 277 BRect BFont::BoundingBox(void) const 278 { 279 // TODO: query server for bounding box 280 return BRect(0,0,0,0); 281 } 282 283 unicode_block BFont::Blocks(void) const 284 { 285 // TODO: Add Block support 286 return unicode_block(); 287 } 288 289 font_file_format BFont::FileFormat(void) const 290 { 291 // TODO: this will not work until I extend FreeType to handle this kind of call 292 return B_TRUETYPE_WINDOWS; 293 } 294 295 int32 BFont::CountTuned(void) const 296 { 297 // TODO: query server for appropriate data 298 return 0; 299 } 300 301 void BFont::GetTunedInfo(int32 index, tuned_font_info *info) const 302 { 303 // TODO: implement 304 } 305 306 void BFont::TruncateString(BString *in_out,uint32 mode,float width) const 307 { 308 // TODO: implement 309 } 310 311 void BFont::GetTruncatedStrings(const char *stringArray[], int32 numStrings, 312 uint32 mode, float width, BString resultArray[]) const 313 { 314 // TODO: implement 315 } 316 317 void BFont::GetTruncatedStrings(const char *stringArray[], int32 numStrings, 318 uint32 mode, float width, char *resultArray[]) const 319 { 320 // TODO: implement 321 } 322 323 float BFont::StringWidth(const char *string) const 324 { 325 // TODO: implement 326 return 0.0; 327 } 328 329 float BFont::StringWidth(const char *string, int32 length) const 330 { 331 // TODO: implement 332 return 0.0; 333 } 334 335 void BFont::GetStringWidths(const char *stringArray[], const int32 lengthArray[], 336 int32 numStrings, float widthArray[]) const 337 { 338 // TODO: implement 339 } 340 341 void BFont::GetEscapements(const char charArray[], int32 numChars, float escapementArray[]) const 342 { 343 // TODO: implement 344 } 345 346 void BFont::GetEscapements(const char charArray[], int32 numChars, escapement_delta *delta, 347 float escapementArray[]) const 348 { 349 // TODO: implement 350 } 351 352 void BFont::GetEscapements(const char charArray[], int32 numChars, escapement_delta *delta, 353 BPoint escapementArray[]) const 354 { 355 // TODO: implement 356 } 357 358 void BFont::GetEscapements(const char charArray[], int32 numChars, escapement_delta *delta, 359 BPoint escapementArray[], BPoint offsetArray[]) const 360 { 361 // TODO: implement 362 } 363 364 void BFont::GetEdges(const char charArray[], int32 numBytes, edge_info edgeArray[]) const 365 { 366 // TODO: implement 367 } 368 369 void BFont::GetHeight(font_height *height) const 370 { 371 if(height) 372 { 373 *height=fHeight; 374 } 375 } 376 377 void BFont::GetBoundingBoxesAsGlyphs(const char charArray[], int32 numChars, font_metric_mode mode, 378 BRect boundingBoxArray[]) const 379 { 380 // TODO: implement 381 } 382 383 void BFont::GetBoundingBoxesAsString(const char charArray[], int32 numChars, font_metric_mode mode, 384 escapement_delta *delta, BRect boundingBoxArray[]) const 385 { 386 // TODO: implement 387 } 388 389 void BFont::GetBoundingBoxesForStrings(const char *stringArray[], int32 numStrings, 390 font_metric_mode mode, escapement_delta deltas[], BRect boundingBoxArray[]) const 391 { 392 // TODO: implement 393 } 394 395 void BFont::GetGlyphShapes(const char charArray[], int32 numChars, BShape *glyphShapeArray[]) const 396 { 397 // TODO: implement 398 } 399 400 void BFont::GetHasGlyphs(const char charArray[], int32 numChars, bool hasArray[]) const 401 { 402 // TODO: implement 403 } 404 405 BFont &BFont::operator=(const BFont &font) 406 { 407 fFamilyID=font.fFamilyID; 408 fStyleID=font.fStyleID; 409 fSize=font.fSize; 410 fShear=font.fShear; 411 fRotation=font.fRotation; 412 fSpacing=font.fSpacing; 413 fEncoding=font.fEncoding; 414 fFace=font.fFace; 415 fHeight=font.fHeight; 416 private_data->fPrivateFlags=font.private_data->fPrivateFlags; 417 return *this; 418 } 419 420 bool BFont::operator==(const BFont &font) const 421 { 422 if( fFamilyID!=font.fFamilyID || 423 fStyleID!=font.fStyleID || 424 fSize!=font.fSize || 425 fShear!=font.fShear || 426 fRotation!=font.fRotation || 427 fSpacing!=font.fSpacing || 428 fEncoding!=font.fEncoding || 429 fFace!=font.fFace || 430 fHeight.ascent!=font.fHeight.ascent || 431 fHeight.descent!=font.fHeight.descent || 432 fHeight.leading!=font.fHeight.leading || 433 private_data->fPrivateFlags!=font.private_data->fPrivateFlags ) 434 return false; 435 return true; 436 } 437 438 bool BFont::operator!=(const BFont &font) const 439 { 440 if( fFamilyID!=font.fFamilyID || 441 fStyleID!=font.fStyleID || 442 fSize!=font.fSize || 443 fShear!=font.fShear || 444 fRotation!=font.fRotation || 445 fSpacing!=font.fSpacing || 446 fEncoding!=font.fEncoding || 447 fFace!=font.fFace || 448 fHeight.ascent!=font.fHeight.ascent || 449 fHeight.descent!=font.fHeight.descent || 450 fHeight.leading!=font.fHeight.leading || 451 private_data->fPrivateFlags!=font.private_data->fPrivateFlags ) 452 return true; 453 return false; 454 } 455 456 void BFont::PrintToStream(void) const 457 { 458 printf("FAMILY STYLE %f %f %f %f %f %f\n", fSize, fShear, fRotation, fHeight.ascent, 459 fHeight.descent, fHeight.leading); 460 } 461 462