From a849cf38976043f75a02b82ec21da0f0fcd16406 Mon Sep 17 00:00:00 2001 From: Shikiryu Date: Wed, 1 Dec 2010 11:38:30 +0000 Subject: [PATCH] =?UTF-8?q?Ajout=20des=20"styles"=20(ne=20suis=20pas=20les?= =?UTF-8?q?=20sp=C3=A9cifications=20mais=20souvent=20utilis=C3=A9s)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- svgtoimage.php | 65 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 8 deletions(-) diff --git a/svgtoimage.php b/svgtoimage.php index 17d71c6..e0a1c6c 100644 --- a/svgtoimage.php +++ b/svgtoimage.php @@ -1,7 +1,6 @@ 0 @@ -160,7 +159,10 @@ class SVGTOIMAGE{ } } - /* return width and height from the SVG */ + /* + * DEPRECATED + * return width and height from the SVG + */ private function _getImageSize(){ $imageSize = array(); $imageSize['width'] = $this->_svgXML->attributes()->width; @@ -262,7 +264,18 @@ class SVGTOIMAGE{ case 'xlink:href':$href = $value; break; //case 'r' : $r = $value; break; // no, use transform instead ! case 'transform': $transform = $value; - case 'style' : if(strripos($value, 'display: none') || strripos($value, 'display:none')) return; break; + case 'style' : + $allStyle = split('[;:]', $value); + $i = 0; + while ($i < count($allStyle)) { + if($allStyle[$i] == 'display' && $allStyle[$i+1] == 'none') return; + if($allStyle[$i] == 'fill') $fill = $allStyle[$i+1]; + if($allStyle[$i] == 'stroke') $stroke = $allStyle[$i+1]; + if($allStyle[$i] == 'stroke-width') $strokeWidth = $allStyle[$i+1]; + $i=$i+2; + } + //if(strripos($value, 'display: none') || strripos($value, 'display:none')) return; + break; } } if($transform != ''){ @@ -397,7 +410,17 @@ class SVGTOIMAGE{ case 'fill': $fill = ($value == 'none') ? '' : $value; break; case 'stroke-width' : $strokeWidth = $value; break; case 'stroke-dasharray' : $strokeDasharray = $value; break; - case 'style' : if(strripos($value, 'display: none') || strripos($value, 'display:none')) return; break; + $allStyle = split('[;:]', $value); + $i = 0; + while ($i < count($allStyle)) { + if($allStyle[$i] == 'display' && $allStyle[$i+1] == 'none') return; + if($allStyle[$i] == 'fill') $fill = $allStyle[$i+1]; + if($allStyle[$i] == 'stroke') $stroke = $allStyle[$i+1]; + if($allStyle[$i] == 'stroke-width') $strokeWidth = $allStyle[$i+1]; + $i=$i+2; + } + //if(strripos($value, 'display: none') || strripos($value, 'display:none')) return; + break; } } if(strtolower(substr($path, 0,1)) != 'm' && !is_numeric(substr($path, 0,1))){ @@ -448,11 +471,15 @@ class SVGTOIMAGE{ $i = 0; $lastX = 0; $lastY = 0; + $lastMX = 0; + $lastMY = 0; while ($i < $nbArray) { // Changement de départ if(strtolower(substr($pathArray[$i], 0, 1)) == 'm'){ $lastX = $this->_parseInt($pathArray[$i]); + $lastMX = $this->_parseInt($pathArray[$i]); $lastY = $this->_parseInt($pathArray[$i+1]); + $lastMY = $this->_parseInt($pathArray[$i+1]); $lastOpe = 'm'; $i=$i+2; // Ligne @@ -497,8 +524,8 @@ class SVGTOIMAGE{ // Dernière ligne droite }elseif(strtolower(substr($pathArray[$i], 0, 1)) == 'z' || (is_numeric(substr($pathArray[$i], 0, 1)) && strtolower($lastOpe) == 'z')){ if($lastOpe == 'z' && $this->_debug) $this->_log->error('2 bouclages dans une boucle'); - $this->_drawLine($lastX , $lastY , $this->_parseInt($pathArray[0]) , $this->_parseInt($pathArray[1]) , IMG_COLOR_STYLED); - $lastOpe = 'z'; //utile? + $this->_drawLine($lastX , $lastY , $lastMX , $lastMY , IMG_COLOR_STYLED); + $lastOpe = 'z'; $i++; // Polyline }else{ @@ -624,7 +651,19 @@ class SVGTOIMAGE{ case 'stroke': $stroke = $value; break; case 'stroke-width' : $strokeWidth = $value; break; case 'stroke-dasharray' : $strokeDasharray = $value; break; - case 'style' : if(strripos($value, 'display: none') || strripos($value, 'display:none')) return; break; + //case 'style' : if(strripos($value, 'display: none') || strripos($value, 'display:none')) return; break; + case 'style' : + $allStyle = split('[;:]', $value); + $i = 0; + while ($i < count($allStyle)) { + if($allStyle[$i] == 'display' && $allStyle[$i+1] == 'none') return; + if($allStyle[$i] == 'fill') $fill = $allStyle[$i+1]; + if($allStyle[$i] == 'stroke') $stroke = $allStyle[$i+1]; + if($allStyle[$i] == 'stroke-width') $strokeWidth = $allStyle[$i+1]; + $i=$i+2; + } + //if(strripos($value, 'display: none') || strripos($value, 'display:none')) return; + break; } } if($width == 0 || $height == 0) @@ -669,7 +708,17 @@ class SVGTOIMAGE{ case 'fill': $fill = ($value == 'none') ? '' : $value; break; case 'stroke': $stroke = $value; break; case 'stroke-width' : $strokeWidth = $value; break; - case 'style' : if(strripos($value, 'display: none') || strripos($value, 'display:none')) return; break; + $allStyle = split('[;:]', $value); + $i = 0; + while ($i < count($allStyle)) { + if($allStyle[$i] == 'display' && $allStyle[$i+1] == 'none') return; + if($allStyle[$i] == 'fill') $fill = $allStyle[$i+1]; + if($allStyle[$i] == 'stroke') $stroke = $allStyle[$i+1]; + if($allStyle[$i] == 'stroke-width') $strokeWidth = $allStyle[$i+1]; + $i=$i+2; + } + //if(strripos($value, 'display: none') || strripos($value, 'display:none')) return; + break; } } if($points == '')