libttf
August 6, 2025 ยท View on GitHub
the objective of libttf is to be a simple and portable library to render .ttf font
orignaly written for the stanix operating system libttf is hopping to one day become a viable concurrent to libfreetype
build and install
start by launching the configure script
./configure
Note
you can use the options --prefix and --host
then run make
make
and finally install
make install
Note
this might require root permission if installing globally
api
you can get started with
#include <stdio.h>
#include <ttf.h>
int main(){
//open a ttf file
ttf_file *font = ttf_open("DejaVuSans.ttf");
if(!font){
printf("libttf : %s\n",ttf_error());
return 1;
}
//get a glyph
ttf_glyph *glyph = ttf_getglyph(font,'A');
//generate a bitmap
ttf_bitmap *bitmap = ttf_render_glyph(glyph);
ttf_free_glyph(glyph);
ttf_close(font);
return 0;
}
and then compile with
gcc test.c -lttf
functions
ttf_file *ttf_open(const char *path)void ttf_close(ttf_file *font)const char *ttf_error()uint32_t ttf_char2glyf(ttf_file *font,wchar_t c)ttf_glyph *ttf_getglyph(ttf_file *font,wchar_t c)void ttf_free_glyph(ttf_glyph *glyph)void ttf_set_font_size(ttf_font *font,int size)void ttf_set_curves_seg(ttf_font *font,int count)ttf_bitmap *ttf_render_glyph(ttf_glyph *glyph)
bitmap
bitmap generated by libttf are black and white bitmap composed of an array of uint8_t a value of 0 correspond to background color and a value of 255 correspond to foreground color value in between are a mix used for anti aliasing
support
currently libttf support only font of type truetype outline
Note
combine char are currently very broken