fix font size
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good

This commit is contained in:
Nishi 2026-04-06 23:27:27 +09:00
commit 5f6789631d
Signed by: nishi
GPG key ID: 27EF69B208EB9343
5 changed files with 13 additions and 13 deletions

2
configure vendored
View file

@ -204,7 +204,7 @@ print(OUT " cp -rf include \$(DESTDIR)\$(PREFIX)/\n");
print(OUT "\n"); print(OUT "\n");
print(OUT "format:\n"); print(OUT "format:\n");
print(OUT print(OUT
" clang-format --verbose -i `find src include examples -name \"*.c\" -or -name \"*.h\" -or -name \"*.m\"`\n" " clang-format --verbose -i `find src include examples \"(\" -name \"*.c\" -or -name \"*.h\" -or -name \"*.m\" \")\" -and -not -name \"*ttf.c\"`\n"
); );
print(OUT print(OUT
" perltidy -b -bext=\"/\" --paren-tightness=2 `find tools pl configure -name \"*.pl\"`\n" " perltidy -b -bext=\"/\" --paren-tightness=2 `find tools pl configure -name \"*.pl\"`\n"

View file

@ -253,7 +253,7 @@ MWDECL int MwFL_STBTTSetup(void);
MWDECL int (*MwFLDrawText)(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text, MwLLColor color); MWDECL int (*MwFLDrawText)(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text, MwLLColor color);
MWDECL int (*MwFLTextWidth)(MwFLFont ttf, const char* text); MWDECL int (*MwFLTextWidth)(MwFLFont ttf, const char* text);
MWDECL int (*MwFLTextHeight)(MwFLFont ttf, int count); MWDECL int (*MwFLTextHeight)(MwFLFont ttf, int count);
MWDECL void* (*MwFLFontLoad)(unsigned char* data, unsigned int size); MWDECL void* (*MwFLFontLoad)(unsigned char* data, unsigned int size, int px);
MWDECL void (*MwFLFontFree)(void* handle); MWDECL void (*MwFLFontFree)(void* handle);
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -4,8 +4,6 @@
#include <ft2build.h> #include <ft2build.h>
#include FT_FREETYPE_H #include FT_FREETYPE_H
#define HEIGHT 14
static struct ft_table { static struct ft_table {
FT_Error (*FT_Init_FreeType)(FT_Library* alibrary); FT_Error (*FT_Init_FreeType)(FT_Library* alibrary);
FT_Error (*FT_New_Memory_Face)(FT_Library library, FT_Error (*FT_New_Memory_Face)(FT_Library library,
@ -33,6 +31,7 @@ struct _MwFLFont {
FT_Library library; FT_Library library;
FT_Face face; FT_Face face;
void* data; void* data;
int px;
}; };
static int ft2_MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text, MwLLColor color) { static int ft2_MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text, MwLLColor color) {
int tw, th; int tw, th;
@ -58,7 +57,7 @@ static int ft2_MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const c
if(c == '\n') { if(c == '\n') {
x = 0; x = 0;
y += ttf->face->height * HEIGHT / ttf->face->units_per_EM; y += ttf->face->height * ttf->px / ttf->face->units_per_EM;
continue; continue;
} }
@ -68,7 +67,7 @@ static int ft2_MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const c
for(cy = 0; cy < bmp->rows; cy++) { for(cy = 0; cy < bmp->rows; cy++) {
for(cx = 0; cx < bmp->width; cx++) { for(cx = 0; cx < bmp->width; cx++) {
int ox = x + (ttf->face->glyph->metrics.horiBearingX / 64) + cx + ttf->face->glyph->bitmap_left; int ox = x + (ttf->face->glyph->metrics.horiBearingX / 64) + cx + ttf->face->glyph->bitmap_left;
int oy = y + (ttf->face->height * HEIGHT / ttf->face->units_per_EM) - ttf->face->glyph->bitmap_top + cy + (ttf->face->descender * HEIGHT / ttf->face->units_per_EM); int oy = y + (ttf->face->height * ttf->px / ttf->face->units_per_EM) - ttf->face->glyph->bitmap_top + cy + (ttf->face->descender * ttf->px / ttf->face->units_per_EM);
unsigned char* opx = &px[(oy * tw + ox) * 4]; unsigned char* opx = &px[(oy * tw + ox) * 4];
opx[0] = color->common.red; opx[0] = color->common.red;
@ -140,17 +139,18 @@ static int ft2_MwTextWidth(MwFLFont ttf, const char* text) {
} }
static int ft2_MwTextHeight(MwFLFont ttf, int count) { static int ft2_MwTextHeight(MwFLFont ttf, int count) {
return ceil((ttf->face->height * HEIGHT / ttf->face->units_per_EM) * count); return ceil((ttf->face->height * ttf->px / ttf->face->units_per_EM) * count);
} }
static void* ft2_MwFontLoad(unsigned char* data, unsigned int size) { static void* ft2_MwFontLoad(unsigned char* data, unsigned int size, int px) {
MwFLFont ttf = malloc(sizeof(*ttf)); MwFLFont ttf = malloc(sizeof(*ttf));
ttf->data = malloc(size); ttf->data = malloc(size);
memcpy(ttf->data, data, size); memcpy(ttf->data, data, size);
ft_table.FT_Init_FreeType(&ttf->library); ft_table.FT_Init_FreeType(&ttf->library);
ft_table.FT_New_Memory_Face(ttf->library, ttf->data, size, 0, &ttf->face); ft_table.FT_New_Memory_Face(ttf->library, ttf->data, size, 0, &ttf->face);
ft_table.FT_Set_Pixel_Sizes(ttf->face, 0, HEIGHT); ttf->px = px;
ft_table.FT_Set_Pixel_Sizes(ttf->face, 0, ttf->px);
return ttf; return ttf;
} }

View file

@ -128,13 +128,13 @@ static int stbtt_MwTextHeight(MwFLFont ttf, int count) {
return ceil((ttf->ascent - ttf->descent) * ttf->scale * count); return ceil((ttf->ascent - ttf->descent) * ttf->scale * count);
} }
static void* stbtt_MwFontLoad(unsigned char* data, unsigned int size) { static void* stbtt_MwFontLoad(unsigned char* data, unsigned int size, int px) {
MwFLFont ttf = malloc(sizeof(*ttf)); MwFLFont ttf = malloc(sizeof(*ttf));
ttf->data = malloc(size); ttf->data = malloc(size);
memcpy(ttf->data, data, size); memcpy(ttf->data, data, size);
stbtt_InitFont(&ttf->font, ttf->data, 0); stbtt_InitFont(&ttf->font, ttf->data, 0);
ttf->scale = stbtt_ScaleForPixelHeight(&ttf->font, 16); ttf->scale = stbtt_ScaleForMappingEmToPixels(&ttf->font, px);
stbtt_GetFontVMetrics(&ttf->font, &ttf->ascent, &ttf->descent, 0); stbtt_GetFontVMetrics(&ttf->font, &ttf->ascent, &ttf->descent, 0);
return ttf; return ttf;

View file

@ -3,7 +3,7 @@
int (*MwFLDrawText)(MwWidget handle, MwFLFont font, MwPoint* point, const char* text, MwLLColor color) = NULL; int (*MwFLDrawText)(MwWidget handle, MwFLFont font, MwPoint* point, const char* text, MwLLColor color) = NULL;
int (*MwFLTextWidth)(MwFLFont font, const char* text) = NULL; int (*MwFLTextWidth)(MwFLFont font, const char* text) = NULL;
int (*MwFLTextHeight)(MwFLFont font, int count) = NULL; int (*MwFLTextHeight)(MwFLFont font, int count) = NULL;
void* (*MwFLFontLoad)(unsigned char* data, unsigned int size) = NULL; void* (*MwFLFontLoad)(unsigned char* data, unsigned int size, int px) = NULL;
void (*MwFLFontFree)(void* handle) = NULL; void (*MwFLFontFree)(void* handle) = NULL;
#if defined(USE_FREETYPE2) || defined(USE_STB_TRUETYPE) #if defined(USE_FREETYPE2) || defined(USE_STB_TRUETYPE)
@ -116,7 +116,7 @@ int MwTextHeight(MwWidget handle, MwFLFont ttf, const char* text) {
void* MwFontLoad(unsigned char* data, unsigned int size) { void* MwFontLoad(unsigned char* data, unsigned int size) {
if(MwFLFontLoad) if(MwFLFontLoad)
return MwFLFontLoad(data, size); return MwFLFontLoad(data, size, 16);
return NULL; return NULL;
} }