1
0
Fork
You've already forked TrueType
0
forked from andrewrk/TrueType
TrueType Font Rendering
C 66.8%
Zig 33.2%
2025年12月05日 22:51:09 +01:00
test port opentype specific code and support testing multiple files 2025年12月05日 13:11:07 -08:00
.gitignore port opentype specific code and support testing multiple files 2025年12月05日 13:11:07 -08:00
build.zig update build.zig for zig 0.15 2025年07月28日 17:36:39 +02:00
build.zig.zon update for zig 0.14.0 2025年04月29日 09:44:08 -07: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 minor cleanups + remove all log.debug()s 2025年12月05日 13:20:52 -08:00

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.