Image_3D
[ class tree: Image_3D ] [ index: Image_3D ] [ all elements ]

Source for file SVG.php

Documentation is available at SVG.php

  1. <?php
  2.  
  3.     
  4.     protected $_x;
  5.     protected $_y;
  6.     
  7.     protected $_id;
  8.     
  9.     protected $_gradients;
  10.     protected $_polygones;
  11.     
  12.     public function __construct({
  13.         $this->_image = '';
  14.         $this->_id = 1;
  15.         $this->_gradients = array();
  16.         $this->_polygones = array();
  17.     }
  18.     
  19.     public function createImage($x$y{
  20.         $this->_x = (int) $x;
  21.         $this->_y = (int) $y;
  22.  
  23.         $this->_image = <<<EOF
  24. <?xml version="1.0" ?>
  25. <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
  26.  
  27. <svg xmlns="http://www.w3.org/2000/svg" width="{$this->_x}" height="{$this->_y}" x="0" y="0">
  28. EOF;
  29.         $this->_image .= "\n\n";
  30.     }
  31.     
  32.     public function setBackground(Image_3D_Color $color{
  33.         $this->_addPolygon(sprintf("\t<polygon id=\"background%d\" points=\"0,0 %d,0 %d,%d 0,%d\" style=\"%s\" />\n"
  34.             $this->_id++,
  35.             $this->_x,
  36.             $this->_x,
  37.             $this->_y,
  38.             $this->_y,
  39.             $this->_getStyle($color)));
  40.     }
  41.     
  42.     protected function _getStyle(Image_3D_Color $color{
  43.         $values $color->getValues();
  44.         
  45.         $values[0= (int) round($values[0* 255);
  46.         $values[1= (int) round($values[1* 255);
  47.         $values[2= (int) round($values[2* 255);
  48.         $values[3= 1 - $values[3];
  49.         
  50.         return sprintf('fill: #%02x%02x%02x; fill-opacity: %.2f; stroke: none;'$values[0]$values[1]$values[2]$values[3]);
  51.     }
  52.     
  53.     protected function _getStop(Image_3D_Color $color$offset = 0$alpha = null{
  54.         $values $color->getValues();
  55.         
  56.         $values[0= (int) round($values[0* 255);
  57.         $values[1= (int) round($values[1* 255);
  58.         $values[2= (int) round($values[2* 255);
  59.         if ($alpha === null{
  60.             $values[3= 1 - $values[3];
  61.         else {
  62.             $values[3= 1 - $alpha;
  63.         }
  64.         
  65.         return sprintf("\t\t\t<stop id=\"stop%d\" offset=\"%.1f\" style=\"stop-color: rgb(%d, %d, %d); stop-opacity: %.4f;\" />\n"$this->_id++$offset$values[0]$values[1]$values[2]$values[3]);
  66.     }
  67.     
  68.     protected function _addGradient($string{
  69.         $id 'linearGradient' $this->_id++;
  70.         $this->_gradients[str_replace('[id]'$id$string);
  71.         return $id;
  72.     }
  73.     
  74.     protected function _addPolygon($string{
  75.         $id 'polygon' $this->_id++;
  76.         $this->_polygones[str_replace('[id]'$id$string);
  77.         return $id;
  78.     }
  79.     
  80.     public function drawPolygon(Image_3D_Polygon $polygon{
  81.         
  82.         $list '';
  83.         $points $polygon->getPoints();
  84.         foreach ($points as $point{
  85.             $pointarray $point->getScreenCoordinates();
  86.             $list .= sprintf('%.2f,%.2f '$pointarray[0]$pointarray[1]);
  87.         }
  88.         
  89.         $this->_addPolygon(sprintf("\t<polygon points=\"%s\" style=\"%s\" />\n"
  90.             substr($list0-1)
  91.             $this->_getStyle($polygon->getColor())));
  92.     }
  93.     
  94.     public function drawGradientPolygon(Image_3D_Polygon $polygon{
  95.         $points $polygon->getPoints();
  96.         
  97.         $list '';
  98.         $pointarray = array();
  99.         foreach ($points as $nr => $point{
  100.             $pointarray[$nr$point->getScreenCoordinates();
  101.             $list .= sprintf('%.2f,%.2f '$pointarray[$nr][0]$pointarray[$nr][1]);
  102.         }
  103.         
  104.         // Groessen
  105.         $xOffset min($pointarray[0][0]$pointarray[1][0]$pointarray[2][0]);
  106.         $yOffset min($pointarray[0][1]$pointarray[1][1]$pointarray[2][1]);
  107.  
  108.         $xSize max(abs($pointarray[0][0$pointarray[1][0])abs($pointarray[0][0$pointarray[2][0])abs($pointarray[1][0$pointarray[2][0]));
  109.         $ySize max(abs($pointarray[0][1$pointarray[1][1])abs($pointarray[0][1$pointarray[2][1])abs($pointarray[1][1$pointarray[2][1]));
  110.         
  111.         // Base Polygon
  112.         $lg $this->_addGradient(sprintf("\t\t<linearGradient id=\"[id]\" x1=\"%.2f\" y1=\"%.2f\" x2=\"%.2f\" y2=\"%.2f\">\n%s\t\t</linearGradient>\n",
  113.             ($pointarray[0][0$xOffset$xSize,
  114.             ($pointarray[0][1$yOffset$ySize,
  115.             ($pointarray[1][0$xOffset$xSize,
  116.             ($pointarray[1][1$yOffset$ySize,
  117.             $this->_getStop($points[0]->getColor()) $this->_getStop($points[1]->getColor()1)));
  118.         
  119.         $this->_addPolygon(sprintf("\t<polygon id=\"[id]\" points=\"%s\" style=\"fill: url(#%s); stroke: none; fill-opacity: 1;\" />\n"$list$lg));
  120.         
  121.         // Overlay Polygon
  122.         $lg $this->_addGradient(sprintf("\t\t<linearGradient id=\"[id]\" x1=\"%.2f\" y1=\"%.2f\" x2=\"%.2f\" y2=\"%.2f\">\n%s\t\t</linearGradient>\n"
  123.             ($pointarray[2][0$xOffset$xSize,
  124.             ($pointarray[2][1$yOffset$ySize,
  125.             ((($pointarray[0][0$pointarray[1][0]/ 2$xOffset$xSize,
  126.             ((($pointarray[0][1$pointarray[1][1]/ 2$yOffset$ySize,
  127.             $this->_getStop($points[2]->getColor()) $this->_getStop($points[2]->getColor()11)));
  128.         
  129.         $this->_addPolygon(sprintf("\t<polygon id=\"[id]\" points=\"%s\" style=\"fill: url(#%s); stroke: none; fill-opacity: 1;\" />\n"$list$lg));
  130.     }
  131.     
  132.     public function save($file{
  133.         $this->_image .= sprintf("\t<defs id=\"defs%d\">\n"$this->_id++);
  134.         $this->_image .= implode(''$this->_gradients);
  135.         $this->_image .= sprintf("\t</defs>\n\n");
  136.  
  137.         $this->_image .= implode(''$this->_polygones);
  138.         $this->_image .= "</svg>\n";
  139.         file_put_contents($file$this->_image);
  140.     }
  141.  
  142.     public function getSupportedShading({
  143.         return array(Image_3D_Renderer::SHADE_NOImage_3D_Renderer::SHADE_FLATImage_3D_Renderer::SHADE_GAUROUD);
  144.     }
  145. }
  146.  
  147. ?>

Documentation generated on Mon, 11 Mar 2019 14:04:20 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.