Skip to content

Commit b5e99a9

Browse files
committed
Improve some coercements
1 parent a7f7c68 commit b5e99a9

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

lib/PDF/AcroForm.rakumod

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,22 @@ has Str $.DA is entry(:alias<default-appearance>); # (Optiona
7878
has UInt $.Q is entry(:alias<quadding>); # (Optional) A document-wide default value for the Q attribute of variable text fields
7979

8080
my subset XFA where .[0] ~~ TextOrStream;
81-
multi sub coerce-xfa-elem(TextOrStream $v) { $v }
82-
multi sub coerce-xfa-elem($v is rw) {
83-
coerce-text-or-stream($v, TextOrStream);
81+
multi sub coerce-xfa-elem(PDF::COS::TextString $v, $ where $_ %% 2) {
82+
$v;
8483
}
84+
multi sub coerce-xfa-elem($v is rw, $ where $_ %% 2) {
85+
$v = PDF::COS::TextString.COERCE: $v;
86+
}
87+
multi sub coerce-xfa-elem(PDF::COS::Stream $s, $ where $_ !%% 2) {
88+
$s
89+
}
90+
multi sub coerce-xfa-elem($e, $_) {
91+
fail "Unable to coerece XFA element of type {$e.WHAT.raku} at index $_";
92+
}
93+
8594
multi sub coerce-xfa(List $a, XFA) {
86-
coerce-xfa-elem( $a[$_])
87-
for 0, 2 ... +$a;
95+
coerce-xfa-elem( $a[$_], $_)
96+
for ^+$a;
8897
}
8998
multi sub coerce-xfa($_, $) { warn "unable to coerce to XFA forms: {.raku}" }
9099
has XFA $.XFA is entry(:coerce(&coerce-xfa)); # (Optional; PDF 1.5) A stream or array containing an XFA resource, whose format is described by the Data Package (XDP) Specification.

lib/PDF/Annot.rakumod

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ use PDF::Class::Defs :BlendMode;
1717
use PDF::Appearance;
1818
use PDF::Border;
1919
use PDF::Filespec;
20-
use PDF::OCG; # optional content group
21-
use PDF::OCMD; # optional content membership dict
22-
my subset OCG-or-OCMD where PDF::OCG|PDF::OCMD;
20+
use PDF::Class::OptionalContent;
2321
use PDF::Page;
2422

2523
use ISO_32000::Table_164-Entries_common_to_all_annotation_dictionaries;
@@ -69,7 +67,7 @@ role Border does PDF::COS::Tie::Array {
6967
has Border $.Border is entry(:default[0, 0, 1]); # (Optional) An array specifying the characteristics of the annotation’s border. The border is specified as a rounded rectangle.
7068
has Numeric @.C is entry(:alias<color>); # (Optional; PDF 1.1) An array of numbers in the range 0.0 to 1.0, representing a color used for (*) background, when closed, (*) title bar of pop-up window, (*) link border
7169
has UInt $.StructParent is entry(:alias<struct-parent>); # (Required if the annotation is a structural content item; PDF 1.3) The integer key of the annotation’s entry in the structural parent tree
72-
has OCG-or-OCMD $.OC is entry(:alias<optional-content>); # (Optional; PDF 1.5) An optional content group or optional content membership dictionary specifying the optional content properties for the annotation.
70+
has PDF::Class::OptionalContent $.OC is entry(:alias<optional-content>); # (Optional; PDF 1.5) An optional content group or optional content membership dictionary specifying the optional content properties for the annotation.
7371

7472
has PDF::Filespec @.AF is entry(); # (Optional; PDF 2.0) An array of one or more file specification dictionaries, which denote the associated files for this annotation).
7573

lib/PDF/Appearance.rakumod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ my role AppearanceStates
2424

2525
my subset AppearEntry where FormLike | AppearanceStates;
2626
multi sub coerce(PDF::COS::Stream $dict is rw, AppearEntry) {
27-
warn "Stream not of /Subtype /Form"
27+
fail "Stream not of /Subtype /Form"
2828
}
2929
multi sub coerce(Hash $dict is rw, AppearEntry) {
3030
AppearanceStates.COERCE: $dict;

0 commit comments

Comments
 (0)