1
0
Fork
You've already forked TrueType
0
forked from andrewrk/TrueType
TrueType Font Rendering
  • C 66.7%
  • Zig 33.3%
2026年06月14日 15:41:09 +02:00
test Removes log based error handling 2026年01月09日 17:58:40 -08:00
.gitignore port opentype specific code and support testing multiple files 2025年12月05日 13:11:07 -08:00
build.zig compile without llvm by default 2026年06月14日 15:41:09 +02:00
build.zig.zon generate own fingerprint, update Zig and package version 2026年06月14日 15:40:49 +02:00
LICENSE readme and license 2024年10月03日 14:42:55 -07:00
README.md added kerning API 2024年10月04日 02:38:01 -07:00
TrueType.zig cast offsize to u32 before multiplying 2026年05月24日 03:02:22 +03:30

TrueType Package for Zig

This project started out as a port of stb_truetype however it is independently maintained and improved upon by the open source community.

Contributions welcome.

Synopsis

constTrueType=@import("TrueType.zig");constttf=tryTrueType.load(@embedFile("GoNotoCurrent-Regular.ttf"));constexample_string="こんにちは!";constscale=ttf.scaleForPixelHeight(20);conststdout=std.io.getStdOut().writer();varbuffer:std.ArrayListUnmanaged(u8)=.empty;deferbuffer.deinit(gpa);varit=std.unicode.Utf8View.initComptime(example_string).iterator();while(it.nextCodepoint())|codepoint|{if(ttf.codepointGlyphIndex(codepoint))|glyph|{std.log.debug("0x{d}: {d}",.{codepoint,glyph});buffer.clearRetainingCapacity();constdims=tryttf.glyphBitmap(gpa,&buffer,glyph,scale,scale);constpixels=buffer.items;for(0..dims.height)|j|{for(0..dims.width)|i|{trystdout.writeByte(" .:ioVM@"[pixels[j*dims.width+i]>>5]);}trystdout.writeByte('\n');}}else{std.log.debug("0x{d}: none",.{codepoint});}}

Features and Limitations

  • Codepoint to glyph lookup
  • Glyph rendering to bitmap
  • Kerning
  • Font shaping and ligatures are not yet implemented.
  • Untrusted font files are not supported.

Roadmap

  • eliminate TODOs
  • eliminate heap allocation
  • support more advanced text shaping like harfbuzz

Why not use FreeType?

FreeType supports a lot more than just TrueType, making it bloated if your use case is only TrueType fonts.

FreeType is written in C. By having it written in Zig, we drop a dependency on a C compiler and allow the code to be in the same compilation unit as the other Zig code.

Healthy competition between open source projects.

Why not use HarfBuzz?

HarfBuzz is written in C++, a programming language everyone agrees should be wiped from the face of the Earth. My personal code of conduct forbids me from adding libc++ as a runtime dependency to any of my projects.

Healthy competition between open source projects.