Phase 5 Implementation: - Link annotations in PDF (clickable in viewers) - Page.addUrlLink() - add URL annotation - Page.addInternalLink() - add internal page link - Page.urlLink() / writeUrlLink() - visual + annotation combined - Page.getLinks() - retrieve page links - OutputProducer generates /Annots arrays for pages - Link annotation objects with /Type /Annot /Subtype /Link New example: - links_demo.zig - demonstrates URL and internal links - 2 pages with cross-page navigation - External URLs (example.com, GitHub, mailto) - Internal links between pages Final state: - 7 examples working (hello, invoice, text_demo, image_demo, table_demo, pagination_demo, links_demo) - ~70 tests passing - Complete feature set for document generation zpdf is now feature-complete for typical document generation needs: text, tables, images, pagination, and clickable links. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
159 lines
5.3 KiB
Zig
159 lines
5.3 KiB
Zig
const std = @import("std");
|
|
|
|
pub fn build(b: *std.Build) void {
|
|
const target = b.standardTargetOptions(.{});
|
|
const optimize = b.standardOptimizeOption(.{});
|
|
|
|
// zpdf module
|
|
const zpdf_mod = b.createModule(.{
|
|
.root_source_file = b.path("src/root.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
|
|
// Tests
|
|
const unit_tests = b.addTest(.{
|
|
.root_module = b.createModule(.{
|
|
.root_source_file = b.path("src/root.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
}),
|
|
});
|
|
|
|
const run_unit_tests = b.addRunArtifact(unit_tests);
|
|
const test_step = b.step("test", "Run unit tests");
|
|
test_step.dependOn(&run_unit_tests.step);
|
|
|
|
// Example: hello
|
|
const hello_exe = b.addExecutable(.{
|
|
.name = "hello",
|
|
.root_module = b.createModule(.{
|
|
.root_source_file = b.path("examples/hello.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.imports = &.{
|
|
.{ .name = "zpdf", .module = zpdf_mod },
|
|
},
|
|
}),
|
|
});
|
|
b.installArtifact(hello_exe);
|
|
|
|
const run_hello = b.addRunArtifact(hello_exe);
|
|
run_hello.step.dependOn(b.getInstallStep());
|
|
const hello_step = b.step("hello", "Run hello example");
|
|
hello_step.dependOn(&run_hello.step);
|
|
|
|
// Example: invoice
|
|
const invoice_exe = b.addExecutable(.{
|
|
.name = "invoice",
|
|
.root_module = b.createModule(.{
|
|
.root_source_file = b.path("examples/invoice.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.imports = &.{
|
|
.{ .name = "zpdf", .module = zpdf_mod },
|
|
},
|
|
}),
|
|
});
|
|
b.installArtifact(invoice_exe);
|
|
|
|
const run_invoice = b.addRunArtifact(invoice_exe);
|
|
run_invoice.step.dependOn(b.getInstallStep());
|
|
const invoice_step = b.step("invoice", "Run invoice example");
|
|
invoice_step.dependOn(&run_invoice.step);
|
|
|
|
// Example: text_demo
|
|
const text_demo_exe = b.addExecutable(.{
|
|
.name = "text_demo",
|
|
.root_module = b.createModule(.{
|
|
.root_source_file = b.path("examples/text_demo.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.imports = &.{
|
|
.{ .name = "zpdf", .module = zpdf_mod },
|
|
},
|
|
}),
|
|
});
|
|
b.installArtifact(text_demo_exe);
|
|
|
|
const run_text_demo = b.addRunArtifact(text_demo_exe);
|
|
run_text_demo.step.dependOn(b.getInstallStep());
|
|
const text_demo_step = b.step("text_demo", "Run text demo example");
|
|
text_demo_step.dependOn(&run_text_demo.step);
|
|
|
|
// Example: image_demo
|
|
const image_demo_exe = b.addExecutable(.{
|
|
.name = "image_demo",
|
|
.root_module = b.createModule(.{
|
|
.root_source_file = b.path("examples/image_demo.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.imports = &.{
|
|
.{ .name = "zpdf", .module = zpdf_mod },
|
|
},
|
|
}),
|
|
});
|
|
b.installArtifact(image_demo_exe);
|
|
|
|
const run_image_demo = b.addRunArtifact(image_demo_exe);
|
|
run_image_demo.step.dependOn(b.getInstallStep());
|
|
const image_demo_step = b.step("image_demo", "Run image demo example");
|
|
image_demo_step.dependOn(&run_image_demo.step);
|
|
|
|
// Example: table_demo
|
|
const table_demo_exe = b.addExecutable(.{
|
|
.name = "table_demo",
|
|
.root_module = b.createModule(.{
|
|
.root_source_file = b.path("examples/table_demo.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.imports = &.{
|
|
.{ .name = "zpdf", .module = zpdf_mod },
|
|
},
|
|
}),
|
|
});
|
|
b.installArtifact(table_demo_exe);
|
|
|
|
const run_table_demo = b.addRunArtifact(table_demo_exe);
|
|
run_table_demo.step.dependOn(b.getInstallStep());
|
|
const table_demo_step = b.step("table_demo", "Run table demo example");
|
|
table_demo_step.dependOn(&run_table_demo.step);
|
|
|
|
// Example: pagination_demo
|
|
const pagination_demo_exe = b.addExecutable(.{
|
|
.name = "pagination_demo",
|
|
.root_module = b.createModule(.{
|
|
.root_source_file = b.path("examples/pagination_demo.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.imports = &.{
|
|
.{ .name = "zpdf", .module = zpdf_mod },
|
|
},
|
|
}),
|
|
});
|
|
b.installArtifact(pagination_demo_exe);
|
|
|
|
const run_pagination_demo = b.addRunArtifact(pagination_demo_exe);
|
|
run_pagination_demo.step.dependOn(b.getInstallStep());
|
|
const pagination_demo_step = b.step("pagination_demo", "Run pagination demo example");
|
|
pagination_demo_step.dependOn(&run_pagination_demo.step);
|
|
|
|
// Example: links_demo
|
|
const links_demo_exe = b.addExecutable(.{
|
|
.name = "links_demo",
|
|
.root_module = b.createModule(.{
|
|
.root_source_file = b.path("examples/links_demo.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.imports = &.{
|
|
.{ .name = "zpdf", .module = zpdf_mod },
|
|
},
|
|
}),
|
|
});
|
|
b.installArtifact(links_demo_exe);
|
|
|
|
const run_links_demo = b.addRunArtifact(links_demo_exe);
|
|
run_links_demo.step.dependOn(b.getInstallStep());
|
|
const links_demo_step = b.step("links_demo", "Run links demo example");
|
|
links_demo_step.dependOn(&run_links_demo.step);
|
|
}
|