| 463 | } |
| 464 | |
| 465 | static cc_result SysFont_Init(const cc_string* path, struct SysFont* font, FT_Open_Args* args) { |
| 466 | cc_filepath str; |
| 467 | cc_file file; |
| 468 | cc_uint32 size; |
| 469 | cc_result res; |
| 470 | #ifdef CC_BUILD_DARWIN |
| 471 | cc_string filename; |
| 472 | #endif |
| 473 | |
| 474 | Platform_EncodePath(&str, path); |
| 475 | if ((res = File_Open(&file, &str))) return res; |
| 476 | if ((res = File_Length(file, &size))) { File_Close(file); return res; } |
| 477 | |
| 478 | font->stream.base = NULL; |
| 479 | font->stream.size = size; |
| 480 | font->stream.pos = 0; |
| 481 | |
| 482 | font->stream.descriptor.pointer = font; |
| 483 | font->stream.read = SysFont_Read; |
| 484 | font->stream.close = SysFont_Close; |
| 485 | |
| 486 | font->stream.memory = &ft_mem; |
| 487 | font->stream.cursor = NULL; |
| 488 | font->stream.limit = NULL; |
| 489 | |
| 490 | args->flags = FT_OPEN_STREAM; |
| 491 | args->pathname = NULL; |
| 492 | args->stream = &font->stream; |
| 493 | |
| 494 | Stream_FromFile(&font->file, file); |
| 495 | Stream_ReadonlyBuffered(&font->src, &font->file, font->buffer, sizeof(font->buffer)); |
| 496 | |
| 497 | /* For OSX font suitcase files */ |
| 498 | #ifdef CC_BUILD_DARWIN |
| 499 | String_InitArray_NT(filename, font->filename); |
| 500 | String_Copy(&filename, path); |
| 501 | font->filename[filename.length] = '\0'; |
| 502 | args->pathname = font->filename; |
| 503 | #endif |
| 504 | Mem_Set(font->widths, 0xFF, sizeof(font->widths)); |
| 505 | Mem_Set(font->glyphs, 0x00, sizeof(font->glyphs)); |
| 506 | Mem_Set(font->shadow_glyphs, 0x00, sizeof(font->shadow_glyphs)); |
| 507 | return 0; |
| 508 | } |
| 509 | |
| 510 | static void* FT_AllocWrapper(FT_Memory memory, long size) { return Mem_TryAlloc(size, 1); } |
| 511 | static void FT_FreeWrapper(FT_Memory memory, void* block) { Mem_Free(block); } |
no test coverage detected