Skip to content

Repository files navigation

stb-truetype

Pure Java 8+, object-oriented port of stb_truetype.h, mainly targeting use-cases where native bindings are not feasible or desired.

This is not a drop-in replacement for the original C library, as its public API has been redesigned to be more idiomatic to Java.

Warning

This is an experimental port that was made prevalently with GPT-5.5 and GPT-5.6-sol, with limited human oversight. If you are looking for a more mature and battle-tested solution, and you can afford native dependencies, consider using the LWJGL3 bindings for the original stb_truetype.h library.

Usage

implementation 'org.ngengine:stb-truetype:VERSION'

API

ByteBuffer bytes = ByteBuffer.wrap(Files.readAllBytes(fontPath));

StbTrueType stb = new StbTrueType(ByteBuffer::allocateDirect);
StbFont font = stb.load(bytes);
StbGlyph glyph = font.glyph('A');

FontMetrics metrics = font.getMetrics();
GlyphMetrics glyphMetrics = glyph.getMetrics();
GlyphBitmap bitmap = glyph.render(32.0f);
ByteBuffer pixels = bitmap.getData();

List<StbFont> faces = stb.loadCollection(ttcBytes);
StbFont japaneseFace = stb.load(ttcBytes, 2);

The package is set to org.ngengine.stbttf to avoid conflicts with other stb-truetype ports.

Testing and debug

./gradlew test
./gradlew parityTest
./gradlew fontViewer

About

Java 8+ object-oriented port of stb_truetype.h

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages