A font cooking library

Overview

Font Chef

Font Chef is a cross-platform C99 and C++ library to create character atlas of pre-rasterized glyphs from a font at a specified size and color. It is mostly useful in situations where you cannot afford to rasterize a piece of text again whenever it changes.

It abstracts stb_truetype to render glyphs to a pixmap and to produce appropriate clipping rects to later display those glyphs.

Hello world in C++

fc::font font = fc::from(font_data, fc::px(30), fc_color_black).add(fc_basic_latin).cook();
fc::render_result result = font.render("Hello, world!");
// use font.pixels() to make a texture
for (auto & map : result) {
    render(texture, map.source, map.target);
}

Hello world in C

fc_font * font = fc_construct(font_data, fc_px(30), fc_color_black);
fc_add(fc_basic_latin.start, fc_basic_latin.end);
fc_cook(font);
// use fc_get_pixels(font) to make a texture

const char hello[] = "Hello, world!";
fc_character_mapping output[32];
int count = fc_render(font, text, strlen(hello), &output);
for (int i = 0; i < count; i++) {
    render(texture, output[i].source, output[i].target
}

Features

  • Small, clean and easy-to-use API
  • Ships with C++ wrapper classes
  • Considers kerning when resolving rendering rects
  • Ships with many standard unicode blocks to choose from
  • Rendering API agnostic (it does not render anything directly, it returns pixels and clipping rects)
  • Fully documented with examples for each function
  • No external dependencies

Integrating with your code

Using pre-built releases

Download a pre-built release package suitable for your platform and uncompress it somewhere you'll remember later (usually where you put other development libraries). Let's assume you uncompressed font-chef to /home/me/libs/font-chef.

Using CMake: If you're using CMake, specify the variable CMAKE_PREFIX_PATH to point to it before running CMake in your project:

cmake -DCMAKE_PREFIX_PATH=/home/me/libs

Afterwards you can use find_package(font-chef) and target_link_libraries(<your-executable> PUBLIC font-chef) to link <your-executable> against font-chef.

Not using CMake: Assuming you uncompressed font-chef to the same path as above, you should configure your build system to look for include files inside /home/me/libs/font-chef/include and to look for shared objects to link against inside /home/me/libs/font-chef/lib. In case of Windows, you should also point your linker to font-chef/bin as well.

Using a source release and CMake

Uncompress font-chef in a folder inside your project (e.g, your-project/third-party/font-chef) and then use add_subdirectory(third-party/font-chef EXCLUDE_FROM_ALL) to add the library target. Afterwards you can use find_package(font-chef) and target_link_libraries(<your-executable> PUBLIC font-chef) to link <your-executable> against font-chef.

Compiling the .c files directly in your project is not recommended nor supported.

Compile from source

You'll need CMake installed and in your path and also capable of finding you compiler and linker. Then, after checking out this repository:

mkdir build/
cd build/
cmake ..
make

Examples

Examples for C and C++ are in the src/examples folder. To build them, when running cmake as in Compile from source, add the following variable:

cmake .. -DFONT_CHEF_BUILD_EXAMPLES=1

You will need SDL2 available and CMake needs to be able to find it.

Documentation

See here

You might also like...
F Graphics Library (FGL) is a small graphics C++ portable library for LCD displays on embedded systems

F Graphics Library (FGL) Full documentation: fgl.docsforge.com (By Filipe Chagas) F Graphics Library is a C++ library that I created for use in embedd

Itpp - IT++ library mirror/fork. C++ library of mathematical, signal processing and communication classes and functions.

Introduction ************ IT++ is a C++ library of mathematical, signal processing and communication classes and functions. Its main use is in simula

2D physics header-only library for videogames developed in C using raylib library.
2D physics header-only library for videogames developed in C using raylib library.

Physac Physac is a small 2D physics engine written in pure C. The engine uses a fixed time-step thread loop to simluate physics. A physics step contai

This is a helper library to abstract away interfacing with floppy disk drives in a cross-platform and open source library.
This is a helper library to abstract away interfacing with floppy disk drives in a cross-platform and open source library.

Adafruit Floppy This is a helper library to abstract away interfacing with floppy disk drives in a cross-platform and open source library. Adafruit Fl

`lv_lib_100ask` is a reference for various out of the box schemes based on lvgl library or an enhanced interface for various components of lvgl library.

Introduction lv_lib_100ask is a reference for various out of the box schemes based on lvgl library or an enhanced interface for various components of

QtVerbalExpressions - This Qt lib is based off of the C++ VerbalExpressions library. [MIT]

QtVerbalExpressions Qt Regular Expressions made easy This Qt lib is based off of the C++ VerbalExpressions library by whackashoe. Testing if we have a

A header-only library for C++(0x) that allows automagic pretty-printing of any container.

cxx-prettyprint =============== A pretty printing library for C++ containers. Synopsis: Simply by including this header-only library in your sourc

A standalone and lightweight C library

Klib: a Generic Library in C Overview Klib is a standalone and lightweight C library distributed under MIT/X11 license. Most components are independen

a small C library for x86 CPU detection and feature extraction

libcpuid libcpuid provides CPU identification for the x86 (and x86_64). For details about the programming API, you might want to take a look at the pr

Comments
  • Header only compile

    Header only compile

    Since font-chef uses stb libs, it would be really cool to follow the stb libs style of compilation. Simply allow the developer to drop a single font-chef.h and define FONT_CHEF_IMPLEMENTATION before including it.

    opened by quetzalsly 1
  • Build fails on 64 bit Windows

    Build fails on 64 bit Windows

    The library fails to build on 64 bit Windows platforms due to a type conversion warning and the warnings-as-errors flag (/WX).

    The offending line is

    https://github.com/mobius3/font-chef/blob/82b9f57c2d1693cfd597791f208657dedb70692b/src/font-chef/render-result.c#L125

    The functions returns a uint32_t but the variable is of type size_t which is 64 bit long on 64 bit architectures.

    opened by chausner 2
Releases(v1.1.0)
Owner
Leonardo Guilherme de Freitas
Leonardo Guilherme de Freitas
Support for TrueType (.ttf) font files with Simple Directmedia Layer.

This library is a wrapper around the excellent FreeType 2.0 library

Simple Directmedia Layer 192 Dec 31, 2022
C++ font-lock for Emacs

Syntax highlighting support for "Modern C++" - until C++20 and Technical Specification. This package aims to provide a simple highlight of the C++ lan

Ludwig PACIFICI 167 Dec 1, 2022
font rendering, Zep vim emulator, microui integration

LabFont This project is an exploration of getting text into a rendeing pipeline based on @floooh's sokol. Frameworks such as Dear ImGui solve text ren

Nick Porcino 14 Sep 11, 2022
Portable, Noto-powered font-rendering abstraction based on FreeType and Raqm

Mechascribe Mechascribe is still under construction and nothing is functional yet. Mechascribe is a text rendering abstraction trying to support as mu

null 4 Jan 27, 2022
A terminal-based, mouse-driven BDF (bitmap) font editor.

bdfedit A terminal-based, mouse-driven BDF font editor. Capable of reading, writing, and editing bitmap font files fully within the terminal, and enti

Andrew 7 Dec 24, 2022
Free (libre) font editor for Windows, Mac OS X and GNU+Linux

FontForge FontForge is a free (libre) font editor for Windows, Mac OS X and GNU+Linux. Use it to create, edit and convert fonts in OpenType, TrueType,

null 5k Dec 27, 2022
cross-platform bitmap font implementation

Component for rendering text with bitmap font on all openfl targets. This set of classes is heavily based on classes from pixelizer (https://github.co

Zaphod 49 Oct 26, 2021
SSD1306 library and simple graphics core library based on Adafruit GFX Library.

Raspberry Pico SSD1306 + GFX Library Based on Adafruit GFX Library https://github.com/adafruit/Adafruit-GFX-Library Usage Hardware Connect your SSD130

Marcin Bober 31 Sep 1, 2022
Libft is an individual project at 42 that requires us to re-create some standard C library functions including some additional ones that can be used later to build a library of useful functions for the rest of the program.

Libft is an individual project at 42 that requires us to re-create some standard C library functions including some additional ones that can be used later to build a library of useful functions for the rest of the program.

Paulo Rafael Ramalho 0 Jan 1, 2023
Samir Teymurov 1 Oct 6, 2021