Skip to content

Commit

Permalink
Refactor ancestor-or-self and descendant-or-self axes
Browse files Browse the repository at this point in the history
  • Loading branch information
dwarring committed Jun 8, 2024
1 parent b87fc5a commit 4dc59b0
Show file tree
Hide file tree
Showing 10 changed files with 7 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/link.raku
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ $page.graphics: -> $gfx {

# Use PDF::API6 to create the link
my $link-text ='Sample Annot';
my $destination = $pdf.destination( :name<sample-annot>, :page(2), :fit(FitWindow) );
my DestRef $destination = $pdf.destination( :name<sample-annot>, :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];

Expand Down
13 changes: 4 additions & 9 deletions lib/PDF/Tags/XPath/Axes.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Binary file modified t/actual-text.pdf
Binary file not shown.
Binary file modified t/attributes.pdf
Binary file not shown.
Binary file modified t/class-maps.pdf
Binary file not shown.
Binary file modified t/fragments.pdf
Binary file not shown.
Binary file modified t/role-maps.pdf
Binary file not shown.
Binary file modified t/span-pages.pdf
Binary file not shown.
Binary file modified t/write-tags.pdf
Binary file not shown.

0 comments on commit 4dc59b0

Please sign in to comment.