3 // FPDI - Version 1.2.1
5 // Copyright 2004-2008 Setasign - Jan Slabon
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
20 if (!defined("ORD_z"))
21 define("ORD_z",ord('z'));
22 if (!defined("ORD_exclmark"))
23 define("ORD_exclmark", ord('!'));
24 if (!defined("ORD_u"))
25 define("ORD_u", ord("u"));
26 if (!defined("ORD_tilde"))
27 define("ORD_tilde", ord('~'));
31 function ASCII85Decode(&$fpdi) {
36 function decode($in) {
43 for ($k = 0; $k < $l; ++$k) {
44 $ch = ord($in[$k]) & 0xff;
46 if ($ch == ORD_tilde) {
49 if (preg_match("/^\s$/",chr($ch))) {
52 if ($ch == ORD_z && $state == 0) {
53 $out .= chr(0).chr(0).chr(0).chr(0);
56 if ($ch < ORD_exclmark || $ch > ORD_u) {
57 $this->fpdi->error("Illegal character in ASCII85Decode.");
60 $chn[$state++] = $ch - ORD_exclmark;
65 for ($j = 0; $j < 5; ++$j)
66 $r = $r * 85 + $chn[$j];
67 $out .= chr($r >> 24);
68 $out .= chr($r >> 16);
76 $this->fpdi->error("Illegal length in ASCII85Decode.");
78 $r = $chn[0] * 85 * 85 * 85 * 85 + ($chn[1]+1) * 85 * 85 * 85;
79 $out .= chr($r >> 24);
81 else if ($state == 3) {
82 $r = $chn[0] * 85 * 85 * 85 * 85 + $chn[1] * 85 * 85 * 85 + ($chn[2]+1) * 85 * 85;
83 $out .= chr($r >> 24);
84 $out .= chr($r >> 16);
86 else if ($state == 4) {
87 $r = $chn[0] * 85 * 85 * 85 * 85 + $chn[1] * 85 * 85 * 85 + $chn[2] * 85 * 85 + ($chn[3]+1) * 85 ;
88 $out .= chr($r >> 24);
89 $out .= chr($r >> 16);