MCPcopy Create free account
hub / github.com/ClassiCube/ClassiCube / SysFont_Init

Function SysFont_Init

src/SystemFonts.c:465–508  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

463}
464
465static 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
510static void* FT_AllocWrapper(FT_Memory memory, long size) { return Mem_TryAlloc(size, 1); }
511static void FT_FreeWrapper(FT_Memory memory, void* block) { Mem_Free(block); }

Callers 2

SysFonts_DoRegisterFunction · 0.85
SysFont_MakeFunction · 0.85

Calls 8

Stream_FromFileFunction · 0.85
Stream_ReadonlyBufferedFunction · 0.85
String_CopyFunction · 0.85
Mem_SetFunction · 0.85
Platform_EncodePathFunction · 0.70
File_OpenFunction · 0.70
File_LengthFunction · 0.70
File_CloseFunction · 0.70

Tested by

no test coverage detected