Skip to content

Commit

Permalink
add coercement rule for Filespec /Thumb (PDF 2.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwarring committed Feb 20, 2024
1 parent 6b978b3 commit ed593a9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions META6.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"PDF::Class": "lib/PDF/Class.rakumod",
"PDF::Class::Defs": "lib/PDF/Class/Defs.rakumod",
"PDF::Class::FieldContainer": "lib/PDF/Class/FieldContainer.rakumod",
"PDF::Class::Image": "lib/PDF/Class/Image.rakumod",
"PDF::Class::Loader": "lib/PDF/Class/Loader.rakumod",
"PDF::Class::OptionalContent": "lib/PDF/Class/OptionalContent.rakumod",
"PDF::Class::OutlineNode": "lib/PDF/Class/OutlineNode.rakumod",
Expand Down
1 change: 1 addition & 0 deletions lib/PDF/Class/Image.rakumod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
unit role PDF::Class::Image;
12 changes: 11 additions & 1 deletion lib/PDF/Filespec.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ also does ISO_32000::Table_44-Entries_in_a_file_specification_dictionary;
use ISO_32000_2::Table_43-Entries_in_a_file_specification_dictionary;
also does ISO_32000_2::Table_43-Entries_in_a_file_specification_dictionary;

use PDF::Class::Image;

# file specifications may be either a dictionary or a simple text-string
my subset FileRef is export(:FileRef) where PDF::COS::TextString|PDF::Filespec;
my subset FileRefLike is export(:FileRefLike) where Str|Hash;
Expand Down Expand Up @@ -63,7 +65,15 @@ has EmbeddedFile %.EF is entry(:alias<embedded-files>); # (Required if RF is pre
has Array %.RF is entry(:alias<related-files>); # (Optional; PDF 1.3) A dictionary with the same structure as the EF dictionary, which shall be present. Each key in the RF dictionary shall also be present in the EF dictionary. Each value shall be a related files array identifying files that are related to the corresponding file in the EF dictionary. If this entry is present, the Type entry is required and the file specification dictionary shall be indirectly referenced.
has PDF::COS::TextString $.Desc is entry; # (Optional; PDF 1.6) Descriptive text associated with the file specification. It shall be used for files in the EmbeddedFiles name tree.
has PDF::COS::Dict $.CI is entry(:indirect); # (Optional; shall be indirect reference; PDF 1.7) A collection item dictionary, which shall be used to create the user interface for portable collections.
has PDF::COS::Stream $.Thumb is entry; # (Optional; PDF 2.0) A stream object defining the thumbnail image for the file specification.
multi sub coerce-thumb(PDF::COS::Stream $thumb, PDF::Class::Image) {
# PDF::Filespec has a cyclic dependency on PDF::Image,
# which does PDF::Class::Image
PDF::COS.coerce: $thumb, PDF::COS.required("PDF::Image");
}
multi sub coerce-thumb($_, PDF::Class::Image) {
fail "unable to coerce thumbnail: {.raku}";
}
has PDF::Class::Image $.Thumb is entry(:coerce(&coerce-thumb)); # (Optional; PDF 2.0) A stream object defining the thumbnail image for the file specification.
has PDF::COS::Dict $.EP is entry; # (PDF 2.0; Required if this file specification references an encrypted payload document as described in 7.6.7, "Unencrypted wrapper document") The value of this key is an encrypted payload dictionary which identifies that the file specified in the EF dictionary is an encrypted payload.

my subset AFRelationship of PDF::COS::Name where 'Source'|'Data'|'Alternative'|'Supplement'|'EncryptedPayload'|'FormData'|'Schema'|'Unspecified';
Expand Down
2 changes: 2 additions & 0 deletions lib/PDF/Image.rakumod
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
unit role PDF::Image;

use PDF::Class::Image;
use PDF::Class::StructItem;
use PDF::Content::XObject;
use PDF::COS::Tie::Hash;

also does PDF::Class::Image;
also does PDF::Class::StructItem;
also does PDF::Content::XObject['Image'];
also does PDF::COS::Tie::Hash;
Expand Down

0 comments on commit ed593a9

Please sign in to comment.