diff options
| -rw-r--r-- | src/pdf.zig | 26 | ||||
| -rw-r--r-- | test/panes.zig | 30 | ||||
| -rw-r--r-- | test/pdf_sections_bench.zig | 6 |
3 files changed, 17 insertions, 45 deletions
diff --git a/src/pdf.zig b/src/pdf.zig index 262af8b9..1a983e2c 100644 --- a/src/pdf.zig +++ b/src/pdf.zig @@ -655,18 +655,7 @@ pub const OutlineEntry = struct { depth: u8, /// Null preserves a missing /Title; a present empty title is "". title: ?[]const u8, - is_open: bool, - flags: u8, - color: [3]u8, destination: OutlineDestination, - - pub fn isBold(entry: OutlineEntry) bool { - return entry.flags & 1 != 0; - } - - pub fn isItalic(entry: OutlineEntry) bool { - return entry.flags & 2 != 0; - } }; /// All title and external-URI slices point into `bytes`. This fixed two-allocation @@ -825,7 +814,7 @@ pub const Document = struct { if (item.depth >= c.PARDES_PDF_MAX_OUTLINE_DEPTH or item.depth > std.math.maxInt(u8) or item.title_present > 1 or item.has_x > 1 or - item.has_y > 1 or item.is_open > 1) + item.has_y > 1) return error.BadOutline; const depth: u8 = @intCast(item.depth); if ((index == 0 and depth != 0) or @@ -866,14 +855,7 @@ pub const Document = struct { }, else => return error.BadOutline, }; - entry.* = .{ - .depth = depth, - .title = title, - .is_open = item.is_open != 0, - .flags = item.flags, - .color = .{ item.r, item.g, item.b }, - .destination = destination, - }; + entry.* = .{ .depth = depth, .title = title, .destination = destination }; } } return .{ .entries = entries, .bytes = bytes }; @@ -1722,12 +1704,8 @@ test "PDF outline is a stable owned DFS view with native destinations" { }); try std.testing.expect(outline.entries[0].title == null); - try std.testing.expect(outline.entries[0].is_open); try std.testing.expect(outline.entries[0].destination == .none); try std.testing.expectEqualStrings("Café 子", outline.entries[1].title.?); - try std.testing.expect(outline.entries[1].isBold()); - try std.testing.expect(outline.entries[1].isItalic()); - try std.testing.expectEqual([3]u8{ 51, 102, 153 }, outline.entries[1].color); const child = outline.entries[1].destination.internal; try std.testing.expectEqual(@as(usize, 1), child.page); try std.testing.expect(child.x != null and child.y != null); diff --git a/test/panes.zig b/test/panes.zig index f083a88e..f472ba81 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -2366,14 +2366,14 @@ const PdfTests = struct { test "PDF section rows preserve DFS ordinals and sanitise hierarchy" { if (!enabled) return; const entries = [_]pdf.OutlineEntry{ - .{ .depth = 0, .title = null, .is_open = true, .flags = 0, .color = @splat(0), .destination = .none }, - .{ .depth = 1, .title = " Child\n\tTitle\x01 Café \u{2028} Next ", .is_open = false, .flags = 0, .color = @splat(0), .destination = .{ .internal = .{ .page = 2, .x = 12, .y = 34 } } }, - .{ .depth = 0, .title = "", .is_open = false, .flags = 0, .color = @splat(0), .destination = .{ .internal = .{ .page = 0, .x = null, .y = null } } }, - .{ .depth = 0, .title = "External", .is_open = false, .flags = 0, .color = @splat(0), .destination = .{ .external = "https://example.com/manual" } }, - .{ .depth = 0, .title = "Dead branch", .is_open = false, .flags = 0, .color = @splat(0), .destination = .none }, - .{ .depth = 0, .title = "Unsafe", .is_open = false, .flags = 0, .color = @splat(0), .destination = .{ .external = "javascript:alert" } }, - .{ .depth = 0, .title = "Linked branch", .is_open = true, .flags = 0, .color = @splat(0), .destination = .none }, - .{ .depth = 1, .title = "Deep link", .is_open = false, .flags = 0, .color = @splat(0), .destination = .{ .external = "https://example.com/deep" } }, + .{ .depth = 0, .title = null, .destination = .none }, + .{ .depth = 1, .title = " Child\n\tTitle\x01 Café \u{2028} Next ", .destination = .{ .internal = .{ .page = 2, .x = 12, .y = 34 } } }, + .{ .depth = 0, .title = "", .destination = .{ .internal = .{ .page = 0, .x = null, .y = null } } }, + .{ .depth = 0, .title = "External", .destination = .{ .external = "https://example.com/manual" } }, + .{ .depth = 0, .title = "Dead branch", .destination = .none }, + .{ .depth = 0, .title = "Unsafe", .destination = .{ .external = "javascript:alert" } }, + .{ .depth = 0, .title = "Linked branch", .destination = .none }, + .{ .depth = 1, .title = "Deep link", .destination = .{ .external = "https://example.com/deep" } }, }; const rows = try SectionRows.render(std.testing.allocator, "/tmp/manual.pdf", &entries); defer std.testing.allocator.free(rows); @@ -2425,13 +2425,13 @@ const PdfTests = struct { test "bulk PDF section resolution matches single Look policy across DFS boundaries" { if (!enabled) return; const entries = [_]pdf.OutlineEntry{ - .{ .depth = 0, .title = "Resolved root", .is_open = true, .flags = 0, .color = @splat(0), .destination = .none }, - .{ .depth = 1, .title = "Unsafe branch", .is_open = true, .flags = 0, .color = @splat(0), .destination = .{ .external = "javascript:unsafe" } }, - .{ .depth = 2, .title = "Safe grandchild", .is_open = false, .flags = 0, .color = @splat(0), .destination = .{ .internal = .{ .page = 1, .x = 4, .y = 8 } } }, - .{ .depth = 1, .title = "Unresolved child", .is_open = false, .flags = 0, .color = @splat(0), .destination = .none }, - .{ .depth = 1, .title = "Sibling", .is_open = false, .flags = 0, .color = @splat(0), .destination = .{ .internal = .{ .page = 2, .x = null, .y = null } } }, - .{ .depth = 0, .title = "Unresolved root", .is_open = false, .flags = 0, .color = @splat(0), .destination = .none }, - .{ .depth = 0, .title = "Next root", .is_open = false, .flags = 0, .color = @splat(0), .destination = .{ .internal = .{ .page = 3, .x = null, .y = null } } }, + .{ .depth = 0, .title = "Resolved root", .destination = .none }, + .{ .depth = 1, .title = "Unsafe branch", .destination = .{ .external = "javascript:unsafe" } }, + .{ .depth = 2, .title = "Safe grandchild", .destination = .{ .internal = .{ .page = 1, .x = 4, .y = 8 } } }, + .{ .depth = 1, .title = "Unresolved child", .destination = .none }, + .{ .depth = 1, .title = "Sibling", .destination = .{ .internal = .{ .page = 2, .x = null, .y = null } } }, + .{ .depth = 0, .title = "Unresolved root", .destination = .none }, + .{ .depth = 0, .title = "Next root", .destination = .{ .internal = .{ .page = 3, .x = null, .y = null } } }, }; const bulk = try SectionRows.resolveOrdinals(std.testing.allocator, &entries); defer std.testing.allocator.free(bulk); diff --git a/test/pdf_sections_bench.zig b/test/pdf_sections_bench.zig index ce548924..47b74018 100644 --- a/test/pdf_sections_bench.zig +++ b/test/pdf_sections_bench.zig @@ -357,9 +357,6 @@ fn outlineIdentity(entries: []const pdf.OutlineEntry) Identity { var bytes: u64 = 0; for (entries) |entry| { checksum = mix(checksum, entry.depth); - checksum = mix(checksum, entry.flags); - checksum = mix(checksum, @intFromBool(entry.is_open)); - checksum = std.hash.Wyhash.hash(checksum, &entry.color); if (entry.title) |title| { bytes += title.len; checksum = std.hash.Wyhash.hash(checksum, title); @@ -389,9 +386,6 @@ fn makeWorstShape() ![]pdf.OutlineEntry { entry.* = .{ .depth = depth, .title = "Worst shape outline title", - .is_open = true, - .flags = 0, - .color = .{ 0, 0, 0 }, .destination = if (depth + 1 == near_limit_depth) .{ .internal = .{ .page = ordinal / near_limit_depth, |
