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

Function SysFont_Make

src/SystemFonts.c:738–771  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

736
737#define TEXT_CEIL(x) (((x) + 63) >> 6)
738cc_result SysFont_Make(struct FontDesc* desc, const cc_string* fontName, int size, int flags) {
739 struct SysFont* font;
740 cc_string value, path, index;
741 int faceIndex, dpiX, dpiY;
742 FT_Open_Args args;
743 FT_Error err;
744
745 desc->size = size;
746 desc->flags = flags;
747 desc->handle = NULL;
748
749 value = Font_Lookup(fontName, flags);
750 if (!value.length) return ERR_INVALID_ARGUMENT;
751 String_UNSAFE_Separate(&value, ',', &path, &index);
752 Convert_ParseInt(&index, &faceIndex);
753
754 font = (struct SysFont*)Mem_TryAlloc(1, sizeof(struct SysFont));
755 if (!font) return ERR_OUT_OF_MEMORY;
756
757 InitFreeTypeLibrary();
758 if ((err = SysFont_Init(&path, font, &args))) { Mem_Free(font); return err; }
759 desc->handle = font;
760
761 /* TODO: Use 72 instead of 96 dpi for mobile devices */
762 dpiX = (int)(DisplayInfo.ScaleX * 96);
763 dpiY = (int)(DisplayInfo.ScaleY * 96);
764
765 if ((err = FT_New_Face(ft_lib, &args, faceIndex, &font->face))) return err;
766 if ((err = FT_Set_Char_Size(font->face, size * 64, 0, dpiX, dpiY))) return err;
767
768 /* height of any text when drawn with the given system font */
769 desc->height = TEXT_CEIL(font->face->size->metrics.height);
770 return 0;
771}
772
773void SysFont_MakeDefault(struct FontDesc* desc, int size, int flags) {
774 cc_string* font;

Callers 2

SysFont_MakeDefaultFunction · 0.85

Calls 11

Font_LookupFunction · 0.85
String_UNSAFE_SeparateFunction · 0.85
Convert_ParseIntFunction · 0.85
InitFreeTypeLibraryFunction · 0.85
SysFont_InitFunction · 0.85
FT_Set_Char_SizeFunction · 0.85
Drawer2D_AdjHeightFunction · 0.85
String_CopyToRawFunction · 0.85
Mem_TryAllocFunction · 0.70
Mem_FreeFunction · 0.70
FT_New_FaceFunction · 0.50

Tested by

no test coverage detected