Пример #1
0
 function transform()
 {
     if (empty($this->transform)) {
         return;
     }
     // do not transform tspans -- done by overwriting this...
     //if ($this->x === false) {
     //    return;
     // }
     // deal with transformation..
     $tr = $this->transform;
     if (preg_match('/scale\\(([0-9e.-]+),([0-9e.-]+)\\)/', $tr, $args)) {
         $xscale = $args[1];
         $yscale = $args[2];
         $method = 'scale';
     } else {
         if (preg_match('/matrix\\(([0-9e.-]+),([0-9e.-]+),([0-9e.-]+),([0-9e.-]+),([0-9e.-]+),([0-9e.-]+)\\)/', $tr, $args)) {
             array_shift($args);
             require_once 'Math/Matrix.php';
             $matrix = new Math_Matrix(array(array($args[0], $args[2], $args[4]), array($args[1], $args[3], $args[5]), array(0, 0, 1)));
             $method = 'matrix';
         } else {
             if (preg_match('/translate\\(([0-9e.-]+),([0-9e.-]+)\\)/', $tr, $args)) {
                 $x = $args[1];
                 $y = $args[2];
                 $method = 'translate';
             } else {
                 echo "<PRE>no match?";
                 print_r($this);
                 exit;
                 return;
             }
         }
     }
     //
     switch ($method) {
         case 'scale':
             $this->x *= $xscale;
             $this->y *= $yscale;
             if (empty($this->children)) {
                 return;
             }
             foreach (array_keys($this->children) as $i) {
                 if ($this->children[$i]->x === false) {
                     continue;
                     // echo "<PRE>";print_r($this);exit;
                 }
                 $this->children[$i]->x *= $xscale;
                 $this->children[$i]->y *= $yscale;
             }
             break;
         case 'matrix':
             $v = new Math_Vector(array($this->x, $this->y, 0));
             $r = $matrix->vectorMultiply($v);
             $r = $r->getData();
             $this->x = $r[0];
             $this->y = $r[1];
             //echo "<PRE>";var_dump(	$r);exit;
             if (empty($this->children)) {
                 return;
             }
             foreach (array_keys($this->children) as $i) {
                 if ($this->children[$i]->x === false) {
                     continue;
                     // echo "<PRE>";print_r($this);exit;
                 }
                 $v = new Math_Vector(array($this->children[$i]->x, $this->children[$i]->y, 0));
                 $r = $matrix->vectorMultiply($v);
                 $r = $r->getData();
                 $this->children[$i]->x = $r[0];
                 $this->children[$i]->y = $r[1];
             }
             break;
         case 'translate':
             if ($this->x !== false && $this->y !== false) {
                 $this->x += $x;
                 $this->y += $y;
             }
             if (empty($this->children)) {
                 return;
             }
             foreach (array_keys($this->children) as $i) {
                 if ($this->children[$i]->x === false || $this->children[$i]->y === false) {
                     continue;
                     // echo "<PRE>";print_r($this);exit;
                 }
                 $this->children[$i]->x += $x;
                 $this->children[$i]->y += $y;
             }
             break;
     }
 }