| @@ -1,65 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | |
| 4 | -// mPDF 6 | |
| 5 | -// Function only available PHP >=5.5.0 | |
| 6 | -if(!function_exists('imagepalettetotruecolor')) { | |
| 7 | - function imagepalettetotruecolor(&$src) { | |
| 8 | - if(imageistruecolor($src)) { | |
| 9 | - return(true); | |
| 10 | - } | |
| 11 | - $dst = imagecreatetruecolor(imagesx($src), imagesy($src)); | |
| 12 | - | |
| 13 | - imagecopy($dst, $src, 0, 0, 0, 0, imagesx($src), imagesy($src)); | |
| 14 | - imagedestroy($src); | |
| 15 | - | |
| 16 | - $src = $dst; | |
| 17 | - | |
| 18 | - return(true); | |
| 19 | - } | |
| 20 | -} | |
| 21 | - | |
| 22 | -// mPDF 5.7 | |
| 23 | -// Replace a section of an array with the elements in reverse | |
| 24 | -function array_splice_reverse(&$arr, $offset, $length) { | |
| 25 | - $tmp = (array_reverse(array_slice($arr, $offset, $length))); | |
| 26 | - array_splice($arr, $offset, $length, $tmp); | |
| 27 | -} | |
| 28 | - | |
| 29 | - | |
| 30 | -function array_insert(&$array, $value, $offset) { | |
| 31 | - if (is_array($array)) { | |
| 32 | - $array = array_values($array); | |
| 33 | - $offset = intval($offset); | |
| 34 | - if ($offset < 0 || $offset >= count($array)) { array_push($array, $value); } | |
| 35 | - else if ($offset == 0) { array_unshift($array, $value); } | |
| 36 | - else { | |
| 37 | - $temp = array_slice($array, 0, $offset); | |
| 38 | - array_push($temp, $value); | |
| 39 | - $array = array_slice($array, $offset); | |
| 40 | - $array = array_merge($temp, $array); | |
| 41 | - } | |
| 42 | - } | |
| 43 | - else { $array = array($value); } | |
| 44 | - return count($array); | |
| 45 | -} | |
| 46 | - | |
| 47 | -// mPDF 5.7.4 URLs | |
| 48 | -function urldecode_parts($url) { | |
| 49 | - $file=$url; | |
| 50 | - $query=''; | |
| 51 | - if (preg_match('/[?]/',$url)) { | |
| 52 | - $bits = preg_split('/[?]/',$url,2); | |
| 53 | - $file=$bits[0]; | |
| 54 | - $query='?'.$bits[1]; | |
| 55 | - } | |
| 56 | - $file = rawurldecode($file); | |
| 57 | - $query = urldecode($query); | |
| 58 | - return $file.$query; | |
| 59 | -} | |
| 60 | - | |
| 61 | - | |
| 62 | 4 | function _strspn($str1, $str2, $start=null, $length=null) { |
| 63 | 5 | $numargs = func_num_args(); |
| 64 | 6 | if ($numargs == 2) { |
| 65 | 7 | return strspn($str1, $str2); |
| @@ -110,8 +52,9 @@ | ||
| 110 | 52 | } |
| 111 | 53 | } |
| 112 | 54 | |
| 113 | 55 | function PreparePreText($text,$ff='//FF//') { |
| 56 | + // mPDF 5.0.053 | |
| 114 | 57 | $text = htmlspecialchars($text); |
| 115 | 58 | if ($ff) { $text = str_replace($ff,'</pre><formfeed /><pre>',$text); } |
| 116 | 59 | return ('<pre>'.$text.'</pre>'); |
| 117 | 60 | } |
| @@ -118,40 +61,22 @@ | ||
| 118 | 61 | |
| 119 | 62 | if(!function_exists('strcode2utf')){ |
| 120 | 63 | function strcode2utf($str,$lo=true) { |
| 121 | 64 | //converts all the &#nnn; and &#xhhh; in a string to Unicode |
| 122 | - // mPDF 5.7 | |
| 123 | - if ($lo) { | |
| 124 | - $str = preg_replace_callback('/\&\#([0-9]+)\;/m', 'code2utf_lo_callback', $str); | |
| 125 | - $str = preg_replace_callback('/\&\#x([0-9a-fA-F]+)\;/m', 'codeHex2utf_lo_callback', $str); | |
| 126 | - } | |
| 127 | - else { | |
| 128 | - $str = preg_replace_callback('/\&\#([0-9]+)\;/m', 'code2utf_callback', $str); | |
| 129 | - $str = preg_replace_callback('/\&\#x([0-9a-fA-F]+)\;/m', 'codeHex2utf_callback', $str); | |
| 130 | - } | |
| 65 | + if ($lo) { $lo = 1; } else { $lo = 0; } | |
| 66 | + $str = preg_replace('/\&\#([0-9]+)\;/me', "code2utf('\\1',{$lo})",$str); | |
| 67 | + $str = preg_replace('/\&\#x([0-9a-fA-F]+)\;/me', "codeHex2utf('\\1',{$lo})",$str); | |
| 131 | 68 | return $str; |
| 132 | 69 | } |
| 133 | 70 | } |
| 134 | -function code2utf_callback($matches) { | |
| 135 | - return code2utf($matches[1], 0); | |
| 136 | -} | |
| 137 | -function code2utf_lo_callback($matches) { | |
| 138 | - return code2utf($matches[1], 1); | |
| 139 | -} | |
| 140 | -function codeHex2utf_callback($matches) { | |
| 141 | - return codeHex2utf($matches[1], 0); | |
| 142 | -} | |
| 143 | -function codeHex2utf_lo_callback($matches) { | |
| 144 | - return codeHex2utf($matches[1], 1); | |
| 145 | -} | |
| 146 | 71 | |
| 147 | - | |
| 148 | 72 | if(!function_exists('code2utf')){ |
| 149 | 73 | function code2utf($num,$lo=true){ |
| 150 | 74 | //Returns the utf string corresponding to the unicode value |
| 75 | + //added notes - http://uk.php.net/utf8_encode | |
| 151 | 76 | if ($num<128) { |
| 152 | 77 | if ($lo) return chr($num); |
| 153 | - else return '&#'.$num.';'; | |
| 78 | + else return '&#'.$num.';'; // i.e. no change | |
| 154 | 79 | } |
| 155 | 80 | if ($num<2048) return chr(($num>>6)+192).chr(($num&63)+128); |
| 156 | 81 | if ($num<65536) return chr(($num>>12)+224).chr((($num>>6)&63)+128).chr(($num&63)+128); |
| 157 | 82 | if ($num<2097152) return chr(($num>>18)+240).chr((($num>>12)&63)+128).chr((($num>>6)&63)+128) .chr(($num&63)+128); |
| @@ -162,11 +87,13 @@ | ||
| 162 | 87 | |
| 163 | 88 | if(!function_exists('codeHex2utf')){ |
| 164 | 89 | function codeHex2utf($hex,$lo=true){ |
| 165 | 90 | $num = hexdec($hex); |
| 166 | - if (($num<128) && !$lo) return '&#x'.$hex.';'; | |
| 91 | + if (($num<128) && !$lo) return '&#x'.$hex.';'; // i.e. no change | |
| 167 | 92 | return code2utf($num,$lo); |
| 168 | 93 | } |
| 169 | 94 | } |
| 95 | + | |
| 96 | + | |
| 170 | 97 | |
| 171 | 98 | |
| 172 | 99 | ?> |