forked from andrewrk/TrueType
TrueType Font Rendering
|
Andrew Kelley
604d4e185e
Merge pull request 'port opentype specific code and support testing multiple files' ( #1 ) from archaistvolts/TrueType:initial-opentype into main
Reviewed-on: andrewrk/TrueType#1 Reviewed-by: Andrew Kelley <andrewrk@noreply.codeberg.org> |
||
|---|---|---|
| test | port opentype specific code and support testing multiple files | |
| .gitignore | port opentype specific code and support testing multiple files | |
| build.zig | update build.zig for zig 0.15 | |
| build.zig.zon | update for zig 0.14.0 | |
| LICENSE | readme and license | |
| README.md | added kerning API | |
| TrueType.zig | minor cleanups + remove all log.debug()s | |
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.