From 4dc59b01d67fc9f11f036c72a6140202c7b67ff9 Mon Sep 17 00:00:00 2001 From: David Warring Date: Sun, 9 Jun 2024 09:03:04 +1200 Subject: [PATCH] Refactor ancestor-or-self and descendant-or-self axes --- README.md | 4 ++-- examples/link.raku | 2 +- lib/PDF/Tags/XPath/Axes.rakumod | 13 ++++--------- t/actual-text.pdf | Bin 2025 -> 2025 bytes t/attributes.pdf | Bin 1633 -> 1633 bytes t/class-maps.pdf | Bin 1669 -> 1669 bytes t/fragments.pdf | Bin 18362 -> 18362 bytes t/role-maps.pdf | Bin 2062 -> 2062 bytes t/span-pages.pdf | Bin 1931 -> 1931 bytes t/write-tags.pdf | Bin 4499 -> 4499 bytes 10 files changed, 7 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 2682ba7..a8a151c 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ PDF tagging may assist PDF readers and other automated tools in reading PDF documents and locating content such as text and images. This module provides a DOM like interface for creating and traversing PDF structure and -content via tags. It also an XPath like search capability. It is designed for use in +content via tags. It also has an XPath like search capability. It is designed for use in conjunction with PDF::Class or PDF::API6. Standard Tags @@ -344,7 +344,7 @@ $page.graphics: -> $gfx { ### Content Continuation -Content sometimes needs to be continued across graphics objects, such as a paragraph that +Content sometimes needs to be continued across graphics elements, such as a paragraph that spans multiple pages. The `mark` method may be called repeatably to achieve this: ```raku diff --git a/examples/link.raku b/examples/link.raku index 7f896e8..53094d2 100644 --- a/examples/link.raku +++ b/examples/link.raku @@ -39,7 +39,7 @@ $page.graphics: -> $gfx { # Use PDF::API6 to create the link my $link-text ='Sample Annot'; - my $destination = $pdf.destination( :name, :page(2), :fit(FitWindow) ); + my DestRef $destination = $pdf.destination( :name, :page(2), :fit(FitWindow) ); my PDF::Action $action = PDF::API6.action: :$destination; my PDF::Annot::Link $href = $pdf.annotation: :$page, :$action, :content($link-text), :Border[0,0,0], :rect[0 xx 4]; diff --git a/lib/PDF/Tags/XPath/Axes.rakumod b/lib/PDF/Tags/XPath/Axes.rakumod index 83d7c73..a10fefc 100644 --- a/lib/PDF/Tags/XPath/Axes.rakumod +++ b/lib/PDF/Tags/XPath/Axes.rakumod @@ -6,22 +6,17 @@ use PDF::Tags::Node; sub child(PDF::Tags::Node:D $_) is export { .?kids // [] } sub ancestor-or-self(PDF::Tags::Node:D $_) is export { - my @nodes = ancestor-or-self($_) - with .?parent; - @nodes.push: $_; + ancestor($_).push: $_; } sub ancestor(PDF::Tags::Node:D $_) is export { my @nodes = ancestor-or-self($_) with .?parent; - @nodes; + @nodes } sub descendant-or-self(PDF::Tags::Node:D $_) is export { - my @nodes = $_; - @nodes.append: descendant-or-self($_) - for .?kids // []; - @nodes; + descendant($_).unshift: $_; } sub descendant(PDF::Tags::Node:D $_) is export { @@ -82,7 +77,7 @@ sub preceding-sibling(PDF::Tags::Node:D $item) is export { } sub parent(PDF::Tags::Node:D $_) is export { - with .?parent { [ $_ ] } else { [] } + .?parent // []; } sub self(PDF::Tags::Node:D $_) is export { diff --git a/t/actual-text.pdf b/t/actual-text.pdf index 52aa2e234d01bcb931e64ee23be1c3d2db6f8796..90a101f586843346b03b3192861d02a8112304de 100644 GIT binary patch delta 17 YcmaFK|B|0WHNeG9*HF)7BgaE_05c&4SpWb4 delta 17 YcmaFK|B|0WHNeG9*HF)RBgaE_05co~SO5S3 diff --git a/t/attributes.pdf b/t/attributes.pdf index 8b57146562fe545f2684e01ea8287bfd29456bde..78a29911d1ff67c723f7d2a554d614b413c81b14 100644 GIT binary patch delta 17 YcmaFJ^N@!_HNeG9*HF)7BS$0~05G-$x&QzG delta 17 YcmaFJ^N@!_HNeG9*HF)RBS$0~05Guxxc~qF diff --git a/t/class-maps.pdf b/t/class-maps.pdf index 6342a56587328f5d370fe9f4ba74095f9970fdeb..59d63a91acb4430c708505e63adaba311f52978f 100644 GIT binary patch delta 17 YcmZqWZRO=q4RCSOHPkcN$WhA%041CRC;$Ke delta 17 YcmZqWZRO=q4RCSOHPkcS$WhA%040|MCjbBd diff --git a/t/fragments.pdf b/t/fragments.pdf index 03e9c9e5804297d4fd68b954bdab9bdf81cc0f25..e774c02096802ba4878198bbd04321f71cab5e29 100644 GIT binary patch delta 31 ncmdnh&$z3fQ9w1o#ZA{x&xA{L>BiT4xC|#NiV1I2p6(6+rMC)N delta 31 ncmdnh&$z3fQ9w1o#ZA{x&zMVf>BiT4xC|#NiV1I2p6(6+rKSp5 diff --git a/t/role-maps.pdf b/t/role-maps.pdf index d13996ddeef05d8195fc34291630921b4880e431..42e1cbb9a9279e56c30466f563690538e59fee46 100644 GIT binary patch delta 17 YcmeAZ=o8>j4RCSOHPkcN$ic<|046E}%K!iX delta 17 YcmeAZ=o8>j4RCSOHPkcS$ic<|045~^$^ZZW diff --git a/t/span-pages.pdf b/t/span-pages.pdf index 2f19589b2e3ed1a9028d45898dd17a074d82632c..d51a13ca7f48881f07445fe5393fb86a9c5b081d 100644 GIT binary patch delta 17 YcmeC?@8;)F4RCSOHPkcN$kEIW04AjbKL7v# delta 17 YcmeC?@8;)F4RCSOHPkcS$kEIW04AUWJ^%m! diff --git a/t/write-tags.pdf b/t/write-tags.pdf index 8cf4220ad1a3a4fdb96fc0c5d35bd5f24e213910..f589bc627a10a1a3f3edb1bfc635b133b64749b7 100644 GIT binary patch delta 17 YcmbQNJXx7THNeG9*HF)7BS*I&04f&*i2wiq delta 17 YcmbQNJXx7THNeG9*HF)RBS*I&04fp$hyVZp