freetype: ~99% Core-API Coverage
- breaking structure changes - optimazed examples - more tests
This commit is contained in:
parent
db377459c4
commit
04a0a79ef6
21 changed files with 1176 additions and 549 deletions
|
|
@ -1,52 +1,27 @@
|
|||
// zig build run-example-single-glyph -- B
|
||||
const std = @import("std");
|
||||
const freetype = @import("freetype");
|
||||
|
||||
const WIDTH = 32;
|
||||
const HEIGHT = 24;
|
||||
|
||||
fn drawBitmap(bitmap: freetype.Bitmap, x: usize, y: usize) [HEIGHT][WIDTH]u8 {
|
||||
var figure = std.mem.zeroes([HEIGHT][WIDTH]u8);
|
||||
var p: usize = 0;
|
||||
var q: usize = 0;
|
||||
const w = bitmap.width();
|
||||
const x_max = x + w;
|
||||
const y_max = y + bitmap.rows();
|
||||
var i: usize = 0;
|
||||
while (i < x_max - x) : (i += 1) {
|
||||
var j: usize = 0;
|
||||
while (j < y_max - y) : (j += 1) {
|
||||
if (i < WIDTH and j < HEIGHT) {
|
||||
figure[j][i] |= bitmap.buffer()[q * w + p];
|
||||
q += 1;
|
||||
}
|
||||
}
|
||||
q = 0;
|
||||
p += 1;
|
||||
}
|
||||
return figure;
|
||||
}
|
||||
|
||||
pub fn main() !void {
|
||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
defer _ = gpa.deinit();
|
||||
const allocator = gpa.allocator();
|
||||
var args = try std.process.argsAlloc(allocator);
|
||||
defer std.process.argsFree(allocator, args);
|
||||
|
||||
const lib = try freetype.Library.init();
|
||||
defer lib.deinit();
|
||||
|
||||
const face = try lib.newFace("upstream/assets/FiraSans-Regular.ttf", 0);
|
||||
defer face.deinit();
|
||||
|
||||
try face.setCharSize(40 * 64, 0, 50, 0);
|
||||
try face.loadChar('@', .{ .render = true });
|
||||
|
||||
const glyph = face.glyph;
|
||||
const x = @intCast(usize, glyph.bitmapLeft());
|
||||
const y = HEIGHT - @intCast(usize, glyph.bitmapTop());
|
||||
|
||||
var figure = drawBitmap(glyph.bitmap(), x, y);
|
||||
try face.setCharSize(60 * 48, 0, 50, 0);
|
||||
try face.loadChar(args[1][0], .{ .render = true });
|
||||
const bitmap = face.glyph().bitmap();
|
||||
|
||||
var i: usize = 0;
|
||||
while (i < HEIGHT) : (i += 1) {
|
||||
while (i < bitmap.rows()) : (i += 1) {
|
||||
var j: usize = 0;
|
||||
while (j < WIDTH) : (j += 1) {
|
||||
const char: u8 = switch (figure[i][j]) {
|
||||
while (j < bitmap.width()) : (j += 1) {
|
||||
const char: u8 = switch (bitmap.buffer()[i * bitmap.width() + j]) {
|
||||
0 => ' ',
|
||||
1...128 => ';',
|
||||
else => '#',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue