Subversion Repositories cheapmusic

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
103 - 1
<?php
2
//
3
//  FPDI - Version 1.3.1
4
//
5
//    Copyright 2004-2009 Setasign - Jan Slabon
6
//
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
10
//
11
//      http://www.apache.org/licenses/LICENSE-2.0
12
//
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.
18
//
19
 
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('~'));
28
 
29
class FilterASCII85 {
30
 
31
    function error($msg) {
32
        die($msg);
33
    }
34
 
35
    function decode($in) {
36
        $out = '';
37
        $state = 0;
38
        $chn = null;
39
 
40
        $l = strlen($in);
41
 
42
        for ($k = 0; $k < $l; ++$k) {
43
            $ch = ord($in[$k]) & 0xff;
44
 
45
            if ($ch == ORD_tilde) {
46
                break;
47
            }
48
            if (preg_match('/^\s$/',chr($ch))) {
49
                continue;
50
            }
51
            if ($ch == ORD_z && $state == 0) {
52
                $out .= chr(0).chr(0).chr(0).chr(0);
53
                continue;
54
            }
55
            if ($ch < ORD_exclmark || $ch > ORD_u) {
56
                $this->error('Illegal character in ASCII85Decode.');
57
            }
58
 
59
            $chn[$state++] = $ch - ORD_exclmark;
60
 
61
            if ($state == 5) {
62
                $state = 0;
63
                $r = 0;
64
                for ($j = 0; $j < 5; ++$j)
65
                    $r = $r * 85 + $chn[$j];
66
                $out .= chr($r >> 24);
67
                $out .= chr($r >> 16);
68
                $out .= chr($r >> 8);
69
                $out .= chr($r);
70
            }
71
        }
72
        $r = 0;
73
 
74
        if ($state == 1)
75
            $this->error('Illegal length in ASCII85Decode.');
76
        if ($state == 2) {
77
            $r = $chn[0] * 85 * 85 * 85 * 85 + ($chn[1]+1) * 85 * 85 * 85;
78
            $out .= chr($r >> 24);
79
        }
80
        else if ($state == 3) {
81
            $r = $chn[0] * 85 * 85 * 85 * 85 + $chn[1] * 85 * 85 * 85  + ($chn[2]+1) * 85 * 85;
82
            $out .= chr($r >> 24);
83
            $out .= chr($r >> 16);
84
        }
85
        else if ($state == 4) {
86
            $r = $chn[0] * 85 * 85 * 85 * 85 + $chn[1] * 85 * 85 * 85  + $chn[2] * 85 * 85  + ($chn[3]+1) * 85 ;
87
            $out .= chr($r >> 24);
88
            $out .= chr($r >> 16);
89
            $out .= chr($r >> 8);
90
        }
91
 
92
        return $out;
93
    }
94
 
95
    function encode($in) {
96
        $this->error("ASCII85 encoding not implemented.");
97
    }
98
}