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.   public $movie;
  26.  
  27.   public function __construct() {
  28.  
  29.     parent::__construct();
  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 awImage $image 
  43.    */
  44.   public function init(awImage $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 awFileImage $fileImage The FileImage object to work on
  87.    * @param string $file Image filename
  88.    */
  89.   public function initFromFile(awFileImage $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.   public 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.   public 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.   public 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.   public 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.   public 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.   public 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.   public 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.   public 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 awColor $color A Color object
  207.    * @return array $rgba A color identifier representing the color composed of the given RGB components
  208.    */
  209.   public function getColor(awColor $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 awImage $image Image
  229.    * @param int $p1 Image top-left point
  230.    * @param int $p2 Image bottom-right point
  231.    */
  232.   public function copyImage(awImage $image, awPoint $p1, awPoint $p2) {
  233.  
  234.   }
  235.  
  236.   /**
  237.    * Draw an image here
  238.    *
  239.    * @param awImage $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.   public function copyResizeImage(awImage $image, awPoint $d1, awPoint $d2, awPoint $s1, awPoint $s2, $resample = TRUE) {
  247.  
  248.   }
  249.  
  250.   /**
  251.    * Draw a string
  252.    *
  253.    * @var awText $text Text to print
  254.    * @param awPoint $point Draw the text at this point
  255.    * @param int $width Text max width
  256.    */
  257.   public function string(awText $text, awPoint $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 awColor $color Pixel color
  301.    * @param awPoint $p 
  302.    */
  303.   public function point(awColor $color, awPoint $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 awColor $color Line color
  322.    * @param awLine $line 
  323.    * @param int $thickness Line tickness
  324.    */
  325.   public function line(awColor $color, awLine $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 awLine::SOLID :
  340.           $mingLine->drawLineTo($this->x + round($p2->x), $this->y + round($p2->y));
  341.           $this->movie->add($mingLine);
  342.           break;
  343.               
  344.         case awLine::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 awLine::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 awColor $color Arc color
  402.    * @param awPoint $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.   public function arc(awColor $color, awPoint $center, $width, $height, $from, $to) {
  409.  
  410.   }
  411.  
  412.   /**
  413.    * Draw an arc with a background color
  414.    *
  415.    * @param awColor $color Arc background color
  416.    * @param awPoint $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.   public function filledArc(awColor $color, awPoint $center, $width, $height, $from, $to) {
  423.  
  424.   }
  425.  
  426.   /**
  427.    * Draw a colored ellipse
  428.    *
  429.    * @param awColor $color Ellipse color
  430.    * @param awPoint $center Ellipse center
  431.    * @param int $width Ellipse width
  432.    * @param int $height Ellipse height
  433.    */
  434.   public function ellipse(awColor $color, awPoint $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 awPoint $center Ellipse center
  443.    * @param int $width Ellipse width
  444.    * @param int $height Ellipse height
  445.    */
  446.   public function filledEllipse($background, awPoint $center, $width, $height) {
  447.  
  448.   }
  449.  
  450.   /**
  451.    * Draw a colored rectangle
  452.    *
  453.    * @param awColor $color Rectangle color
  454.    * @param awLine $line Rectangle diagonale
  455.    * @param awPoint $p2 
  456.    */
  457.   public function rectangle(awColor $color, awLine $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.     /* <php5> */
  468.     $side = clone $line;
  469.     /* </php5> */
  470.  
  471.     /* <php4> --
  472.      $side = new Line($p1, $p2);
  473.      -- </php4> */
  474.  
  475.     // Draw the four sides of the rectangle, clockwise
  476.     if(
  477.     ($p1->x <= $p2->x and $p1->y <= $p2->y)
  478.     or
  479.     ($p1->x >= $p2->x and $p1->y >= $p2->y)
  480.     ) {
  481.       $side->setLocation($p1, $p4);
  482.       $this->line($color, $side);
  483.           
  484.       $side->setLocation($p4, $p2);
  485.       $this->line($color, $side);
  486.           
  487.       $side->setLocation($p2, $p3);
  488.       $this->line($color, $side);
  489.           
  490.       $side->setLocation($p3, $p1);
  491.       $this->line($color, $side);
  492.     } else {
  493.       $side->setLocation($p1, $p3);
  494.       $this->line($color, $side);
  495.           
  496.       $side->setLocation($p3, $p2);
  497.       $this->line($color, $side);
  498.           
  499.       $side->setLocation($p2, $p4);
  500.       $this->line($color, $side);
  501.           
  502.       $side->setLocation($p4, $p1);
  503.       $this->line($color, $side);
  504.     }
  505.   }
  506.  
  507.   /**
  508.    * Draw a rectangle with a background
  509.    *
  510.    * @param mixed $background Background (can be a color or a gradient)
  511.    * @param awLine $line Rectangle diagonale
  512.    */
  513.   public function filledRectangle($background, awLine $line) {
  514.     list($p1, $p2) = $line->getLocation();
  515.  
  516.     // Common shape settings
  517.     $shape = new SWFShape();
  518.     $shape->setLine(0);
  519.  
  520.     if($background instanceof awColor) {
  521.           
  522.       // Get the Red, Green, Blue and Alpha values
  523.       list($r, $g, $b, $a) = $this->getColor($background);
  524.       $shape->setRightFill($r, $g, $b, $a);
  525.           
  526.     } else if($background instanceof awGradient) {
  527.           
  528.       // Get the Gradient object as an SWFGradient one
  529.       list($flashGradient, $style) = $this->getGradient($background);
  530.           
  531.       $fill = $shape->addFill($flashGradient, $style);
  532.           
  533.       // Angles between Artichow and Ming don't match.
  534.       // Don't use abs() or vertical gradients get inverted.
  535.       $angle = $background->angle - 90;
  536.       $fill->rotateTo($angle);
  537.           
  538.       // Move the gradient based on the position of the rectangle we're drawing
  539.       $centerX = min($p1->x, $p2->y) + abs($p1->x - $p2->x) / 2;
  540.       $centerY = min($p1->y, $p2->y) + abs($p1->y - $p2->y) / 2;
  541.       $fill->moveTo($centerX, $centerY);
  542.           
  543.       // Ming draws its gradients on a 1600x1600 image,
  544.       // so we have to resize it.
  545.       if($angle === -90) {
  546.         $ratio = abs($p1->y - $p2->y) / 1600;
  547.       } else {
  548.         $ratio = abs($p1->x - $p2->x) / 1600;
  549.       }
  550.       $fill->scaleTo($ratio);
  551.           
  552.       $shape->setRightFill($fill);
  553.           
  554.     }
  555.  
  556.     // Set starting position
  557.     $shape->movePenTo($this->x + round($p1->x), $this->y + round($p1->y));
  558.  
  559.     // Depending on the points' relative positions,
  560.     // we have two drawing possibilities
  561.     if(
  562.     ($p1->x <= $p2->x and $p1->y <= $p2->y)
  563.     or
  564.     ($p1->x >= $p2->x and $p1->y >= $p2->y)
  565.     ) {
  566.       $shape->drawLineTo($this->x + round($p2->x), $this->y + round($p1->y));
  567.       $shape->drawLineTo($this->x + round($p2->x), $this->y + round($p2->y));
  568.       $shape->drawLineTo($this->x + round($p1->x), $this->y + round($p2->y));
  569.       $shape->drawLineTo($this->x + round($p1->x), $this->y + round($p1->y));
  570.     } else {
  571.       $shape->drawLineTo($this->x + round($p1->x), $this->y + round($p2->y));
  572.       $shape->drawLineTo($this->x + round($p2->x), $this->y + round($p2->y));
  573.       $shape->drawLineTo($this->x + round($p2->x), $this->y + round($p1->y));
  574.       $shape->drawLineTo($this->x + round($p1->x), $this->y + round($p1->y));
  575.     }
  576.  
  577.     $this->movie->add($shape);
  578.   }
  579.  
  580.   /**
  581.    * Draw a polygon
  582.    *
  583.    * @param awColor $color Polygon color
  584.    * @param Polygon A polygon
  585.    */
  586.   public function polygon(awColor $color, awPolygon $polygon) {
  587.     $points = $polygon->all();
  588.     $count = count($points);
  589.  
  590.     if($count > 1) {
  591.           
  592.       $side = new awLine;
  593.       $side->setStyle($polygon->getStyle());
  594.       $side->setThickness($polygon->getThickness());
  595.           
  596.       $prev = $points[0];
  597.           
  598.       for($i = 1; $i < $count; $i++) {
  599.         $current = $points[$i];
  600.         $side->setLocation($prev, $current);
  601.         $this->line($color, $side);
  602.         $prev = $current;
  603.       }
  604.           
  605.       // Close the polygon
  606.       $side->setLocation($prev, $points[0]);
  607.       $this->line($color, $side);
  608.     }
  609.   }
  610.  
  611.   /**
  612.    * Draw a polygon with a background
  613.    *
  614.    * @param mixed $background Background (can be a color or a gradient)
  615.    * @param Polygon A polygon
  616.    */
  617.   public function filledPolygon($background, awPolygon $polygon) {
  618.     $shape = new SWFShape();
  619.  
  620.     if($background instanceof awColor) {
  621.       list($red, $green, $blue, $alpha) = $this->getColor($background);
  622.           
  623.       $shape->setRightFill($red, $green, $blue, $alpha);
  624.     } elseif($background instanceof awGradient) {
  625.       list($flashGradient, $style) = $this->getGradient($background);
  626.           
  627.       $fill = $shape->addFill($flashGradient, $style);
  628.           
  629.       list($xMin, $xMax) = $polygon->getBoxXRange();
  630.       list($yMin, $yMax) = $polygon->getBoxYRange();
  631.           
  632.       if($background->angle === 0) {
  633.         $fill->scaleTo(($yMax - $yMin) / 1600);
  634.       } else {
  635.         $fill->scaleTo(($xMax - $xMin) / 1600);
  636.       }
  637.       $fill->moveTo($xMin + ($xMax - $xMin) / 2, $yMin + ($yMax - $yMin) / 2);
  638.           
  639.       $shape->setRightFill($fill);
  640.     }
  641.  
  642.     $points = $polygon->all();
  643.     $count = count($points);
  644.  
  645.     if($count > 1) {
  646.           
  647.       $prev = $points[0];
  648.           
  649.       $shape->movePenTo($prev->x, $prev->y);
  650.           
  651.       for($i = 1; $i < $count; $i++) {
  652.         $current = $points[$i];
  653.         $shape->drawLineTo($current->x, $current->y);
  654.       }
  655.           
  656.       // Close the polygon
  657.       $shape->drawLineTo($prev->x, $prev->y);
  658.           
  659.       $this->movie->add($shape);
  660.           
  661.     }
  662.   }
  663.  
  664.   /**
  665.    * Sends the image, as well as the correct HTTP headers, to the browser
  666.    *
  667.    * @param awImage $image The Image object to send
  668.    */
  669.   public function send(awImage $image) {
  670.     $this->drawImage($image);
  671.   }
  672.  
  673.   /**
  674.    * Get the image as binary data
  675.    *
  676.    * @param awImage $image 
  677.    */
  678.   public function get(awImage $image) {
  679.     return $this->drawImage($image, TRUE, FALSE);
  680.   }
  681.  
  682.   public function getTextWidth(awText $text) {
  683.     $font = $text->getFont();
  684.     if($this->isCompatibleWithFont($font) === FALSE) {
  685.       awImage::drawError('Class MingDriver: Incompatible font type (\''.get_class($font).'\')');
  686.     }
  687.  
  688.     // Ming only supports FileFont
  689.     $fontDriver = $this->fileFontDriver;
  690.  
  691.     return $fontDriver->getTextWidth($text, $this);
  692.   }
  693.  
  694.   public function getTextHeight(awText $text) {
  695.     $font = $text->getFont();
  696.     if($this->isCompatibleWithFont($font) === FALSE) {
  697.       awImage::drawError('Class MingDriver: Incompatible font type (\''.get_class($font).'\')');
  698.     }
  699.  
  700.     // Ming only supports FileFont
  701.     $fontDriver = $this->fileFontDriver;
  702.  
  703.     return $fontDriver->getTextHeight($text, $this);
  704.   }
  705.  
  706.   protected function isCompatibleWithFont(awFont $font) {
  707.     if($font instanceof awTTFFont or $font instanceof awPHPFont) {
  708.       return FALSE;
  709.     } else {
  710.       return TRUE;
  711.     }
  712.   }
  713.  
  714.   private function drawImage(awImage $image, $return = FALSE, $header = TRUE) {
  715.  
  716.     // Send headers to the browser
  717.     if($header === TRUE) {
  718.       $image->sendHeaders();
  719.     }
  720.  
  721.     if($return) {
  722.       ob_start();
  723.     }
  724.  
  725.     $this->movie->output();
  726.  
  727.     if($return) {
  728.       return ob_get_clean();
  729.     }
  730.   }
  731.  
  732.   /**
  733.    * Convert an awGradient object to an SWFGradient one.
  734.    * Returns an object as well as the style of the Flash gradient.
  735.    *
  736.    * @param awGradient $gradient The awGradient object to convert
  737.    * @return array 
  738.    */
  739.   private function getGradient(awGradient $gradient) {
  740.     $flashGradient = new SWFGradient();
  741.  
  742.     // Get RGBA values for the gradient boundaries
  743.     list($r1, $g1, $b1, $a1) = $this->getColor($gradient->from);
  744.     list($r2, $g2, $b2, $a2) = $this->getColor($gradient->to);
  745.  
  746.     $flashGradient->addEntry(0, $r1, $g1, $b1, $a1);
  747.  
  748.     if($gradient instanceof awBilinearGradient) {
  749.           
  750.       $flashGradient->addEntry($gradient->center, $r2, $g2, $b2, $a2);
  751.       $flashGradient->addEntry(1, $r1, $g1, $b1, $a1);
  752.           
  753.       return array($flashGradient, SWFFILL_LINEAR_GRADIENT);
  754.     } else {
  755.  
  756.       $flashGradient->addEntry(1, $r2, $g2, $b2, $a2);
  757.           
  758.       if($gradient instanceof awLinearGradient) {
  759.         return array($flashGradient, SWFFILL_LINEAR_GRADIENT);
  760.       } else {
  761.         return array($flashGradient, SWFFILL_RADIAL_GRADIENT);
  762.       }
  763.     }
  764.   }
  765.   //    abstract private function getPolygonPoints(awPolygon $polygon);
  766.  
  767. }
  768.  
  769. registerClass('MingDriver');
  770.  
  771. /*
  772.  * Check for ming presence
  773.  */
  774. if(function_exists('ming_useswfversion') === FALSE) {
  775.   awImage::drawErrorFile('missing-ming');
  776. }
  777.  
  778. ?>

Documentation generated on Thu, 03 May 2012 15:06:21 +0200 by phpDocumentor 1.4.1