1<?php 2 3/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 4 5/** 6 * Class for handling output in SWF flash format. 7 * 8 * Requires PHP extension ming 9 * 10 * LICENSE: This library is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU Lesser General Public License as published by 12 * the Free Software Foundation; either version 2.1 of the License, or (at your 13 * option) any later version. This library is distributed in the hope that it 14 * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 16 * General Public License for more details. You should have received a copy of 17 * the GNU Lesser General Public License along with this library; if not, write 18 * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 19 * 02111-1307 USA 20 * 21 * @category Images 22 * @package Image_Canvas 23 * @author Torsten Roehr <troehr@php.net> 24 * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen 25 * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 26 * @version CVS: $Id: SWF.php 287471 2009-08-18 23:12:01Z clockwerx $ 27 * @link http://pear.php.net/package/Image_Canvas 28 */ 29 30/** 31 * Include file Image/Canvas.php 32 */ 33require_once 'Image/Canvas.php'; 34 35/** 36 * Include file Image/Canvas/Color.php 37 */ 38require_once 'Image/Canvas/Color.php'; 39 40/** 41 * SVG Canvas class. 42 * 43 * @category Images 44 * @package Image_Canvas 45 * @author Torsten Roehr <troehr@php.net> 46 * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen 47 * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 48 * @version Release: @package_version@ 49 * @link http://pear.php.net/package/Image_Canvas 50 */ 51class Image_Canvas_SWF extends Image_Canvas 52{ 53 54 /** 55 * The canvas of the graph 56 * @var object SWFMovie 57 * @access private 58 */ 59 var $_canvas; 60 61 /** 62 * The default Flash version 63 * 64 * Ming supports up to Flash version 6 65 * 66 * @var int 67 * @access private 68 */ 69 var $_version = 6; 70 71 /** 72 * Creates the SWF movie object 73 * 74 * Parameters available: 75 * 76 * 'width' The width of the graph 77 * 'height' The height of the graph 78 * 'version' The flash version, supports up to version 6 79 * 'background' An array with the background color, e.g. 80 * array('red' => 255, 81 * 'green' => 0, 82 * 'blue' => 0) 83 * Either integers between 0 and 255 or hexadecimals 84 * between 0x00 and 0xFF 85 * 86 * @param array $param Parameter array 87 * @return Image_Canvas_SWF 88 */ 89 function Image_Canvas_SWF($params) 90 { 91 parent::Image_Canvas($params); 92 $this->_reset(); 93 94 $version = (isset($params['version']) && $params['version'] <= 6) 95 ? $params['version'] : $this->_version; 96 97 $this->_canvas = new SWFMovie($version); 98 $this->_canvas->setDimension($this->_width, $this->_height); 99 100 if (isset($params['background'])) { 101 $this->setBackground($params['background']); 102 } 103 } 104 105 /** 106 * Sets the background color 107 * 108 * Values can be specified either as integers between 0 and 255 or as hexadecimals between 0x00 and 0xFF 109 * 110 * @param mixed $color Color 111 * @access public 112 * @return void 113 */ 114 function setBackground($color) 115 { 116 $color = Image_Canvas_Color::color2RGB($color); 117 $this->_canvas->setBackground($color[0], $color[1], $color[2]); 118 } 119 120 /** 121 * Add an object to the movie 122 * 123 * @param string $element The element 124 * @access public 125 */ 126 function addElement($element) 127 { 128 $this->_canvas->add($element); 129 } 130 131 /** 132 * Get the color index for the RGB color 133 * 134 * @param int $color The color 135 * @return int A SVG compatible color 136 * @access private 137 */ 138 function _color($color = false) 139 { 140 if ($color === false) { 141 return array(); 142 } else { 143 return Image_Canvas_Color::color2RGB($color); 144 } 145 } 146 147 /** 148 * Get the opacity for the RGB color 149 * 150 * @param int $color The color 151 * @return int A SWF compatible opacity value 152 * @access private 153 */ 154 function _opacity($color = false) 155 { 156 if ($color === false) { 157 return false; 158 } else { 159 $color = Image_Canvas_Color::color2RGB($color); 160 if ($color[3] != 255) { 161 return sprintf('%0.1f', $color[3]/255); 162 } else { 163 return 255; 164 } 165 } 166 } 167 168 /** 169 * Get the applicable linestyle 170 * 171 * @param mixed $lineStyle The line style to return, false if the one 172 * explicitly set 173 * @return mixed A compatible linestyle 174 * @access private 175 */ 176 function _getLineStyle($lineStyle = false) 177 { 178 if ($lineStyle === false) { 179 $lineStyle = $this->_lineStyle; 180 } 181 182 return $this->_color($lineStyle); 183 } 184 185 /** 186 * Get the applicable fillstyle 187 * 188 * @param mixed $fillStyle The fillstyle to return, false if the one 189 * explicitly set 190 * @return mixed A compatible fillstyle 191 * @access private 192 */ 193 function _getFillStyle($fillStyle = false) 194 { 195 if ($fillStyle === false) { 196 $fillStyle = $this->_fillStyle; 197 } 198 199 return $this->_color($fillStyle); 200 } 201 202 /** 203 * Sets an image that should be used for filling 204 * 205 * @todo 206 * @param string $filename The filename of the image to fill with 207 */ 208 function setFillImage($filename) 209 { 210 } 211 212 /** 213 * Sets a gradient fill 214 * 215 * @todo 216 * @param array $gradient Gradient fill options 217 */ 218 function setGradientFill($gradient) 219 { 220 } 221 222 /** 223 * Sets the font options. 224 * 225 * The $font array may have the following entries: 226 * 'type' : 'ttf' (TrueType) or omitted for default<br> 227 * If 'type' is 'ttf' then the following can be specified<br> 228 * 'size' : size in pixels<br> 229 * 'angle' : the angle with which to write the text 230 * 'file' : the .ttf file (either the basename, filename or full path) 231 * 232 * @param array $font The font options. 233 */ 234 function setFont($fontOptions) 235 { 236 parent::setFont($fontOptions); 237 if (!isset($this->_font['size'])) { 238 $this->_font['size'] = 10; 239 } 240 } 241 242 /** 243 * Draw a line end 244 * 245 * Parameter array: 246 * 'x' : int X point 247 * 'y' : int Y point 248 * 'end' : string The end type of the end 249 * 'size' : int The size of the end 250 * 'color' : string The color of the end 251 * 'angle' : int [optional] The angle with which to draw the end 252 * 'url' : string [optional] Target URL 253 * 254 * @param array $params Parameter array 255 */ 256 function drawEnd($params) 257 { 258 $x = $this->_getX($params['x']); 259 $y = $this->_getY($params['y']); 260 $size = $params['size']; 261 $angle = deg2rad((isset($params['angle']) ? $params['angle'] : 0)); 262 $pi2 = pi() / 2; 263 264 switch ($params['end']) { 265 266 case 'lollipop': 267 case 'circle': 268 if (($fill = $this->_getFillStyle($params['color'])) !== false) { 269 $shapeObj = new SWFShape(); 270 $shapeObj->setRightFill($fill[0], $fill[1], $fill[2]); 271 $shapeObj->movePenTo($x + $size / 2, $y); 272 $shapeObj->drawCircle($size / 2); 273 274 if (isset($params['url'])) { 275 $button = new SWFButton(); 276 $button->addShape($shapeObj, SWFBUTTON_HIT | SWFBUTTON_UP | SWFBUTTON_DOWN | SWFBUTTON_OVER); 277 $button->addAction(new SWFAction("getURL('{$params['url']}');"), SWFBUTTON_MOUSEUP); 278 $this->_canvas->add($button); 279 } else { 280 $this->_canvas->add($shapeObj); 281 } 282 283 parent::drawEnd($params); 284 } 285 break; 286 287 case 'diamond': 288 $x0 = round($params['x'] + cos($angle) * $size * 0.65); 289 $y0 = round($params['y'] - sin($angle) * $size * 0.65); 290 $shape = array( 291 array($x0 + round(cos($angle) * $size * 0.65), 292 $y0 - round(sin($angle) * $size * 0.65)), 293 array($x0 + round(cos($angle + $pi2) * $size * 0.65), 294 $y0 - round(sin($angle + $pi2) * $size * 0.65)), 295 array($x0 + round(cos($angle + pi()) * $size * 0.65), 296 $y0 - round(sin($angle + pi()) * $size * 0.65)), 297 array($x0 + round(cos($angle + 3 * $pi2) * $size * 0.65), 298 $y0 - round(sin($angle + 3 * $pi2) * $size * 0.65)) 299 ); 300 break; 301 302 case 'line': 303 $shape = array( 304 array($x + round(cos($angle + $pi2) * $size / 2), 305 $y - round(sin($angle + $pi2) * $size / 2)), 306 array($x + round(cos($angle + 3 * $pi2) * $size / 2), 307 $y - round(sin($angle + 3 * $pi2) * $size / 2)) 308 ); 309 break; 310 311 case 'box': 312 case 'rectangle': 313 $x0 = round($params['x'] + cos($angle) * $size / 2); 314 $y0 = round($params['y'] - sin($angle) * $size / 2); 315 $pi4 = pi() / 4; 316 $shape = array( 317 array($x0 + round(cos($angle + $pi4) * $size / 2), 318 $y0 - round(sin($angle + $pi4) * $size / 2)), 319 array($x0 + round(cos($angle + $pi2 + $pi4) * $size / 2), 320 $y0 - round(sin($angle + $pi2 + $pi4) * $size / 2)), 321 array($x0 + round(cos($angle + pi() + $pi4) * $size / 2), 322 $y0 - round(sin($angle + pi() + $pi4) * $size / 2)), 323 array($x0 + round(cos($angle + 3 * $pi2 + $pi4) * $size / 2), 324 $y0 - round(sin($angle + 3 * $pi2 + $pi4) * $size / 2)) 325 ); 326 break; 327 328 case 'arrow': 329 $shape = array( 330 array($x + cos($angle) * $size, 331 $y - sin($angle) * $size), 332 array($x + cos($angle + $pi2) * $size * 0.4, 333 $y - sin($angle + $pi2) * $size * 0.4), 334 array($x + cos($angle + 3 * $pi2) * $size * 0.4, 335 $y - sin($angle + 3 * $pi2) * $size * 0.4) 336 ); 337 break; 338 339 case 'arrow2': 340 $shape = array( 341 array($x + round(cos($angle) * $size), 342 $y - round(sin($angle) * $size)), 343 array($x + round(cos($angle + $pi2 + deg2rad(45)) * $size), 344 $y - round(sin($angle + $pi2 + deg2rad(45)) * $size)), 345 array($x, 346 $y), 347 array($x + round(cos($angle + 3 * $pi2 - deg2rad(45)) * $size), 348 $y - round(sin($angle + 3 * $pi2 - deg2rad(45)) * $size)) 349 ); 350 break; 351 } 352 353 if (isset($shape)) { 354 // output the shape 355 if (($fill = $this->_getFillStyle($params['color'])) !== false) { 356 $shapeObj = new SWFShape(); 357 $shapeObj->setRightFill($fill[0], $fill[1], $fill[2]); 358 $shapeObj->setLine(0, $fill[0], $fill[1], $fill[2]); 359 $shapeObj->movePenTo($shape[0][0], $shape[0][1]); 360 for ($count = count($shape); $count--; $count > 0) { 361 $shapeObj->drawLineTo($shape[$count][0], $shape[$count][1]); 362 } 363 364 if (isset($params['url'])) { 365 $button = new SWFButton(); 366 $button->addShape($shapeObj, SWFBUTTON_HIT | SWFBUTTON_UP | SWFBUTTON_DOWN | SWFBUTTON_OVER); 367 $button->addAction(new SWFAction("getURL('{$params['url']}');"), SWFBUTTON_MOUSEUP); 368 $this->_canvas->add($button); 369 } else { 370 $this->_canvas->add($shapeObj); 371 } 372 } 373 } 374 parent::drawEnd($params); 375 } 376 377 /** 378 * Parameter array: 379 * 'x0' : int X start point 380 * 'y0' : int Y start point 381 * 'x1' : int X end point 382 * 'y1' : int Y end point 383 * 'color' : mixed [optional] The line color 384 * 'url' : string [optional] Target URL 385 * @param array $params Parameter array 386 */ 387 function line($params) 388 { 389 $x0 = $this->_getX($params['x0']); 390 $y0 = $this->_getY($params['y0']); 391 $x1 = $this->_getX($params['x1']); 392 $y1 = $this->_getY($params['y1']); 393 394 $color = (isset($params['color']) ? $params['color'] : false); 395 $color = $this->_getLineStyle($color); 396 397 $shape = new SWFShape(); 398 $shape->setLine(1, $color[0], $color[1], $color[2]); 399 400 $shape->movePenTo($x0, $y0); 401 $shape->drawLine($x1 - $x0, $y1 - $y0); 402 403 if (isset($params['url'])) { 404 $button = new SWFButton(); 405 $button->addShape($shape, SWFBUTTON_HIT | SWFBUTTON_UP | SWFBUTTON_DOWN | SWFBUTTON_OVER); 406 $button->addAction(new SWFAction("getURL('{$params['url']}');"), SWFBUTTON_MOUSEUP); 407 $this->_canvas->add($button); 408 } else { 409 $this->_canvas->add($shape); 410 } 411 412 parent::line($params); 413 } 414 415 /** 416 * Parameter array: 417 * 'connect': bool [optional] Specifies whether the start point should be 418 * connected to the endpoint (closed polygon) 419 * or not (connected line) 420 * 'fill' : mixed [optional] The fill color 421 * 'line' : mixed [optional] The line color 422 * 'url' : string [optional] Target URL 423 * @param array $params Parameter array 424 */ 425 function polygon($params = array()) 426 { 427 $connectEnds = (isset($params['connect']) ? $params['connect'] : false); 428 $fillColor = (isset($params['fill']) ? $params['fill'] : false); 429 $lineColor = (isset($params['line']) ? $params['line'] : false); 430 431 $lineStyle = $this->_getLineStyle($lineColor); 432 $fillStyle = $this->_getFillStyle($fillColor); 433 434 $shape = new SWFShape(); 435 if ($connectEnds) { 436 $shape->setRightFill($fillStyle[0], $fillStyle[1], $fillStyle[2]); 437 } 438 $shape->setLine(0, $lineStyle[0], $lineStyle[1], $lineStyle[2]); 439 $shape->movePenTo($this->_polygon[0]['X'], $this->_polygon[0]['Y']); 440 441 foreach ($this->_polygon as $point) { 442 $shape->drawLineTo($point['X'], $point['Y']); 443 } 444 445 if ($connectEnds) { 446 $shape->drawLineTo($this->_polygon[0]['X'], $this->_polygon[0]['Y']); 447 } 448 449 if (isset($params['url'])) { 450 $button = new SWFButton(); 451 $button->addShape($shape, SWFBUTTON_HIT | SWFBUTTON_UP | SWFBUTTON_DOWN | SWFBUTTON_OVER); 452 $button->addAction(new SWFAction("getURL('{$params['url']}');"), SWFBUTTON_MOUSEUP); 453 $this->_canvas->add($button); 454 } else { 455 $this->_canvas->add($shape); 456 } 457 458 parent::polygon($params); 459 } 460 461 /** 462 * Draw a rectangle 463 * 464 * Parameter array: 465 * 'x0' : int X start point 466 * 'y0' : int Y start point 467 * 'x1' : int X end point 468 * 'y1' : int Y end point 469 * 'fill' : The fill style 470 * 'line' : The line style 471 * 'url' : string [optional] Target URL 472 * 473 * @param array $params Parameter array 474 */ 475 function rectangle($params) 476 { 477 $x0 = min($this->_getX($params['x0']), $this->_getX($params['x1'])); 478 $y0 = min($this->_getY($params['y0']), $this->_getY($params['y1'])); 479 $x1 = max($this->_getX($params['x0']), $this->_getX($params['x1'])); 480 $y1 = max($this->_getY($params['y0']), $this->_getY($params['y1'])); 481 482 $fillColor = (isset($params['fill']) ? $params['fill'] : false); 483 $lineColor = (isset($params['line']) ? $params['line'] : false); 484 485 $fillColor = $this->_getFillStyle($fillColor); 486 $lineColor = $this->_getLineStyle($lineColor); 487 488 // use fill color if no line color is set or transparent 489 if (count($lineColor) === 0) { 490 $lineColor = $fillColor; 491 } 492 493 $shape = new SWFShape(); 494 $shape->setLine(1, $lineColor[0], $lineColor[1], $lineColor[2]); 495 496 if (count($fillColor)) { 497 $shape->setRightFill($fillColor[0], $fillColor[1], $fillColor[2]); 498 } 499 500 $shape->movePenTo($x0, $y0); 501 $shape->drawLine($x1 - $x0, 0); 502 $shape->drawLine(0, $y1 - $y0); 503 $shape->drawLine($x0 - $x1, 0); 504 $shape->drawLine(0, $y0 - $y1); 505 506 if (isset($params['url'])) { 507 $button = new SWFButton(); 508 $button->addShape($shape, SWFBUTTON_HIT | SWFBUTTON_UP | SWFBUTTON_DOWN | SWFBUTTON_OVER); 509 $button->addAction(new SWFAction("getURL('{$params['url']}');"), SWFBUTTON_MOUSEUP); 510 $this->_canvas->add($button); 511 } else { 512 $this->_canvas->add($shape); 513 } 514 515 parent::rectangle($params); 516 } 517 518 /** 519 * Draw an ellipse 520 * 521 * Parameter array: 522 * 'x' : int X center point 523 * 'y' : int Y center point 524 * 'rx' : int X radius 525 * 'ry' : int Y radius 526 * 'fill' : mixed [optional] The fill color 527 * 'line' : mixed [optional] The line color 528 * 'url' : string [optional] Target URL 529 * @param array $params Parameter array 530 */ 531 function ellipse($params) 532 { 533 $x = $this->_getX($params['x']); 534 $y = $this->_getY($params['y']); 535 $rx = $this->_getX($params['rx']); 536 $ry = $this->_getY($params['ry']); 537 538 // calculate scale factors 539 $scaleX = 1.0; 540 $scaleY = 1.0; 541 $moveX = 0; 542 $moveY = 0; 543 544 if ($rx > $ry) { 545 $scaleY = $ry / $rx; 546 $moveY = $ry * (1 - $scaleY); 547 } elseif ($rx < $ry) { 548 $scaleX = $rx / $ry; 549 $moveX = $rx * (1 - $scaleX); 550 } 551 552 $fillColor = (isset($params['fill']) ? $params['fill'] : false); 553 $lineColor = (isset($params['line']) ? $params['line'] : false); 554 555 $fillColor = $this->_getFillStyle($fillColor); 556 $lineColor = $this->_getLineStyle($lineColor); 557 558 $shape = new SWFShape(); 559 $shape->setRightFill($fillColor[0], $fillColor[1], $fillColor[2]); 560 $shape->movePenTo($x, $y); 561 $shape->setLine(1, $lineColor[0], $lineColor[1], $lineColor[2]); 562 563 if (count($fillColor)) { 564 $shape->setRightFill($fillColor[0], $fillColor[1], $fillColor[2]); 565 } 566 567 $shape->drawCircle(max($rx, $ry)); 568 569 if (isset($params['url'])) { 570 $button = new SWFButton(); 571 $button->addShape($shape, SWFBUTTON_HIT | SWFBUTTON_UP | SWFBUTTON_DOWN | SWFBUTTON_OVER); 572 $button->addAction(new SWFAction("getURL('{$params['url']}');"), SWFBUTTON_MOUSEUP); 573 $ellipse = $this->_canvas->add($button); 574 } else { 575 $ellipse = $this->_canvas->add($shape); 576 } 577 578 $ellipse->move($moveX, $moveY); 579 $ellipse->scaleTo($scaleX, $scaleY); 580 581 parent::ellipse($params); 582 } 583 584 /** 585 * Draw a pie slice 586 * 587 * Parameter array: 588 * 'x' : int X center point 589 * 'y' : int Y center point 590 * 'rx' : int X radius 591 * 'ry' : int Y radius 592 * 'v1' : int The starting angle (in degrees) 593 * 'v2' : int The end angle (in degrees) 594 * 'srx' : int [optional] Starting X-radius of the pie slice (i.e. for a doughnut) 595 * 'sry' : int [optional] Starting Y-radius of the pie slice (i.e. for a doughnut) 596 * 'fill' : mixed [optional] The fill color 597 * 'line' : mixed [optional] The line color 598 * @param array $params Parameter array 599 * @todo 600 */ 601 function pieslice($params) 602 { 603 } 604 605 /** 606 * Get the width of a text, 607 * 608 * @param string $text The text to get the width of 609 * @return int The width of the text 610 */ 611 function textWidth($text) 612 { 613 if (isset($this->_font['vertical']) && $this->_font['vertical']) { 614 return $this->_font['size']; 615 } else { 616 return round($this->_font['size'] * 0.5 * strlen($text)); 617 } 618 } 619 620 /** 621 * Get the height of a text, 622 * 623 * @param string $text The text to get the height of 624 * @return int The height of the text 625 */ 626 function textHeight($text) 627 { 628 if (isset($this->_font['vertical']) && $this->_font['vertical']) { 629 return round($this->_font['size'] * 0.7 * strlen($text)); 630 } else { 631 return $this->_font['size']; 632 } 633 } 634 635 /** 636 * Writes text 637 * 638 * Parameter array: 639 * 'x' : int X-point of text 640 * 'y' : int Y-point of text 641 * 'text' : string The text to add 642 * 'color' : mixed [optional] The color of the text 643 * 644 * @todo Vertical alignment 645 */ 646 function addText($params) 647 { 648 $x0 = $this->_getX($params['x']); 649 $y0 = $this->_getY($params['y']); 650 $text = str_replace("\r", '', $params['text']); 651 $color = (isset($params['color']) ? $params['color'] : false); 652 $textHeight = $this->textHeight($text); 653 $alignment = (isset($params['alignment']) ? $params['alignment'] : false); 654 655 if (!is_array($alignment)) { 656 $alignment = array('vertical' => 'top', 'horizontal' => 'left'); 657 } 658 659 if (!isset($alignment['vertical'])) { 660 $alignment['vertical'] = 'top'; 661 } 662 663 if (!isset($alignment['horizontal'])) { 664 $alignment['horizontal'] = 'left'; 665 } 666 667 if (($color === false) && (isset($this->_font['color']))) { 668 $color = $this->_font['color']; 669 } 670 671 if ($color == 'transparent') { 672 return; 673 } 674 675 if (strpos($this->_font['file'], '.') === false) { 676 $this->_font['file'] = IMAGE_CANVAS_SYSTEM_FONT_PATH . $this->_font['file'] . '.fdb'; 677 } 678 679 $textColor = $this->_color($color); 680 $textOpacity = $this->_opacity($color); 681 682 $lines = explode("\n", $text); 683 foreach ($lines as $line) { 684 685 $x = $x0; 686 $y = $y0; 687 688 $y0 += $textHeight + 2; 689 690 $width = $this->textWidth($line); 691 $height = $this->textHeight($line); 692 693 if ($alignment['horizontal'] == 'right') { 694 $x -= $width; 695 } else if ($alignment['horizontal'] == 'center') { 696 $x -= $width / 2; 697 } 698 699 $font = new SWFFont($this->_font['file']); 700 $text = new SWFText(); 701 $text->setFont($font); 702 $text->moveTo($x, $y + $this->_font['size']); 703 $text->setColor($textColor[0], $textColor[1], $textColor[2], $textOpacity); 704 $text->setHeight($this->_font['size']); 705 $text->addString($line); 706 $this->_canvas->add($text); 707 } 708 709 parent::addText($params); 710 } 711 712 /** 713 * Overlay image 714 * 715 * Parameter array: 716 * 'x' : int X-point of overlayed image 717 * 'y' : int Y-point of overlayed image 718 * 'filename' : string The filename of the image to overlay 719 * 'width' : int [optional] The width of the overlayed image (resizing if possible) 720 * 'height' : int [optional] The height of the overlayed image (resizing if possible) 721 * 'alignment' : array [optional] Alignment 722 * 'url' : string [optional] Target URL 723 */ 724 function image($params) 725 { 726 parent::image($params); 727 } 728 729 /** 730 * Display the SWF 731 * 732 * @param array $param Parameter array 733 */ 734 function show($param = false) 735 { 736 parent::show($param); 737 $this->_canvas->output(); 738 } 739 740 /** 741 * Save the SWF to a file 742 * 743 * @param array $param Parameter array 744 * array('filename' => 'canvas.swf', 745 * 'compression' => 0) 746 * 747 * The compression level can be a value between 0 and 9, 748 * defining the SWF compression similar to gzip compression. 749 * This parameter is only available as of Flash MX (6). 750 */ 751 function save($param = false) 752 { 753 if (!isset($param['compression'])) { 754 $param['compression'] = 0; 755 } 756 757 parent::save($param); 758 $this->_canvas->save($param['filename'], $param['compression']); 759 } 760 761 /** 762 * Get SWF movie object 763 * 764 * @return object 765 */ 766 function getData() 767 { 768 return $this->_canvas; 769 } 770 771 /** 772 * Set clipping to occur 773 * 774 * Parameter array: 775 * 776 * 'x0' : int X point of Upper-left corner 777 * 'y0' : int X point of Upper-left corner 778 * 'x1' : int X point of lower-right corner 779 * 'y1' : int Y point of lower-right corner 780 * 781 * @todo 782 */ 783 function setClipping($params = false) 784 { 785 } 786 787 /** 788 * Get an SWF specific HTML tag 789 * 790 * This method implicitly saves the canvas to the filename in the 791 * filesystem path specified and parses it as URL specified by URL path 792 * 793 * Parameter array: 794 * 'filename' : string 795 * 'filepath' : string Path to the file on the file system. Remember the final slash 796 * 'urlpath' : string Path to the file available through an URL. Remember the final slash 797 * 'width' : int The width in pixels 798 * 'height' : int The height in pixels 799 * 'quality' : Flash quality 800 * 'scale' : Scale 801 * 'menu' : Whether to display the Flash menu on mouse right-click 802 */ 803 function toHtml($params) 804 { 805 parent::toHtml($params); 806 return '<object data="' . $params['urlpath'] . $params['filename'] . '" type="application/x-shockwave-flash" width="' . $params['width'] . '" height="' . $params['height'] . '"> 807 <param name="movie" value="' . $params['urlpath'] . $params['filename'] . '"> 808 <param name="quality" value="' . $params['quality'] . '"> 809 <param name="scale" value="' . $params['scale'] . '"> 810 <param name="menu" value="' . $params['menu'] . '"> 811 </object>'; 812 } 813} 814?>