/application/helpers/mpdf/classes/svg.php
PHP | 2600 lines | 1990 code | 333 blank | 277 comment | 682 complexity | 6c44e0c0b88fc77a1c9b2fb137254866 MD5 | raw file
Possible License(s): LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- <?php
- // svg class modified for mPDF version 4.4.003 by Ian Back: based on -
- // svg2pdf fpdf class
- // sylvain briand (syb@godisaduck.com), modified by rick trevino (rtrevino1@yahoo.com)
- // http://www.godisaduck.com/svg2pdf_with_fpdf
- // http://rhodopsin.blogspot.com
- //
- // cette class etendue est open source, toute modification devra cependant etre repertoriée~
-
-
- // NB UNITS - Works in pixels as main units - converting to PDF units when outputing to PDF string
- // and on returning size
-
- class SVG {
-
- var $svg_gradient; // array - contient les infos sur les gradient fill du svg classé par id du svg
- var $svg_shadinglist; // array - contient les ids des objet shading
- var $svg_info; // array contenant les infos du svg voulue par l'utilisateur
- var $svg_attribs; // array - holds all attributes of root <svg> tag
- var $svg_style; // array contenant les style de groupes du svg
- var $svg_string; // String contenant le tracage du svg en lui męme.
- var $txt_data; // array - holds string info to write txt to image
- var $txt_style; // array - current text style
- var $mpdf_ref;
- var $xbase; // mPDF 4.4.003
- var $ybase; // mPDF 4.4.003
- var $svg_error; // mPDF 4.4.003
- var $subPathInit; // mPDF 4.4.003
- var $spxstart; // mPDF 4.4.003
- var $spystart; // mPDF 4.4.003
- var $kp; // mPDF 4.4.003 convert pixels to PDF units
- var $pathBBox; // mPDF 5.0.039
-
- function SVG(&$mpdf){
- $this->svg_gradient = array();
- $this->svg_shadinglist = array();
- $this->txt_data = array();
- $this->svg_string = '';
- $this->svg_info = array();
- $this->svg_attribs = array();
- $this->xbase = 0;
- $this->ybase = 0;
- $this->svg_error = false;
- $this->subPathInit = false; // mPDF 4.4.003
- $this->dashesUsed = false; // mPDF 5.0
- $this->mpdf_ref =& $mpdf;
-
- $this->kp = 72 / $mpdf->img_dpi; // mPDF 4.4.003 constant To convert pixels to pts/PDF units
- $this->kf = 1; // mPDF 5.0.039 constant To convert font size if re-mapped
- $this->pathBBox = array(); // mPDF 5.0.039
-
- $this->svg_style = array(
- array(
- 'fill' => 'black', // mPDF 4.4.008
- 'fill-opacity' => 1, // remplissage opaque par defaut
- 'fill-rule' => 'nonzero', // mode de remplissage par defaut
- 'stroke' => 'none', // pas de trait par defaut
- 'stroke-linecap' => 'butt', // style de langle par defaut
- 'stroke-linejoin' => 'miter', //
- 'stroke-miterlimit' => 4, // limite de langle par defaut
- 'stroke-opacity' => 1, // trait opaque par defaut
- 'stroke-width' => 1, // mPDF 4.4.011
- 'stroke-dasharray' => 0, // mPDF 4.4.003
- 'stroke-dashoffset' => 0, // mPDF 4.4.003
- 'color' => '' // mPDF 4.4.005
- )
- );
-
- $this->txt_style = array(
- array(
- 'fill' => 'black', // pas de remplissage par defaut
- 'font-family' => $mpdf->default_font,
- 'font-size' => $mpdf->default_font_size, // ****** this is pts
- 'font-weight' => 'normal', // normal | bold
- 'font-style' => 'normal', // italic | normal
- 'text-anchor' => 'start', // alignment: start, middle, end
- /* mPDF 5.0.041 */
- 'fill-opacity' => 1, // remplissage opaque par defaut
- 'fill-rule' => 'nonzero', // mode de remplissage par defaut
- 'stroke' => 'none', // pas de trait par defaut
- 'stroke-opacity' => 1, // trait opaque par defaut
- 'stroke-width' => 1, // mPDF 4.4.011
- 'color' => '' // mPDF 4.4.005
- )
- );
-
-
-
- }
-
- function svgGradient($gradient_info, $attribs, $element){
- $n = count($this->mpdf_ref->gradients)+1;
-
- // Get bounding dimensions of element
- $w = 100;
- $h = 100;
- $x_offset = 0;
- $y_offset = 0;
- if ($element=='rect') {
- $w = $attribs['width'];
- $h = $attribs['height'];
- $x_offset = $attribs['x'];
- $y_offset = $attribs['y'];
- }
- else if ($element=='ellipse') {
- $w = $attribs['rx']*2;
- $h = $attribs['ry']*2;
- $x_offset = $attribs['cx']-$attribs['rx'];
- $y_offset = $attribs['cy']-$attribs['ry'];
- }
- else if ($element=='circle') {
- $w = $attribs['r']*2;
- $h = $attribs['r']*2;
- $x_offset = $attribs['cx']-$attribs['r'];
- $y_offset = $attribs['cy']-$attribs['r'];
- }
- else if ($element=='polygon') {
- $pts = preg_split('/[ ,]+/', trim($attribs['points']));
- $maxr=$maxb=0;
- $minl=$mint=999999;
- for ($i=0;$i<count($pts); $i++) {
- if ($i % 2 == 0) { // x values
- $minl = min($minl,$pts[$i]);
- $maxr = max($maxr,$pts[$i]);
- }
- else { // y values
- $mint = min($mint,$pts[$i]);
- $maxb = max($maxb,$pts[$i]);
- }
- }
- $w = $maxr-$minl;
- $h = $maxb-$mint;
- $x_offset = $minl;
- $y_offset = $mint;
- }
- else if ($element=='path') {
- // mPDF 5.0.039
- if (is_array($this->pathBBox) && $this->pathBBox[2]>0) {
- $w = $this->pathBBox[2];
- $h = $this->pathBBox[3];
- $x_offset = $this->pathBBox[0];
- $y_offset = $this->pathBBox[1];
- }
- else {
- preg_match_all('/([a-z]|[A-Z])([ ,\-.\d]+)*/', $attribs['d'], $commands, PREG_SET_ORDER);
- $maxr=$maxb=0;
- $minl=$mint=999999;
- foreach($commands as $c){
- if(count($c)==3){
- list($tmp, $cmd, $arg) = $c;
- if ($cmd=='M' || $cmd=='L' || $cmd=='C' || $cmd=='S' || $cmd=='Q' || $cmd=='T') {
- $pts = preg_split('/[ ,]+/', trim($arg));
- for ($i=0;$i<count($pts); $i++) {
- if ($i % 2 == 0) { // x values
- $minl = min($minl,$pts[$i]);
- $maxr = max($maxr,$pts[$i]);
- }
- else { // y values
- $mint = min($mint,$pts[$i]);
- $maxb = max($maxb,$pts[$i]);
- }
- }
- }
- if ($cmd=='H') { // sets new x
- $minl = min($minl,$arg);
- $maxr = max($maxr,$arg);
- }
- if ($cmd=='V') { // sets new y
- $mint = min($mint,$arg);
- $maxb = max($maxb,$arg);
- }
- }
- }
- $w = $maxr-$minl;
- $h = $maxb-$mint;
- $x_offset = $minl;
- $y_offset = $mint;
- }
- }
- if (!$w || $w==-999999) { $w = 100; }
- if (!$h || $h==-999999) { $h = 100; }
- if ($x_offset==999999) { $x_offset = 0; }
- if ($y_offset==999999) { $y_offset = 0; }
-
- // mPDF 4.5.010
- // TRANSFORMATIONS
- $transformations = '';
- if (isset($gradient_info['transform'])){
- preg_match_all('/(matrix|translate|scale|rotate|skewX|skewY)\((.*?)\)/is',$gradient_info['transform'],$m);
- if (count($m[0])) {
- for($i=0; $i<count($m[0]); $i++) {
- $c = strtolower($m[1][$i]);
- $v = trim($m[2][$i]);
- $vv = preg_split('/[ ,]+/',$v);
- if ($c=='matrix' && count($vv)==6) {
- // mPDF 5.0.039
- // Note angle of rotation is reversed (from SVG to PDF), so vv[1] and vv[2] are negated
- // cf svgDefineStyle()
- $transformations .= sprintf(' %.3F %.3F %.3F %.3F %.3F %.3F cm ', $vv[0], -$vv[1], -$vv[2], $vv[3], $vv[4]*$this->kp, -$vv[5]*$this->kp);
- }
- else if ($c=='translate' && count($vv)) {
- $tm[4] = $vv[0];
- if (count($vv)==2) { $t_y = -$vv[1]; }
- else { $t_y = 0; }
- $tm[5] = $t_y;
- $transformations .= sprintf(' 1 0 0 1 %.3F %.3F cm ', $tm[4]*$this->kp, $tm[5]*$this->kp);
- }
- else if ($c=='scale' && count($vv)) {
- if (count($vv)==2) { $s_y = $vv[1]; }
- else { $s_y = $vv[0]; }
- $tm[0] = $vv[0];
- $tm[3] = $s_y;
- $transformations .= sprintf(' %.3F 0 0 %.3F 0 0 cm ', $tm[0], $tm[3]);
- }
- else if ($c=='rotate' && count($vv)) {
- $tm[0] = cos(deg2rad(-$vv[0]));
- $tm[1] = sin(deg2rad(-$vv[0]));
- $tm[2] = -$tm[1];
- $tm[3] = $tm[0];
- if (count($vv)==3) {
- $transformations .= sprintf(' 1 0 0 1 %.3F %.3F cm ', $vv[1]*$this->kp, -$vv[2]*$this->kp);
- }
- $transformations .= sprintf(' %.3F %.3F %.3F %.3F 0 0 cm ', $tm[0], $tm[1], $tm[2], $tm[3]);
- if (count($vv)==3) {
- $transformations .= sprintf(' 1 0 0 1 %.3F %.3F cm ', -$vv[1]*$this->kp, $vv[2]*$this->kp);
- }
- }
- else if ($c=='skewx' && count($vv)) {
- $tm[2] = tan(deg2rad(-$vv[0]));
- $transformations .= sprintf(' 1 0 %.3F 1 0 0 cm ', $tm[2]);
- }
- else if ($c=='skewy' && count($vv)) {
- $tm[1] = tan(deg2rad(-$vv[0]));
- $transformations .= sprintf(' 1 %.3F 0 1 0 0 cm ', $tm[1]);
- }
-
- }
- }
- }
-
-
- $return = "";
-
- // mPDF 5.0.039
- if (isset($gradient_info['units']) && strtolower($gradient_info['units'])=='userspaceonuse') {
- if ($transformations) { $return .= $transformations; }
- }
- // mPDF 5.0.040
- $spread = 'P'; // pad
- if (isset($gradient_info['spread'])) {
- if (strtolower($gradient_info['spread'])=='reflect') { $spread = 'F'; } // reflect
- else if (strtolower($gradient_info['spread'])=='repeat') { $spread = 'R'; } // repeat
- }
-
-
- for ($i=0; $i<(count($gradient_info['color'])); $i++) {
- if (stristr($gradient_info['color'][$i]['offset'], '%')!== false) { $gradient_info['color'][$i]['offset'] = ($gradient_info['color'][$i]['offset']+0)/100; }
- if (stristr($gradient_info['color'][($i+1)]['offset'], '%')!== false) { $gradient_info['color'][($i+1)]['offset'] = ($gradient_info['color'][($i+1)]['offset']+0)/100; }
- if ($gradient_info['color'][$i]['offset']<0) { $gradient_info['color'][$i]['offset'] = 0; }
- if ($gradient_info['color'][$i]['offset']>1) { $gradient_info['color'][$i]['offset'] = 1; }
- if ($i>0) {
- if ($gradient_info['color'][$i]['offset']<$gradient_info['color'][($i-1)]['offset']) {
- $gradient_info['color'][$i]['offset']=$gradient_info['color'][($i-1)]['offset'];
- }
- }
- }
-
- if ($gradient_info['color'][0]['offset']>0) {
- array_unshift($gradient_info['color'], $gradient_info['color'][0]);
- $gradient_info['color'][0]['offset'] = 0;
- }
- $ns = count($gradient_info['color']);
- if ($gradient_info['color'][($ns-1)]['offset']<1) {
- $gradient_info['color'][] = $gradient_info['color'][($ns-1)];
- $gradient_info['color'][($ns)]['offset'] = 1;
- }
- $ns = count($gradient_info['color']);
-
-
-
-
- if ($gradient_info['type'] == 'linear'){
- // mPDF 4.4.003
- if (isset($gradient_info['units']) && strtolower($gradient_info['units'])=='userspaceonuse') {
- if (isset($gradient_info['info']['x1'])) { $gradient_info['info']['x1'] = ($gradient_info['info']['x1']-$x_offset) / $w; }
- if (isset($gradient_info['info']['y1'])) { $gradient_info['info']['y1'] = ($gradient_info['info']['y1']-$y_offset) / $h; }
- if (isset($gradient_info['info']['x2'])) { $gradient_info['info']['x2'] = ($gradient_info['info']['x2']-$x_offset) / $w; }
- if (isset($gradient_info['info']['y2'])) { $gradient_info['info']['y2'] = ($gradient_info['info']['y2']-$y_offset) / $h; }
- }
- if (isset($gradient_info['info']['x1'])) { $x1 = $gradient_info['info']['x1']; }
- else { $x1 = 0; }
- if (isset($gradient_info['info']['y1'])) { $y1 = $gradient_info['info']['y1']; }
- else { $y1 = 0; }
- if (isset($gradient_info['info']['x2'])) { $x2 = $gradient_info['info']['x2']; }
- else { $x2 = 1; }
- if (isset($gradient_info['info']['y2'])) { $y2 = $gradient_info['info']['y2']; }
- else { $y2 = 0; }
-
- if (stristr($x1, '%')!== false) { $x1 = ($x1+0)/100; }
- if (stristr($x2, '%')!== false) { $x2 = ($x2+0)/100; }
- if (stristr($y1, '%')!== false) { $y1 = ($y1+0)/100; }
- if (stristr($y2, '%')!== false) { $y2 = ($y2+0)/100; }
-
- // mPDF 5.0.042
- $bboxw = $w;
- $bboxh = $h;
- $usex = $x_offset;
- $usey = $y_offset;
- $usew = $bboxw;
- $useh = $bboxh;
- if (isset($gradient_info['units']) && strtolower($gradient_info['units'])=='userspaceonuse') {
- $angle = rad2deg(atan2(($gradient_info['info']['y2']-$gradient_info['info']['y1']), ($gradient_info['info']['x2']-$gradient_info['info']['x1'])));
- if ($angle < 0) { $angle += 360; }
- else if ($angle > 360) { $angle -= 360; }
- if ($angle!=0 && $angle!=360 && $angle!=90 && $angle!=180 && $angle!=270) {
- if ($w >= $h) {
- $y1 *= $h/$w ;
- $y2 *= $h/$w ;
- $usew = $useh = $bboxw;
- }
- else {
- $x1 *= $w/$h ;
- $x2 *= $w/$h ;
- $usew = $useh = $bboxh;
- }
- }
- }
- $a = $usew; // width
- $d = -$useh; // height
- $e = $usex; // x- offset
- $f = -$usey; // -y-offset
-
- $return .= sprintf('%.3F 0 0 %.3F %.3F %.3F cm ', $a*$this->kp, $d*$this->kp, $e*$this->kp, $f*$this->kp);
-
- // mPDF 5.0.039
- if (isset($gradient_info['units']) && strtolower($gradient_info['units'])=='objectboundingbox') {
- if ($transformations) { $return .= $transformations; }
- }
-
- // mPDF 5.0.020
- $trans = false;
-
- // mPDF 5.0.040
- if ($spread=='R' || $spread=='F') { // Repeat / Reflect
- $offs = array();
- for($i=0;$i<$ns;$i++) {
- $offs[$i] = $gradient_info['color'][$i]['offset'];
- }
- $gp = 0;
- $inside=true;
- while($inside) {
- $gp++;
- for($i=0;$i<$ns;$i++) {
- if ($spread=='F' && ($gp % 2) == 1) { // Reflect
- $gradient_info['color'][(($ns*$gp)+$i)] = $gradient_info['color'][(($ns*($gp-1))+($ns-$i-1))];
- $tmp = $gp+(1-$offs[($ns-$i-1)]) ;
- $gradient_info['color'][(($ns*$gp)+$i)]['offset'] = $tmp;
- }
- else { // Reflect
- $gradient_info['color'][(($ns*$gp)+$i)] = $gradient_info['color'][$i];
- $tmp = $gp+$offs[$i] ;
- $gradient_info['color'][(($ns*$gp)+$i)]['offset'] = $tmp;
- }
- // IF STILL INSIDE BOX OR STILL VALID
- // Point on axis to test
- $px1 = $x1 + ($x2-$x1)*$tmp;
- $py1 = $y1 + ($y2-$y1)*$tmp;
- // Get perpendicular axis
- $alpha = atan2($y2-$y1, $x2-$x1);
- $alpha += M_PI/2; // rotate 90 degrees
- // Get arbitrary point to define line perpendicular to axis
- $px2 = $px1+cos($alpha);
- $py2 = $py1+sin($alpha);
-
- $res1 = _testIntersect($px1, $py1, $px2, $py2, 0, 0, 0, 1); // $x=0 vert axis
- $res2 = _testIntersect($px1, $py1, $px2, $py2, 1, 0, 1, 1); // $x=1 vert axis
- $res3 = _testIntersect($px1, $py1, $px2, $py2, 0, 0, 1, 0); // $y=0 horiz axis
- $res4 = _testIntersect($px1, $py1, $px2, $py2, 0, 1, 1, 1); // $y=1 horiz axis
- if (!$res1 && !$res2 && !$res3 && !$res4) { $inside = false; }
- }
- }
-
- $inside=true;
- $gp = 0;
- while($inside) {
- $gp++;
- $newarr = array();
- for($i=0;$i<$ns;$i++) {
- if ($spread=='F') { // Reflect
- $newarr[$i] = $gradient_info['color'][($ns-$i-1)];
- if (($gp % 2) == 1) {
- $tmp = -$gp+(1-$offs[($ns-$i-1)]);
- $newarr[$i]['offset'] = $tmp;
- }
- else {
- $tmp = -$gp+$offs[$i];
- $newarr[$i]['offset'] = $tmp;
- }
- }
- else { // Reflect
- $newarr[$i] = $gradient_info['color'][$i];
- $tmp = -$gp+$offs[$i];
- $newarr[$i]['offset'] = $tmp;
- }
-
- // IF STILL INSIDE BOX OR STILL VALID
- // Point on axis to test
- $px1 = $x1 + ($x2-$x1)*$tmp;
- $py1 = $y1 + ($y2-$y1)*$tmp;
- // Get perpendicular axis
- $alpha = atan2($y2-$y1, $x2-$x1);
- $alpha += M_PI/2; // rotate 90 degrees
- // Get arbitrary point to define line perpendicular to axis
- $px2 = $px1+cos($alpha);
- $py2 = $py1+sin($alpha);
-
- $res1 = _testIntersect($px1, $py1, $px2, $py2, 0, 0, 0, 1); // $x=0 vert axis
- $res2 = _testIntersect($px1, $py1, $px2, $py2, 1, 0, 1, 1); // $x=1 vert axis
- $res3 = _testIntersect($px1, $py1, $px2, $py2, 0, 0, 1, 0); // $y=0 horiz axis
- $res4 = _testIntersect($px1, $py1, $px2, $py2, 0, 1, 1, 1); // $y=1 horiz axis
- if (!$res1 && !$res2 && !$res3 && !$res4) { $inside = false; }
- }
- for($i=($ns-1);$i>=0;$i--) {
- if (isset($newarr[$i]['offset'])) array_unshift($gradient_info['color'], $newarr[$i]);
- }
- }
- }
-
- // mPDF 4.4.007 Gradient STOPs
- $stops = count($gradient_info['color']);
- if ($stops < 2) { return ''; }
-
- // mPDF 5.0.042
- $range = $gradient_info['color'][count($gradient_info['color'])-1]['offset']-$gradient_info['color'][0]['offset'];
- $min = $gradient_info['color'][0]['offset'];
-
- for ($i=0; $i<($stops); $i++) {
- // mPDF 5.0.051
- if (!$gradient_info['color'][$i]['color']) {
- if ($gradient_info['colorspace']=='RGB') $gradient_info['color'][$i]['color'] = '0 0 0';
- else if ($gradient_info['colorspace']=='Gray') $gradient_info['color'][$i]['color'] = '0';
- else if ($gradient_info['colorspace']=='CMYK') $gradient_info['color'][$i]['color'] = '1 1 1 1';
- }
- $offset = ($gradient_info['color'][$i]['offset'] - $min)/$range;
- $this->mpdf_ref->gradients[$n]['stops'][] = array(
- 'col' => $gradient_info['color'][$i]['color'],
- 'opacity' => $gradient_info['color'][$i]['opacity'],
- 'offset' => $offset);
- if ($gradient_info['color'][$i]['opacity']<1) { $trans = true; }
- }
- $grx1 = $x1 + ($x2-$x1)*$gradient_info['color'][0]['offset'];
- $gry1 = $y1 + ($y2-$y1)*$gradient_info['color'][0]['offset'];
- $grx2 = $x1 + ($x2-$x1)*$gradient_info['color'][count($gradient_info['color'])-1]['offset'];
- $gry2 = $y1 + ($y2-$y1)*$gradient_info['color'][count($gradient_info['color'])-1]['offset'];
-
- $this->mpdf_ref->gradients[$n]['coords']=array($grx1, $gry1, $grx2, $gry2);
-
- $this->mpdf_ref->gradients[$n]['colorspace'] = $gradient_info['colorspace']; // mPDF 5.0.051
-
- $this->mpdf_ref->gradients[$n]['type'] = 2;
- $this->mpdf_ref->gradients[$n]['fo'] = true;
-
- $this->mpdf_ref->gradients[$n]['extend']=array('true','true');
- if ($trans) {
- $this->mpdf_ref->gradients[$n]['trans'] = true;
- $return .= ' /TGS'.($n).' gs ';
- }
- $return .= ' /Sh'.($n).' sh ';
- $return .= " Q\n";
- }
- else if ($gradient_info['type'] == 'radial'){
- // mPDF 4.4.003
- if (isset($gradient_info['units']) && strtolower($gradient_info['units'])=='userspaceonuse') {
- if ($w > $h) { $h = $w; }
- else { $w = $h; }
- if (isset($gradient_info['info']['x0'])) { $gradient_info['info']['x0'] = ($gradient_info['info']['x0']-$x_offset) / $w; }
- if (isset($gradient_info['info']['y0'])) { $gradient_info['info']['y0'] = ($gradient_info['info']['y0']-$y_offset) / $h; }
- if (isset($gradient_info['info']['x1'])) { $gradient_info['info']['x1'] = ($gradient_info['info']['x1']-$x_offset) / $w; }
- if (isset($gradient_info['info']['y1'])) { $gradient_info['info']['y1'] = ($gradient_info['info']['y1']-$y_offset) / $h; }
- if (isset($gradient_info['info']['r'])) { $gradient_info['info']['rx'] = $gradient_info['info']['r'] / $w; }
- if (isset($gradient_info['info']['r'])) { $gradient_info['info']['ry'] = $gradient_info['info']['r'] / $h; }
- }
-
- if ($gradient_info['info']['x0'] || $gradient_info['info']['x0']===0) { $x0 = $gradient_info['info']['x0']; }
- else { $x0 = 0.5; }
- if ($gradient_info['info']['y0'] || $gradient_info['info']['y0']===0) { $y0 = $gradient_info['info']['y0']; }
- else { $y0 = 0.5; }
- if ($gradient_info['info']['rx'] || $gradient_info['info']['rx']===0) { $rx = $gradient_info['info']['rx']; }
- else if ($gradient_info['info']['r'] || $gradient_info['info']['r']===0) { $rx = $gradient_info['info']['r']; }
- else { $rx = 0.5; }
- if ($gradient_info['info']['ry'] || $gradient_info['info']['ry']===0) { $ry = $gradient_info['info']['ry']; }
- else if ($gradient_info['info']['r'] || $gradient_info['info']['r']===0) { $ry = $gradient_info['info']['r']; }
- else { $ry = 0.5; }
- if ($gradient_info['info']['x1'] || $gradient_info['info']['x1']===0) { $x1 = $gradient_info['info']['x1']; }
- else { $x1 = $x0; }
- if ($gradient_info['info']['y1'] || $gradient_info['info']['y1']===0) { $y1 = $gradient_info['info']['y1']; }
- else { $y1 = $y0; }
-
- if (stristr($x1, '%')!== false) { $x1 = ($x1+0)/100; }
- if (stristr($x0, '%')!== false) { $x0 = ($x0+0)/100; }
- if (stristr($y1, '%')!== false) { $y1 = ($y1+0)/100; }
- if (stristr($y0, '%')!== false) { $y0 = ($y0+0)/100; }
- if (stristr($rx, '%')!== false) { $rx = ($rx+0)/100; }
- if (stristr($ry, '%')!== false) { $ry = ($ry+0)/100; }
-
- // mPDF 5.0.043
- $bboxw = $w;
- $bboxh = $h;
- $usex = $x_offset;
- $usey = $y_offset;
- $usew = $bboxw;
- $useh = $bboxh;
- if (isset($gradient_info['units']) && strtolower($gradient_info['units'])=='userspaceonuse') {
- $angle = rad2deg(atan2(($gradient_info['info']['y0']-$gradient_info['info']['y1']), ($gradient_info['info']['x0']-$gradient_info['info']['x1'])));
- if ($angle < 0) { $angle += 360; }
- else if ($angle > 360) { $angle -= 360; }
- if ($angle!=0 && $angle!=360 && $angle!=90 && $angle!=180 && $angle!=270) {
- if ($w >= $h) {
- $y1 *= $h/$w ;
- $y0 *= $h/$w ;
- $rx *= $h/$w ;
- $ry *= $h/$w ;
- $usew = $useh = $bboxw;
- }
- else {
- $x1 *= $w/$h ;
- $x0 *= $w/$h ;
- $rx *= $w/$h ;
- $ry *= $w/$h ;
- $usew = $useh = $bboxh;
- }
- }
- }
- $a = $usew; // width
- $d = -$useh; // height
- $e = $usex; // x- offset
- $f = -$usey; // -y-offset
-
- $r = $rx;
-
-
- $return .= sprintf('%.3F 0 0 %.3F %.3F %.3F cm ', $a*$this->kp, $d*$this->kp, $e*$this->kp, $f*$this->kp);
-
- // mPDF 5.0.039
- if (isset($gradient_info['units']) && strtolower($gradient_info['units'])=='objectboundingbox') {
- if ($transformations) { $return .= $transformations; }
- }
-
- // x1 and y1 (fx, fy) should be inside the circle defined by x0 y0 and r else error in mPDF
- while (pow(($x1-$x0),2) + pow(($y1 - $y0),2) >= pow($r,2)) { $r += 0.05; }
-
- // mPDF 5.0.040
- if ($spread=='R' || $spread=='F') { // Repeat / Reflect
- $offs = array();
- for($i=0;$i<$ns;$i++) {
- $offs[$i] = $gradient_info['color'][$i]['offset'];
- }
- $gp = 0;
- $inside=true;
- while($inside) {
- $gp++;
- for($i=0;$i<$ns;$i++) {
- if ($spread=='F' && ($gp % 2) == 1) { // Reflect
- $gradient_info['color'][(($ns*$gp)+$i)] = $gradient_info['color'][(($ns*($gp-1))+($ns-$i-1))];
- $tmp = $gp+(1-$offs[($ns-$i-1)]) ;
- $gradient_info['color'][(($ns*$gp)+$i)]['offset'] = $tmp;
- }
- else { // Reflect
- $gradient_info['color'][(($ns*$gp)+$i)] = $gradient_info['color'][$i];
- $tmp = $gp+$offs[$i] ;
- $gradient_info['color'][(($ns*$gp)+$i)]['offset'] = $tmp;
- }
- // IF STILL INSIDE BOX OR STILL VALID
- // TEST IF circle (perimeter) intersects with
- // or is enclosed
- // Point on axis to test
- $px = $x1 + ($x0-$x1)*$tmp;
- $py = $y1 + ($y0-$y1)*$tmp;
- $pr = $r*$tmp;
- $res = _testIntersectCircle($px, $py, $pr);
- if (!$res) { $inside = false; }
- }
- }
- }
-
- // mPDF 4.4.007 Gradient STOPs
- $stops = count($gradient_info['color']);
- if ($stops < 2) { return ''; }
-
- // mPDF 5.0.043
- $range = $gradient_info['color'][count($gradient_info['color'])-1]['offset']-$gradient_info['color'][0]['offset'];
- $min = $gradient_info['color'][0]['offset'];
-
- for ($i=0; $i<($stops); $i++) {
- // mPDF 5.0.051
- if (!$gradient_info['color'][$i]['color']) {
- if ($gradient_info['colorspace']=='RGB') $gradient_info['color'][$i]['color'] = '0 0 0';
- else if ($gradient_info['colorspace']=='Gray') $gradient_info['color'][$i]['color'] = '0';
- else if ($gradient_info['colorspace']=='CMYK') $gradient_info['color'][$i]['color'] = '1 1 1 1';
- }
- $offset = ($gradient_info['color'][$i]['offset'] - $min)/$range;
- $this->mpdf_ref->gradients[$n]['stops'][] = array(
- 'col' => $gradient_info['color'][$i]['color'],
- 'opacity' => $gradient_info['color'][$i]['opacity'],
- 'offset' => $offset);
- if ($gradient_info['color'][$i]['opacity']<1) { $trans = true; }
- }
- $grx1 = $x1 + ($x0-$x1)*$gradient_info['color'][0]['offset'];
- $gry1 = $y1 + ($y0-$y1)*$gradient_info['color'][0]['offset'];
- $grx2 = $x1 + ($x0-$x1)*$gradient_info['color'][count($gradient_info['color'])-1]['offset'];
- $gry2 = $y1 + ($y0-$y1)*$gradient_info['color'][count($gradient_info['color'])-1]['offset'];
- $grir = $r*$gradient_info['color'][0]['offset'];
- $grr = $r*$gradient_info['color'][count($gradient_info['color'])-1]['offset'];
-
- $this->mpdf_ref->gradients[$n]['coords']=array($grx1, $gry1, $grx2, $gry2, abs($grr), abs($grir) );
-
- $grx1 = $x1 + ($x0-$x1)*$first_stop;
- $gry1 = $y1 + ($y0-$y1)*$first_stop;
- $grx2 = $x1 + ($x0-$x1)*$last_stop;
- $gry2 = $y1 + ($y0-$y1)*$last_stop;
- $grir = $r*$first_stop;
- $grr = $r*$last_stop;
- $this->mpdf_ref->gradients[$n]['colorspace'] = $gradient_info['colorspace']; // mPDF 5.0.051
-
- $this->mpdf_ref->gradients[$n]['type'] = 3;
- $this->mpdf_ref->gradients[$n]['fo'] = true;
-
- $this->mpdf_ref->gradients[$n]['extend']=array('true','true');
- if ($trans) {
- $this->mpdf_ref->gradients[$n]['trans'] = true;
- $return .= ' /TGS'.($n).' gs ';
- }
- $return .= ' /Sh'.($n).' sh ';
- $return .= " Q\n";
-
-
- }
-
- return $return;
- }
-
-
- function svgOffset ($attribs){
- // save all <svg> tag attributes
- $this->svg_attribs = $attribs;
- if(isset($this->svg_attribs['viewBox'])) {
- $vb = preg_split('/\s+/is', trim($this->svg_attribs['viewBox']));
- if (count($vb)==4) {
- $this->svg_info['x'] = $vb[0];
- $this->svg_info['y'] = $vb[1];
- $this->svg_info['w'] = $vb[2];
- $this->svg_info['h'] = $vb[3];
- // return; // mPDF 5.0.005
- }
- }
-
- $svg_w = $this->mpdf_ref->ConvertSize($attribs['width']); // mm (interprets numbers as pixels)
- $svg_h = $this->mpdf_ref->ConvertSize($attribs['height']); // mm
-
- ///*
- // mPDF 5.0.005
- if ($this->svg_info['w']) { // if 'w' set by viewBox
- if ($svg_w) { // if width also set, use these values to determine to set size of "pixel"
- $this->kp *= ($svg_w/0.2645) / $this->svg_info['w'];
- $this->kf = ($svg_w/0.2645) / $this->svg_info['w']; // mPDF 5.0.039
- }
- else if ($svg_h) {
- $this->kp *= ($svg_h/0.2645) / $this->svg_info['h'];
- $this->kf = ($svg_h/0.2645) / $this->svg_info['h']; // mPDF 5.0.039
- }
- return;
- }
- //*/
-
- // Added to handle file without height or width specified
- if (!$svg_w && !$svg_h) { $svg_w = $svg_h = $this->mpdf_ref->blk[$this->mpdf_ref->blklvl]['inner_width'] ; } // DEFAULT
- if (!$svg_w) { $svg_w = $svg_h; }
- if (!$svg_h) { $svg_h = $svg_w; }
-
- $this->svg_info['x'] = 0;
- $this->svg_info['y'] = 0;
- $this->svg_info['w'] = $svg_w/0.2645; // mm->pixels
- $this->svg_info['h'] = $svg_h/0.2645; // mm->pixels
-
- }
-
-
- //
- // check if points are within svg, if not, set to max
- function svg_overflow($x,$y)
- {
- $x2 = $x;
- $y2 = $y;
- if(isset($this->svg_attribs['overflow']))
- {
- if($this->svg_attribs['overflow'] == 'hidden')
- {
- // Not sure if this is supposed to strip off units, but since I dont use any I will omlt this step
- $svg_w = preg_replace("/([0-9\.]*)(.*)/i","$1",$this->svg_attribs['width']);
- $svg_h = preg_replace("/([0-9\.]*)(.*)/i","$1",$this->svg_attribs['height']);
-
- // $xmax = floor($this->svg_attribs['width']);
- $xmax = floor($svg_w);
- $xmin = 0;
- // $ymax = floor(($this->svg_attribs['height'] * -1));
- $ymax = floor(($svg_h * -1));
- $ymin = 0;
-
- if($x > $xmax) $x2 = $xmax; // right edge
- if($x < $xmin) $x2 = $xmin; // left edge
- if($y < $ymax) $y2 = $ymax; // bottom
- if($y > $ymin) $y2 = $ymin; // top
-
- }
- }
-
-
- return array( 'x' => $x2, 'y' => $y2);
- }
-
-
-
- function svgDefineStyle($critere_style){
-
- $tmp = count($this->svg_style)-1;
- $current_style = $this->svg_style[$tmp];
-
- unset($current_style['transformations']);
-
- // TRANSFORM SCALE
- $transformations = '';
- if (isset($critere_style['transform'])){
- preg_match_all('/(matrix|translate|scale|rotate|skewX|skewY)\((.*?)\)/is',$critere_style['transform'],$m);
- if (count($m[0])) {
- for($i=0; $i<count($m[0]); $i++) {
- $c = strtolower($m[1][$i]);
- $v = trim($m[2][$i]);
- $vv = preg_split('/[ ,]+/',$v);
- if ($c=='matrix' && count($vv)==6) {
- // mPDF 5.0.039
- // Note angle of rotation is reversed (from SVG to PDF), so vv[1] and vv[2] are negated
- $transformations .= sprintf(' %.3F %.3F %.3F %.3F %.3F %.3F cm ', $vv[0], -$vv[1], -$vv[2], $vv[3], $vv[4]*$this->kp, -$vv[5]*$this->kp);
-
- /*
- // The long way of doing this??
- // need to reverse angle of rotation from SVG to PDF
- $sx=sqrt(pow($vv[0],2)+pow($vv[2],2));
- if ($vv[0] < 0) { $sx *= -1; } // change sign
- $sy=sqrt(pow($vv[1],2)+pow($vv[3],2));
- if ($vv[3] < 0) { $sy *= -1; } // change sign
-
- // rotation angle is
- $t=atan2($vv[1],$vv[3]);
- $t=atan2(-$vv[2],$vv[0]); // Should be the same value or skew has been applied
-
- // Reverse angle
- $t *= -1;
-
- // Rebuild matrix
- $ma = $sx * cos($t);
- $mb = $sy * sin($t);
- $mc = -$sx * sin($t);
- $md = $sy * cos($t);
-
- // $transformations .= sprintf(' %.3F %.3F %.3F %.3F %.3F %.3F cm ', $ma, $mb, $mc, $md, $vv[4]*$this->kp, -$vv[5]*$this->kp);
- */
-
- }
- else if ($c=='translate' && count($vv)) {
- $tm[4] = $vv[0];
- if (count($vv)==2) { $t_y = -$vv[1]; }
- else { $t_y = 0; }
- $tm[5] = $t_y;
- $transformations .= sprintf(' 1 0 0 1 %.3F %.3F cm ', $tm[4]*$this->kp, $tm[5]*$this->kp);
- }
- else if ($c=='scale' && count($vv)) {
- if (count($vv)==2) { $s_y = $vv[1]; }
- else { $s_y = $vv[0]; }
- $tm[0] = $vv[0];
- $tm[3] = $s_y;
- $transformations .= sprintf(' %.3F 0 0 %.3F 0 0 cm ', $tm[0], $tm[3]);
- }
- else if ($c=='rotate' && count($vv)) {
- $tm[0] = cos(deg2rad(-$vv[0]));
- $tm[1] = sin(deg2rad(-$vv[0]));
- $tm[2] = -$tm[1];
- $tm[3] = $tm[0];
- if (count($vv)==3) {
- $transformations .= sprintf(' 1 0 0 1 %.3F %.3F cm ', $vv[1]*$this->kp, -$vv[2]*$this->kp);
- }
- $transformations .= sprintf(' %.3F %.3F %.3F %.3F 0 0 cm ', $tm[0], $tm[1], $tm[2], $tm[3]);
- if (count($vv)==3) {
- $transformations .= sprintf(' 1 0 0 1 %.3F %.3F cm ', -$vv[1]*$this->kp, $vv[2]*$this->kp);
- }
- }
- else if ($c=='skewx' && count($vv)) {
- $tm[2] = tan(deg2rad(-$vv[0]));
- $transformations .= sprintf(' 1 0 %.3F 1 0 0 cm ', $tm[2]);
- }
- else if ($c=='skewy' && count($vv)) {
- $tm[1] = tan(deg2rad(-$vv[0]));
- $transformations .= sprintf(' 1 %.3F 0 1 0 0 cm ', $tm[1]);
- }
-
- }
- }
- $current_style['transformations'] = $transformations;
- }
-
- if (isset($critere_style['style'])){
- if (preg_match('/fill:\s*rgb\((\d+),\s*(\d+),\s*(\d+)\)/',$critere_style['style'], $m)) {
- $current_style['fill'] = '#'.str_pad(dechex($m[1]), 2, "0", STR_PAD_LEFT).str_pad(dechex($m[2]), 2, "0", STR_PAD_LEFT).str_pad(dechex($m[3]), 2, "0", STR_PAD_LEFT);
- }
- else { $tmp = preg_replace("/(.*)fill:\s*([a-z0-9#_()]*|none)(.*)/i","$2",$critere_style['style']); // mPDF 4.4.003
- if ($tmp != $critere_style['style']){ $current_style['fill'] = $tmp; }
- }
-
- $tmp = preg_replace("/(.*)fill-opacity:\s*([a-z0-9.]*|none)(.*)/i","$2",$critere_style['style']);
- if ($tmp != $critere_style['style']){ $current_style['fill-opacity'] = $tmp;}
-
- $tmp = preg_replace("/(.*)fill-rule:\s*([a-z0-9#]*|none)(.*)/i","$2",$critere_style['style']);
- if ($tmp != $critere_style['style']){ $current_style['fill-rule'] = $tmp;}
-
- if (preg_match('/stroke:\s*rgb\((\d+),\s*(\d+),\s*(\d+)\)/',$critere_style['style'], $m)) {
- $current_style['stroke'] = '#'.str_pad(dechex($m[1]), 2, "0", STR_PAD_LEFT).str_pad(dechex($m[2]), 2, "0", STR_PAD_LEFT).str_pad(dechex($m[3]), 2, "0", STR_PAD_LEFT);
- }
- else { $tmp = preg_replace("/(.*)stroke:\s*([a-z0-9#]*|none)(.*)/i","$2",$critere_style['style']);
- if ($tmp != $critere_style['style']){ $current_style['stroke'] = $tmp; }
- }
-
- $tmp = preg_replace("/(.*)stroke-linecap:\s*([a-z0-9#]*|none)(.*)/i","$2",$critere_style['style']);
- if ($tmp != $critere_style['style']){ $current_style['stroke-linecap'] = $tmp;}
-
- $tmp = preg_replace("/(.*)stroke-linejoin:\s*([a-z0-9#]*|none)(.*)/i","$2",$critere_style['style']);
- if ($tmp != $critere_style['style']){ $current_style['stroke-linejoin'] = $tmp;}
-
- $tmp = preg_replace("/(.*)stroke-miterlimit:\s*([a-z0-9#]*|none)(.*)/i","$2",$critere_style['style']);
- if ($tmp != $critere_style['style']){ $current_style['stroke-miterlimit'] = $tmp;}
-
- $tmp = preg_replace("/(.*)stroke-opacity:\s*([a-z0-9.]*|none)(.*)/i","$2",$critere_style['style']);
- if ($tmp != $critere_style['style']){ $current_style['stroke-opacity'] = $tmp; }
-
- $tmp = preg_replace("/(.*)stroke-width:\s*([a-z0-9.]*|none)(.*)/i","$2",$critere_style['style']);
- if ($tmp != $critere_style['style']){ $current_style['stroke-width'] = $tmp;}
-
- // mPDF 4.4.003
- $tmp = preg_replace("/(.*)stroke-dasharray:\s*([a-z0-9., ]*|none)(.*)/i","$2",$critere_style['style']);
- if ($tmp != $critere_style['style']){ $current_style['stroke-dasharray'] = $tmp;}
-
- // mPDF 4.4.003
- $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;}
-
- }
- if(isset($critere_style['fill'])){
- $current_style['fill'] = $critere_style['fill'];
- }
-
- if(isset($critere_style['fill-opacity'])){
- $current_style['fill-opacity'] = $critere_style['fill-opacity'];
- }
-
- if(isset($critere_style['fill-rule'])){
- $current_style['fill-rule'] = $critere_style['fill-rule'];
- }
-
- if(isset($critere_style['stroke'])){
- $current_style['stroke'] = $critere_style['stroke'];
- }
-
- if(isset($critere_style['stroke-linecap'])){
- $current_style['stroke-linecap'] = $critere_style['stroke-linecap'];
- }
-
- if(isset($critere_style['stroke-linejoin'])){
- $current_style['stroke-linejoin'] = $critere_style['stroke-linejoin'];
- }
-
- if(isset($critere_style['stroke-miterlimit'])){
- $current_style['stroke-miterlimit'] = $critere_style['stroke-miterlimit'];
- }
-
- if(isset($critere_style['stroke-opacity'])){
- $current_style['stroke-opacity'] = $critere_style['stroke-opacity'];
- }
-
- if(isset($critere_style['stroke-width'])){
- $current_style['stroke-width'] = $critere_style['stroke-width'];
- }
-
- // mPDF 4.4.003
- if(isset($critere_style['stroke-dasharray'])){
- $current_style['stroke-dasharray'] = $critere_style['stroke-dasharray'];
- }
- if(isset($critere_style['stroke-dashoffset'])){
- $current_style['stroke-dashoffset'] = $critere_style['stroke-dashoffset'];
- }
-
- // mPDF 4.4.005 Used as indirect setting for currentColor
- if(isset($critere_style['color']) && $critere_style['color'] != 'inherit'){
- $current_style['color'] = $critere_style['color'];
- }
-
- return $current_style;
-
- }
-
- //
- // Cette fonction ecrit le style dans le stream svg.
- function svgStyle($critere_style, $attribs, $element){
- $path_style = '';
- if (substr_count($critere_style['fill'],'url')>0){
- //
- // couleur degradé
- $id_gradient = preg_replace("/url\(#([\w_]*)\)/i","$1",$critere_style['fill']);
- if ($id_gradient != $critere_style['fill']) {
- if (isset($this->svg_gradient[$id_gradient])) {
- $fill_gradient = $this->svgGradient($this->svg_gradient[$id_gradient], $attribs, $element);
- if ($fill_gradient) { // mPDF 4.4.003
- $path_style = "q ";
- $w = "W";
- $style .= 'N';
- }
- }
- }
-
- }
- // mPDF 4.4.005 Used as indirect setting for currentColor
- else if (strtolower($critere_style['fill']) == 'currentcolor'){
- $col = $this->mpdf_ref->ConvertColor($critere_style['color']);
- if ($col) {
- // mPDF 5.0.051
- // mPDF 5.3.74
- if ($col{0}==5) { $critere_style['fill-opacity'] = ord($col{4}/100); } // RGBa
- if ($col{0}==6) { $critere_style['fill-opacity'] = ord($col{5}/100); } // CMYKa
- $path_style .= $this->mpdf_ref->SetFColor($col, true).' '; // mPDF 5.0.051
- $style .= 'F';
- }
- }
- else if ($critere_style['fill'] != 'none'){
- $col = $this->mpdf_ref->ConvertColor($critere_style['fill']);
- if ($col) {
- // mPDF 5.0.051
- // mPDF 5.3.74
- if ($col{0}==5) { $critere_style['fill-opacity'] = ord($col{4}/100); } // RGBa
- if ($col{0}==6) { $critere_style['fill-opacity'] = ord($col{5}/100); } // CMYKa
- $path_style .= $this->mpdf_ref->SetFColor($col, true).' '; // mPDF 5.0.051
- $style .= 'F';
- }
- }
-
- // mPDF 5.0.040
- if (substr_count($critere_style['stroke'],'url')>0){
- /*
- // Cannot put a gradient on a "stroke" in PDF?
- $id_gradient = preg_replace("/url\(#([\w_]*)\)/i","$1",$critere_style['stroke']);
- if ($id_gradient != $critere_style['stroke']) {
- if (isset($this->svg_gradient[$id_gradient])) {
- $fill_gradient = $this->svgGradient($this->svg_gradient[$id_gradient], $attribs, $element);
- if ($fill_gradient) {
- $path_style = "q ";
- $w = "W";
- $style .= 'D';
- }
- }
- }
- */
- }
- // mPDF 4.4.005 Used as indirect setting for currentColor
- else if (strtolower($critere_style['stroke']) == 'currentcolor'){
- $col = $this->mpdf_ref->ConvertColor($critere_style['color']);
- if ($col) {
- // mPDF 5.0.051
- // mPDF 5.3.74
- if ($col{0}==5) { $critere_style['stroke-opacity'] = ord($col{4}/100); } // RGBa
- if ($col{0}==6) { $critere_style['stroke-opacity'] = ord($col{5}/100); } // CMYKa
- $path_style .= $this->mpdf_ref->SetDColor($col, true).' '; // mPDF 5.0.051
- $style .= 'D';
- $lw = $this->ConvertSVGSizePixels($critere_style['stroke-width']);
- $path_style .= sprintf('%.3F w ',$lw*$this->kp);
- }
- }
- else if ($critere_style['stroke'] != 'none'){
- $col = $this->mpdf_ref->ConvertColor($critere_style['stroke']);
- if ($col) {
- // mPDF 5.0.051
- // mPDF 5.3.74
- if ($col{0}==5) { $critere_style['stroke-opacity'] = ord($col{4}/100); } // RGBa
- if ($col{0}==6) { $critere_style['stroke-opacity'] = ord($col{5}/100); } // CMYKa
- $path_style .= $this->mpdf_ref->SetDColor($col, true).' '; // mPDF 5.0.051
- $style .= 'D';
- $lw = $this->ConvertSVGSizePixels($critere_style['stroke-width']); // mPDF 4.4.003
- $path_style .= sprintf('%.3F w ',$lw*$this->kp);
- }
- }
-
-
- if ($critere_style['stroke'] != 'none'){
- if ($critere_style['stroke-linejoin'] == 'miter'){
- $path_style .= ' 0 j ';
- }
- else if ($critere_style['stroke-linejoin'] == 'round'){
- $path_style .= ' 1 j ';
- }
- else if ($critere_style['stroke-linejoin'] == 'bevel'){
- $path_style .= ' 2 j ';
- }
-
- if ($critere_style['stroke-linecap'] == 'butt'){
- $path_style .= ' 0 J ';
- }
- else if ($critere_style['stroke-linecap'] == 'round'){
- $path_style .= ' 1 J ';
- }
- else if ($critere_style['stroke-linecap'] == 'square'){
- $path_style .= ' 2 J ';
- }
-
- if (isset($critere_style['stroke-miterlimit'])){
- if ($critere_style['stroke-miterlimit'] == 'none'){
- }
- else if (preg_match('/^[\d.]+$/',$critere_style['stroke-miterlimit'])) {
- $path_style .= sprintf('%.2F M ',$critere_style['stroke-miterlimit']);
- }
- }
- // mPDF 4.4.003
- if (isset($critere_style['stroke-dasharray'])){
- $off = 0;
- $d = preg_split('/[ ,]/',$critere_style['stroke-dasharray']);
- if (count($d) == 1 && $d[0]==0) {
- $path_style .= '[] 0 d ';
- }
- else {
- if (count($d) % 2 == 1) { $d = array_merge($d, $d); } // 5, 3, 1 => 5,3,1,5,3,1 OR 3 => 3,3
- $arr = '';
- for($i=0; $i<count($d); $i+=2) {
- $arr .= sprintf('%.3F %.3F ', $d[$i]*$this->kp, $d[$i+1]*$this->kp);
- }
- if (isset($critere_style['stroke-dashoffset'])){ $off = $critere_style['stroke-dashoffset'] + 0; }
- $path_style .= sprintf('[%s] %.3F d ', $arr, $off*$this->kp);
- }
- }
- }
-
- // mPDF 4.4.003
- if ($critere_style['fill-rule']=='evenodd') { $fr = '*'; }
- else { $fr = ''; }
-
- // mPDF 4.4.003
- if (isset($critere_style['fill-opacity'])) {
- $opacity = 1;
- if ($critere_style['fill-opacity'] == 0) { $opacity = 0; }
- else if ($critere_style['fill-opacity'] > 1) { $opacity = 1; }
- else if ($critere_style['fill-opacity'] > 0) { $opacity = $critere_style['fill-opacity']; }
- else if ($critere_style['fill-opacity'] < 0) { $opacity = 0; }
- $gs = $this->mpdf_ref->AddExtGState(array('ca'=>$opacity, 'BM'=>'/Normal'));
- $this->mpdf_ref->extgstates[$gs]['fo'] = true; // mPDF 5.0.039
- $path_style .= sprintf(' /GS%d gs ', $gs);
- }
-
- // mPDF 4.4.003
- if (isset($critere_style['stroke-opacity'])) {
- $opacity = 1;
- if ($critere_style['stroke-opacity'] == 0) { $opacity = 0; }
- else if ($critere_style['stroke-opacity'] > 1) { $opacity = 1; }
- else if ($critere_style['stroke-opacity'] > 0) { $opacity = $critere_style['stroke-opacity']; }
- else if ($critere_style['stroke-opacity'] < 0) { $opacity = 0; }
- $gs = $this->mpdf_ref->AddExtGState(array('CA'=>$opacity, 'BM'=>'/Normal'));
- $this->mpdf_ref->extgstates[$gs]['fo'] = true; // mPDF 5.0.039
- $path_style .= sprintf(' /GS%d gs ', $gs);
- }
-
- switch ($style){
- case 'F':
- $op = 'f';
- break;
- case 'FD':
- $op = 'B';
- break;
- case 'ND':
- $op = 'S';
- break;
- case 'D':
- $op = 'S';
- break;
- default:
- $op = 'n';
- }
-
- // mPDF 5.0
- $prestyle = $path_style.' ';
- $poststyle = $w.' '. $op.$fr.' '.$fill_gradient."\n";
- return array($prestyle,$poststyle);
-
- }
-
- //
- // fonction retracant les <path />
- function svgPath($command, $arguments){
- $path_cmd = '';
- $newsubpath = false; // mPDF 4.4.003
- // mPDF 5.0.039
- $minl = $this->pathBBox[0];
- $mint = $this->pathBBox[1];
- $maxr = $this->pathBBox[2]+$this->pathBBox[0];
- $maxb = $this->pathBBox[3]+$this->pathBBox[1];
- // mPDF 5.0.040
- $start = array($this->xbase, -$this->ybase);
-
- // mPDF 4.4.003
- preg_match_all('/[\-^]?[\d.]+(e[\-]?[\d]+){0,1}/i', $arguments, $a, PREG_SET_ORDER);
-
- // if the command is a capital letter, the coords go absolute, otherwise relative
- if(strtolower($command) == $command) $relative = true;
- else $relative = false;
-
-
- $ile_argumentow = count($a);
-
- // each command may have different needs for arguments [1 to 8]
-
- switch(strtolower($command)){
- case 'm': // move
- for($i = 0; $i<$ile_argumentow; $i+=2){
- $x = $a[$i][0];
- $y = $a[$i+1][0];
- if($relative){
- $pdfx = ($this->xbase + $x);
- $pdfy = ($this->ybase - $y);
- $this->xbase += $x;
- $this->ybase += -$y;
- }
- else{
- $pdfx = $x;
- $pdfy = -$y ;
- $this->xbase = $x;
- $this->ybase = -$y;
- }
- $pdf_pt = $this->svg_overflow($pdfx,$pdfy);
- // mPDF 5.0.039
- $minl = min($minl,$pdf_pt['x']);
- $maxr = max($maxr,$pdf_pt['x']);
- $mint = min($mint,-$pdf_pt['y']);
- $maxb = max($maxb,-$pdf_pt['y']);
- if($i == 0) $path_cmd .= sprintf('%.3F %.3F m ', $pdf_pt['x']*$this->kp, $pdf_pt['y']*$this->kp);
- else $path_cmd .= sprintf('%.3F %.3F l ', $pdf_pt['x']*$this->kp, $pdf_pt['y']*$this->kp);
- // mPDF 4.4.003 Save start points of subpath
- if ($this->subPathInit) {
- $this->spxstart = $this->xbase;
- $this->spystart = $this->ybase;
- $this->subPathInit = false;
- }
- }
- break;
- case 'l': // a simple line
- for($i = 0; $i<$ile_argumentow; $i+=2){
- $x = ($a[$i][0]);
- $y = ($a[$i+1][0]);
- if($relative){
- $pdfx = ($this->xbase + $x);
- $pdfy = ($this->ybase - $y);
- $this->xbase += $x;
- $this->ybase += -$y;
- }
- else{
- $pdfx = $x ;
- $pdfy = -$y ;
- $this->xbase = $x;
- $this->ybase = -$y;
- }
- $pdf_pt = $this->svg_overflow($pdfx,$pdfy);
- // mPDF 5.0.039
- $minl = min($minl,$pdf_pt['x']);
- $maxr = max($maxr,$pdf_pt['x']);
- $mint = min($mint,-$pdf_pt['y']);
- $maxb = max($maxb,-$pdf_pt['y']);
- $path_cmd .= sprintf('%.3F %.3F l ', $pdf_pt['x']*$this->kp, $pdf_pt['y']*$this->kp);
- }
- break;
- case 'h': // a very simple horizontal line
- for($i = 0; $i<$ile_argumentow; $i++){
- $x = ($a[$i][0]);
- if($relative){
- $y = 0;
- $pdfx = ($this->xbase + $x) ;
- $pdfy = ($this->ybase - $y) ;
- $this->xbase += $x;
- $this->ybase += -$y;
- }
- else{
- $y = -$this->ybase;
- $pdfx = $x;
- $pdfy = -$y;
- $this->xbase = $x;
- $this->ybase = -$y;
- }
- $pdf_pt = $this->svg_overflow($pdfx,$pdfy);
- // mPDF 5.0.039
- $minl = min($minl,$pdf_pt['x']);
- $maxr = max($maxr,$pdf_pt['x']);
- $mint = min($mint,-$pdf_pt['y']);
- $maxb = max($maxb,-$pdf_pt['y']);
- $path_cmd .= sprintf('%.3F %.3F l ', $pdf_pt['x']*$this->kp, $pdf_pt['y']*$this->kp);
- }
- break;
- case 'v': // the simplest line, vertical
- for($i = 0; $i<$ile_argumentow; $i++){
- $y = ($a[$i][0]);
- if($relative){
- $x = 0;
- $pdfx = ($this->xbase + $x);
- $pdfy = ($this->ybase - $y);
- $this->xbase += $x;
- $this->ybase += -$y;
- }
- else{
- $x = $this->xbase;
- $pdfx = $x;
- $pdfy = -$y;
- $this->xbase = $x;
- $this->ybase = -$y;
- }
- $pdf_pt = $this->svg_overflow($pdfx,$pdfy);
- // mPDF 5.0.039
- $minl = min($minl,$pdf_pt['x']);
- $maxr = max($maxr,$pdf_pt['x']);
- $mint = min($mint,-$pdf_pt['y']);
- $maxb = max($maxb,-$pdf_pt['y']);
- $path_cmd .= sprintf('%.3F %.3F l ', $pdf_pt['x']*$this->kp, $pdf_pt['y']*$this->kp);
- }
- break;
- case 's': // bezier with first vertex equal first control
- // mPDF 4.4.003
- if (!($this->lastcommand == 'C' || $this->lastcommand == 'c' || $this->lastcommand == 'S' || $this->lastcommand == 's')) {
- $this->lastcontrolpoints = array(0,0);
- }
- for($i = 0; $i<$ile_argumentow; $i += 4){
- $x1 = $this->lastcontrolpoints[0];
- $y1 = $this->lastcontrolpoints[1];
- $x2 = ($a[$i][0]);
- $y2 = ($a[$i+1][0]);
- $x = ($a[$i+2][0]);
- $y = ($a[$i+3][0]);
- if($relative){
- $pdfx1 = ($this->xbase + $x1);
- $pdfy1 = ($this->ybase - $y1);
- $pdfx2 = ($this->xbase + $x2);
- $pdfy2 = ($this->ybase - $y2);
- $pdfx = ($this->xbase + $x);
- $pdfy = ($this->ybase - $y);
- $this->xbase += $x;
- $this->ybase += -$y;
- }
- else{
- $pdfx1 = $this->xbase + $x1;
- $pdfy1 = $this->ybase -$y1;
- $pdfx2 = $x2;
- $pdfy2 = -$y2;
- $pdfx = $x;
- $pdfy = -$y;
- $this->xbase = $x;
- $this->ybase = -$y;
- }
- $this->lastcontrolpoints = array(($pdfx-$pdfx2),-($pdfy-$pdfy2)); // mPDF 4.4.003 always relative
-
- $pdf_pt = $this->svg_overflow($pdfx,$pdfy);
-
- // mPDF 5.0.040
- $curves = array($pdfx1,-$pdfy1,$pdfx2,-$pdfy2,$pdfx,-$pdfy);
- $bx = calc_bezier_bbox($start, $curves);
- $minl = min($minl,$bx[0]);
- $maxr = max($maxr,$bx[2]);
- $mint = min($mint,$bx[1]);
- $maxb = max($maxb,$bx[3]);
-
- if( ($pdf_pt['x'] != $pdfx) || ($pdf_pt['y'] != $pdfy) )
- {
- $path_cmd .= sprintf('%.3F %.3F l ', $pdf_pt['x']*$this->kp, $pdf_pt['y']*$this->kp);
- }
- else
- {
- $path_cmd .= sprintf('%.3F %.3F %.3F %.3F %.3F %.3F c ', $pdfx1*$this->kp, $pdfy1*$this->kp, $pdfx2*$this->kp, $pdfy2*$this->kp, $pdfx*$this->kp, $pdfy*$this->kp);
- }
-
- }
- break;
- case 'c': // bezier with second vertex equal second control
- for($i = 0; $i<$ile_argumentow; $i += 6){
- $x1 = ($a[$i][0]);
- $y1 = ($a[$i+1][0]);
- $x2 = ($a[$i+2][0]);
- $y2 = ($a[$i+3][0]);
- $x = ($a[$i+4][0]);
- $y = ($a[$i+5][0]);
-
-
- if($relative){
- $pdfx1 = ($this->xbase + $x1);
- $pdfy1 = ($this->ybase - $y1);
- $pdfx2 = ($this->xbase + $x2);
- $pdfy2 = ($this->ybase - $y2);
- $pdfx = ($this->xbase + $x);
- $pdfy = ($this->ybase - $y);
- $this->xbase += $x;
- $this->ybase += -$y;
- }
- else{
- $pdfx1 = $x1;
- $pdfy1 = -$y1;
- $pdfx2 = $x2;
- $pdfy2 = -$y2;
- $pdfx = $x;
- $pdfy = -$y;
- $this->xbase = $x;
- $this->ybase = -$y;
- }
- $this->lastcontrolpoints = array(($pdfx-$pdfx2),-($pdfy-$pdfy2)); // mPDF 4.4.003 always relative
- // $pdf_pt2 = $this->svg_overflow($pdfx2,$pdfy2);
- // $pdf_pt1 = $this->svg_overflow($pdfx1,$pdfy1);
- $pdf_pt = $this->svg_overflow($pdfx,$pdfy);
-
- // mPDF 5.0.040
- $curves = array($pdfx1,-$pdfy1,$pdfx2,-$pdfy2,$pdfx,-$pdfy);
- $bx = calc_bezier_bbox($start, $curves);
- $minl = min($minl,$bx[0]);
- $maxr = max($maxr,$bx[2]);
- $mint = min($mint,$bx[1]);
- $maxb = max($maxb,$bx[3]);
-
- if( ($pdf_pt['x'] != $pdfx) || ($pdf_pt['y'] != $pdfy) )
- {
- $path_cmd .= sprintf('%.3F %.3F l ', $pdf_pt['x']*$this->kp, $pdf_pt['y']*$this->kp);
- }
- else
- {
- $path_cmd .= sprintf('%.3F %.3F %.3F %.3F %.3F %.3F c ', $pdfx1*$this->kp, $pdfy1*$this->kp, $pdfx2*$this->kp, $pdfy2*$this->kp, $pdfx*$this->kp, $pdfy*$this->kp);
- }
-
- }
- break;
-
- case 'q': // bezier quadratic avec point de control
- for($i = 0; $i<$ile_argumentow; $i += 4){
- $x1 = ($a[$i][0]);
- $y1 = ($a[$i+1][0]);
- $x = ($a[$i+2][0]);
- $y = ($a[$i+3][0]);
- if($relative){
- $pdfx = ($this->xbase + $x);
- $pdfy = ($this->ybase - $y);
-
- $pdfx1 = ($this->xbase + ($x1*2/3));
- $pdfy1 = ($this->ybase - ($y1*2/3));
- // mPDF 4.4.003
- $pdfx2 = $pdfx1 + 1/3 *($x);
- $pdfy2 = $pdfy1 + 1/3 *(-$y) ;
-
- $this->xbase += $x;
- $this->ybase += -$y;
- }
- else{
- $pdfx = $x;
- $pdfy = -$y;
-
- $pdfx1 = ($this->xbase+(($x1-$this->xbase)*2/3));
- $pdfy1 = ($this->ybase-(($y1+$this->ybase)*2/3));
-
- $pdfx2 = ($x+(($x1-$x)*2/3));
- $pdfy2 = (-$y-(($y1-$y)*2/3));
-
- // mPDF 4.4.003 …
Large files files are truncated, but you can click here to view the full file