https://github.com/tayoky/libttf
a simple library to render ttf font
https://github.com/tayoky/libttf
font library ttf ttf-fonts
Last synced: about 2 months ago
JSON representation
a simple library to render ttf font
- Host: GitHub
- URL: https://github.com/tayoky/libttf
- Owner: tayoky
- Created: 2025-06-24T21:55:27.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-25T07:28:10.000Z (about 1 year ago)
- Last Synced: 2025-06-25T08:28:10.024Z (about 1 year ago)
- Topics: font, library, ttf, ttf-fonts
- Language: C
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# libttf
the objective of libttf is to be a simple and portable library to render `.ttf` font
orignaly written for [the stanix operating system](https://github.com/tayoky/stanix) libttf is hopping to one day become a viable concurrent to libfreetype
# build and install
start by launching the configure script
```sh
./configure
```
> [!NOTE]
> you can use the options `--prefix` and `--host`
then run make
```sh
make
```
and finally install
```sh
make install
```
> [!NOTE]
> this might require root permission if installing globally
# api
you can get started with
```c
#include
#include
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
```sh
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