Skip to content

Commit

Permalink
Ensure named destinations are unique
Browse files Browse the repository at this point in the history
  • Loading branch information
dwarring committed Aug 20, 2024
1 parent d544724 commit fa6153e
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions lib/PDF/API6.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,27 @@ class PDF::API6:ver<0.2.8>
$.protect: { $!preferences //= PDF::API6::Preferences.new: :$.catalog };
}

method !unique-dest-name($name) {
my $gen-name = $name;
my Int $n;
while $.destinations{$gen-name}:exists {
$gen-name = $name ~ '_' ~ ++$n;
}
$gen-name;
}

my subset DestName where PDF::COS::Name|PDF::COS::ByteString;
#| Make a miscellaneous named destination
multi method destination(Str:D :$name! is copy, |c) {
multi method destination(Str:D :$name!, |c --> DestName:D) {
my PDF::Destination $dest = $.destination: |c;
given $name {
$_ = PDF::COS::Name.COERCE($_)
unless $_ ~~ PDF::COS::Name|PDF::COS::ByteString;
$.protect: {
given self!unique-dest-name($name) {
$.destinations{$_} = $dest;
$_ ~~ DestName
?? $_
!! PDF::COS::Name.COERCE($_)
}
}
$.protect: { $.destinations{$name} = $dest };
$name;
}

#| Make a remote destination to a page (by number) in another PDF file
Expand Down

0 comments on commit fa6153e

Please sign in to comment.