Created
March 13, 2019 16:21
-
-
Save fridgerator/b0abd96f423d77f63630275426a3f68b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ft2build.h> | |
#include FT_FREETYPE_H | |
static FT_Library library; | |
static FT_Face face; | |
int load_custom_font(void) | |
{ | |
int error; | |
error = FT_Init_FreeType(&library); | |
if (error) { | |
printf("error init freetype\n"); | |
return EXIT_FAILURE; | |
} | |
error = FT_New_Face(library, "./freudian.ttf", 0, &face); | |
if (error == FT_Err_Unknown_File_Format) { | |
printf("unkown file format\n"); | |
return EXIT_FAILURE; | |
} else if (error) { | |
printf("error loading font\n"); | |
return EXIT_FAILURE; | |
} | |
error = FT_Set_Char_Size(face, 0, 16*64, 300, 300); | |
// error = FT_Set_Pixel_Sizes(face, 0, 16); | |
if (error) { | |
printf("coudlnt get char size\n"); | |
return EXIT_FAILURE; | |
} | |
return EXIT_SUCCESS; | |
} | |
const uint8_t * get_ttf_bitmap(const lv_font_t * font, uint32_t unicode_letter) | |
{ | |
printf("get bitmap\n"); | |
int error; | |
error = FT_Load_Char ( face, unicode_letter, FT_LOAD_RENDER); | |
if (error) { | |
printf("could not load char in bitmap\n"); | |
return NULL; | |
} | |
printf("buffer : %s\n", face->glyph->bitmap.buffer); | |
return face->glyph->bitmap.buffer; | |
} | |
int16_t get_ttf_width(const lv_font_t * font, uint32_t unicode_letter) | |
{ | |
int error; | |
error = FT_Load_Char(face, unicode_letter, FT_LOAD_RENDER); | |
if (error) { | |
printf("could not load char in width\n"); | |
return -1; | |
} | |
printf("width : %i\n", face->glyph->bitmap.width); | |
return face->glyph->bitmap.width; | |
} | |
lv_font_t custom_font = | |
{ | |
.unicode_first = 32, | |
.unicode_last = 126, | |
.h_px = 0, | |
.glyph_bitmap = NULL, | |
.glyph_dsc = NULL, | |
.unicode_list = NULL, | |
.get_bitmap = get_ttf_bitmap, | |
.get_width = get_ttf_width, | |
.bpp = 8, | |
.next_page = NULL | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment