linea21-externals
[ class tree: linea21-externals ] [ index: linea21-externals ] [ all elements ]

Source for file ming.class.php

Documentation is available at ming.class.php

  1. <?php
  2. /*
  3.  * This work is hereby released into the Public Domain.
  4.  * To view a copy of the public domain dedication,
  5.  * visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
  6.  * Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
  7.  *
  8.  */
  9.  
  10. require_once dirname(__FILE__)."/../Driver.class.php";
  11.  
  12. /**
  13.  * Draw your objects
  14.  *
  15.  * @package linea21.externals
  16.  * @subpackage artichow
  17.  */
  18. class awMingDriver extends awDriver {
  19.  
  20.   /**
  21.    * The Flash movie
  22.    *
  23.    * @var $movie 
  24.    */
  25.   var $movie;
  26.  
  27.   function awMingDriver() {
  28.  
  29.     parent::awDriver();
  30.  
  31.     $this->driverString = 'ming';
  32.  
  33.     // Nice defaults
  34.     ming_setScale(20.0);
  35.     ming_useswfversion(6);
  36.  
  37.   }
  38.  
  39.   /**
  40.    * Initialize the driver for a particular awImage object
  41.    *
  42.    * @param &$image 
  43.    */
  44.   function init(&$image) {
  45.  
  46.     if($this->movie === NULL) {
  47.       $this->setImageSize($image->width, $image->height);
  48.           
  49.       // Create movie
  50.       $this->movie = new SWFMovie();
  51.       if(!$this->movie) {
  52.         awImage::drawError("Class Image: Unable to create a graph.");
  53.       }
  54.           
  55.       $this->movie->setDimension($image->width, $image->height);
  56.           
  57.       $this->setAntiAliasing($image->getAntiAliasing());
  58.           
  59.       // Original color
  60.       $this->filledRectangle(
  61.       new awWhite,
  62.       new awLine(
  63.       new awPoint(0, 0),
  64.       new awPoint($this->imageWidth, $this->imageHeight)
  65.       )
  66.       );
  67.           
  68.       $shadow = $image->shadow;
  69.       if($shadow !== NULL) {
  70.         $shadow = $shadow->getSpace();
  71.         $p1 = new awPoint($shadow->left, $shadow->top);
  72.         $p2 = new awPoint($this->imageWidth - $shadow->right - 1, $this->imageHeight - $shadow->bottom - 1);
  73.  
  74.         // Draw image background
  75.         $this->filledRectangle($image->getBackground(), new awLine($p1, $p2));
  76.  
  77.         // Draw image border
  78.         $image->border->rectangle($this, $p1, $p2);
  79.       }
  80.     }
  81.   }
  82.  
  83.   /**
  84.    * Initialize the Driver for a particular FileImage object
  85.    *
  86.    * @param &$fileImage The FileImage object to work on
  87.    * @param string $file Image filename
  88.    */
  89.   function initFromFile(&$fileImage, $file) {
  90.  
  91.   }
  92.  
  93.   /**
  94.    * Change the image size
  95.    *
  96.    * @param int $width Image width
  97.    * @param int $height Image height
  98.    */
  99.   function setImageSize($width, $height) {
  100.     $this->imageWidth = $width;
  101.     $this->imageHeight = $height;
  102.   }
  103.  
  104.   /**
  105.    * Inform the driver of the position of your image
  106.    *
  107.    * @param float $x Position on X axis of the center of the component
  108.    * @param float $y Position on Y axis of the center of the component
  109.    */
  110.   function setPosition($x, $y) {
  111.     // Calculate absolute position
  112.     $this->x = round($x * $this->imageWidth - $this->w / 2);
  113.     $this->y = round($y * $this->imageHeight - $this->h / 2);
  114.   }
  115.  
  116.   /**
  117.    * Inform the driver of the position of your image
  118.    * This method need absolutes values
  119.    *
  120.    * @param int $x Left-top corner X position
  121.    * @param int $y Left-top corner Y position
  122.    */
  123.   function setAbsPosition($x, $y) {
  124.     $this->x = $x;
  125.     $this->y = $y;
  126.   }
  127.  
  128.   /**
  129.    * Move the position of the image
  130.    *
  131.    * @param int $x Add this value to X axis
  132.    * @param int $y Add this value to Y axis
  133.    */
  134.   function movePosition($x, $y) {
  135.     $this->x += (int)$x;
  136.     $this->y += (int)$y;
  137.   }
  138.  
  139.   /**
  140.    * Inform the driver of the size of your image
  141.    * Height and width must be between 0 and 1.
  142.    *
  143.    * @param int $w Image width
  144.    * @param int $h Image height
  145.    * @return array Absolute width and height of the image
  146.    */
  147.   function setSize($w, $h) {
  148.  
  149.     // Calcul absolute size
  150.     $this->w = round($w * $this->imageWidth);
  151.     $this->h = round($h * $this->imageHeight);
  152.  
  153.     return $this->getSize();
  154.  
  155.   }
  156.  
  157.   /**
  158.    * Inform the driver of the size of your image
  159.    * You can set absolute size with this method.
  160.    *
  161.    * @param int $w Image width
  162.    * @param int $h Image height
  163.    */
  164.   function setAbsSize($w, $h) {
  165.     $this->w = $w;
  166.     $this->h = $h;
  167.  
  168.     return $this->getSize();
  169.   }
  170.  
  171.   /**
  172.    * Get the size of the component handled by the driver
  173.    *
  174.    * @return array Absolute width and height of the component
  175.    */
  176.   function getSize() {
  177.     return array($this->w, $this->h);
  178.   }
  179.  
  180.   /**
  181.    * Turn antialiasing on or off
  182.    *
  183.    * @var bool $bool 
  184.    */
  185.   function setAntiAliasing($bool) {
  186.     if($this->movie !== NULL) {
  187.  
  188.       $actionscript = '
  189.             _quality = "%s";
  190.             ';
  191.  
  192.       if((bool)$bool) {
  193.         $actionscript = sprintf($actionscript, 'high');
  194.       } else {
  195.         $actionscript = sprintf($actionscript, 'low');
  196.       }
  197.           
  198.       $this->movie->add(new SWFAction(str_replace("\r", "", $actionscript)));
  199.     }
  200.   }
  201.  
  202.   /**
  203.    * When passed a Color object, returns the corresponding
  204.    * color identifier (driver dependant).
  205.    *
  206.    * @param $color A Color object
  207.    * @return array $rgba A color identifier representing the color composed of the given RGB components
  208.    */
  209.   function getColor($color) {
  210.  
  211.     // Ming simply works with R, G, B and Alpha values.
  212.     list($red, $green, $blue, $alpha) = $color->rgba();
  213.  
  214.     // However, the Ming alpha channel ranges from 255 (opaque) to 0 (transparent),
  215.     // while the awColor alpha channel ranges from 0 (opaque) to 100 (transparent).
  216.     // First, we convert from 0-100 to 0-255.
  217.     $alpha = (int)($alpha * 255 / 100);
  218.  
  219.     // Then from 0-255 to 255-0.
  220.     $alpha = abs($alpha - 255);
  221.  
  222.     return array($red, $green, $blue, $alpha);
  223.   }
  224.  
  225.   /**
  226.    * Draw an image here
  227.    *
  228.    * @param &$image Image
  229.    * @param int $p1 Image top-left point
  230.    * @param int $p2 Image bottom-right point
  231.    */
  232.   function copyImage(&$image, $p1, $p2) {
  233.  
  234.   }
  235.  
  236.   /**
  237.    * Draw an image here
  238.    *
  239.    * @param &$image Image
  240.    * @param int $d1 Destination top-left position
  241.    * @param int $d2 Destination bottom-right position
  242.    * @param int $s1 Source top-left position
  243.    * @param int $s2 Source bottom-right position
  244.    * @param bool $resample Resample image ? (default to TRUE)
  245.    */
  246.   function copyResizeImage(&$image, $d1, $d2, $s1, $s2, $resample = TRUE) {
  247.  
  248.   }
  249.  
  250.   /**
  251.    * Draw a string
  252.    *
  253.    * @var &$text Text to print
  254.    * @param $point Draw the text at this point
  255.    * @param int $width Text max width
  256.    */
  257.   function string(&$text, $point, $width = NULL) {
  258.     $font = $text->getFont();
  259.  
  260.     // Can we deal with that font?
  261.     if($this->isCompatibleWithFont($font) === FALSE) {
  262.       awImage::drawError('Class MingDriver: Incompatible font type (\''.get_class($font).'\')');
  263.     }
  264.  
  265.     // Ming can only work with awFileFont objects for now
  266.     // (i.e. awFDBFont, or awTuffy et al.)
  267.     $fontDriver = $this->fileFontDriver;
  268.  
  269.     if($text->getBackground() !== NULL or $text->border->visible()) {
  270.  
  271.       list($left, $right, $top, $bottom) = $text->getPadding();
  272.  
  273.       $textWidth = $fontDriver->getTextWidth($text, $this);
  274.       $textHeight = $fontDriver->getTextHeight($text, $this);
  275.           
  276.       $x1 = floor($point->x - $left);
  277.       $y1 = floor($point->y - $top);
  278.       $x2 = $x1 + $textWidth + $left + $right;
  279.       $y2 = $y1 + $textHeight + $top + $bottom;
  280.           
  281.       $this->filledRectangle(
  282.       $text->getBackground(),
  283.       awLine::build($x1, $y1, $x2, $y2)
  284.       );
  285.           
  286.       $text->border->rectangle(
  287.       $this,
  288.       new awPoint($x1 - 1, $y1 - 1),
  289.       new awPoint($x2 + 1, $y2 + 1)
  290.       );
  291.           
  292.     }
  293.  
  294.     $fontDriver->string($this, $text, $point, $width);
  295.   }
  296.  
  297.   /**
  298.    * Draw a pixel
  299.    *
  300.    * @param $color Pixel color
  301.    * @param $p 
  302.    */
  303.   function point($color, $p) {
  304.     if($p->isHidden() === FALSE) {
  305.       list($red, $green, $blue, $alpha) = $this->getColor($color);
  306.           
  307.       $point = new SWFShape();
  308.       $point->setLine(1, $red, $green, $blue, $alpha);
  309.       $point->movePenTo($this->x + round($p->x), $this->y + round($p->y));
  310.       $point->drawLine(0.5, 0.5);
  311.       $point->movePen(-0.5, 0);
  312.       $point->drawLine(0.5, -0.5);
  313.           
  314.       $this->movie->add($point);
  315.     }
  316.   }
  317.  
  318.   /**
  319.    * Draw a colored line
  320.    *
  321.    * @param $color Line color
  322.    * @param $line 
  323.    * @param int $thickness Line tickness
  324.    */
  325.   function line($color, $line) {
  326.     if($line->getThickness() > 0 and $line->isHidden() === FALSE) {
  327.  
  328.       list($red, $green, $blue, $alpha) = $this->getColor($color);
  329.  
  330.       $mingLine = new SWFShape();
  331.       $mingLine->setLine($line->getThickness(), $red, $green, $blue, $alpha);
  332.  
  333.       list($p1, $p2) = $line->getLocation();
  334.           
  335.       $mingLine->movePenTo($this->x + round($p1->x), $this->y + round($p1->y));
  336.  
  337.       switch($line->getStyle()) {
  338.             
  339.         case LINE_SOLID :
  340.           $mingLine->drawLineTo($this->x + round($p2->x), $this->y + round($p2->y));
  341.           $this->movie->add($mingLine);
  342.           break;
  343.               
  344.         case LINE_DOTTED :
  345.           $size = sqrt(pow($p2->y - $p1->y, 2) + pow($p2->x - $p1->x, 2));
  346.           $cos = ($p2->x - $p1->x) / $size;
  347.           $sin = ($p2->y - $p1->y) / $size;
  348.               
  349.           for($i = 0; $i <= $size; $i += 2) {
  350.             $p = new awPoint(
  351.             round($i * $cos + $p1->x),
  352.             round($i * $sin + $p1->y)
  353.             );
  354.             $this->point($color, $p);
  355.           }
  356.               
  357.           break;
  358.               
  359.         case LINE_DASHED :
  360.           $width = $p2->x - $p1->x;
  361.           $height = $p2->y - $p1->y;
  362.           $size = sqrt(pow($height, 2) + pow($width, 2));
  363.               
  364.           if($size == 0) {
  365.             return;
  366.           }
  367.               
  368.           $cos = $width / $size;
  369.           $sin = $height / $size;
  370.               
  371.           $functionX = ($width  > 0) ? 'min' : 'max';
  372.           $functionY = ($height > 0) ? 'min' : 'max';
  373.               
  374.           for($i = 0; $i <= $size; $i += 6) {
  375.  
  376.             $t1 = new awPoint(
  377.             round($i * $cos + $p1->x),
  378.             round($i * $sin + $p1->y)
  379.             );
  380.  
  381.             $t2 = new awPoint(
  382.             round($functionX(($i + 3) * $cos, $width) + $p1->x),
  383.             round($functionY(($i + 3) * $sin, $height) + $p1->y)
  384.             );
  385.  
  386.             $this->line($color, new awLine($t1, $t2));
  387.  
  388.           }
  389.               
  390.           break;
  391.               
  392.       }
  393.  
  394.     }
  395.  
  396.   }
  397.  
  398.   /**
  399.    * Draw a color arc
  400.  
  401.    * @param $color Arc color
  402.    * @param $center Point center
  403.    * @param int $width Ellipse width
  404.    * @param int $height Ellipse height
  405.    * @param int $from Start angle
  406.    * @param int $to End angle
  407.    */
  408.   function arc($color, $center, $width, $height, $from, $to) {
  409.  
  410.   }
  411.  
  412.   /**
  413.    * Draw an arc with a background color
  414.    *
  415.    * @param $color Arc background color
  416.    * @param $center Point center
  417.    * @param int $width Ellipse width
  418.    * @param int $height Ellipse height
  419.    * @param int $from Start angle
  420.    * @param int $to End angle
  421.    */
  422.   function filledArc($color, $center, $width, $height, $from, $to) {
  423.  
  424.   }
  425.  
  426.   /**
  427.    * Draw a colored ellipse
  428.    *
  429.    * @param $color Ellipse color
  430.    * @param $center Ellipse center
  431.    * @param int $width Ellipse width
  432.    * @param int $height Ellipse height
  433.    */
  434.   function ellipse($color, $center, $width, $height) {
  435.  
  436.   }
  437.  
  438.   /**
  439.    * Draw an ellipse with a background
  440.    *
  441.    * @param mixed $background Background (can be a color or a gradient)
  442.    * @param $center Ellipse center
  443.    * @param int $width Ellipse width
  444.    * @param int $height Ellipse height
  445.    */
  446.   function filledEllipse($background, $center, $width, $height) {
  447.  
  448.   }
  449.  
  450.   /**
  451.    * Draw a colored rectangle
  452.    *
  453.    * @param $color Rectangle color
  454.    * @param $line Rectangle diagonale
  455.    * @param $p2 
  456.    */
  457.   function rectangle($color, $line) {
  458.     list($p1, $p2) = $line->getLocation();
  459.  
  460.     // Get Red, Green, Blue and Alpha values for the line
  461.     list($r, $g, $b, $a) = $this->getColor($color);
  462.  
  463.     // Calculate the coordinates of the two other points of the rectangle
  464.     $p3 = new Point($p1->x, $p2->y);
  465.     $p4 = new Point($p2->x, $p1->y);
  466.  
  467.  
  468.  
  469.     $side = new Line($p1, $p2);
  470.  
  471.  
  472.     // Draw the four sides of the rectangle, clockwise
  473.     if(
  474.     ($p1->x <= $p2->x and $p1->y <= $p2->y)
  475.     or
  476.     ($p1->x >= $p2->x and $p1->y >= $p2->y)
  477.     ) {
  478.       $side->setLocation($p1, $p4);
  479.       $this->line($color, $side);
  480.           
  481.       $side->setLocation($p4, $p2);
  482.       $this->line($color, $side);
  483.           
  484.       $side->setLocation($p2, $p3);
  485.       $this->line($color, $side);
  486.           
  487.       $side->setLocation($p3, $p1);
  488.       $this->line($color, $side);
  489.     } else {
  490.       $side->setLocation($p1, $p3);
  491.       $this->line($color, $side);
  492.           
  493.       $side->setLocation($p3, $p2);
  494.       $this->line($color, $side);
  495.           
  496.       $side->setLocation($p2, $p4);
  497.       $this->line($color, $side);
  498.           
  499.       $side->setLocation($p4, $p1);
  500.       $this->line($color, $side);
  501.     }
  502.   }
  503.  
  504.   /**
  505.    * Draw a rectangle with a background
  506.    *
  507.    * @param mixed $background Background (can be a color or a gradient)
  508.    * @param $line Rectangle diagonale
  509.    */
  510.   function filledRectangle($background, $line) {
  511.     list($p1, $p2) = $line->getLocation();
  512.  
  513.     // Common shape settings
  514.     $shape = new SWFShape();
  515.     $shape->setLine(0);
  516.  
  517.     if(is_a($background, 'awColor')) {
  518.           
  519.       // Get the Red, Green, Blue and Alpha values
  520.       list($r, $g, $b, $a) = $this->getColor($background);
  521.       $shape->setRightFill($r, $g, $b, $a);
  522.           
  523.     } else if(is_a($background, 'awGradient')) {
  524.           
  525.       // Get the Gradient object as an SWFGradient one
  526.       list($flashGradient, $style) = $this->getGradient($background);
  527.           
  528.       $fill = $shape->addFill($flashGradient, $style);
  529.           
  530.       // Angles between Artichow and Ming don't match.
  531.       // Don't use abs() or vertical gradients get inverted.
  532.       $angle = $background->angle - 90;
  533.       $fill->rotateTo($angle);
  534.           
  535.       // Move the gradient based on the position of the rectangle we're drawing
  536.       $centerX = min($p1->x, $p2->y) + abs($p1->x - $p2->x) / 2;
  537.       $centerY = min($p1->y, $p2->y) + abs($p1->y - $p2->y) / 2;
  538.       $fill->moveTo($centerX, $centerY);
  539.           
  540.       // Ming draws its gradients on a 1600x1600 image,
  541.       // so we have to resize it.
  542.       if($angle === -90) {
  543.         $ratio = abs($p1->y - $p2->y) / 1600;
  544.       } else {
  545.         $ratio = abs($p1->x - $p2->x) / 1600;
  546.       }
  547.       $fill->scaleTo($ratio);
  548.           
  549.       $shape->setRightFill($fill);
  550.           
  551.     }
  552.  
  553.     // Set starting position
  554.     $shape->movePenTo($this->x + round($p1->x), $this->y + round($p1->y));
  555.  
  556.     // Depending on the points' relative positions,
  557.     // we have two drawing possibilities
  558.     if(
  559.     ($p1->x <= $p2->x and $p1->y <= $p2->y)
  560.     or
  561.     ($p1->x >= $p2->x and $p1->y >= $p2->y)
  562.     ) {
  563.       $shape->drawLineTo($this->x + round($p2->x), $this->y + round($p1->y));
  564.       $shape->drawLineTo($this->x + round($p2->x), $this->y + round($p2->y));
  565.       $shape->drawLineTo($this->x + round($p1->x), $this->y + round($p2->y));
  566.       $shape->drawLineTo($this->x + round($p1->x), $this->y + round($p1->y));
  567.     } else {
  568.       $shape->drawLineTo($this->x + round($p1->x), $this->y + round($p2->y));
  569.       $shape->drawLineTo($this->x + round($p2->x), $this->y + round($p2->y));
  570.       $shape->drawLineTo($this->x + round($p2->x), $this->y + round($p1->y));
  571.       $shape->drawLineTo($this->x + round($p1->x), $this->y + round($p1->y));
  572.     }
  573.  
  574.     $this->movie->add($shape);
  575.   }
  576.  
  577.   /**
  578.    * Draw a polygon
  579.    *
  580.    * @param $color Polygon color
  581.    * @param Polygon A polygon
  582.    */
  583.   function polygon($color, &$polygon) {
  584.     $points = $polygon->all();
  585.     $count = count($points);
  586.  
  587.     if($count > 1) {
  588.           
  589.       $side = new awLine;
  590.       $side->setStyle($polygon->getStyle());
  591.       $side->setThickness($polygon->getThickness());
  592.           
  593.       $prev = $points[0];
  594.           
  595.       for($i = 1; $i < $count; $i++) {
  596.         $current = $points[$i];
  597.         $side->setLocation($prev, $current);
  598.         $this->line($color, $side);
  599.         $prev = $current;
  600.       }
  601.           
  602.       // Close the polygon
  603.       $side->setLocation($prev, $points[0]);
  604.       $this->line($color, $side);
  605.     }
  606.   }
  607.  
  608.   /**
  609.    * Draw a polygon with a background
  610.    *
  611.    * @param mixed $background Background (can be a color or a gradient)
  612.    * @param Polygon A polygon
  613.    */
  614.   function filledPolygon($background, &$polygon) {
  615.     $shape = new SWFShape();
  616.  
  617.     if(is_a($background, 'awColor')) {
  618.       list($red, $green, $blue, $alpha) = $this->getColor($background);
  619.           
  620.       $shape->setRightFill($red, $green, $blue, $alpha);
  621.     } elseif(is_a($background, 'awGradient')) {
  622.       list($flashGradient, $style) = $this->getGradient($background);
  623.           
  624.       $fill = $shape->addFill($flashGradient, $style);
  625.           
  626.       list($xMin, $xMax) = $polygon->getBoxXRange();
  627.       list($yMin, $yMax) = $polygon->getBoxYRange();
  628.           
  629.       if($background->angle === 0) {
  630.         $fill->scaleTo(($yMax - $yMin) / 1600);
  631.       } else {
  632.         $fill->scaleTo(($xMax - $xMin) / 1600);
  633.       }
  634.       $fill->moveTo($xMin + ($xMax - $xMin) / 2, $yMin + ($yMax - $yMin) / 2);
  635.           
  636.       $shape->setRightFill($fill);
  637.     }
  638.  
  639.     $points = $polygon->all();
  640.     $count = count($points);
  641.  
  642.     if($count > 1) {
  643.           
  644.       $prev = $points[0];
  645.           
  646.       $shape->movePenTo($prev->x, $prev->y);
  647.           
  648.       for($i = 1; $i < $count; $i++) {
  649.         $current = $points[$i];
  650.         $shape->drawLineTo($current->x, $current->y);
  651.       }
  652.           
  653.       // Close the polygon
  654.       $shape->drawLineTo($prev->x, $prev->y);
  655.           
  656.       $this->movie->add($shape);
  657.           
  658.     }
  659.   }
  660.  
  661.   /**
  662.    * Sends the image, as well as the correct HTTP headers, to the browser
  663.    *
  664.    * @param &$image The Image object to send
  665.    */
  666.   function send(&$image) {
  667.     $this->drawImage($image);
  668.   }
  669.  
  670.   /**
  671.    * Get the image as binary data
  672.    *
  673.    * @param &$image 
  674.    */
  675.   function get(&$image) {
  676.     return $this->drawImage($image, TRUE, FALSE);
  677.   }
  678.  
  679.   function getTextWidth(&$text) {
  680.     $font = $text->getFont();
  681.     if($this->isCompatibleWithFont($font) === FALSE) {
  682.       awImage::drawError('Class MingDriver: Incompatible font type (\''.get_class($font).'\')');
  683.     }
  684.  
  685.     // Ming only supports FileFont
  686.     $fontDriver = $this->fileFontDriver;
  687.  
  688.     return $fontDriver->getTextWidth($text, $this);
  689.   }
  690.  
  691.   function getTextHeight(&$text) {
  692.     $font = $text->getFont();
  693.     if($this->isCompatibleWithFont($font) === FALSE) {
  694.       awImage::drawError('Class MingDriver: Incompatible font type (\''.get_class($font).'\')');
  695.     }
  696.  
  697.     // Ming only supports FileFont
  698.     $fontDriver = $this->fileFontDriver;
  699.  
  700.     return $fontDriver->getTextHeight($text, $this);
  701.   }
  702.  
  703.   function isCompatibleWithFont(&$font) {
  704.     if(is_a($font, 'awTTFFont') or is_a($font, 'awPHPFont')) {
  705.       return FALSE;
  706.     } else {
  707.       return TRUE;
  708.     }
  709.   }
  710.  
  711.   function drawImage(&$image, $return = FALSE, $header = TRUE) {
  712.  
  713.     // Send headers to the browser
  714.     if($header === TRUE) {
  715.       $image->sendHeaders();
  716.     }
  717.  
  718.     if($return) {
  719.       ob_start();
  720.     }
  721.  
  722.     $this->movie->output();
  723.  
  724.     if($return) {
  725.       return ob_get_clean();
  726.     }
  727.   }
  728.  
  729.   /**
  730.    * Convert an awGradient object to an SWFGradient one.
  731.    * Returns an object as well as the style of the Flash gradient.
  732.    *
  733.    * @param $gradient The awGradient object to convert
  734.    * @return array 
  735.    */
  736.   function getGradient($gradient) {
  737.     $flashGradient = new SWFGradient();
  738.  
  739.     // Get RGBA values for the gradient boundaries
  740.     list($r1, $g1, $b1, $a1) = $this->getColor($gradient->from);
  741.     list($r2, $g2, $b2, $a2) = $this->getColor($gradient->to);
  742.  
  743.     $flashGradient->addEntry(0, $r1, $g1, $b1, $a1);
  744.  
  745.     if(is_a($gradient, 'awBilinearGradient')) {
  746.           
  747.       $flashGradient->addEntry($gradient->center, $r2, $g2, $b2, $a2);
  748.       $flashGradient->addEntry(1, $r1, $g1, $b1, $a1);
  749.           
  750.       return array($flashGradient, SWFFILL_LINEAR_GRADIENT);
  751.     } else {
  752.  
  753.       $flashGradient->addEntry(1, $r2, $g2, $b2, $a2);
  754.           
  755.       if(is_a($gradient, 'awLinearGradient')) {
  756.         return array($flashGradient, SWFFILL_LINEAR_GRADIENT);
  757.       } else {
  758.         return array($flashGradient, SWFFILL_RADIAL_GRADIENT);
  759.       }
  760.     }
  761.   }
  762.   //    abstract private
  763.  
  764. }
  765.  
  766. registerClass('MingDriver');
  767.  
  768. /*
  769.  * Check for ming presence
  770.  */
  771. if(function_exists('ming_useswfversion') === FALSE) {
  772.   awImage::drawErrorFile('missing-ming');
  773. }
  774.  
  775. ?>

Documentation generated on Fri, 01 Apr 2011 09:33:00 +0200 by phpDocumentor 1.4.1