dynload freetype2
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
This commit is contained in:
parent
2e30d7f4d9
commit
9d7d4541e4
2 changed files with 39 additions and 12 deletions
|
|
@ -78,12 +78,8 @@ add_incdir("-Iexternal/libz/include");
|
|||
|
||||
if (param_get("freetype2")) {
|
||||
add_cflags("-DUSE_FREETYPE2");
|
||||
if ($cross) {
|
||||
add_libs("-lfreetype");
|
||||
}
|
||||
else {
|
||||
if (!$cross) {
|
||||
add_cflags(`pkg-config --cflags freetype2`);
|
||||
add_libs(`pkg-config --libs freetype2`);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,24 @@
|
|||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
static struct {
|
||||
FT_Error (*FT_Init_FreeType)(FT_Library* alibrary);
|
||||
FT_Error (*FT_New_Memory_Face)(FT_Library library,
|
||||
const FT_Byte* file_base,
|
||||
FT_Long file_size,
|
||||
FT_Long face_index,
|
||||
FT_Face* aface);
|
||||
FT_Error (*FT_Set_Pixel_Sizes)(FT_Face face,
|
||||
FT_UInt pixel_width,
|
||||
FT_UInt pixel_height);
|
||||
FT_Error (*FT_Load_Char)(FT_Face face,
|
||||
FT_ULong char_code,
|
||||
FT_Int32 load_flags);
|
||||
FT_Error (*FT_Done_Face)(FT_Face face);
|
||||
FT_Error (*FT_Done_FreeType)(FT_Library library);
|
||||
|
||||
} ft_table;
|
||||
|
||||
struct _MwFLFont {
|
||||
FT_Library library;
|
||||
FT_Face face;
|
||||
|
|
@ -37,7 +55,7 @@ static int ft2_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int
|
|||
continue;
|
||||
}
|
||||
|
||||
FT_Load_Char(ttf->face, c, FT_LOAD_RENDER);
|
||||
ft_table.FT_Load_Char(ttf->face, c, FT_LOAD_RENDER);
|
||||
bmp = &ttf->face->glyph->bitmap;
|
||||
|
||||
for(cy = 0; cy < bmp->rows; cy++) {
|
||||
|
|
@ -90,7 +108,7 @@ static int ft2_MwTextWidth(MwWidget handle, const char* text) {
|
|||
continue;
|
||||
}
|
||||
|
||||
FT_Load_Char(ttf->face, c, FT_LOAD_RENDER);
|
||||
ft_table.FT_Load_Char(ttf->face, c, FT_LOAD_RENDER);
|
||||
|
||||
tw += ttf->face->glyph->metrics.horiAdvance / 64;
|
||||
if(tw > mtw) mtw = tw;
|
||||
|
|
@ -110,10 +128,10 @@ static void* ft2_MwFontLoad(unsigned char* data, unsigned int size) {
|
|||
MwFLFont ttf = malloc(sizeof(*ttf));
|
||||
ttf->data = malloc(size);
|
||||
memcpy(ttf->data, data, size);
|
||||
FT_Init_FreeType(&ttf->library);
|
||||
FT_New_Memory_Face(ttf->library, ttf->data, size, 0, &ttf->face);
|
||||
ft_table.FT_Init_FreeType(&ttf->library);
|
||||
ft_table.FT_New_Memory_Face(ttf->library, ttf->data, size, 0, &ttf->face);
|
||||
|
||||
FT_Set_Pixel_Sizes(ttf->face, 0, 14);
|
||||
ft_table.FT_Set_Pixel_Sizes(ttf->face, 0, 14);
|
||||
|
||||
return ttf;
|
||||
}
|
||||
|
|
@ -121,14 +139,27 @@ static void* ft2_MwFontLoad(unsigned char* data, unsigned int size) {
|
|||
static void ft2_MwFontFree(void* handle) {
|
||||
MwFLFont ttf = handle;
|
||||
|
||||
FT_Done_Face(ttf->face);
|
||||
FT_Done_FreeType(ttf->library);
|
||||
ft_table.FT_Done_Face(ttf->face);
|
||||
ft_table.FT_Done_FreeType(ttf->library);
|
||||
|
||||
free(ttf->data);
|
||||
free(ttf);
|
||||
}
|
||||
|
||||
int MWFL_FT2Setup(void) {
|
||||
/* Try and load FreeType2. If it fails, return 1, signifying we default to stbtt. */
|
||||
void* ftlib;
|
||||
if(!(ftlib = MwDynamicOpen("libfreetype.so"))) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
ft_table.FT_Init_FreeType = MwDynamicSymbol(ftlib, "FT_Init_FreeType");
|
||||
ft_table.FT_New_Memory_Face = MwDynamicSymbol(ftlib, "FT_New_Memory_Face");
|
||||
ft_table.FT_Set_Pixel_Sizes = MwDynamicSymbol(ftlib, "FT_Set_Pixel_Sizes");
|
||||
ft_table.FT_Load_Char = MwDynamicSymbol(ftlib, "FT_Load_Char");
|
||||
ft_table.FT_Done_Face = MwDynamicSymbol(ftlib, "FT_Done_Face");
|
||||
ft_table.FT_Done_FreeType = MwDynamicSymbol(ftlib, "FT_Done_FreeType");
|
||||
|
||||
MwFLDrawText = ft2_MwDrawText;
|
||||
MwFLTextWidth = ft2_MwTextWidth;
|
||||
MwFLTextHeight = ft2_MwTextHeight;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue