X-Git-Url: https://git.llucax.com/mecon/meconlib.git/blobdiff_plain/53dea79e14a592c07d0211cb7a7d93949c231fe1..59ef1bb1bc43dce4e8add06eac8e56ea9a043661:/lib/MECON/PDF/external/phppdflib.class.php diff --git a/lib/MECON/PDF/external/phppdflib.class.php b/lib/MECON/PDF/external/phppdflib.class.php index 3b4f360..f821c10 100755 --- a/lib/MECON/PDF/external/phppdflib.class.php +++ b/lib/MECON/PDF/external/phppdflib.class.php @@ -18,7 +18,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: phppdflib.class.php,v 2.5 2003/07/05 21:33:07 wmoran Exp $ + $Id: phppdflib.class.php,v 2.6 2003/08/29 21:15:21 wmoran Exp $ */ class pdffile @@ -655,11 +655,103 @@ class pdffile function png_embed($data) { // Sanity, make sure this is a png - if (substr($data, 0, 8) != "\137PNG\x0d\x0a\x1a\x0d") { - $this->_push_std_error(6011); + if (substr($data, 0, 8) != "\x89PNG\x0d\x0a\x1a\x0a") { + $this->_push_error(6011, 'brand not valid'); return false; } - + $data = substr($data, 12); + if (substr($data, 0, 4) != 'IHDR') { + $this->_push_error(6011, 'IHDR chunk missing'); + return false; + } + $data = substr($data, 4); + $width = $this->_int_val(substr($data, 0, 4)); + $height = $this->_int_val(substr($data, 4, 4)); + $data = substr($data, 8); + $bpc = ord(substr($data, 0, 1)); + $ct = ord(substr($data, 1, 1)); + if ($bpc > 8) { + $this->_push_error(6014, '16 bit PNG unsupported'); + return false; + } + switch ($ct) { + case 0 : $cspace = '/DeviceGray'; break; + case 2 : $cspace = '/DeviceRGB'; break; + case 3 : $cspace = '/Indexed'; break; + default: + $this->_push_error(6015, 'PNG with alpha not supported'); + return false; + } + if (ord(substr($data, 2, 1)) != 0) { + $this->_push_error(6016, 'Unknown compression type'); + return false; + } + if (ord(substr($data, 3, 1)) != 0) { + $this->_push_error(6017, 'Unknown PNG filter method'); + return false; + } + if (ord(substr($data, 4, 1)) != 0) { + $this->_push_error(6018, 'PNG interlacing not supported'); + return false; + } + $params['Predictor'] = '15'; + $params['Colors'] = $ct == 2 ? 3 : 1; + $params['BitsPerComponent'] = $bpc; + $params['Columns'] = $width; + $additional['DecodeParms'] = $this->_makedictionary($params); + $data = substr($data, 9); + $pal = ''; + $trns = ''; + $rawdata = ''; + do { + $n = $this->_int_val(substr($data, 0, 4)); + $type = substr($data, 4, 4); + $data = substr($data, 8); + switch ($type) { + case 'PLTE' : + $pal = substr($data, 0, $n); + $data = substr($data, $n + 4); + break; + + case 'tRNS' : + $t = substr($data, 0, $n); + if ($ct == 0) + $trns = array(ord(substr($t, 1, 1))); + elseif ($ct == 2) + $trns = array(ord(substr($t, 1, 1)), + ord(substr($t, 3, 1)), + ord(substr($t, 5, 1))); + else { + $pos = strpos($t, chr(0)); + if (is_int($pos)) + $trns = array($pos); + } + $data = substr($data, $n + 4); + break; + + case 'IDAT' : + $rawdata .= substr($data, 0, $n); + $data = substr($data, $n + 4); + break; + + case 'IEND' : + break 2; + + default : + $data = substr($data, $n + 4); + } + } while ($n); + if ($cspace == '/Indexed') { + $this->_push_error(6011, 'Indexed without palette'); + return false; + } + return $this->image_raw_embed($rawdata, + $cspace, + $bpc, + $height, + $width, + '/FlateDecode', + $additional); } function jfif_embed($data) @@ -747,16 +839,23 @@ class pdffile "/DCTDecode"); } - function image_raw_embed($data, $cspace, $bpc, $height, $width, $filter = "") + function image_raw_embed($data, + $cspace, + $bpc, + $height, + $width, + $filter = "", + $addtl = array()) { $o = $this->_addnewoid(); - $t["data"] = $data; - $t["colorspace"] = $cspace; - $t["bpc"] = $bpc; - $t["type"] = "image"; - $t["height"] = $height; - $t["width"] = $width; - $t["filter"] = $filter; + $t['additional'] = $addtl; + $t['data'] = $data; + $t['colorspace'] = $cspace; + $t['bpc'] = $bpc; + $t['type'] = "image"; + $t['height'] = $height; + $t['width'] = $width; + $t['filter'] = $filter; $this->objects[$o] = $t; return $o; } @@ -1157,6 +1256,8 @@ class pdffile function _make_raw_image($liboid) { + if (is_array($this->objects[$liboid]['additional'])) + $s = $this->objects[$liboid]['additional']; $s["Type"] = "/XObject"; $s["Subtype"] = "/Image"; $s["Width"] = $this->objects[$liboid]["width"]; @@ -1193,7 +1294,7 @@ class pdffile $a = deg2rad($angle); $cos = cos($a); $sin = sin($a); - $r = sprintf("%1\$01.6f %2\$01.6f %3\$01.6f %1\$01.6f 0 0", $cos, $sin, -$sin); + $r = sprintf("%1\$1.6f %2\$1.6f %3\$1.6f %1\$1.6f 0 0", $cos, $sin, -$sin); return $r; } @@ -1454,16 +1555,19 @@ class pdffile * for php, thus we need to make sure it's * available before using it. */ - if ( function_exists('gzcompress') && $this->builddata["compress"] ) { - // For now, we don't compress if already using a filter - if ( !isset($sarray["Filter"]) || strlen($sarray["Filter"]) == 0 ) { - $sarray["Filter"] = "/FlateDecode"; + $go = true; + if (function_exists('gzcompress') && $this->builddata['compress']) { + if ( !isset($sarray['Filter']) || strlen($sarray['Filter']) == 0 ) { + $sarray['Filter'] = '/FlateDecode'; } else { - $sarray['Filter'] = "[/FlateDecode " . $sarray['Filter'] . "]"; + if ($sarray['Filter'] != '/FlateDecode') + $sarray['Filter'] = '[/FlateDecode ' . $sarray['Filter'] . ']'; + else + $go = false; } - $data = gzcompress($data, $this->builddata["compress"]); + if ($go) $data = gzcompress($data, $this->builddata['compress']); } - $sarray["Length"] = strlen($data); + $sarray['Length'] = strlen($data); $os = $this->_makedictionary($sarray); $os .= "stream\x0a" . $data . "\x0aendstream"; return $os;