re-implemented sorting

This commit is contained in:
Lumen Keyes 2024-07-14 23:34:39 -06:00
parent 44869a7926
commit 07993f5bb5
3 changed files with 1021 additions and 1938 deletions

2948
output.pdf

File diff suppressed because it is too large Load Diff

View File

@ -30,6 +30,13 @@ const Card = struct {
const TextCard = struct { const TextCard = struct {
lines: [][]const u8 = undefined, lines: [][]const u8 = undefined,
}; };
const CardSortContext = struct {
const Self = @This();
list: []TextCard,
pub fn lessThan(ctx: Self, a: usize, b: usize) bool {
return ctx.list[a].lines.len < ctx.list[b].lines.len;
}
};
//dimension constants and defaults //dimension constants and defaults
const cardWidth = 30; const cardWidth = 30;
@ -89,6 +96,7 @@ pub fn main() !void {
} }
} }
cards.sort(CardSortContext{ .list = cards.values() });
var allPrinted = std.ArrayList([]const u8).init(allocator); var allPrinted = std.ArrayList([]const u8).init(allocator);
const pdf_doc: *c.pdf_doc = @ptrCast(c.pdf_create(c.PDF_A4_WIDTH, c.PDF_A4_HEIGHT, &c.pdf_info{ .creator = ("My Software" ++ " " ** 53).* }).?); const pdf_doc: *c.pdf_doc = @ptrCast(c.pdf_create(c.PDF_A4_WIDTH, c.PDF_A4_HEIGHT, &c.pdf_info{ .creator = ("My Software" ++ " " ** 53).* }).?);
@ -213,9 +221,6 @@ const cardRow = struct {
const strippedLine = std.mem.trimRight(u8, line, " "); const strippedLine = std.mem.trimRight(u8, line, " ");
const paddedLine = try std.fmt.allocPrint(gpa.allocator(), lineFormatter, .{strippedLine}); const paddedLine = try std.fmt.allocPrint(gpa.allocator(), lineFormatter, .{strippedLine});
// const theoreticalLength = (paddedLine.len * 3) + 1; // const theoreticalLength = (paddedLine.len * 3) + 1;
std.debug.print("{s}\n", .{paddedLine});
std.debug.print("expected {d}, got: ", .{dw.strWidth(spacer)});
std.debug.print("{d}\n", .{dw.strWidth(paddedLine)});
assert(dw.strWidth(paddedLine) == dw.strWidth(spacer)); assert(dw.strWidth(paddedLine) == dw.strWidth(spacer));
// assert(theoreticalLength == pageWidth); // assert(theoreticalLength == pageWidth);
const placeholder = if (idx < lines.items(.first).len) lines.get(idx) else cardRow{}; const placeholder = if (idx < lines.items(.first).len) lines.get(idx) else cardRow{};

Binary file not shown.