Compare commits
No commits in common. "07d34128dd729d0500ae25d3d3a9a8b3439d6f1b" and "22e1bcccea71d8059fc27cca09df6ad15823a99a" have entirely different histories.
07d34128dd
...
22e1bcccea
3 changed files with 10 additions and 115 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -2,4 +2,4 @@ zig-cache
|
||||||
zig-out
|
zig-out
|
||||||
*.bdf
|
*.bdf
|
||||||
out
|
out
|
||||||
*.font.json
|
*.font.zon
|
85
src/bdf.zig
85
src/bdf.zig
|
@ -134,58 +134,6 @@ fn parseLine(allocator: std.mem.Allocator, line: []const u8) !ParsedCommand {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
test "parseLine: Parses FONTBOUNDINGBOX correctly" {
|
|
||||||
const allocator = std.testing.allocator;
|
|
||||||
const line = "FONTBOUNDINGBOX 10 20";
|
|
||||||
const parsed = try parseLine(allocator, line);
|
|
||||||
|
|
||||||
try std.testing.expectEqual(ParsedCommand{ .FONTBOUNDINGBOX = .{ .width = 10, .height = 20 } }, parsed);
|
|
||||||
}
|
|
||||||
|
|
||||||
test "parseLine: Parses ENCODING correctly" {
|
|
||||||
const allocator = std.testing.allocator;
|
|
||||||
const line = "ENCODING 123";
|
|
||||||
const parsed = try parseLine(allocator, line);
|
|
||||||
|
|
||||||
try std.testing.expectEqual(ParsedCommand{ .ENCODING = 123 }, parsed);
|
|
||||||
}
|
|
||||||
|
|
||||||
test "parseLine: Parses STARTCHAR correctly" {
|
|
||||||
const allocator = std.testing.allocator;
|
|
||||||
const line = "STARTCHAR ABC";
|
|
||||||
const parsed = try parseLine(allocator, line);
|
|
||||||
|
|
||||||
switch (parsed) {
|
|
||||||
.STARTCHAR => |name| {
|
|
||||||
try std.testing.expectEqualStrings("ABC", name);
|
|
||||||
allocator.free(name);
|
|
||||||
},
|
|
||||||
else => unreachable,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
test "parseLine: Parses FONT correctly" {
|
|
||||||
const allocator = std.testing.allocator;
|
|
||||||
const line = "FONT ABC";
|
|
||||||
const parsed = try parseLine(allocator, line);
|
|
||||||
|
|
||||||
switch (parsed) {
|
|
||||||
.FONT => |name| {
|
|
||||||
try std.testing.expectEqualStrings("ABC", name);
|
|
||||||
allocator.free(name);
|
|
||||||
},
|
|
||||||
else => unreachable,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
test "parseLine: Parses BITMAP correctly" {
|
|
||||||
const allocator = std.testing.allocator;
|
|
||||||
const line = "BITMAP";
|
|
||||||
const parsed = try parseLine(allocator, line);
|
|
||||||
|
|
||||||
try std.testing.expectEqual(ParsedCommand{ .BITMAP = {} }, parsed);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn readBitmap(
|
fn readBitmap(
|
||||||
allocator: std.mem.Allocator,
|
allocator: std.mem.Allocator,
|
||||||
width: u8,
|
width: u8,
|
||||||
|
@ -233,36 +181,3 @@ fn readBitmap(
|
||||||
|
|
||||||
return char;
|
return char;
|
||||||
}
|
}
|
||||||
|
|
||||||
test "readBitmap: Reads bitmap correctly for < 8px wide glyphs" {
|
|
||||||
const allocator = std.testing.allocator;
|
|
||||||
|
|
||||||
var reader = std.io.fixedBufferStream("10\n20\n30\nENDCHAR");
|
|
||||||
|
|
||||||
const bitmap = try readBitmap(allocator, 8, 3, reader.reader());
|
|
||||||
try std.testing.expectEqual(@as(usize, 3), bitmap.len);
|
|
||||||
try std.testing.expectEqualSlices(u8, &[_]u8{0x10}, bitmap[0]);
|
|
||||||
try std.testing.expectEqualSlices(u8, &[_]u8{0x20}, bitmap[1]);
|
|
||||||
try std.testing.expectEqualSlices(u8, &[_]u8{0x30}, bitmap[2]);
|
|
||||||
|
|
||||||
for (bitmap) |line| {
|
|
||||||
allocator.free(line);
|
|
||||||
}
|
|
||||||
allocator.free(bitmap);
|
|
||||||
}
|
|
||||||
|
|
||||||
test "readBitmap: Reads bitmap correctly for > 8px wide glyphs" {
|
|
||||||
const allocator = std.testing.allocator;
|
|
||||||
|
|
||||||
var reader = std.io.fixedBufferStream("1234\nABDC\nENDCHAR");
|
|
||||||
|
|
||||||
const bitmap = try readBitmap(allocator, 16, 2, reader.reader());
|
|
||||||
try std.testing.expectEqual(@as(usize, 2), bitmap.len);
|
|
||||||
try std.testing.expectEqualSlices(u8, &[_]u8{ 0x12, 0x34 }, bitmap[0]);
|
|
||||||
try std.testing.expectEqualSlices(u8, &[_]u8{ 0xAB, 0xDC }, bitmap[1]);
|
|
||||||
|
|
||||||
for (bitmap) |line| {
|
|
||||||
allocator.free(line);
|
|
||||||
}
|
|
||||||
allocator.free(bitmap);
|
|
||||||
}
|
|
||||||
|
|
38
src/main.zig
38
src/main.zig
|
@ -1,11 +1,6 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const bdf = @import("bdf.zig");
|
const bdf = @import("bdf.zig");
|
||||||
|
|
||||||
const FontConfig = struct {
|
|
||||||
inputFile: []const u8,
|
|
||||||
outputFile: []const u8,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
// Get allocator
|
// Get allocator
|
||||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||||
|
@ -16,36 +11,21 @@ pub fn main() !void {
|
||||||
const args = try std.process.argsAlloc(allocator);
|
const args = try std.process.argsAlloc(allocator);
|
||||||
defer std.process.argsFree(allocator, args);
|
defer std.process.argsFree(allocator, args);
|
||||||
|
|
||||||
if (args.len < 2) {
|
if (args.len < 4) {
|
||||||
std.log.err("Usage: {s} <config.json>", .{args[0]});
|
std.log.err("Usage: {s} <input.bdf> <input.zon> <output-dir>", .{args[0]});
|
||||||
std.process.exit(1);
|
std.process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const inputConfig = args[1];
|
const inputFile = args[1];
|
||||||
|
const inputConfig = args[2];
|
||||||
|
_ = inputConfig; // autofix
|
||||||
|
const outputPath = args[3];
|
||||||
|
_ = outputPath; // autofix
|
||||||
|
|
||||||
// Read config
|
// Read font
|
||||||
const configFile = try std.fs.cwd().readFileAlloc(allocator, inputConfig, std.math.maxInt(usize));
|
const input = try std.fs.cwd().openFile(inputFile, .{});
|
||||||
defer allocator.free(configFile);
|
|
||||||
|
|
||||||
const fontConfig = try readConfig(allocator, configFile);
|
|
||||||
defer fontConfig.deinit();
|
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn readConfig(allocator: std.mem.Allocator, input: []u8) !std.json.Parsed(FontConfig) {
|
|
||||||
const fontConfig = try std.json.parseFromSlice(
|
|
||||||
FontConfig,
|
|
||||||
allocator,
|
|
||||||
input,
|
|
||||||
.{
|
|
||||||
.ignore_unknown_fields = true,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
return fontConfig;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue