Skip to content

Commit 318903d

Browse files
committed
0.6.13
1 parent 871a81e commit 318903d

File tree

13 files changed

+163
-174
lines changed

13 files changed

+163
-174
lines changed

Changes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{{$NEXT}}
2+
3+
0.6.13 2025-08-05T17:34:05+12:00
24
- Deprecate Hash to Stream dictionary coercement
35
- Remove deprecated PDF permitted() method.
46
- Give PDF::Class::Loader precedence over PDF::Lite::Loader

META6.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,5 @@
7272
],
7373
"test-depends": [
7474
],
75-
"version": "0.6.12"
75+
"version": "0.6.13"
7676
}

coverage/PDF.rakucov

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
* #| this class represents the top level node in a PDF or FDF document,
22
#| the trailer dictionary
3-
* unit class PDF:ver<0.6.12>;
3+
* unit class PDF:ver<0.6.13>;
44

55
use PDF::COS::Dict;
66
also is PDF::COS::Dict;
@@ -34,10 +34,6 @@
3434
has UInt $.Prev is entry;
3535

3636
* submethod TWEAK(:$file, |c) is hidden-from-backtrace {
37-
* given PDF::COS.loader.?target-class -> $target-class {
38-
* die "Unable to mix {self.WHAT.raku} with {$target-class}"
39-
unless $target-class === Nil || self.isa($target-class);
40-
}
4137
* self!open-file($_, |c) with $file;
4238
}
4339

@@ -60,17 +56,17 @@
6056
* method open($spec, |c) is hidden-from-backtrace {
6157
* self.new!open-file: $spec, |c;
6258
}
63-
* method !open-file(::?CLASS:D: $spec, Str :$type, |c) is hidden-from-backtrace {
64-
✱ my PDF::IO::Reader $reader .= new: :trailer(self);
65-
* self.reader = $reader;
59+
* method !open-file(::?CLASS:D $trailer: $spec, Str :$type, |c) is hidden-from-backtrace {
60+
✱ my PDF::IO::Reader $reader .= new: :$trailer;
61+
* $trailer.reader = $reader;
6662
* $reader.open($spec, |c);
6763
* with $type {
6864
* die "PDF file has wrong type: " ~ $reader.type
6965
unless $reader.type eq $_;
7066
}
7167
* $!crypt = $_
7268
with $reader.crypt;
73-
self;
69+
$trailer;
7470
}
7571

7672
* method encrypt(PDF:D $doc: Str :$owner-pass!, Str :$user-pass = '', Bool :$EncryptMetadata = True, |c ) {
@@ -233,20 +229,6 @@ x self!ast-writer(|c).stream-cos($ioh);
233229
* self!ast-writer(|c).write;
234230
}
235231

236-
# permissions check, e.g: $doc.permitted( PermissionsFlag::Modify )
237-
x method permitted(UInt $flag --> Bool) is DEPRECATED('please use PDF::Class.permitted') {
238-
239-
x return True
240-
if $!crypt.?is-owner;
241-
242-
x with self.Encrypt {
243-
x .permitted($flag);
244-
}
245-
else {
246-
True;
247-
}
248-
}
249-
250232
* method Blob(|c) returns Blob {
251233
* self.Str(|c).encode: "latin-1";
252234
}

coverage/PDF/COS.rakucov

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,8 @@
3232

3333
# low precedence fallback
3434
* multi method COERCE($v is raw) {
35-
* if !$v.defined && self.isa("PDF::COS::Null") {
36-
* self.new;
37-
}
38-
✱ else {
39-
* warn "failed to coerce {$v.raku} to {self.WHAT.raku}";
40-
$v;
41-
}
35+
* warn "failed to coerce {$v.raku} to {self.WHAT.raku}";
36+
$v;
4237
}
4338

4439
proto method coerce(|) {*}
@@ -163,10 +158,17 @@ x :$ind-ref
163158
}
164159

165160
* method loader is rw handles <load-delegate> {
166-
* unless $loader.can('load-delegate') {
167-
* $loader = $.required('PDF::COS::Loader');
161+
* sub FETCH($) {
162+
* $loader = $.required('PDF::COS::Loader')
163+
if $loader === Any;
164+
$loader;
165+
}
166+
x sub STORE($, $l) {
167+
x $loader = $l
168+
unless $loader.isa('PDF::Class::Loader')
169+
&& $l.isa('PDF::Lite::Loader');
168170
}
169-
$loader
171+
* Proxy.new: :&FETCH, :&STORE;
170172
}
171173

172174
* multi method ACCEPTS(Any:D: Any:D $v) is default {

coverage/PDF/COS/Loader.rakucov

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,5 @@ x $handler-class = $base-class;
6969
$base-class;
7070
}
7171

72-
* method target-class { 'PDF' }
72+
x method target-class { 'PDF' }
7373

coverage/PDF/COS/Null.rakucov

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88

99
* method defined { False }
1010
* method content { :null(Any) }
11+
* multi method COERCE(Any:U) is default { self.new }
1112
* multi method ACCEPTS(Any:U) { True }

coverage/PDF/COS/Stream.rakucov

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ x $!encoded = Nil;
127127
}
128128
}
129129

130-
x multi method gist(::?CLASS:U:) { nextsame() }
131130
* multi method gist(::?CLASS:D:) {
132131
* callsame() ~ "\n" ~ self.encoded.Str.raku
133132
}
134133

135-
* multi method COERCE(Hash $dict, |c) {
136-
✱ my $params = <dict encoded decoded>.first({ $dict{$_}:exists })
137-
?? $dict
138-
!! %( :$dict );
139-
✱ my $class := PDF::COS.load-dict: $params<dict>//{}, :base-class(self.WHAT);
140-
* $class.new: |$params, |c;
134+
* multi method COERCE(Associative $_ where {.<dict>|.<encoded>|.<decoded>}, |c) {
135+
✱ my $class := PDF::COS.load-dict: .<dict>//{}, :base-class(self.WHAT);
136+
* $class.new: |$_, |c;
137+
}
138+
x multi method COERCE(Associative $dict, |c) is DEPRECATED('COERCE({:$dict, :$encoded, :$decoded})') {
139+
my $class := PDF::COS.load-dict: $dict, :base-class(self.WHAT);
140+
x $class.new: :$dict, |c;
141141
}

coverage/PDF/COS/Type/XRef.rakucov

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,20 @@
5454
* nextwith( PDF::IO::Blob.new: buf );
5555
}
5656

57-
* sub pack-xref-stream-raku($xref-index where .shape[1] ~~ 4, @xref, @index) {
57+
x sub pack-xref-stream-raku($xref-index where .shape[1] ~~ 4, @xref, @index) {
5858
my $size = -1;
59-
my $n = +$xref-index;
60-
* for ^$n -> $i {
61-
my $obj-num = $xref-index[$i; 0];
62-
* given $obj-num <=> $size {
63-
* when More { @index.push( $obj-num, 0 ) }
64-
* when Less { die "/XRef /Index is not sorted by ascending obj-num" }
59+
my $n = +$xref-index;
60+
x for ^$n -> $i {
61+
my $obj-num = $xref-index[$i; 0];
62+
x given $obj-num <=> $size {
63+
x when More { @index.push( $obj-num, 0 ) }
64+
x when Less { die "/XRef /Index is not sorted by ascending obj-num" }
6565
}
66-
* @index.tail++;
67-
* @xref[$i; 0] = $xref-index[$i; 1];
68-
* @xref[$i; 1] = $xref-index[$i; 2];
69-
* @xref[$i; 2] = $xref-index[$i; 3];
70-
* $size = $obj-num + 1;
66+
x @index.tail++;
67+
x @xref[$i; 0] = $xref-index[$i; 1];
68+
x @xref[$i; 1] = $xref-index[$i; 2];
69+
x @xref[$i; 2] = $xref-index[$i; 3];
70+
x $size = $obj-num + 1;
7171
}
7272
$size;
7373
}
@@ -107,19 +107,19 @@
107107

108108
#= an extra decoding stage - build index entries from raw decoded data
109109

110-
* sub unpack-xref-stream-raku(\decoded where .shape[1] ~~ 3, \index) {
111-
my uint64 @index[+decoded;4];
110+
x sub unpack-xref-stream-raku(\decoded where .shape[1] ~~ 3, \index) {
111+
my uint64 @index[+decoded;4];
112112
my uint $i = 0;
113-
* for index.list -> $obj-num is rw, \num-entries {
114-
* die "/XRef stream content overflow"
113+
x for index.list -> $obj-num is rw, \num-entries {
114+
x die "/XRef stream content overflow"
115115
if $i + num-entries > +decoded;
116-
* for ^num-entries {
117-
* @index[$i;0] = $obj-num;
118-
* @index[$i;1] = decoded[$i;0];
119-
* @index[$i;2] = decoded[$i;1];
120-
* @index[$i;3] = decoded[$i;2];
121-
* $obj-num++;
122-
* $i++;
116+
x for ^num-entries {
117+
x @index[$i;0] = $obj-num;
118+
x @index[$i;1] = decoded[$i;0];
119+
x @index[$i;2] = decoded[$i;1];
120+
x @index[$i;3] = decoded[$i;2];
121+
x $obj-num++;
122+
x $i++;
123123
}
124124
}
125125

coverage/PDF/IO/Reader.rakucov

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -46,78 +46,78 @@ x STORE => -> $, $!compat {}
4646
my enum IndexType <Free External Embedded>;
4747

4848
# faster native method overrides
49-
x role NativeReader[$native-reader] {
49+
* role NativeReader[$native-reader] {
5050
#| load PDF 1.4- xref table followed by trailer
51-
x method load-xref-table(Str $xref is copy, $dict is rw, :$offset) {
51+
* method load-xref-table(Str $xref is copy, $dict is rw, :$offset) {
5252
# fast load of the xref segments
53-
my $buf = $xref.encode("latin-1");
54-
my array $entries = $native-reader.read-xref($buf)
53+
my $buf = $xref.encode("latin-1");
54+
my array $entries = $native-reader.read-xref($buf)
5555
// die X::PDF::BadXRef::Parse.new( :$offset, :$xref );
56-
my $bytes = $native-reader.xref-bytes;
56+
my $bytes = $native-reader.xref-bytes;
5757

5858
# parse and load the trailer
59-
my $trailer = $buf.subbuf($bytes).decode("latin-1");
60-
my $parse = PDF::Grammar::COS.subparse( $trailer.trim, :rule<trailer>, actions => $.scan-actions );
61-
x die X::PDF::BadXRef::Parse.new( :$offset, :$xref )
59+
my $trailer = $buf.subbuf($bytes).decode("latin-1");
60+
my $parse = PDF::Grammar::COS.subparse( $trailer.trim, :rule<trailer>, actions => $.scan-actions );
61+
* die X::PDF::BadXRef::Parse.new( :$offset, :$xref )
6262
unless $parse;
63-
x my \index = $parse.ast;
64-
x $dict = PDF::COS.coerce( |index<trailer>, :reader(self) );
63+
* my \index = $parse.ast;
64+
* $dict = PDF::COS.coerce( |index<trailer>, :reader(self) );
6565

66-
my uint64 @seg[+$entries div 4;4] Z= @$entries;
66+
my uint64 @seg[+$entries div 4;4] Z= @$entries;
6767

68-
x [@seg, ];
68+
* [@seg, ];
6969
}
7070
}
7171

7272
# further COS object native method overrides
73-
x role NativeCOS[$cos-node, $cos-ind-obj] {
74-
x method parse-ind-obj(Str:D $input) {
75-
x $cos-ind-obj.parse($input)
73+
* role NativeCOS[$cos-node, $cos-ind-obj] {
74+
* method parse-ind-obj(Str:D $input) {
75+
* $cos-ind-obj.parse($input)
7676
}
77-
x method parse-object(Str:D $input) {
78-
x $cos-node.parse($input)
77+
* method parse-object(Str:D $input) {
78+
* $cos-node.parse($input)
7979
}
80-
x my class COSScanActions {
80+
* my class COSScanActions {
8181
has Bool $.get-offsets is rw = False; #| return ind-obj byte offsets in AST
82-
x method TOP($/) { make $<cos>.ast }
83-
x method cos($/) {
84-
my @body = @<body>».ast;
85-
x make (:@body);
82+
* method TOP($/) { make $<cos>.ast }
83+
* method cos($/) {
84+
my @body = @<body>».ast;
85+
* make (:@body);
8686
}
87-
x method body($/) {
88-
my @objects = @<ind-obj>».ast;
89-
my %body = :@objects;
90-
x %body ,= .<trailer>.ast with $<index>;
91-
x make %body;
87+
* method body($/) {
88+
my @objects = @<ind-obj>».ast;
89+
my %body = :@objects;
90+
* %body ,= .<trailer>.ast with $<index>;
91+
* make %body;
9292
}
93-
x method ind-obj($/) {
93+
* method ind-obj($/) {
9494
my Str:D() $input = $/;
95-
my $ind-obj = $cos-ind-obj.parse($input, :scan)
95+
my $ind-obj = $cos-ind-obj.parse($input, :scan)
9696
x // die "Native indirect Object parse failed at byte offset:{$/.from}";
97-
my $ast = $ind-obj.ast;
98-
x $ast.value.push: $/.from
97+
my $ast = $ind-obj.ast;
98+
* $ast.value.push: $/.from
9999
if self.get-offsets;
100-
x make $ast;
100+
* make $ast;
101101
}
102-
x method trailer($/) {
103-
my $dict = $cos-node.parse: $<dict>.Str
102+
* method trailer($/) {
103+
my $dict = $cos-node.parse: $<dict>.Str
104104
x // die "Native trailer dictionary parse failed at byte offset:{$/.from}";
105-
x make (:trailer($dict.ast))
105+
* make (:trailer($dict.ast))
106106
}
107107
}
108-
x method scan-actions { COSScanActions.new }
108+
* method scan-actions { COSScanActions.new }
109109
}
110110

111111
* submethod TWEAK(PDF::COS::Dict :$trailer) {
112112
* self!install-trailer($_) with $trailer;
113113

114114
* try {
115115
* require ::('PDF::Native::Reader');
116-
x self does NativeReader[::('PDF::Native::Reader').new];
116+
* self does NativeReader[::('PDF::Native::Reader').new];
117117
}
118118
* try {
119119
* require ::('PDF::Native::COS');
120-
x self does NativeCOS[::('PDF::Native::COS::COSNode'), ::('PDF::Native::COS::COSIndObj'), ];
120+
* self does NativeCOS[::('PDF::Native::COS::COSNode'), ::('PDF::Native::COS::COSIndObj'), ];
121121
}
122122
}
123123

@@ -319,13 +319,13 @@ x :details("Ignoring {$/.from} bytes before 'endstream' marker")
319319
};
320320
}
321321

322-
* method parse-ind-obj(Str:D $input) {
323-
* PDF::Grammar::COS.subparse( $input, :$.actions, :rule<ind-obj-nibble> );
322+
x method parse-ind-obj(Str:D $input) {
323+
x PDF::Grammar::COS.subparse( $input, :$.actions, :rule<ind-obj-nibble> );
324324
x $/;
325325
}
326326

327-
* method parse-object(Str:D $input) {
328-
* PDF::Grammar::COS.subparse( trim($input), :$.actions, :rule<object> );
327+
x method parse-object(Str:D $input) {
328+
x PDF::Grammar::COS.subparse( trim($input), :$.actions, :rule<object> );
329329
x $/;
330330
}
331331

@@ -503,16 +503,16 @@ x repeat {
503503
}
504504

505505
#| load PDF 1.4- xref table followed by trailer
506-
* method load-xref-table(Str $xref, $dict is rw, :$offset) {
507-
my $parse = PDF::Grammar::COS.subparse( $xref, :rule<index>, :$.actions );
508-
* die X::PDF::BadXRef::Parse.new( :$offset, :$xref )
506+
x method load-xref-table(Str $xref, $dict is rw, :$offset) {
507+
my $parse = PDF::Grammar::COS.subparse( $xref, :rule<index>, :$.actions );
508+
x die X::PDF::BadXRef::Parse.new( :$offset, :$xref )
509509
unless $parse;
510510

511-
* my \index = $parse.ast;
511+
x my \index = $parse.ast;
512512

513-
* $dict = PDF::COS.coerce( |index<trailer>, :reader(self) );
513+
x $dict = PDF::COS.coerce( |index<trailer>, :reader(self) );
514514

515-
* index<xref>».<entries>;
515+
x index<xref>».<entries>;
516516
}
517517

518518
#| load a PDF 1.5+ XRef Stream

coverage/PDF/IO/Serializer.rakucov

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@
3232
#| we don't reference count anything else at the moment.
3333
* multi method ref-count($) { }
3434

35-
✱ my subset DictIndObj of Pair where {.key eq 'ind-obj'
36-
&& .value[2] ~~ Pair
37-
&& .value[2].key eq 'dict'}
35+
✱ my subset DictIndObj of Pair where {
36+
* .key eq 'ind-obj'
37+
&& .value[2] ~~ Pair
38+
&& .value[2].key eq 'dict'
39+
}
3840

3941
✱ my subset LazyObj of Pair where {.key eq 'copy'}
4042

0 commit comments

Comments
 (0)