From d07abb5c42a816c94d05c5a1d7a78122e1b8b65c Mon Sep 17 00:00:00 2001 From: tcit Date: Thu, 24 Jul 2014 22:01:35 +0200 Subject: updated mpdf to 5.7.2 --- inc/3rdparty/libraries/mpdf/classes/barcode.php | 1 + inc/3rdparty/libraries/mpdf/classes/cssmgr.php | 10 +- inc/3rdparty/libraries/mpdf/classes/svg.php | 333 ++++++++++++++------- inc/3rdparty/libraries/mpdf/classes/tocontents.php | 3 +- 4 files changed, 228 insertions(+), 119 deletions(-) (limited to 'inc/3rdparty/libraries/mpdf/classes') diff --git a/inc/3rdparty/libraries/mpdf/classes/barcode.php b/inc/3rdparty/libraries/mpdf/classes/barcode.php index 2a002693..9a230f0e 100644 --- a/inc/3rdparty/libraries/mpdf/classes/barcode.php +++ b/inc/3rdparty/libraries/mpdf/classes/barcode.php @@ -871,6 +871,7 @@ class PDFBarcode { * Very capable code, excellent density, high reliability; in very wide use world-wide */ protected function barcode_c128($code, $type='B', $ean=false) { + $code = strcode2utf($code); // mPDF 5.7.1 Allows e.g. $chr = array( '212222', /* 00 */ '222122', /* 01 */ diff --git a/inc/3rdparty/libraries/mpdf/classes/cssmgr.php b/inc/3rdparty/libraries/mpdf/classes/cssmgr.php index 9bbbed9c..db325034 100644 --- a/inc/3rdparty/libraries/mpdf/classes/cssmgr.php +++ b/inc/3rdparty/libraries/mpdf/classes/cssmgr.php @@ -221,9 +221,8 @@ function ReadCSS($html) { } } - // mPDF 5.5.13 // Replace any background: url(data:image... with temporary image file reference - preg_match_all("/(url\(data:image\/(jpeg|gif|png);base64,(.*)\))/si", $CSSstr, $idata); + preg_match_all("/(url\(data:image\/(jpeg|gif|png);base64,(.*?)\))/si", $CSSstr, $idata); // mPDF 5.7.2 if (count($idata[0])) { for($i=0;$i0){ + if (substr_count($critere_style['fill'],'url')>0 && $element != 'line'){ // // couleur degradé $id_gradient = preg_replace("/url\(#([\w_]*)\)/i","$1",$critere_style['fill']); @@ -926,7 +939,7 @@ $md = $sy * cos($t); } // mPDF 4.4.005 Used as indirect setting for currentColor - else if (strtolower($critere_style['fill']) == 'currentcolor'){ + else if (strtolower($critere_style['fill']) == 'currentcolor' && $element != 'line'){ $col = $this->mpdf_ref->ConvertColor($critere_style['color']); if ($col) { // mPDF 5.0.051 @@ -937,7 +950,7 @@ $md = $sy * cos($t); $style .= 'F'; } } - else if ($critere_style['fill'] != 'none'){ + else if ($critere_style['fill'] != 'none' && $element != 'line'){ $col = $this->mpdf_ref->ConvertColor($critere_style['fill']); if ($col) { // mPDF 5.0.051 @@ -1898,12 +1911,10 @@ function Arcto($x1, $y1, $x2, $y2, $rx, $ry, $angle, $largeArcFlag, $sweepFlag) $xbase = $x; $ybase = -$y; - // mPDF 5.0.041 - // mPDF 5.0.051 - $path_cmd = sprintf('q BT /F%d %s %.3F Tf %.3F %.3F Td %s Tr %s %s %s Tj ET Q ',$this->mpdf_ref->CurrentFont['i'],$opacitystr, $this->mpdf_ref->FontSizePt,$pdfx*$this->kp,$pdfy*$this->kp,$render,$fillstr,$strokestr,$txt)."\n"; + // mPDF 5.7.2 + $path_cmd = sprintf('q BT /F%d %.3F Tf %s %.3F %.3F Td %s Tr %s %s %s Tj ET Q ',$this->mpdf_ref->CurrentFont['i'], $this->mpdf_ref->FontSizePt, $opacitystr, $pdfx*$this->kp,$pdfy*$this->kp,$render,$fillstr,$strokestr,$txt)."\n"; unset($this->txt_data[0], $this->txt_data[1],$this->txt_data[2]); - // mPDF 5.4.12 if (isset($current_style['font-size-parent'])) { $this->mpdf_ref->SetFontSize($current_style['font-size-parent']); } @@ -1912,7 +1923,6 @@ function Arcto($x1, $y1, $x2, $y2, $rx, $ry, $angle, $largeArcFlag, $sweepFlag) { return ' '; } -// $path_cmd .= 'h '; // mPDF 5.0 return $path_cmd; } @@ -1964,8 +1974,8 @@ function svgDefineTxtStyle($critere_style) $tmp = preg_replace("/(.*)stroke-dashoffset:\s*([a-z0-9.]*|none)(.*)/i","$2",$critere_style['style']); if ($tmp != $critere_style['style']){ $current_style['stroke-dashoffset'] = $tmp;} - // mPDF 5.0.039 - $tmp = preg_replace("/(.*)font-family:\s*([a-z0-9.]*|none)(.*)/i","$2",$critere_style['style']); + // mPDF 5.7.2 + $tmp = preg_replace("/(.*)font-family:\s*([a-z0-9.\"' ,\-]*|none)(.*)/i","$2",$critere_style['style']); if ($tmp != $critere_style['style']){ $critere_style['font-family'] = $tmp;} $tmp = preg_replace("/(.*)font-size:\s*([a-z0-9.]*|none)(.*)/i","$2",$critere_style['style']); @@ -2120,15 +2130,15 @@ function svgDefineTxtStyle($critere_style) } - // mPDF 4.4.003 if (preg_match('/xlink:href=/si',$data)) { + // GRADIENTS // Get links preg_match_all('/(<(linearGradient|radialgradient)[^>]*)xlink:href=["\']#(.*?)["\'](.*?)\/>/si',$data, $links); - if (count($links[0])) { $links[5] = array(); } // mPDF 4.5.010 + if (count($links[0])) { $links[5] = array(); } // Delete links from data - keeping in $links for ($i=0; $i' , $data); // mPDF 4.5.010 + $links[5][$i] = 'tmpLink'.RAND(100000,9999999); + $data = preg_replace('/'.preg_quote($links[0][$i],'/').'/is', '' , $data); } // Get targets preg_match_all('/<(linearGradient|radialgradient)([^>]*)id=["\'](.*?)["\'](.*?)>(.*?)<\/(linearGradient|radialgradient)>/si',$data, $m); @@ -2140,13 +2150,110 @@ function svgDefineTxtStyle($critere_style) } // Add back links this time as targets (gradients) for ($i=0; $i'. $stops[$links[3][$i]].'' ; // mPDF 4.5.010 - $data = preg_replace('//is', $def , $data); // mPDF 4.5.010 + $def = $links[1][$i] .' '.$links[4][$i].'>'. $stops[$links[3][$i]].'' ; + $data = preg_replace('//is', $def , $data); + } + + // mPDF 5.7.2 + // + preg_match_all('/]*)xlink:href=["\']#([^>]*?)["\']([^>]*)\/>/si',$data, $links); + for ($i=0; $i]*id=["\']'.$links[2][$i].'["\'][^>]*\/>/si',$data, $m)) { + $insert = $m[0]; + } + if (!$insert && preg_match('/<([a-zA-Z]*) [^>]*id=["\']'.$links[2][$i].'["\']/si',$data, $m)) { + + if (preg_match('/<'.$m[1].'[^>]*id=["\']'.$links[2][$i].'["\'][^>]*>.*?<\/'.$m[1].'>/si',$data, $m)) { + $insert = $m[0]; + } + } + + if ($insert) { + + $inners = $links[1][$i] . ' ' . $links[3][$i]; + // Change x,y coords to translate() + if (preg_match('/y=["\']([^>]*?)["\']/', $inners, $m)) { $y = $m[1]; } + else { $y = 0; } + if (preg_match('/x=["\']([^>]*?)["\']/', $inners, $m)) { $x = $m[1]; } + else { $x = 0; } + if ($x || $y) { + $inners = preg_replace('/(y|x)=["\']([^>]*?)["\']/', '', $inners); + if (preg_match('/transform=["\']([^>]*?)["\']/', $inners, $m)) { + if (preg_match('/translate\(\s*([0-9\.]+)\s*,\s*([0-9\.]+)\s*\)/', $m[1], $mm)) { + $transform = $m[1]; // transform="...." + $x += $mm[1]; + $y += $mm[2]; + $transform = preg_replace('/'.preg_quote($mm[0],'/').'/', '', $transform); + $transform = 'transform="'.$transform.' translate('.$x.', '.$y.')"'; + $inners = preg_replace('/'.preg_quote($m[0],'/').'/is', $transform, $inners); + } + else { + $inners = preg_replace('/'.preg_quote($m[0],'/').'/is', 'transform="'.$m[1].' translate('.$x.', '.$y.')"', $inners); + } + } + else { + $inners .= ' transform="translate('.$x.', '.$y.')"'; + } + } + } + $replacement = ''.$insert.''; + $data = preg_replace('/'.preg_quote($links[0][$i],'/').'/is', $replacement, $data); + } + preg_match_all('/]*)xlink:href=["\']#([^>]*?)["\']([^>]*)>\s*<\/use>/si',$data, $links); + for ($i=0; $i]*id=["\']'.$links[2][$i].'["\'][^>]*\/>/si',$data, $m)) { + $insert = $m[0]; + } + if (!$insert && preg_match('/<([a-zA-Z]*) [^>]*id=["\']'.$links[2][$i].'["\']/si',$data, $m)) { + + if (preg_match('/<'.$m[1].'[^>]*id=["\']'.$links[2][$i].'["\'][^>]*>.*?<\/'.$m[1].'>/si',$data, $m)) { + $insert = $m[0]; + } + } + + if ($insert) { + + $inners = $links[1][$i] . ' ' . $links[3][$i]; + // Change x,y coords to translate() + if (preg_match('/y=["\']([^>]*?)["\']/', $inners, $m)) { $y = $m[1]; } + else { $y = 0; } + if (preg_match('/x=["\']([^>]*?)["\']/', $inners, $m)) { $x = $m[1]; } + else { $x = 0; } + if ($x || $y) { + $inners = preg_replace('/(y|x)=["\']([^>]*?)["\']/', '', $inners); + if (preg_match('/transform=["\']([^>]*?)["\']/', $inners, $m)) { + if (preg_match('/translate\(\s*([0-9\.]+)\s*,\s*([0-9\.]+)\s*\)/', $m[1], $mm)) { + $transform = $m[1]; // transform="...." + $x += $mm[1]; + $y += $mm[2]; + $transform = preg_replace('/'.preg_quote($mm[0],'/').'/', '', $transform); + $transform = 'transform="'.$transform.' translate('.$x.', '.$y.')"'; + $inners = preg_replace('/'.preg_quote($m[0],'/').'/is', $transform, $inners); + } + else { + $inners = preg_replace('/'.preg_quote($m[0],'/').'/is', 'transform="'.$m[1].' translate('.$x.', '.$y.')"', $inners); + } + } + else { + $inners .= ' transform="translate('.$x.', '.$y.')"'; + } + } + $replacement = ''.$insert.''; + $data = preg_replace('/'.preg_quote($links[0][$i],'/').'/is', $replacement, $data); + + + } } } - // mPDF 4.4.003 - Removes + // Removes $data = preg_replace('//is', '', $data); - // mPDF 4.4.003 - Removes + // Removes $data = preg_replace('//is', '', $data); $this->svg_info['data'] = $data; @@ -2155,14 +2262,96 @@ function svgDefineTxtStyle($critere_style) // // chargement unique des fonctions - if(!function_exists("xml_svg2pdf_start")){ // mPDF 5.3.76 + if(!function_exists("xml_svg2pdf_start")){ function xml_svg2pdf_start($parser, $name, $attribs){ // // definition global $svg_class, $last_gradid; - // mPDF 4.4.003 + // mPDF 5.7.2 + if (strtolower($name) == 'lineargradient'){ + $tmp_gradient = array( + 'type' => 'linear', + 'info' => array( + 'x1' => $attribs['x1'], + 'y1' => $attribs['y1'], + 'x2' => $attribs['x2'], + 'y2' => $attribs['y2'] + ), + 'transform' => $attribs['gradientTransform'], + 'units' => $attribs['gradientUnits'], + 'spread' => $attribs['spreadMethod'], + 'color' => array() + ); + $last_gradid = $attribs['id']; + $svg_class->svgAddGradient($attribs['id'],$tmp_gradient); + return; + } + else if (strtolower($name) == 'radialgradient'){ + $tmp_gradient = array( + 'type' => 'radial', + 'info' => array( + 'x0' => $attribs['cx'], + 'y0' => $attribs['cy'], + 'x1' => $attribs['fx'], + 'y1' => $attribs['fy'], + 'r' => $attribs['r'] + ), + 'transform' => $attribs['gradientTransform'], + 'units' => $attribs['gradientUnits'], + 'spread' => $attribs['spreadMethod'], + 'color' => array() + ); + $last_gradid = $attribs['id']; + $svg_class->svgAddGradient($attribs['id'],$tmp_gradient); + return; + } + else if (strtolower($name) == 'stop'){ + if (!$last_gradid) break; + if (isset($attribs['style']) AND preg_match('/stop-color:\s*([^;]*)/i',$attribs['style'],$m)) { + $color = trim($m[1]); + } else if (isset($attribs['stop-color'])) { + $color = $attribs['stop-color']; + } + $col = $svg_class->mpdf_ref->ConvertColor($color); + + if ($col{0}==3 || $col{0}==5) { // RGB + $color_final = sprintf('%.3F %.3F %.3F',ord($col{1})/255,ord($col{2})/255,ord($col{3})/255); + $svg_class->svg_gradient[$last_gradid]['colorspace']='RGB'; + } + else if ($col{0}==4 || $col{0}==6) { // CMYK + $color_final = sprintf('%.3F %.3F %.3F %.3F',ord($col{1})/100,ord($col{2})/100,ord($col{3})/100,ord($col{4})/100); + $svg_class->svg_gradient[$last_gradid]['colorspace']='CMYK'; + } + else if ($col{0}==1) { // Grayscale + $color_final = sprintf('%.3F',ord($col{1})/255); + $svg_class->svg_gradient[$last_gradid]['colorspace']='Gray'; + } + + $stop_opacity = 1; + if (isset($attribs['style']) AND preg_match('/stop-opacity:\s*([0-9.]*)/i',$attribs['style'],$m)) { + $stop_opacity = $m[1]; + } else if (isset($attribs['stop-opacity'])) { + $stop_opacity = $attribs['stop-opacity']; + } + else if ($col{0}==5) { // RGBa + $stop_opacity = ord($col{4}/100); + } + else if ($col{0}==6) { // CMYKa + $stop_opacity = ord($col{5}/100); + } + + $tmp_color = array( + 'color' => $color_final, + 'offset' => $attribs['offset'], + 'opacity' => $stop_opacity + ); + array_push($svg_class->svg_gradient[$last_gradid]['color'],$tmp_color); + return; + } + if ($svg_class->inDefs) { return; } + $svg_class->xbase = 0; $svg_class->ybase = 0; switch (strtolower($name)){ @@ -2293,99 +2482,6 @@ function svgDefineTxtStyle($critere_style) $path_style = $svg_class->svgDefineStyle($critere_style); break; - case 'lineargradient': - $tmp_gradient = array( - 'type' => 'linear', - 'info' => array( - 'x1' => $attribs['x1'], - 'y1' => $attribs['y1'], - 'x2' => $attribs['x2'], - 'y2' => $attribs['y2'] - ), - 'transform' => $attribs['gradientTransform'], - 'units' => $attribs['gradientUnits'], /* mPDF 4.4.003 */ - 'spread' => $attribs['spreadMethod'], /* mPDF 5.0.040 */ - 'color' => array() - ); - - $last_gradid = $attribs['id']; - $svg_class->svgAddGradient($attribs['id'],$tmp_gradient); - break; - - case 'radialgradient': - $tmp_gradient = array( - 'type' => 'radial', - 'info' => array( - 'x0' => $attribs['cx'], - 'y0' => $attribs['cy'], - 'x1' => $attribs['fx'], - 'y1' => $attribs['fy'], - 'r' => $attribs['r'] - ), - 'transform' => $attribs['gradientTransform'], - 'units' => $attribs['gradientUnits'], /* mPDF 4.4.003 */ - 'spread' => $attribs['spreadMethod'], /* mPDF 5.0.040 */ - 'color' => array() - ); - - $last_gradid = $attribs['id']; - - $svg_class->svgAddGradient($attribs['id'],$tmp_gradient); - - break; - - case 'stop': - if (!$last_gradid) break; - // mPDF 4.4.003 // mPDF 5.0.040 - if (isset($attribs['style']) AND preg_match('/stop-color:\s*([^;]*)/i',$attribs['style'],$m)) { - $color = trim($m[1]); - } else if (isset($attribs['stop-color'])) { - $color = $attribs['stop-color']; - } - $col = $svg_class->mpdf_ref->ConvertColor($color); - - // mPDF 5.0.051 - // mPDF 5.3.74 - if ($col{0}==3 || $col{0}==5) { // RGB - $color_final = sprintf('%.3F %.3F %.3F',ord($col{1})/255,ord($col{2})/255,ord($col{3})/255); - $svg_class->svg_gradient[$last_gradid]['colorspace']='RGB'; - } - else if ($col{0}==4 || $col{0}==6) { // CMYK - $color_final = sprintf('%.3F %.3F %.3F %.3F',ord($col{1})/100,ord($col{2})/100,ord($col{3})/100,ord($col{4})/100); - $svg_class->svg_gradient[$last_gradid]['colorspace']='CMYK'; - } - else if ($col{0}==1) { // Grayscale - $color_final = sprintf('%.3F',ord($col{1})/255); - $svg_class->svg_gradient[$last_gradid]['colorspace']='Gray'; - } - - - // mPDF 5.0.020 - $stop_opacity = 1; - // mPDF 4.4.003 - if (isset($attribs['style']) AND preg_match('/stop-opacity:\s*([0-9.]*)/i',$attribs['style'],$m)) { - $stop_opacity = $m[1]; - } else if (isset($attribs['stop-opacity'])) { - $stop_opacity = $attribs['stop-opacity']; - } - // mPDF 5.0.051 - // mPDF 5.3.74 - else if ($col{0}==5) { // RGBa - $stop_opacity = ord($col{4}/100); - } - else if ($col{0}==6) { // CMYKa - $stop_opacity = ord($col{5}/100); - } - - $tmp_color = array( - 'color' => $color_final, - 'offset' => $attribs['offset'], - 'opacity' => $stop_opacity - ); - array_push($svg_class->svg_gradient[$last_gradid]['color'],$tmp_color); - break; - - case 'a': if (isset($attribs['xlink:href'])) { unset($attribs['xlink:href']); // this should be a hyperlink @@ -2403,7 +2499,6 @@ function svgDefineTxtStyle($critere_style) break; case 'text': - // mPDF 4.4.003 $array_style = $svg_class->svgDefineStyle($attribs); if ($array_style['transformations']) { $svg_class->svgWriteString(' q '.$array_style['transformations']); @@ -2436,6 +2531,7 @@ function svgDefineTxtStyle($critere_style) function characterData($parser, $data) { global $svg_class; + if ($svg_class->inDefs) { return; } // mPDF 5.7.2 if(isset($svg_class->txt_data[2])) { $svg_class->txt_data[2] .= $data; } @@ -2447,6 +2543,13 @@ function svgDefineTxtStyle($critere_style) function xml_svg2pdf_end($parser, $name){ global $svg_class; + // Don't output stuff inside + // mPDF 5.7.2 + if ($name == 'defs') { + $svg_class->inDefs = false; + return; + } + if ($svg_class->inDefs) { return; } switch($name){ case "g": diff --git a/inc/3rdparty/libraries/mpdf/classes/tocontents.php b/inc/3rdparty/libraries/mpdf/classes/tocontents.php index 4e0065d2..b1b61446 100644 --- a/inc/3rdparty/libraries/mpdf/classes/tocontents.php +++ b/inc/3rdparty/libraries/mpdf/classes/tocontents.php @@ -224,7 +224,6 @@ function insertTOC() { $tocstart=count($this->mpdf->pages); if ($toc_preHTML) { $this->mpdf->WriteHTML($toc_preHTML); } - // mPDF 5.6.19 $html ='
'; foreach($this->_toc as $t) { @@ -268,7 +267,7 @@ function insertTOC() { $s .= $this->mpdf->PrintBodyBackgrounds(); $s .= $this->mpdf->PrintPageBackgrounds(); - $this->mpdf->pages[$this->mpdf->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', "\n".$s."\n".'\\1', $this->mpdf->pages[$this->mpdf->page]); + $this->mpdf->pages[$this->mpdf->page] = preg_replace('/(___BACKGROUND___PATTERNS'.$this->mpdf->uniqstr.')/', "\n".$s."\n".'\\1', $this->mpdf->pages[$this->mpdf->page]); $this->mpdf->pageBackgrounds = array(); //Page footer -- cgit v1.2.3