it is done
This commit is contained in:
parent
07d34128dd
commit
e259535320
4 changed files with 30 additions and 2 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -2,4 +2,6 @@ zig-cache
|
||||||
zig-out
|
zig-out
|
||||||
*.bdf
|
*.bdf
|
||||||
out
|
out
|
||||||
*.font.json
|
*.font.json
|
||||||
|
*.exe
|
||||||
|
*.bin
|
|
@ -16,7 +16,7 @@ const Character = struct {
|
||||||
};
|
};
|
||||||
const CharacterMap = std.AutoHashMap(u16, Character);
|
const CharacterMap = std.AutoHashMap(u16, Character);
|
||||||
|
|
||||||
const Font = struct {
|
pub const Font = struct {
|
||||||
name: []const u8,
|
name: []const u8,
|
||||||
height: u8,
|
height: u8,
|
||||||
width: u8,
|
width: u8,
|
||||||
|
|
17
src/bin.zig
Normal file
17
src/bin.zig
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
const std = @import("std");
|
||||||
|
const bdf = @import("bdf.zig");
|
||||||
|
|
||||||
|
const WriteError = error{UnknownGlyph};
|
||||||
|
|
||||||
|
pub fn writeGlyphs(output: anytype, font: bdf.Font, glyphs: []const u16) !void {
|
||||||
|
for (glyphs) |glyph| {
|
||||||
|
const character = font.characters.get(glyph) orelse {
|
||||||
|
std.log.err("Unknown glyph: {d}", .{glyph});
|
||||||
|
return WriteError.UnknownGlyph;
|
||||||
|
};
|
||||||
|
|
||||||
|
for (character.bitmap) |line| {
|
||||||
|
_ = try output.write(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,11 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const bdf = @import("bdf.zig");
|
const bdf = @import("bdf.zig");
|
||||||
|
const bin = @import("bin.zig");
|
||||||
|
|
||||||
const FontConfig = struct {
|
const FontConfig = struct {
|
||||||
inputFile: []const u8,
|
inputFile: []const u8,
|
||||||
outputFile: []const u8,
|
outputFile: []const u8,
|
||||||
|
glyphs: []const u16,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
|
@ -30,11 +32,18 @@ pub fn main() !void {
|
||||||
const fontConfig = try readConfig(allocator, configFile);
|
const fontConfig = try readConfig(allocator, configFile);
|
||||||
defer fontConfig.deinit();
|
defer fontConfig.deinit();
|
||||||
|
|
||||||
|
// Open and parse BDF font
|
||||||
const input = try std.fs.cwd().openFile(fontConfig.value.inputFile, .{});
|
const input = try std.fs.cwd().openFile(fontConfig.value.inputFile, .{});
|
||||||
defer input.close();
|
defer input.close();
|
||||||
|
|
||||||
var font = try bdf.parse(allocator, input.reader());
|
var font = try bdf.parse(allocator, input.reader());
|
||||||
defer font.deinit(allocator);
|
defer font.deinit(allocator);
|
||||||
|
|
||||||
|
// Write output
|
||||||
|
const output = try std.fs.cwd().createFile(fontConfig.value.outputFile, .{});
|
||||||
|
defer output.close();
|
||||||
|
|
||||||
|
try bin.writeGlyphs(output.writer(), font, fontConfig.value.glyphs);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn readConfig(allocator: std.mem.Allocator, input: []u8) !std.json.Parsed(FontConfig) {
|
fn readConfig(allocator: std.mem.Allocator, input: []u8) !std.json.Parsed(FontConfig) {
|
||||||
|
|
Loading…
Reference in a new issue