| 1 | #! perl | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 12 | ▶ | use v5.26; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 12 | ▶ | use Object::Pad; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 12 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 12 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | class SVGPDF::Image :isa(SVGPDF::Element); | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 0 | ▶ | method process () { | ||||||||||||||||||||||||||
|
Subroutine
process: not called CC=24 SCAR=62.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 11 | 0 | my $atts = $self->atts; | |||||||||||||||||||||||||||
| 12 | 0 | my $xo = $self->xo; | |||||||||||||||||||||||||||
| 13 | 0 | ▶ | return if $atts->{omit}; # for testing/debugging. | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 0 | my ( $x, $y, $w, $h, $link, $tf ) = | |||||||||||||||||||||||||||
| 16 | $self->get_params( $atts, qw( x:H y:V width:H height:V href:! transform:s ) ); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | $x ||= 0; $y ||= 0; | ||||||||||||||||||||||||||
|
Condition0%0/4
$x ||= 0
$y ||= 0
MC/DC0%0/1
$x ||= 0
$x
MC/DC0%0/1
$y ||= 0
$y
Truth table0%0/2
A
A= $x
Truth table0%0/2
A
A= $y
| |||||||||||||||||||||||||||||
| 19 | 0 | ▶ | $w ||= 0; $h ||= 0; | ||||||||||||||||||||||||||
|
Condition0%0/4
$w ||= 0
$h ||= 0
MC/DC0%0/1
$w ||= 0
$w
MC/DC0%0/1
$h ||= 0
$h
Truth table0%0/2
A
A= $w
Truth table0%0/2
A
A= $h
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 0 | ▶ | unless ( $w && $h ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$w and $h
MC/DC0%0/2
$w and $h
$w
$h
Truth table0%0/3
A and B
A= $wB= $h
| |||||||||||||||||||||||||||||
| 22 | 0 | $self->_dbg( $self->name, " x=$x y=$y w=$w h=$h **skipped**" ); | |||||||||||||||||||||||||||
| 23 | 0 | return; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 0 | $self->_dbg( $self->name, " x=$x y=$y w=$w h=$h" ); | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | my $img; | |||||||||||||||||||||||||||
| 29 | 0 | ▶ | if ( $link =~ /^data:/ ) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 30 | # In-line image asset. | ||||||||||||||||||||||||||||
| 31 | 0 | my $info = $self->data_inline($link); | |||||||||||||||||||||||||||
| 32 | 0 | ▶ | if ( $info->{error} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 0 | warn( "SVG: ", $info->{error}, "\n" ); | |||||||||||||||||||||||||||
| 34 | 0 | $self->css_pop, return; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | my $mimetype = $info->{mimetype}; | |||||||||||||||||||||||||||
| 38 | 0 | my $subtype = $info->{subtype}; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | unless ( $mimetype eq "image" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 0 | warn("SVG: Unhandled mime type \"mimetype/$subtype\" in inline image\n"); | |||||||||||||||||||||||||||
| 42 | 0 | $self->css_pop, return; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | 0 | my $data = $info->{data}; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | # Get info. | ||||||||||||||||||||||||||||
| 47 | 0 | require Image::Info; | |||||||||||||||||||||||||||
| 48 | 0 | $info = Image::Info::image_info(\$data); | |||||||||||||||||||||||||||
| 49 | 0 | ▶ | if ( $info->{error} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 0 | warn($info->{error}); | |||||||||||||||||||||||||||
| 51 | 0 | $self->css_pop, return; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | my $format = $info->{file_ext}; | |||||||||||||||||||||||||||
| 55 | 0 | ▶ | $format = "jpeg" if $format eq "jpg"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | $format = "pnm" if $format =~ /^p[bgp]m$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | $format = "pnm" if $format =~ /^x[bp]m$/; # bonus | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | $format = "tiff" if $format eq "tif"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | # Make the image. Silence missing library warnings. | ||||||||||||||||||||||||||||
| 61 | 0 | my $fh; | |||||||||||||||||||||||||||
| 62 | # Also, do not use the fast IPL module, it cannot read from scalar. | ||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if ( $format eq "tiff" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | # TIFF can't read from scalar file handle. | ||||||||||||||||||||||||||||
| 65 | 12 | ▶ | use File::Temp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 66 | 0 | ( my $fd, $fh ) = File::Temp::tempfile( UNLINK => 1 ); | |||||||||||||||||||||||||||
| 67 | 0 | binmode $fd => ':raw'; | |||||||||||||||||||||||||||
| 68 | 0 | print $fd $data; | |||||||||||||||||||||||||||
| 69 | 0 | close($fd); | |||||||||||||||||||||||||||
| 70 | # Yes, trickery... $fh is now a file name, not a handle. | ||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | else { | ||||||||||||||||||||||||||||
| 73 | 0 | open( $fh, '<:raw', \$data ); | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | 0 | $img = $self->root->pdf->image( $fh, format => $format, | |||||||||||||||||||||||||||
| 76 | silent => 1, nouseIPL => 1 ); | ||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | ▶ | elsif ( $link =~ m!^.+\.(png|jpe?g|gif)$!i && -s $link ) { | |||||||||||||||||||||||||||
|
Condition0%0/3
$link =~ /^.+\.(png|jpe?g|gif)$/iu and -s $link
MC/DC0%0/2
$link =~ /^.+\.(png|jpe?g|gif)$/iu and -s $link
$link =~ /^.+\.(png|jpe?g|gif)$/iu
-s $link
Truth table0%0/3
A and B
A= $link =~ /^.+\.(png|jpe?g|gif)$/iuB= -s $link
| |||||||||||||||||||||||||||||
| 79 | # Autodetected. Make the image. | ||||||||||||||||||||||||||||
| 80 | 0 | $img = $self->root->pdf->image( $link, silent => 1 ); | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | ▶ | elsif ( $link =~ m!^.+\.(tiff?|p[bgp]m|x[bp]m)$!i && -s $link ) { | |||||||||||||||||||||||||||
|
Condition0%0/3
$link =~ /^.+\.(tiff?|p[bgp]m|x[bp]m)$/iu and -s $link
MC/DC0%0/2
$link =~ /^.+\.(tiff?|p[bgp]m|x[bp]m)$/iu and -s $link
$link =~ /^.+\.(tiff?|p[bgp]m|x[bp]m)$/iu
-s $link
Truth table0%0/3
A and B
A= $link =~ /^.+\.(tiff?|p[bgp]m|x[bp]m)$/iuB= -s $link
| |||||||||||||||||||||||||||||
| 83 | # Not autodetected, need format. | ||||||||||||||||||||||||||||
| 84 | # Note that xbm and xpm are bonus. | ||||||||||||||||||||||||||||
| 85 | 0 | ▶ | my $format = $1 =~ /tif/i ? "tiff" : "pnm"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | # Make the image. | ||||||||||||||||||||||||||||
| 87 | 0 | $img = $self->root->pdf->image( $link, format => $format, silent => 1 ); | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | else { | ||||||||||||||||||||||||||||
| 90 | 0 | ▶ | warn("SVG: Unhandled or missing image link: ", | ||||||||||||||||||||||||||
|
Condition0%0/2
qq["$link"] // "<undef>"
MC/DC0%0/1
qq["$link"] // "<undef>"
qq["$link"]
Truth table0%0/2
A
A= qq["$link"]
| |||||||||||||||||||||||||||||
| 91 | "\"$link\""//"<undef>", "\n"); | ||||||||||||||||||||||||||||
| 92 | 0 | return; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | $self->_dbg( "xo save" ); | |||||||||||||||||||||||||||
| 96 | 0 | $xo->save; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | # Place the image. | ||||||||||||||||||||||||||||
| 99 | 0 | ▶ | $self->set_transform($tf) if $tf; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 0 | $xo->transform( translate => [ $x, $y+$h ] ); | |||||||||||||||||||||||||||
| 101 | 0 | $xo->image( $img, 0, 0, $w, -$h ); | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | $self->_dbg( "xo restore" ); | |||||||||||||||||||||||||||
| 104 | 0 | $xo->restore; | |||||||||||||||||||||||||||
| 105 | 0 | $self->css_pop; | |||||||||||||||||||||||||||
| 106 | 12 | } | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 12 | 1; | |||||||||||||||||||||||||||