stb_truetype.cr
stb_truetype.cr
Lightweight, fast Crystal bindings for stb_truetype.h, the single-header TrueType font rasterizer and pack engine.
This shard allows loading, rendering, packing, and querying kerning metrics from .ttf files directly inside your Crystal applications.
Installation
Add this dependency to your application's shard.yml:
dependencies:
stb_truetype:
github: mswieboda/stb_truetype.cr
version: "~> 1.0"
And run shards install.
Native C Compilation Integration
Following secure and modern Crystal guidelines, this shard does not use post-install scripts to compile the C object files automatically. Instead, it provides a simple, portable Makefile fragment (stb_truetype.mk) which you can include directly in your project's main Makefile to handle lazy C compilation securely.
Integrating with your project's Makefile
Add this to your project's Makefile:
# 1. Include the dependency's makefile fragment (the hyphen ignores it if it doesn't exist yet)
-include lib/stb_truetype/stb_truetype.mk
# 2. Append $(STB_TRUETYPE_OBJ) to your application prerequisites/sources list
SOURCES := $(STB_TRUETYPE_OBJ) $(shell find src -name "*.cr")
# 3. Your build target will compile the dependency's .o file automatically before building
build: $(SOURCES)
crystal build src/your_app.cr -o bin/your_app
When building, the makefile will check if lib/stb_truetype/src/stb_truetype.o needs to be built on-the-fly and compile it using your host C compiler (gcc or clang with -O3 -fPIC).
Windows Support
On Windows (win32), a pre-compiled object file src/stb_truetype_win_x64.obj is checked into the repository and linked automatically. You do not need a C compiler setup to compile the native library on Windows!
Usage
Require the library:
require "stb_truetype"
Refer to the bindings under the LibSTBTrueType namespace in src/stb_truetype.cr for standard initializers and functions.
License
This shard is released under the MIT License. stb_truetype.h is public domain.
stb_truetype.cr
- 0
- 0
- 0
- 1
- 0
- about 8 hours ago
- May 24, 2026
MIT License
Sun, 24 May 2026 04:04:14 GMT