Skip to content

Commit

Permalink
add --quiet option to pdf-tag-dump.raku; also use :quiet in for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
dwarring committed Nov 7, 2023
1 parent 08295f1 commit 621e6ee
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 8 deletions.
4 changes: 3 additions & 1 deletion bin/pdf-tag-dump.raku
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ sub MAIN(Str $infile, #= Input PDF
Bool :$marks, #= Descend into marked content
Bool :$fields = True, #= Include referenced field data
Bool :$strict = True, #= Warn about unknown tags, etc
Bool :$quiet, #= avoid printing any messages to stderr
Bool :$style = True, #= Include stylesheet header
Str :$dtd, #= Extern DtD to use
Bool :$valid = !$marks && !$roles, #= include external DtD declaration
Expand All @@ -36,7 +37,7 @@ sub MAIN(Str $infile, #= Input PDF
my %o = :$dtd with $dtd;

my PDF::Class $pdf .= open( $input, :$password );
my PDF::Tags::Reader $dom .= read: :$pdf, :$strict, :$marks;
my PDF::Tags::Reader $dom .= read: :$pdf, :$strict, :$marks, :$quiet;
my PDF::Tags::XML-Writer $xml .= new: :$max-depth, :$atts, :$debug, :$omit, :$style, :$root-tag, :$marks, :$valid, :$roles, |%o;

my PDF::Tags::Node @nodes = do with $select {
Expand Down Expand Up @@ -79,6 +80,7 @@ Options:
--valid add external DtD declaration
--/atts omit attributes in tags
--/strict suppress warnings
--quiet avoid printing messages
--/style omit root stylesheet link
=head1 DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion lib/PDF/Tags/Reader.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ sub build-tag-index(%tags, PDF::Content::Tag $tag) {

method canvas-tags($canvas --> Hash) {
%!canvas-tags{$canvas} //= do {
$*ERR.print: '.';
$*ERR.print: '.' unless $!quiet;
my &callback = TextDecoder.new(:$!lock, :$!quiet).callback;
my PDF::Content $gfx = $canvas.gfx: :&callback, :$!strict;
$canvas.render;
Expand Down
2 changes: 1 addition & 1 deletion t/02xpath-basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ sub tags(@elems) {

my PDF::Class $pdf .= open("t/pdf/tagged.pdf");

my PDF::Tags::Reader $dom .= read: :$pdf;
my PDF::Tags::Reader $dom .= read: :$pdf, :quiet;

for $dom.find('Document') -> $elem {
isa-ok($elem, PDF::Tags::Elem);
Expand Down
2 changes: 1 addition & 1 deletion t/04xpath-node-test.t
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sub names(@elems) {

my PDF::Class $pdf .= open("t/pdf/tagged.pdf");

my PDF::Tags::Reader $dom .= read: :$pdf;
my PDF::Tags::Reader $dom .= read: :$pdf, :quiet;

is names($dom.find('Document/H1/*[1]')), 'Span Span Span Span Span';
is names($dom.find('Document/H1[1]/node()')), 'Span';
Expand Down
5 changes: 3 additions & 2 deletions t/05xpath-axis.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ use PDF::Tags::Reader;
use PDF::Tags::Elem;
use PDF::Class;

plan 19;
plan 20;

sub names(@elems) {
@elems>>.name.join(' ');
}

my PDF::Class $pdf .= open("t/pdf/tagged.pdf");

my PDF::Tags::Reader $dom .= read: :$pdf;
my PDF::Tags::Reader $dom .= read: :$pdf, :quiet;

is names($dom.find('Document/L')), ['L', 'L'], "child, repeated";
is names($dom.find('Document/L[1]/LI[1]/LBody/ancestor::*')), 'Document L LI', 'ancestor';
Expand All @@ -30,6 +30,7 @@ my $lbody = $li.first('LBody');
is names($lbl.find('following-sibling::*')), 'LBody', 'following-sibling';
is names($lbody.find('/Document/L[1]/LI[1]/LBody/preceding::*')), 'Lbl', 'preceding';
is names($lbody.find('preceding-sibling::*')), ['Lbl'], 'preceding-sibling';
is names($lbody.find('preceding-sibling::Lbl')), ['Lbl'], 'preceding-sibling';
is names($lbody.find('self::*')), ['LBody'], 'self';
is names($lbody.find('.')), ['LBody'], 'self (abbreviated)';
is names($lbody.find('parent::*')), ['LI'], 'parent';
Expand Down
2 changes: 1 addition & 1 deletion t/06xml.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use PDF::Tags::XML-Writer;
plan 3;

my PDF::Class $pdf .= open: "t/pdf/tagged.pdf";
my PDF::Tags::Reader $dom .= read: :$pdf;
my PDF::Tags::Reader $dom .= read: :$pdf, :quiet;

is-deeply $dom.root[0].xml.lines.head(3), (
'<Document>',
Expand Down
2 changes: 1 addition & 1 deletion t/10-reversed-chars.t
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ $pdf.id = $*PROGRAM-NAME.fmt('%-16.16s');
$pdf.save-as: "t/10-reversed-chars.pdf", :!info;

$pdf .= open: "t/10-reversed-chars.pdf";
$tags = PDF::Tags::Reader.read: :$pdf;
$tags = PDF::Tags::Reader.read: :$pdf, :quiet;

is $tags[0].xml, $xml, 'XML, round-tripped';

Expand Down

0 comments on commit 621e6ee

Please sign in to comment.