| 1 | package App::paperback; | ||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use v5.10; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 5 | # use warnings; | ||||||||||||||||||||||||||||||||||||||
| 6 | 1 | $^W = 0; | |||||||||||||||||||||||||||||||||||||
| 7 | 1 | our $VERSION = "1.42"; | |||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||
| 9 | 1 | my ($GinFile, $GpageObjNr, $GrootNr, $Gpos, $GobjNr, $Gstream, $GoWid, $GoHei, | |||||||||||||||||||||||||||||||||||||
| 10 | $GpagesObjContent); | ||||||||||||||||||||||||||||||||||||||
| 11 | 1 | my (@Gkids, @Gcounts, @GmediaBox, @Gobject, @Gparents, @Gto_be_created); | |||||||||||||||||||||||||||||||||||||
| 12 | 1 | my (%GpageXObject, %GObjects, %Gpaper); | |||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||
| 14 | 1 | my $cr = '\s*(?:\015|\012|(?:\015\012))'; | |||||||||||||||||||||||||||||||||||||
| 15 | 1 | my ( $IN_FILE, $OUT_FILE ); | |||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||
| 17 | # ISO 216 paper sizes in pt (four decimals will do): | ||||||||||||||||||||||||||||||||||||||
| 18 | 1 | my $JH = 1190.5512; # [J] A3 ~ 420 mm (H) | |||||||||||||||||||||||||||||||||||||
| 19 | 1 | my $JW = 841.8898; # [J] A3 ~ 297 mm (W) | |||||||||||||||||||||||||||||||||||||
| 20 | 1 | my $AH = $JW; # [A] A4 ~ 297 mm (H) | |||||||||||||||||||||||||||||||||||||
| 21 | 1 | my $AW = 595.2756; # [A] A4 ~ 210 mm (W) | |||||||||||||||||||||||||||||||||||||
| 22 | 1 | my $BH = $AW; # [B] A5 ~ 210 mm (H) | |||||||||||||||||||||||||||||||||||||
| 23 | 1 | my $BW = 419.5276; # [B] A5 ~ 148 mm (W) | |||||||||||||||||||||||||||||||||||||
| 24 | 1 | my $CH = $BW; # [C] A6 ~ 148 mm (H) | |||||||||||||||||||||||||||||||||||||
| 25 | 1 | my $CW = 297.6378; # [C] A6 ~ 105 mm (W) | |||||||||||||||||||||||||||||||||||||
| 26 | # + 1 mm (2.8346 pt) to account for rounding in ISO 216 (148+148=296): | ||||||||||||||||||||||||||||||||||||||
| 27 | 1 | my $CX = 422.3622; # [C] A6 $CH + 1 mm (H) | |||||||||||||||||||||||||||||||||||||
| 28 | 1 | my $BX = $CX; # [B] A5 $BW + 1 mm (W) | |||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||
| 30 | # US paper sizes in pt: | ||||||||||||||||||||||||||||||||||||||
| 31 | 1 | my $DH = 792; # [D] US Letter Full (H) | |||||||||||||||||||||||||||||||||||||
| 32 | 1 | my $DW = 612; # [D] US Letter Full (W) | |||||||||||||||||||||||||||||||||||||
| 33 | 1 | my $EH = $DW; # [E] US Letter Half (H) | |||||||||||||||||||||||||||||||||||||
| 34 | 1 | my $EW = 396; # [E] US Letter Half (W) | |||||||||||||||||||||||||||||||||||||
| 35 | 1 | my $FH = $EW; # [F] US Letter Quarter (H) | |||||||||||||||||||||||||||||||||||||
| 36 | 1 | my $FW = 306; # [F] US Letter Quarter (W) | |||||||||||||||||||||||||||||||||||||
| 37 | 1 | my $GH = 1008; # [G] US Legal Full (H) | |||||||||||||||||||||||||||||||||||||
| 38 | 1 | my $GW = $DW; # [G] US Legal Full (W) | |||||||||||||||||||||||||||||||||||||
| 39 | 1 | my $HH = $DW; # [H] US Legal Half (H) | |||||||||||||||||||||||||||||||||||||
| 40 | 1 | my $HW = 504; # [H] US Legal Half (W) | |||||||||||||||||||||||||||||||||||||
| 41 | 1 | my $IH = $HW; # [I] US Legal Quarter (H) | |||||||||||||||||||||||||||||||||||||
| 42 | 1 | my $IW = $FW; # [I] US Legal Quarter (W) | |||||||||||||||||||||||||||||||||||||
| 43 | 1 | my $KH = 1224; # [K] US Tabloid (H) | |||||||||||||||||||||||||||||||||||||
| 44 | 1 | my $KW = $DH; # [K] US Tabloid (W) | |||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||
| 46 | # Paper surfaces in square pts (expressed as HxW in pts): | ||||||||||||||||||||||||||||||||||||||
| 47 | 1 | %Gpaper = ( | |||||||||||||||||||||||||||||||||||||
| 48 | QuarterLetter => $FH * $FW, # = 121_176 | ||||||||||||||||||||||||||||||||||||||
| 49 | A6 => $CH * $CW, # ~ 124_867 | ||||||||||||||||||||||||||||||||||||||
| 50 | QuarterLegal => $IH * $IW, # = 154_224 | ||||||||||||||||||||||||||||||||||||||
| 51 | HalfLetter => $EH * $EW, # = 242_352 | ||||||||||||||||||||||||||||||||||||||
| 52 | A5 => $BH * $BW, # ~ 249_735 | ||||||||||||||||||||||||||||||||||||||
| 53 | HalfLegal => $HH * $HW, # = 308_448 | ||||||||||||||||||||||||||||||||||||||
| 54 | Letter => $DH * $DW, # = 484_704 | ||||||||||||||||||||||||||||||||||||||
| 55 | A4 => $AH * $AW, # ~ 501_156 | ||||||||||||||||||||||||||||||||||||||
| 56 | Legal => $GH * $GW, # = 616_896 | ||||||||||||||||||||||||||||||||||||||
| 57 | Tabloid => $KH * $KW, # = 969_408 | ||||||||||||||||||||||||||||||||||||||
| 58 | A3 => $JH * $JW, # ~ 1_002_312 | ||||||||||||||||||||||||||||||||||||||
| 59 | ); | ||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||
| 61 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | sub main { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
main: not called CC=28 SCAR=67.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 63 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 64 | 0 | my $input = $ARGV[0]; | |||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||
| 66 | # Page reordering and position offset schemas for "4 up": | ||||||||||||||||||||||||||||||||||||||
| 67 | 0 | my @P_4UP_13PLUS = (16,1,13,4,2,15,3,14,12,5,9,8,6,11,7,10); | |||||||||||||||||||||||||||||||||||||
| 68 | 0 | my @P_4UP_9PLUS = (12,1,9,4,2,11,3,10,6,7,9999,9999,8,5); | |||||||||||||||||||||||||||||||||||||
| 69 | 0 | my @P_4UP_5PLUS = (8,1,5,4,2,7,3,6); | |||||||||||||||||||||||||||||||||||||
| 70 | 0 | my @P_4UP_1PLUS = (4,1,9999,9999,2,3); | |||||||||||||||||||||||||||||||||||||
| 71 | 0 | my @X_A6_ON_A4 = (000,$CW,$CW,$AW) x 4; | |||||||||||||||||||||||||||||||||||||
| 72 | 0 | my @Y_A6_ON_A4 = ($CX,$CX,$CH,$CH) x 4; | |||||||||||||||||||||||||||||||||||||
| 73 | 0 | my @X_QT_ON_LT = (000,$FW,$FW,$DW) x 4; | |||||||||||||||||||||||||||||||||||||
| 74 | 0 | my @Y_QT_ON_LT = ($FH,$FH,$FH,$FH) x 4; | |||||||||||||||||||||||||||||||||||||
| 75 | 0 | my @X_QG_ON_LG = (000,$IW,$IW,$GW) x 4; | |||||||||||||||||||||||||||||||||||||
| 76 | 0 | my @Y_QG_ON_LG = ($IH,$IH,$IH,$IH) x 4; | |||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||
| 78 | # Page reordering and position offset schemas for "2 up": | ||||||||||||||||||||||||||||||||||||||
| 79 | 0 | my @P_2UP_13PLUS = (1,16,2,15,3,14,4,13,5,12,6,11,7,10,8,9); | |||||||||||||||||||||||||||||||||||||
| 80 | 0 | my @P_2UP_9PLUS = (1,12,2,11,3,10,4,9,5,8,6,7); | |||||||||||||||||||||||||||||||||||||
| 81 | 0 | my @P_2UP_5PLUS = (1,8,2,7,3,6,4,5); | |||||||||||||||||||||||||||||||||||||
| 82 | 0 | my @P_2UP_1PLUS = (1,4,2,3); | |||||||||||||||||||||||||||||||||||||
| 83 | 0 | my @X_A5_ON_A4 = ($BH,$BH,000,000) x 4; | |||||||||||||||||||||||||||||||||||||
| 84 | 0 | my @Y_A5_ON_A4 = ($BX,000,$AH,$BX) x 4; | |||||||||||||||||||||||||||||||||||||
| 85 | 0 | my @X_HT_ON_LT = ($EH,$EH,000,000) x 4; | |||||||||||||||||||||||||||||||||||||
| 86 | 0 | my @Y_HT_ON_LT = ($EW,000,$DH,$EW) x 4; | |||||||||||||||||||||||||||||||||||||
| 87 | 0 | my @X_HG_ON_LG = ($HH,$HH,000,000) x 4; | |||||||||||||||||||||||||||||||||||||
| 88 | 0 | my @Y_HG_ON_LG = ($HW,000,$GH,$HW) x 4; | |||||||||||||||||||||||||||||||||||||
| 89 | 0 | my @X_LT_ON_TA = ($DH,$DH,000,000) x 4; | |||||||||||||||||||||||||||||||||||||
| 90 | 0 | my @Y_LT_ON_TA = ($DW,000,$KH,$DW) x 4; | |||||||||||||||||||||||||||||||||||||
| 91 | 0 | my @X_A4_ON_A3 = ($AH,$AH,000,000) x 4; | |||||||||||||||||||||||||||||||||||||
| 92 | 0 | my @Y_A4_ON_A3 = ($AW,000,$JH,$AW) x 4; | |||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||
| 94 | 0 | my ($inpPgNum, $inpPgSize); | |||||||||||||||||||||||||||||||||||||
| 95 | 0 | my $numPagImposed = 0; | |||||||||||||||||||||||||||||||||||||
| 96 | 0 | my $sayUsage = "Usage: paperback file.pdf (will produce 'file-paperback.pdf')."; | |||||||||||||||||||||||||||||||||||||
| 97 | 0 | my $sayVers = "This is paperback v${VERSION}, (c) 2023 Hector M. Monacci."; | |||||||||||||||||||||||||||||||||||||
| 98 | 0 | my $sayHelp = <<"END_MESSAGE"; | |||||||||||||||||||||||||||||||||||||
| 99 | ${sayUsage} | ||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||
| 101 | All pages in the input PDF file will be imposed on a new PDF with | ||||||||||||||||||||||||||||||||||||||
| 102 | bigger paper size, ready to be duplex-printed, folded and put together | ||||||||||||||||||||||||||||||||||||||
| 103 | into signatures, according to its original page size. Input PDF is | ||||||||||||||||||||||||||||||||||||||
| 104 | always assumed to be composed of vertical pages of the same size. | ||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||
| 106 | Input page sizes allowed are A4, A5, A6, Letter, Half Letter, Quarter | ||||||||||||||||||||||||||||||||||||||
| 107 | Letter, Half Legal, Quarter Legal. Other sizes give an error message. | ||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||
| 109 | Only PDF v1.4 is supported as input, although many higher-labeled | ||||||||||||||||||||||||||||||||||||||
| 110 | PDF files are correctly handled since they are essentially v1.4 PDF | ||||||||||||||||||||||||||||||||||||||
| 111 | files stamped as something more modern. Encrypted PDFs are not supported. | ||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||
| 113 | ISO 216 normalised (international) page sizes: | ||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||
| 115 | Input page sizes A6 (105 x 148 mm) and A5 (148 x 210 mm) produce an | ||||||||||||||||||||||||||||||||||||||
| 116 | output page size of A4 (210 x 297 mm). Input page size A4 (210 x 297 mm) | ||||||||||||||||||||||||||||||||||||||
| 117 | produces an output page size of A3 (297 x 420 mm). Four A6 pages will | ||||||||||||||||||||||||||||||||||||||
| 118 | be put on each A4 page, two A5 pages will be put on each A4 page, or | ||||||||||||||||||||||||||||||||||||||
| 119 | two A4 pages will be put on each A3 page. Before that, input pages will | ||||||||||||||||||||||||||||||||||||||
| 120 | be reordered and reoriented so as to produce a final PDF fit for duplex | ||||||||||||||||||||||||||||||||||||||
| 121 | 'long-edge-flip' printing. | ||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||
| 123 | ANSI normalised (US) page sizes: | ||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||
| 125 | Input page sizes Quarter Letter (4.25 x 5.5 in) and Half Letter (5.5 | ||||||||||||||||||||||||||||||||||||||
| 126 | x 8.5 in) produce a Letter output page size (8.5 x 11 in). Input | ||||||||||||||||||||||||||||||||||||||
| 127 | page sizes Quarter Legal (4.25 x 7 in) and Half Legal (7 x 8.5 in) | ||||||||||||||||||||||||||||||||||||||
| 128 | produce a Legal output page size (8.5 x 14 in). Input page size Letter | ||||||||||||||||||||||||||||||||||||||
| 129 | (8.5 x 11 in) produces a Tabloid output page size (11 x 17 in). | ||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||
| 131 | Four Quarter-Letter pages will be put on each Letter page, two Half-Letter | ||||||||||||||||||||||||||||||||||||||
| 132 | pages will be put on each Letter page, four Quarter-Legal pages will be | ||||||||||||||||||||||||||||||||||||||
| 133 | put on each Legal page, two Half-Legal pages will be put on each Legal page, | ||||||||||||||||||||||||||||||||||||||
| 134 | or two Letter pages will be put on each Tabloid page. Before that, input | ||||||||||||||||||||||||||||||||||||||
| 135 | pages will be reordered and reoriented so as to produce a final PDF fit for | ||||||||||||||||||||||||||||||||||||||
| 136 | duplex 'long-edge-flip' printing. | ||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||
| 138 | For further details, please try 'perldoc paperback'. | ||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||
| 140 | ${sayVers} | ||||||||||||||||||||||||||||||||||||||
| 141 | END_MESSAGE | ||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | die "[!] ${sayUsage}\n" if ! defined $input; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | do {print STDERR "${sayHelp}"; exit} | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$input =~ /^-h$/ or $input =~ /^--help$/
MC/DC0%0/2
$input =~ /^-h$/ or $input =~ /^--help$/
$input =~ /^-h$/
$input =~ /^--help$/
Truth table0%0/3
A or B
A= $input =~ /^-h$/B= $input =~ /^--help$/
| |||||||||||||||||||||||||||||||||||||||
| 145 | if $input =~ "^-h\$" or $input =~ "^--help\$"; | ||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | do {print STDERR "${sayVers}\n"; exit} | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$input =~ /^-v$/ or $input =~ /^--version$/
MC/DC0%0/2
$input =~ /^-v$/ or $input =~ /^--version$/
$input =~ /^-v$/
$input =~ /^--version$/
Truth table0%0/3
A or B
A= $input =~ /^-v$/B= $input =~ /^--version$/
| |||||||||||||||||||||||||||||||||||||||
| 147 | if $input =~ "^-v\$" or $input =~ "^--version\$"; | ||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ($inpPgNum, $inpPgSize) = openInputFile($input); | |||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||
| 150 | 0 | my ($pgPerOutputPage, @x, @y); | |||||||||||||||||||||||||||||||||||||
| 151 | 0 | for ($inpPgSize) { | |||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | if ($_ eq "A6") { $pgPerOutputPage = 4; @x = @X_A6_ON_A4; @y = @Y_A6_ON_A4; } | ||||||||||||||||||||||||||||||||||||
|
Branch: 8 branches
| |||||||||||||||||||||||||||||||||||||||
| 153 | 0 | elsif ($_ eq "A5") { $pgPerOutputPage = 2; @x = @X_A5_ON_A4; @y = @Y_A5_ON_A4; } | |||||||||||||||||||||||||||||||||||||
| 154 | 0 | elsif ($_ eq "QT") { $pgPerOutputPage = 4; @x = @X_QT_ON_LT; @y = @Y_QT_ON_LT; } | |||||||||||||||||||||||||||||||||||||
| 155 | 0 | elsif ($_ eq "QG") { $pgPerOutputPage = 4; @x = @X_QG_ON_LG; @y = @Y_QG_ON_LG; } | |||||||||||||||||||||||||||||||||||||
| 156 | 0 | elsif ($_ eq "HT") { $pgPerOutputPage = 2; @x = @X_HT_ON_LT; @y = @Y_HT_ON_LT; } | |||||||||||||||||||||||||||||||||||||
| 157 | 0 | elsif ($_ eq "HG") { $pgPerOutputPage = 2; @x = @X_HG_ON_LG; @y = @Y_HG_ON_LG; } | |||||||||||||||||||||||||||||||||||||
| 158 | 0 | elsif ($_ eq "LT") { $pgPerOutputPage = 2; @x = @X_LT_ON_TA; @y = @Y_LT_ON_TA; } | |||||||||||||||||||||||||||||||||||||
| 159 | 0 | elsif ($_ eq "A4") { $pgPerOutputPage = 2; @x = @X_A4_ON_A3; @y = @Y_A4_ON_A3; } | |||||||||||||||||||||||||||||||||||||
| 160 | 0 | else {die "[!] File '${GinFile}' has bad page size (${_}). Try 'paperback -h' for more info.\n"} | |||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||
| 163 | 0 | my ($name) = $input =~ /(.+)\.[^.]+$/; | |||||||||||||||||||||||||||||||||||||
| 164 | 0 | createOutputFile("${name}-paperback.pdf"); | |||||||||||||||||||||||||||||||||||||
| 165 | 0 | my ($rot_extra, @p); | |||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | if ($pgPerOutputPage == 4) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 167 | 0 | $rot_extra = 0; | |||||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | @p = $inpPgNum >= 13 ? @P_4UP_13PLUS : | ||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||
| 169 | $inpPgNum >= 9 ? @P_4UP_9PLUS : | ||||||||||||||||||||||||||||||||||||||
| 170 | $inpPgNum >= 5 ? @P_4UP_5PLUS : @P_4UP_1PLUS; | ||||||||||||||||||||||||||||||||||||||
| 171 | } else { | ||||||||||||||||||||||||||||||||||||||
| 172 | 0 | $rot_extra = 90; | |||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | @p = $inpPgNum >= 13 ? @P_2UP_13PLUS : | ||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||
| 174 | $inpPgNum >= 9 ? @P_2UP_9PLUS : | ||||||||||||||||||||||||||||||||||||||
| 175 | $inpPgNum >= 5 ? @P_2UP_5PLUS : @P_2UP_1PLUS; | ||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||
| 177 | 0 | my $lastSignature = $inpPgNum >> 4; | |||||||||||||||||||||||||||||||||||||
| 178 | 0 | my ($rotation, $target_page); | |||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | for (my $thisSignature = 0; $thisSignature <= $lastSignature; ++$thisSignature) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 180 | 0 | for (0 .. 15) { | |||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | &newPageInOutputFile if $_ % $pgPerOutputPage == 0; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 182 | 0 | $target_page = $p[$_] + 16 * $thisSignature; | |||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | next if $target_page > $inpPgNum; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | $rotation = $_ % 4 > 1 ? $rot_extra + 180 : $rot_extra; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 186 | 0 | copyPageFromInputToOutput ({page => $target_page, | |||||||||||||||||||||||||||||||||||||
| 187 | rotate => $rotation, x => $x[$_], y => $y[$_]}); | ||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ++$numPagImposed; | |||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | last if $numPagImposed == $inpPgNum; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||
| 192 | 0 | &closeInputFile; | |||||||||||||||||||||||||||||||||||||
| 193 | 0 | &closeOutputFile; | |||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||
| 196 | 1 | ▶ | &main if not caller(); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||
| 199 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | sub newPageInOutputFile { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
newPageInOutputFile: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 201 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | die "[!] No output file, you must call createOutputFile first.\n" if ! $Gpos; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | &writePage if $Gstream; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ++$GobjNr; | |||||||||||||||||||||||||||||||||||||
| 206 | 0 | $GpageObjNr = $GobjNr; | |||||||||||||||||||||||||||||||||||||
| 207 | 0 | undef %GpageXObject; | |||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||
| 209 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||
| 213 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | sub copyPageFromInputToOutput { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
copyPageFromInputToOutput: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 215 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | die "[!] No output file, you have to call createOutputFile first.\n" if ! $Gpos; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 217 | 0 | my $param = $_[0]; | |||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | my $pagenumber = $param->{'page'} or 1; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | my $x = $param->{'x'} or 0; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | my $y = $param->{'y'} or 0; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | my $rotate = $param->{'rotate'} or 0; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||
| 223 | 0 | state $formNr; # Este uso de "state" requiere v5.10 (que salió en 2007) | |||||||||||||||||||||||||||||||||||||
| 224 | 0 | ++$formNr; | |||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||
| 226 | 0 | my $name = "Fm${formNr}"; | |||||||||||||||||||||||||||||||||||||
| 227 | 0 | my ($formRes, $formCont) = getPage($pagenumber); | |||||||||||||||||||||||||||||||||||||
| 228 | 0 | my $refNr = writeRes($formRes, $formCont); | |||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | die "[!] Page ${pagenumber} in ${GinFile} can't be used. Concatenate streams!\n" | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 230 | if !defined $refNr; | ||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | die "[!] Page ${pagenumber} doesn't exist in file ${GinFile}.\n" if !$refNr; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 232 | 0 | &writePageObjectsToOutputFile; | |||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||
| 234 | 0 | $Gstream .= "q\n". calcRotateMatrix($x, $y, $rotate) ."\n/Gs0 gs\n/${name} Do\nQ\n"; | |||||||||||||||||||||||||||||||||||||
| 235 | 0 | $GpageXObject{$name} = $refNr; | |||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||
| 237 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||
| 241 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | sub setInitGrState { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
setInitGrState: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 243 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 244 | 0 | ++$GobjNr; | |||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||
| 246 | 0 | $Gobject[$GobjNr] = $Gpos; | |||||||||||||||||||||||||||||||||||||
| 247 | 0 | $Gpos += syswrite $OUT_FILE, | |||||||||||||||||||||||||||||||||||||
| 248 | "${GobjNr} 0 obj<</Type/ExtGState/SA false/SM 0.02/TR2 /Default>>endobj\n"; | ||||||||||||||||||||||||||||||||||||||
| 249 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||
| 253 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | sub createPageResourceDict { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
createPageResourceDict: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 255 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 256 | 0 | my $resourceDict = "/ProcSet[/PDF/Text]/XObject<<"; | |||||||||||||||||||||||||||||||||||||
| 257 | 0 | $resourceDict .= "/${_} ${GpageXObject{${_}}} 0 R" for keys %GpageXObject; | |||||||||||||||||||||||||||||||||||||
| 258 | 0 | $resourceDict .= ">>/ExtGState<</Gs0 4 0 R>>"; | |||||||||||||||||||||||||||||||||||||
| 259 | # return $resourceDict; | ||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||
| 263 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | sub writePageResourceDict { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
writePageResourceDict: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 265 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 266 | 0 | my $resourceDict = $_[0]; | |||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||
| 268 | 0 | state %resources; | |||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||
| 270 | # Found one identical, use it: | ||||||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | return $resources{$resourceDict} if exists $resources{$resourceDict}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ++$GobjNr; | |||||||||||||||||||||||||||||||||||||
| 273 | # Save first 10 resources: | ||||||||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | $resources{$resourceDict} = $GobjNr if keys(%resources) < 10; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 275 | 0 | $Gobject[$GobjNr] = $Gpos; | |||||||||||||||||||||||||||||||||||||
| 276 | 0 | $resourceDict = "${GobjNr} 0 obj<<${resourceDict}>>endobj\n"; | |||||||||||||||||||||||||||||||||||||
| 277 | 0 | $Gpos += syswrite $OUT_FILE, $resourceDict; | |||||||||||||||||||||||||||||||||||||
| 278 | 0 | return $GobjNr; | |||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||
| 282 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | sub writePageStream { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
writePageStream: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 284 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 285 | 0 | ++$GobjNr; | |||||||||||||||||||||||||||||||||||||
| 286 | 0 | $Gobject[$GobjNr] = $Gpos; | |||||||||||||||||||||||||||||||||||||
| 287 | 0 | $Gpos += syswrite $OUT_FILE, "${GobjNr} 0 obj<</Length " . length($Gstream) | |||||||||||||||||||||||||||||||||||||
| 288 | . ">>stream\n${Gstream}\nendstream\nendobj\n"; | ||||||||||||||||||||||||||||||||||||||
| 289 | 0 | $Gobject[$GpageObjNr] = $Gpos; | |||||||||||||||||||||||||||||||||||||
| 290 | 0 | $Gstream = ""; | |||||||||||||||||||||||||||||||||||||
| 291 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||
| 295 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | sub writePageResources { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
writePageResources: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 297 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 298 | 0 | my ($parent, $resourceObject) = ($_[0], $_[1]); | |||||||||||||||||||||||||||||||||||||
| 299 | 0 | $Gpos += syswrite $OUT_FILE, "${GpageObjNr} 0 obj<</Type/Page/Parent ${parent} 0 " | |||||||||||||||||||||||||||||||||||||
| 300 | . "R/Contents ${GobjNr} 0 R/Resources ${resourceObject} 0 R>>endobj\n"; | ||||||||||||||||||||||||||||||||||||||
| 301 | 0 | push @{ $Gkids[0] }, $GpageObjNr; | |||||||||||||||||||||||||||||||||||||
| 302 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||
| 306 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 307 | 0 | ▶ | sub writePage { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
writePage: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 308 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 309 | 0 | ▶ | $Gparents[0] = ++$GobjNr if ! $Gparents[0]; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||
| 311 | 0 | my $parent = $Gparents[0]; | |||||||||||||||||||||||||||||||||||||
| 312 | 0 | my $resourceObjectNr = writePageResourceDict(&createPageResourceDict); | |||||||||||||||||||||||||||||||||||||
| 313 | 0 | &writePageStream; | |||||||||||||||||||||||||||||||||||||
| 314 | 0 | writePageResources($parent, $resourceObjectNr); | |||||||||||||||||||||||||||||||||||||
| 315 | 0 | ++$Gcounts[0]; | |||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | writePageNodes(8) if $Gcounts[0] > 9; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 317 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||
| 321 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | sub closeOutputFile { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
closeOutputFile: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 323 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 324 | 0 | ▶ | return if !$Gpos; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | &writePage if $Gstream; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 327 | 0 | my $endNode = &writeEndNode; | |||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||
| 329 | 0 | my $out_line = "1 0 obj<</Type/Catalog/Pages ${endNode} 0 R>>endobj\n"; | |||||||||||||||||||||||||||||||||||||
| 330 | 0 | $Gobject[1] = $Gpos; | |||||||||||||||||||||||||||||||||||||
| 331 | 0 | $Gpos += syswrite $OUT_FILE, $out_line; | |||||||||||||||||||||||||||||||||||||
| 332 | 0 | my $qty = $#Gobject; | |||||||||||||||||||||||||||||||||||||
| 333 | 0 | my $startxref = $Gpos; | |||||||||||||||||||||||||||||||||||||
| 334 | 0 | my $xrefQty = $qty + 1; | |||||||||||||||||||||||||||||||||||||
| 335 | 0 | $out_line = "xref\n0 ${xrefQty}\n0000000000 65535 f \n"; | |||||||||||||||||||||||||||||||||||||
| 336 | 0 | $out_line .= sprintf "%.10d 00000 n \n", $_ for @Gobject[1 .. $qty]; | |||||||||||||||||||||||||||||||||||||
| 337 | 0 | $out_line .= "trailer\n<<\n/Size ${xrefQty}\n/Root 1 0 R\n" | |||||||||||||||||||||||||||||||||||||
| 338 | . ">>\nstartxref\n${startxref}\n%%EOF\n"; | ||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||
| 340 | 0 | syswrite $OUT_FILE, $out_line; | |||||||||||||||||||||||||||||||||||||
| 341 | 0 | close $OUT_FILE; | |||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||
| 343 | 0 | $Gpos = 0; | |||||||||||||||||||||||||||||||||||||
| 344 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||
| 348 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | sub writePageNodes { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
writePageNodes: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 350 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 351 | 0 | my $qtyChildren = $_[0]; | |||||||||||||||||||||||||||||||||||||
| 352 | 0 | my $i = 0; | |||||||||||||||||||||||||||||||||||||
| 353 | 0 | my $j = 1; | |||||||||||||||||||||||||||||||||||||
| 354 | 0 | my $nodeObj; | |||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | while ( $qtyChildren < $#{ $Gkids[$i] } ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 357 | # Imprimir padre actual y pasar al siguiente nivel: | ||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | $Gparents[$j] = ++$GobjNr if ! $Gparents[$j] ; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||
| 360 | 0 | $nodeObj = | |||||||||||||||||||||||||||||||||||||
| 361 | "${Gparents[$i]} 0 obj<</Type/Pages/Parent ${Gparents[$j]} 0 R\n/Kids ["; | ||||||||||||||||||||||||||||||||||||||
| 362 | 0 | $nodeObj .= "${_} 0 R " for @{ $Gkids[$i] }; | |||||||||||||||||||||||||||||||||||||
| 363 | 0 | $nodeObj .= "]\n/Count ${Gcounts[$i]}>>endobj\n"; | |||||||||||||||||||||||||||||||||||||
| 364 | 0 | $Gobject[ $Gparents[$i] ] = $Gpos; | |||||||||||||||||||||||||||||||||||||
| 365 | 0 | $Gpos += syswrite $OUT_FILE, $nodeObj; | |||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||
| 367 | 0 | $Gcounts[$j] += $Gcounts[$i]; | |||||||||||||||||||||||||||||||||||||
| 368 | 0 | $Gcounts[$i] = 0; | |||||||||||||||||||||||||||||||||||||
| 369 | 0 | $Gkids[$i] = []; | |||||||||||||||||||||||||||||||||||||
| 370 | 0 | push @{ $Gkids[$j] }, $Gparents[$i]; | |||||||||||||||||||||||||||||||||||||
| 371 | 0 | undef $Gparents[$i]; | |||||||||||||||||||||||||||||||||||||
| 372 | 0 | ++$i; | |||||||||||||||||||||||||||||||||||||
| 373 | 0 | ++$j; | |||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||
| 375 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||
| 379 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 380 | 0 | ▶ | sub writeEndNode { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
writeEndNode: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 381 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 382 | 0 | my $nodeObj; | |||||||||||||||||||||||||||||||||||||
| 383 | 0 | my $endNode = $Gparents[-1]; # content of the last element | |||||||||||||||||||||||||||||||||||||
| 384 | 0 | my $si = $#Gparents; # index of the last element | |||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||
| 386 | 0 | ▶ | my $min = defined $Gparents[0] ? 0 : 1; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | for ( my $i = $min; $i < $si; ++$i ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | if ( defined $Gparents[$i] ) { # Only defined if there are kids | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 389 | # Find parent of current parent: | ||||||||||||||||||||||||||||||||||||||
| 390 | 0 | my $node; | |||||||||||||||||||||||||||||||||||||
| 391 | 0 | ▶ | for ( my $j = $i + 1 ; ( !$node ) ; ++$j ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 392 | 0 | ▶ | if ( $Gparents[$j] ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 393 | 0 | $node = $Gparents[$j]; | |||||||||||||||||||||||||||||||||||||
| 394 | 0 | $Gcounts[$j] += $Gcounts[$i]; | |||||||||||||||||||||||||||||||||||||
| 395 | 0 | push @{ $Gkids[$j] }, $Gparents[$i]; | |||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||
| 399 | 0 | $nodeObj = "${Gparents[$i]} 0 obj<</Type/Pages/Parent ${node} 0 R\n/Kids ["; | |||||||||||||||||||||||||||||||||||||
| 400 | 0 | $nodeObj .= "${_} 0 R " for @{ $Gkids[$i] }; | |||||||||||||||||||||||||||||||||||||
| 401 | 0 | $nodeObj .= "]/Count ${Gcounts[$i]}>>endobj\n"; | |||||||||||||||||||||||||||||||||||||
| 402 | 0 | $Gobject[ $Gparents[$i] ] = $Gpos; | |||||||||||||||||||||||||||||||||||||
| 403 | 0 | $Gpos += syswrite $OUT_FILE, $nodeObj; | |||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||
| 407 | # Arrange and print the end node: | ||||||||||||||||||||||||||||||||||||||
| 408 | 0 | $nodeObj = "${endNode} 0 obj<</Type/Pages/Kids ["; | |||||||||||||||||||||||||||||||||||||
| 409 | 0 | $nodeObj .= "${_} 0 R " for @{ $Gkids[$si] }; | |||||||||||||||||||||||||||||||||||||
| 410 | 0 | $nodeObj .= "]/Count ${Gcounts[$si]}/MediaBox [0 0 ${GoWid} ${GoHei}]>>endobj\n"; | |||||||||||||||||||||||||||||||||||||
| 411 | 0 | $Gobject[$endNode] = $Gpos; | |||||||||||||||||||||||||||||||||||||
| 412 | 0 | $Gpos += syswrite $OUT_FILE, $nodeObj; | |||||||||||||||||||||||||||||||||||||
| 413 | 0 | return $endNode; | |||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||
| 417 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 418 | 0 | ▶ | sub calcRotateMatrix { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
calcRotateMatrix: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 419 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 420 | 0 | my $str = "1 0 0 1 ${_[0]} ${_[1]} cm\n"; | |||||||||||||||||||||||||||||||||||||
| 421 | 0 | my $rotate = $_[2]; | |||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||
| 423 | 0 | ▶ | return $str if ! $rotate; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||
| 425 | 0 | my $upperX = 0; my $upperY = 0; | |||||||||||||||||||||||||||||||||||||
| 426 | 0 | my $radian = sprintf( "%.6f", $rotate / 57.2957795 ); # approx. | |||||||||||||||||||||||||||||||||||||
| 427 | 0 | my $Cos = sprintf( "%.6f", cos($radian) ); | |||||||||||||||||||||||||||||||||||||
| 428 | 0 | my $Sin = sprintf( "%.6f", sin($radian) ); | |||||||||||||||||||||||||||||||||||||
| 429 | 0 | my $negSin = $Sin * -1; | |||||||||||||||||||||||||||||||||||||
| 430 | 0 | $str .= "${Cos} ${Sin} ${negSin} ${Cos} ${upperX} ${upperY} cm\n"; | |||||||||||||||||||||||||||||||||||||
| 431 | # return $str; | ||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||
| 435 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 436 | 0 | ▶ | sub getRootAndMapGobjects { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
getRootAndMapGobjects: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 437 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 438 | 0 | my ( $xref, $tempRoot, $buf, $buf2 ); | |||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||
| 440 | 0 | sysseek $IN_FILE, -150, 2; | |||||||||||||||||||||||||||||||||||||
| 441 | 0 | sysread $IN_FILE, $buf, 200; | |||||||||||||||||||||||||||||||||||||
| 442 | 0 | ▶ | die "[!] File '${GinFile}' is encrypted, cannot be used. Aborting.\n" | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 443 | if $buf =~ m'Encrypt'; | ||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||
| 445 | 0 | ▶ | if ($buf =~ m'/Prev\s+\d') { # "Versioned" PDF file (several xref sections) | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | while ($buf =~ m'/Prev\s+(\d+)') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 447 | 0 | $xref = $1; | |||||||||||||||||||||||||||||||||||||
| 448 | 0 | sysseek $IN_FILE, $xref, 0; | |||||||||||||||||||||||||||||||||||||
| 449 | 0 | sysread $IN_FILE, $buf, 1024; | |||||||||||||||||||||||||||||||||||||
| 450 | # Reading 1024 bytes may NOT be enough. Read on till we find 1st %%EOF: | ||||||||||||||||||||||||||||||||||||||
| 451 | 0 | ▶ | until ($buf =~ m'%%EOF') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 452 | 0 | sysread $IN_FILE, $buf2, 1024; | |||||||||||||||||||||||||||||||||||||
| 453 | 0 | $buf .= $buf2; | |||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||
| 456 | } elsif ( $buf =~ m'\bstartxref\s+(\d+)' ) { # Non-versioned PDF file | ||||||||||||||||||||||||||||||||||||||
| 457 | 0 | $xref = $1; | |||||||||||||||||||||||||||||||||||||
| 458 | } else { | ||||||||||||||||||||||||||||||||||||||
| 459 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||
| 462 | 0 | ▶ | die "[!] Invalid XREF. Aborting.\n" if $xref > &getInputFileWeight; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 463 | 0 | populateGobjects($xref); | |||||||||||||||||||||||||||||||||||||
| 464 | 0 | $tempRoot = &getRootFromTraditionalXrefSection; | |||||||||||||||||||||||||||||||||||||
| 465 | 0 | ▶ | return 0 unless $tempRoot; # No Root object in ${GinFile}, aborting | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 466 | 0 | return $tempRoot; | |||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||
| 470 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 471 | 0 | ▶ | sub mapGobjectsFromTraditionalXref { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
mapGobjectsFromTraditionalXref: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 472 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 473 | 0 | my ( $idx, $qty, $readBytes ); | |||||||||||||||||||||||||||||||||||||
| 474 | 0 | sysseek $IN_FILE, $_[0], 0; | |||||||||||||||||||||||||||||||||||||
| 475 | 0 | ($qty, $idx) = &extractXrefSection; | |||||||||||||||||||||||||||||||||||||
| 476 | 0 | ▶ | while ($qty) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 477 | 0 | for (1 .. $qty) { | |||||||||||||||||||||||||||||||||||||
| 478 | 0 | sysread $IN_FILE, $readBytes, 20; | |||||||||||||||||||||||||||||||||||||
| 479 | 0 | ▶ | $GObjects{$idx} = $1 if $readBytes =~ m'^\s?(\d{10}) \d{5} n'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 480 | 0 | ++$idx; | |||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||
| 482 | 0 | ($qty, $idx) = &extractXrefSection; | |||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||
| 484 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||
| 488 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 489 | 0 | ▶ | sub populateGobjects { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
populateGobjects: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 490 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 491 | 0 | my $xrefPos = $_[0]; | |||||||||||||||||||||||||||||||||||||
| 492 | 0 | my $readBytes; | |||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||
| 494 | 0 | sysseek $IN_FILE, $xrefPos, 0; | |||||||||||||||||||||||||||||||||||||
| 495 | 0 | sysread $IN_FILE, $readBytes, 22; | |||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||
| 497 | 0 | ▶ | if ($readBytes =~ /^(xref$cr)/) { # Input PDF is v1.4 or lower | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 498 | 0 | mapGobjectsFromTraditionalXref($xrefPos + length($1)); | |||||||||||||||||||||||||||||||||||||
| 499 | } elsif ($readBytes =~ m'^\d+\s+\d+\s+obj') { # Input PDF is v1.5 or higher: uses xref streams | ||||||||||||||||||||||||||||||||||||||
| 500 | 0 | &dieInvalid; | |||||||||||||||||||||||||||||||||||||
| 501 | } else { # Input PDF has a malformed xref table | ||||||||||||||||||||||||||||||||||||||
| 502 | 0 | &dieInvalid; | |||||||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||
| 505 | 0 | &addSizeToGObjects; | |||||||||||||||||||||||||||||||||||||
| 506 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||
| 510 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 511 | 0 | ▶ | sub getRootFromTraditionalXrefSection { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
getRootFromTraditionalXrefSection: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 512 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 513 | 0 | my $readBytes = " "; | |||||||||||||||||||||||||||||||||||||
| 514 | 0 | my $buf; | |||||||||||||||||||||||||||||||||||||
| 515 | 0 | ▶ | while ($readBytes) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 516 | 0 | sysread $IN_FILE, $readBytes, 1024; | |||||||||||||||||||||||||||||||||||||
| 517 | 0 | $buf .= $readBytes; | |||||||||||||||||||||||||||||||||||||
| 518 | 0 | ▶ | return $1 if $buf =~ m'\/Root\s+(\d+)\s+\d+\s+R'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||||||||
| 520 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||
| 524 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 525 | 0 | ▶ | sub getContentOfObjectNr { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
getContentOfObjectNr: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 526 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 527 | 0 | my $index = $_[0]; | |||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||
| 529 | 0 | ▶ | return 0 if ! defined $GObjects{$index}; # A non-1.4 PDF | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 530 | 0 | my ($offset, $size) = @{ $GObjects{$index} }; | |||||||||||||||||||||||||||||||||||||
| 531 | 0 | sysseek $IN_FILE, $offset, 0; | |||||||||||||||||||||||||||||||||||||
| 532 | 0 | sysread ($IN_FILE, my $buf, $size); | |||||||||||||||||||||||||||||||||||||
| 533 | 0 | return $buf; | |||||||||||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||
| 537 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 538 | 0 | ▶ | sub writePageObjectsToOutputFile { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
writePageObjectsToOutputFile: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 539 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 540 | 0 | my ($objContent, $out_line, $part, $strPos, $old_one, $new_one); | |||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||
| 542 | 0 | for (@Gto_be_created) { | |||||||||||||||||||||||||||||||||||||
| 543 | 0 | $old_one = $_->[0]; | |||||||||||||||||||||||||||||||||||||
| 544 | 0 | $new_one = $_->[1]; | |||||||||||||||||||||||||||||||||||||
| 545 | 0 | $objContent = getContentOfObjectNr($old_one); | |||||||||||||||||||||||||||||||||||||
| 546 | 0 | ▶ | if ( $objContent =~ m'^(\d+ \d+ obj\s*<<)(.+)(>>\s*stream)'s ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 547 | 0 | $part = $2; | |||||||||||||||||||||||||||||||||||||
| 548 | 0 | $strPos = length($1) + length($2) + length($3); | |||||||||||||||||||||||||||||||||||||
| 549 | 0 | update_references_and_populate_to_be_created($part); | |||||||||||||||||||||||||||||||||||||
| 550 | 0 | $out_line = "${new_one} 0 obj\n<<${part}>>stream"; | |||||||||||||||||||||||||||||||||||||
| 551 | 0 | $out_line .= substr( $objContent, $strPos ); | |||||||||||||||||||||||||||||||||||||
| 552 | } else { | ||||||||||||||||||||||||||||||||||||||
| 553 | 0 | ▶ | $objContent = substr( $objContent, length($1) ) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 554 | if $objContent =~ m'^(\d+ \d+ obj)\b'; | ||||||||||||||||||||||||||||||||||||||
| 555 | 0 | update_references_and_populate_to_be_created($objContent); | |||||||||||||||||||||||||||||||||||||
| 556 | 0 | $out_line = "${new_one} 0 obj ${objContent}"; | |||||||||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||||||||
| 558 | 0 | $Gobject[$new_one] = $Gpos; | |||||||||||||||||||||||||||||||||||||
| 559 | 0 | $Gpos += syswrite $OUT_FILE, $out_line; | |||||||||||||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||||||||||||
| 561 | 0 | undef @Gto_be_created; | |||||||||||||||||||||||||||||||||||||
| 562 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||
| 566 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 567 | 0 | ▶ | sub dieInvalid { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
dieInvalid: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 568 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 569 | 0 | die "[!] File '${GinFile}' is not a valid v1.4 PDF file.\n" | |||||||||||||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||
| 573 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 574 | 0 | ▶ | sub setOutputPageDimensionAndSchema { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
setOutputPageDimensionAndSchema: not called CC=14 SCAR=53.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 575 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 576 | 0 | ▶ | &dieInvalid unless &getPageSizeAndSetMediabox; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||
| 578 | 0 | my $surface = $GmediaBox[2] * $GmediaBox[3]; | |||||||||||||||||||||||||||||||||||||
| 579 | 0 | my $measuresInMm = | |||||||||||||||||||||||||||||||||||||
| 580 | int($GmediaBox[2] / 72 * 25.4) . " x " . int($GmediaBox[3] / 72 * 25.4) . " mm"; | ||||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||||
| 582 | 0 | for ($surface) { | |||||||||||||||||||||||||||||||||||||
| 583 | 0 | ▶ | if (alike($_, $Gpaper{QuarterLetter})) {$GoWid = $DW; $GoHei = $DH; return "QT"}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 584 | 0 | ▶ | if (alike($_, $Gpaper{A6})) {$GoWid = $AW; $GoHei = $AH; return "A6"}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 585 | 0 | ▶ | if (alike($_, $Gpaper{HalfLetter})) {$GoWid = $DW; $GoHei = $DH; return "HT"}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 586 | 0 | ▶ | if (alike($_, $Gpaper{QuarterLegal})) {$GoWid = $GW; $GoHei = $GH; return "QG"}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 587 | 0 | ▶ | if (alike($_, $Gpaper{A5})) {$GoWid = $AW; $GoHei = $AH; return "A5"}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 588 | 0 | ▶ | if (alike($_, $Gpaper{HalfLegal})) {$GoWid = $GW; $GoHei = $GH; return "HG"}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 589 | 0 | ▶ | if (alike($_, $Gpaper{Letter})) {$GoWid = $KW; $GoHei = $KH; return "LT"}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 590 | 0 | ▶ | if (alike($_, $Gpaper{A4})) {$GoWid = $JW; $GoHei = $JH; return "A4"}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 591 | 0 | ▶ | if (alike($_, $Gpaper{Legal})) {return "USlegal, ${measuresInMm}"}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 592 | 0 | ▶ | if (alike($_, $Gpaper{Tabloid})) {return "UStabloid, ${measuresInMm}"}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 593 | 0 | ▶ | if (alike($_, $Gpaper{A3})) {return "A3, ${measuresInMm}"}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||||||||||||
| 595 | 0 | return "unknown, ${measuresInMm}"; | |||||||||||||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||
| 599 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 600 | 0 | ▶ | sub alike { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
alike: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 601 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 602 | 0 | my $num1 = $_[0]; my $num2 = $_[1]; | |||||||||||||||||||||||||||||||||||||
| 603 | 0 | my $tolerance = 1500; | |||||||||||||||||||||||||||||||||||||
| 604 | 0 | ▶ | return 0 if $num1 > $num2 + $tolerance or $num1 < $num2 - $tolerance; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$num1 > $num2 + $tolerance or $num1 < $num2 - $tolerance
MC/DC0%0/2
$num1 > $num2 + $tolerance or $num1 < $num2 - $tolerance
$num1 > $num2 + $tolerance
$num1 < $num2 - $tolerance
Truth table0%0/3
A or B
A= $num1 > $num2 + $toleranceB= $num1 < $num2 - $tolerance
| |||||||||||||||||||||||||||||||||||||||
| 605 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||
| 609 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 610 | 0 | ▶ | sub getPage { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
getPage: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 611 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 612 | 0 | my $pagenumber = $_[0]; | |||||||||||||||||||||||||||||||||||||
| 613 | 0 | ▶ | die "[!] Page requested (${pagenumber}) does not exist. Aborting.\n" | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 614 | if $pagenumber > &getInputPageCount; | ||||||||||||||||||||||||||||||||||||||
| 615 | 0 | my ($formRes, $formCont); | |||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||
| 617 | 0 | my $thisPageObjContent = xformObjForThisPage($pagenumber); | |||||||||||||||||||||||||||||||||||||
| 618 | 0 | ($formRes, $formCont) = parseAsResourcesAndContentRef($thisPageObjContent); | |||||||||||||||||||||||||||||||||||||
| 619 | # return ($formRes, $formCont); | ||||||||||||||||||||||||||||||||||||||
| 620 | } | ||||||||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||
| 623 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 624 | 0 | ▶ | sub writeRes { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
writeRes: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 625 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 626 | 0 | my ($formRes, $objNr) = ($_[0], $_[1]); | |||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||
| 628 | 0 | my $objContent = getContentOfObjectNr($objNr); | |||||||||||||||||||||||||||||||||||||
| 629 | 0 | $objContent =~ m'^(\d+ \d+ obj\s*<<)(.+)(>>\s*stream)'s; | |||||||||||||||||||||||||||||||||||||
| 630 | 0 | my $strPos = length($1) + length($2) + length($3); | |||||||||||||||||||||||||||||||||||||
| 631 | 0 | my $newPart = "<</Type/XObject/Subtype/Form/FormType 1/Resources ${formRes}" | |||||||||||||||||||||||||||||||||||||
| 632 | . "/BBox [@{GmediaBox}] ${2}"; | ||||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||||
| 634 | 0 | ++$GobjNr; | |||||||||||||||||||||||||||||||||||||
| 635 | 0 | $Gobject[$GobjNr] = $Gpos; | |||||||||||||||||||||||||||||||||||||
| 636 | 0 | my $reference = $GobjNr; | |||||||||||||||||||||||||||||||||||||
| 637 | 0 | update_references_and_populate_to_be_created($newPart); | |||||||||||||||||||||||||||||||||||||
| 638 | 0 | my $out_line = "${reference} 0 obj\n${newPart}>>\nstream"; | |||||||||||||||||||||||||||||||||||||
| 639 | 0 | $out_line .= substr( $objContent, $strPos ); | |||||||||||||||||||||||||||||||||||||
| 640 | 0 | $Gpos += syswrite $OUT_FILE, $out_line; | |||||||||||||||||||||||||||||||||||||
| 641 | 0 | return $reference; | |||||||||||||||||||||||||||||||||||||
| 642 | } | ||||||||||||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||||||
| 645 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 646 | 0 | ▶ | sub xformObjForThisPage { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
xformObjForThisPage: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 647 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 648 | 0 | my $pagenumber = $_[0]; | |||||||||||||||||||||||||||||||||||||
| 649 | 0 | my ($objContent, $vector, @pageObj, @pageObjBackup, $pageAccumulator); | |||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||||
| 651 | 0 | ▶ | return 0 unless $GpagesObjContent =~ m'/Kids\s*\[([^\]]+)'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 652 | 0 | $vector = $1; | |||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||
| 654 | 0 | $pageAccumulator = 0; | |||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||
| 656 | 0 | ▶ | push @pageObj, $1 while $vector =~ m'(\d+)\s+\d+\s+R'g; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 657 | 0 | ▶ | while ( $pageAccumulator < $pagenumber ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 658 | 0 | @pageObjBackup = @pageObj; | |||||||||||||||||||||||||||||||||||||
| 659 | 0 | undef @pageObj; | |||||||||||||||||||||||||||||||||||||
| 660 | 0 | ▶ | last if ! @pageObjBackup; # $pagenumber is > than number of pages in PDF | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 661 | 0 | for (@pageObjBackup) { | |||||||||||||||||||||||||||||||||||||
| 662 | 0 | $objContent = getContentOfObjectNr($_); | |||||||||||||||||||||||||||||||||||||
| 663 | 0 | ▶ | if ( $objContent =~ m'/Count\s+(\d+)' ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 664 | 0 | ▶ | if ( ( $pageAccumulator + $1 ) < $pagenumber ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 665 | 0 | $pageAccumulator += $1; | |||||||||||||||||||||||||||||||||||||
| 666 | } else { | ||||||||||||||||||||||||||||||||||||||
| 667 | 0 | ▶ | $vector = $1 if $objContent =~ m'/Kids\s*\[([^\]]+)' ; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 668 | 0 | ▶ | push @pageObj, $1 while $vector =~ m'(\d+)\s+\d+\s+R'g; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 669 | 0 | last; | |||||||||||||||||||||||||||||||||||||
| 670 | } | ||||||||||||||||||||||||||||||||||||||
| 671 | } else { | ||||||||||||||||||||||||||||||||||||||
| 672 | 0 | ++$pageAccumulator; | |||||||||||||||||||||||||||||||||||||
| 673 | } | ||||||||||||||||||||||||||||||||||||||
| 674 | 0 | ▶ | last if $pageAccumulator == $pagenumber; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 675 | } | ||||||||||||||||||||||||||||||||||||||
| 676 | } | ||||||||||||||||||||||||||||||||||||||
| 677 | 0 | return $objContent; | |||||||||||||||||||||||||||||||||||||
| 678 | } | ||||||||||||||||||||||||||||||||||||||
| 679 | |||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||
| 681 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 682 | 0 | ▶ | sub getPageSizeAndSetMediabox { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
getPageSizeAndSetMediabox: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 683 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 684 | 0 | my $objContent; | |||||||||||||||||||||||||||||||||||||
| 685 | 0 | ▶ | if ($GpagesObjContent =~ m'MediaBox') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 686 | 0 | $objContent = $GpagesObjContent; | |||||||||||||||||||||||||||||||||||||
| 687 | } else { | ||||||||||||||||||||||||||||||||||||||
| 688 | 0 | $objContent = xformObjForThisPage(1); | |||||||||||||||||||||||||||||||||||||
| 689 | 0 | ▶ | $objContent =~ m'MediaBox' or return 0; # Meaning "failure" | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 690 | } | ||||||||||||||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||||||||||||
| 692 | # Assume all input PDF pages have the same dimensions as first MediaBox found: | ||||||||||||||||||||||||||||||||||||||
| 693 | 0 | ▶ | if (! @GmediaBox) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 694 | 0 | for ($objContent) { | |||||||||||||||||||||||||||||||||||||
| 695 | 0 | ▶ | if (m'MediaBox\s*\[\s*([\S]+)\s+([\S]+)\s+([\S]+)\s+([\S]+)\s*\]') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 696 | 0 | @GmediaBox = ($1, $2, $3, $4); | |||||||||||||||||||||||||||||||||||||
| 697 | } elsif (m'MediaBox\s*(\d+)\s+\d+\s+R\b') { # Pagesize to be found in reference | ||||||||||||||||||||||||||||||||||||||
| 698 | 0 | my $ref = getContentOfObjectNr($1); | |||||||||||||||||||||||||||||||||||||
| 699 | 0 | ▶ | if ($ref =~ m'\[\s*([\S]+)\s+([\S]+)\s+([\S]+)\s+([\S]+)\s*\]') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 700 | 0 | @GmediaBox = ($1, $2, $3, $4) | |||||||||||||||||||||||||||||||||||||
| 701 | } else { | ||||||||||||||||||||||||||||||||||||||
| 702 | 0 | return 0; # Meaning "failure" | |||||||||||||||||||||||||||||||||||||
| 703 | } | ||||||||||||||||||||||||||||||||||||||
| 704 | } | ||||||||||||||||||||||||||||||||||||||
| 705 | } | ||||||||||||||||||||||||||||||||||||||
| 706 | } | ||||||||||||||||||||||||||||||||||||||
| 707 | 0 | return 1; # Meaning "success" | |||||||||||||||||||||||||||||||||||||
| 708 | } | ||||||||||||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||||||||||||
| 711 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 712 | 0 | ▶ | sub parseAsResourcesAndContentRef { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
parseAsResourcesAndContentRef: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 713 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 714 | 0 | my $objContent = $_[0]; | |||||||||||||||||||||||||||||||||||||
| 715 | 0 | my ($resources, $formCont); | |||||||||||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||||||||||||
| 717 | 0 | ▶ | $formCont = $1 if $objContent =~ m'/Contents\s+(\d+)' | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$objContent =~ m[/Contents\s+(\d+)] or $objContent =~ m(/Contents\s*\[\s*(\d+)\s+\d+\s+R\s*\])
MC/DC0%0/2
$objContent =~ m[/Contents\s+(\d+)] or $objContent =~ m(/Contents\s*\[\s*(\d+)\s+\d+\s+R\s*\])
$objContent =~ m[/Contents\s+(\d+)]
$objContent =~ m(/Contents\s*\[\s*(\d+)\s+\d+\s+R\s*\])
Truth table0%0/3
A or B
A= $objContent =~ m[/Contents\s+(\d+)]B= $objContent =~ m(/Contents\s*\[\s*(\d+)\s+\d+\s+R\s*\])
| |||||||||||||||||||||||||||||||||||||||
| 718 | or $objContent =~ m'/Contents\s*\[\s*(\d+)\s+\d+\s+R\s*\]'; | ||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||
| 720 | 0 | $resources = getResourcesFromObj($objContent); | |||||||||||||||||||||||||||||||||||||
| 721 | 0 | return ($resources, $formCont); | |||||||||||||||||||||||||||||||||||||
| 722 | } | ||||||||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||||||
| 724 | |||||||||||||||||||||||||||||||||||||||
| 725 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 726 | 0 | ▶ | sub getResourcesFromObj { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
getResourcesFromObj: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 727 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 728 | 0 | my $objContent = $_[0]; | |||||||||||||||||||||||||||||||||||||
| 729 | 0 | my $resources; | |||||||||||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||||||||||||
| 731 | 0 | ▶ | return $1 if $objContent =~ m'Resources\s+(\d+\s+\d+\s+R)'; # Reference (95%) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 732 | 0 | ▶ | if ( $objContent =~ m'^.+/Resources's ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 733 | # The resources are a dictionary. The whole is copied (morfologia.pdf): | ||||||||||||||||||||||||||||||||||||||
| 734 | 0 | my $k; | |||||||||||||||||||||||||||||||||||||
| 735 | 0 | ( undef, $objContent ) = split /\/Resources/, $objContent; | |||||||||||||||||||||||||||||||||||||
| 736 | 0 | $objContent =~ s/<</#<</g; | |||||||||||||||||||||||||||||||||||||
| 737 | 0 | $objContent =~ s/>>/>>#/g; | |||||||||||||||||||||||||||||||||||||
| 738 | 0 | for ( split /#/, $objContent ) { | |||||||||||||||||||||||||||||||||||||
| 739 | 0 | ▶ | if ( m'\S' ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 740 | 0 | $resources .= $_; | |||||||||||||||||||||||||||||||||||||
| 741 | 0 | ▶ | ++$k if m'<<'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 742 | 0 | ▶ | --$k if m'>>'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 743 | 0 | ▶ | last if $k == 0; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 744 | } | ||||||||||||||||||||||||||||||||||||||
| 745 | } | ||||||||||||||||||||||||||||||||||||||
| 746 | } | ||||||||||||||||||||||||||||||||||||||
| 747 | 0 | return $resources; | |||||||||||||||||||||||||||||||||||||
| 748 | } | ||||||||||||||||||||||||||||||||||||||
| 749 | |||||||||||||||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||||||||||||
| 751 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 752 | 0 | ▶ | sub getInputPageCount { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
getInputPageCount: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 753 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 754 | 0 | state $maxPages; | |||||||||||||||||||||||||||||||||||||
| 755 | 0 | ▶ | return $maxPages if defined $maxPages; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 756 | 0 | my $objContent; | |||||||||||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||||||||||||
| 758 | 0 | ▶ | return 0 unless eval { $objContent = getContentOfObjectNr($GrootNr); 1; }; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 759 | 0 | ▶ | if ( $objContent =~ m'/Pages\s+(\d+)\s+\d+\s+R' ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 760 | 0 | $objContent = getContentOfObjectNr($1); | |||||||||||||||||||||||||||||||||||||
| 761 | 0 | ▶ | $maxPages = $1 if $objContent =~ m'/Count\s+(\d+)'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 762 | } | ||||||||||||||||||||||||||||||||||||||
| 763 | 0 | return $maxPages; | |||||||||||||||||||||||||||||||||||||
| 764 | } | ||||||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||||
| 766 | |||||||||||||||||||||||||||||||||||||||
| 767 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 768 | 0 | ▶ | sub openInputFile { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
openInputFile: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 769 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 770 | 0 | $GinFile = $_[0]; | |||||||||||||||||||||||||||||||||||||
| 771 | 0 | my ( $inputPageSize, $inputPageCount, $c ); | |||||||||||||||||||||||||||||||||||||
| 772 | 0 | ▶ | die "[!] File '${GinFile}' is empty.\n" if ! &getInputFileWeight; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||||||||
| 774 | 0 | ▶ | open($IN_FILE, q{<}, $GinFile) or die "[!] File '${GinFile}' cannot be read.\n"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 775 | 0 | binmode $IN_FILE; | |||||||||||||||||||||||||||||||||||||
| 776 | |||||||||||||||||||||||||||||||||||||||
| 777 | 0 | sysread $IN_FILE, $c, 5; | |||||||||||||||||||||||||||||||||||||
| 778 | 0 | ▶ | &dieInvalid if $c ne "%PDF-"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 779 | |||||||||||||||||||||||||||||||||||||||
| 780 | # Find root | ||||||||||||||||||||||||||||||||||||||
| 781 | 0 | $GrootNr = &getRootAndMapGobjects; | |||||||||||||||||||||||||||||||||||||
| 782 | 0 | ▶ | &dieInvalid unless $GrootNr > 0; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 783 | # Find $rootObjContent | ||||||||||||||||||||||||||||||||||||||
| 784 | 0 | my $rootObjContent = getContentOfObjectNr($GrootNr); | |||||||||||||||||||||||||||||||||||||
| 785 | 0 | ▶ | die "[!] File '${GinFile}' has no Pages section.\n" | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 786 | unless $rootObjContent =~ m'/Pages\s+(\d+)\s+\d+\s+R'; | ||||||||||||||||||||||||||||||||||||||
| 787 | # Find GpagesObjContent | ||||||||||||||||||||||||||||||||||||||
| 788 | 0 | $GpagesObjContent = getContentOfObjectNr($1); | |||||||||||||||||||||||||||||||||||||
| 789 | |||||||||||||||||||||||||||||||||||||||
| 790 | 0 | $inputPageSize = &setOutputPageDimensionAndSchema; | |||||||||||||||||||||||||||||||||||||
| 791 | 0 | $inputPageCount = &getInputPageCount; | |||||||||||||||||||||||||||||||||||||
| 792 | |||||||||||||||||||||||||||||||||||||||
| 793 | 0 | return ($inputPageCount, $inputPageSize); | |||||||||||||||||||||||||||||||||||||
| 794 | } | ||||||||||||||||||||||||||||||||||||||
| 795 | |||||||||||||||||||||||||||||||||||||||
| 796 | |||||||||||||||||||||||||||||||||||||||
| 797 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 798 | 0 | ▶ | sub getInputFileWeight { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
getInputFileWeight: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 799 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 800 | 0 | state $known; | |||||||||||||||||||||||||||||||||||||
| 801 | 0 | ▶ | return $known if $known; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 802 | 0 | $known = (stat($GinFile))[7]; | |||||||||||||||||||||||||||||||||||||
| 803 | } | ||||||||||||||||||||||||||||||||||||||
| 804 | |||||||||||||||||||||||||||||||||||||||
| 805 | |||||||||||||||||||||||||||||||||||||||
| 806 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 807 | 0 | ▶ | sub addSizeToGObjects { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
addSizeToGObjects: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 808 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 809 | 0 | my $size = &getInputFileWeight; | |||||||||||||||||||||||||||||||||||||
| 810 | # Objects are sorted numerically (<=>) and in reverse order ($b $a) | ||||||||||||||||||||||||||||||||||||||
| 811 | # according to their offset in the file: last first | ||||||||||||||||||||||||||||||||||||||
| 812 | 0 | my @offset = sort { $GObjects{$b} <=> $GObjects{$a} } keys %GObjects; | |||||||||||||||||||||||||||||||||||||
| 813 | 0 | my $pos; | |||||||||||||||||||||||||||||||||||||
| 814 | |||||||||||||||||||||||||||||||||||||||
| 815 | 0 | for (@offset) { | |||||||||||||||||||||||||||||||||||||
| 816 | 0 | $pos = $GObjects{$_}; | |||||||||||||||||||||||||||||||||||||
| 817 | 0 | $size -= $pos; | |||||||||||||||||||||||||||||||||||||
| 818 | 0 | $GObjects{$_} = [ $pos, $size ]; | |||||||||||||||||||||||||||||||||||||
| 819 | 0 | $size = $pos; | |||||||||||||||||||||||||||||||||||||
| 820 | } | ||||||||||||||||||||||||||||||||||||||
| 821 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 822 | } | ||||||||||||||||||||||||||||||||||||||
| 823 | |||||||||||||||||||||||||||||||||||||||
| 824 | |||||||||||||||||||||||||||||||||||||||
| 825 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 826 | 0 | ▶ | sub update_references_and_populate_to_be_created { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
update_references_and_populate_to_be_created: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 827 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 828 | 0 | $_[0] =~ s/\b(\d+)\s+\d+\s+R\b/&xform . " 0 R"/eg; | |||||||||||||||||||||||||||||||||||||
| 829 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 830 | } | ||||||||||||||||||||||||||||||||||||||
| 831 | |||||||||||||||||||||||||||||||||||||||
| 832 | |||||||||||||||||||||||||||||||||||||||
| 833 | # xform translates an old object reference to a new one | ||||||||||||||||||||||||||||||||||||||
| 834 | # and populates a table with what objects must be created | ||||||||||||||||||||||||||||||||||||||
| 835 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 836 | 0 | ▶ | sub xform { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
xform: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 837 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 838 | 0 | state %known; | |||||||||||||||||||||||||||||||||||||
| 839 | 0 | ▶ | return $known{$1} if exists $known{$1}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 840 | 0 | push @Gto_be_created, [ $1, ++$GobjNr ]; | |||||||||||||||||||||||||||||||||||||
| 841 | 0 | $known{$1} = $GobjNr; # implicit return value (faster) | |||||||||||||||||||||||||||||||||||||
| 842 | } | ||||||||||||||||||||||||||||||||||||||
| 843 | |||||||||||||||||||||||||||||||||||||||
| 844 | |||||||||||||||||||||||||||||||||||||||
| 845 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 846 | 0 | ▶ | sub extractXrefSection { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
extractXrefSection: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 847 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 848 | 0 | my $readBytes = ""; my ($qty, $idx, $c); | |||||||||||||||||||||||||||||||||||||
| 849 | |||||||||||||||||||||||||||||||||||||||
| 850 | 0 | sysread $IN_FILE, $c, 1; | |||||||||||||||||||||||||||||||||||||
| 851 | 0 | ▶ | sysread $IN_FILE, $c, 1 while $c =~ m'\s'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 852 | 0 | ▶ | while ( $c =~ /[\d ]/ ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 853 | 0 | $readBytes .= $c; | |||||||||||||||||||||||||||||||||||||
| 854 | 0 | sysread $IN_FILE, $c, 1; | |||||||||||||||||||||||||||||||||||||
| 855 | } | ||||||||||||||||||||||||||||||||||||||
| 856 | 0 | ▶ | ($qty, $idx) = ($2, $1) if $readBytes =~ m'^(\d+)\s+(\d+)'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 857 | # return ($qty, $idx); | ||||||||||||||||||||||||||||||||||||||
| 858 | } | ||||||||||||||||||||||||||||||||||||||
| 859 | |||||||||||||||||||||||||||||||||||||||
| 860 | |||||||||||||||||||||||||||||||||||||||
| 861 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 862 | 0 | ▶ | sub createOutputFile { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
createOutputFile: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 863 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 864 | 0 | ▶ | &closeOutputFile if $Gpos; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 865 | |||||||||||||||||||||||||||||||||||||||
| 866 | 0 | my $outputfile = $_[0]; | |||||||||||||||||||||||||||||||||||||
| 867 | 0 | my $pdf_signature = "%PDF-1.4\n%\â\ã\Ï\Ó\n"; # Keep this far from file beginning! | |||||||||||||||||||||||||||||||||||||
| 868 | |||||||||||||||||||||||||||||||||||||||
| 869 | 0 | ▶ | open( $OUT_FILE, q{>}, $outputfile ) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 870 | or die "[!] File '${outputfile}' cannot be created.\n"; | ||||||||||||||||||||||||||||||||||||||
| 871 | 0 | binmode $OUT_FILE; | |||||||||||||||||||||||||||||||||||||
| 872 | 0 | $Gpos = syswrite $OUT_FILE, $pdf_signature; | |||||||||||||||||||||||||||||||||||||
| 873 | |||||||||||||||||||||||||||||||||||||||
| 874 | 0 | $GobjNr = 2; # Objeto reservado 1 para raíz y 2 para nodo de pág. inicial | |||||||||||||||||||||||||||||||||||||
| 875 | 0 | $Gparents[0] = 2; | |||||||||||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||||||||||||
| 877 | 0 | &setInitGrState; | |||||||||||||||||||||||||||||||||||||
| 878 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 879 | } | ||||||||||||||||||||||||||||||||||||||
| 880 | |||||||||||||||||||||||||||||||||||||||
| 881 | |||||||||||||||||||||||||||||||||||||||
| 882 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 883 | 0 | ▶ | sub closeInputFile { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
closeInputFile: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 884 | ########################################################## | ||||||||||||||||||||||||||||||||||||||
| 885 | 0 | close $IN_FILE; | |||||||||||||||||||||||||||||||||||||
| 886 | } | ||||||||||||||||||||||||||||||||||||||
| 887 | |||||||||||||||||||||||||||||||||||||||
| 888 | 1 | 1; | |||||||||||||||||||||||||||||||||||||
| 889 | |||||||||||||||||||||||||||||||||||||||
| 890 | __END__ | ||||||||||||||||||||||||||||||||||||||