ghaerr / microwindows

The Nano-X Window System
Other
648 stars 91 forks source link

SetFontSize failed #88

Closed ChauncyZhang closed 4 weeks ago

ChauncyZhang commented 4 weeks ago

Hi, I tested the nano-x to draw font, but I found the font size can't be changed whether I set the size. Can you tell me how to set the font size? best wish!@ghaerr

code below: const char* font_path = "microwindows/src/fonts/em-fonts/arial.ttf"; printf("Loading custom font from %s\n", font_path); GR_FONT_ID font = GrCreateFontEx(font_path, 100, 100, NULL); if (font == 0) { fprintf(stderr, "Error loading font: %s\n", font_path); return; } GrSetFontSizeEx(font, 72, 72); GrSetGCFont(gc, font);

GrSetGCForeground(gc, BLACK);

GR_FONT_INFO fip;
GrGetFontInfo(font, &fip);
printf("maxwidth=%d height=%d\n", fip.maxwidth, fip.height);

GrSetFontAttr(font, GR_TFKERNING | GR_TFANTIALIAS, 0);
GrText(wid, gc, x, y, buffer, strlen(buffer), GR_TFASCII);
GrDestroyFont(font);
ChauncyZhang commented 4 weeks ago

maxwidth=11 height=13 And I saw that is very small

ghaerr commented 4 weeks ago

maxwidth=11 height=13

It sounds like you have not configured your system to use Freetype, which is required to use TTF fonts. When a font is requested that is not available, usually the "WinFreeSansSerif11x13" font is returned which seems to be what you are getting.

You must ensure that your config file has something like:

####################################################################
# Truetype fonts - .ttf and .otf loadable fonts thru Freetype 2.x
####################################################################
HAVE_FREETYPE_2_SUPPORT  = Y
INCFT2LIB                = /usr/include
LIBFT2LIB                = -lfreetype
FREETYPE_FONT_DIR        = "fonts/truetype"

And that the freetype library is compiled and installed on your system.

ChauncyZhang commented 4 weeks ago

That's ok, thank you!