Author: kn Date: Tue Dec 18 21:22:21 2007 New Revision: 7023 Log: - Fixed support for bitmaps in flash driver # - Removed exception, because scaling bimaps is possible, and we do not # need to throw an exception in this case. # - Fixed test cases, because PNGs are supported, even the documentation # says otherwise
Added: trunk/Graph/tests/data/compare/ezcGraphFlashDriverTest_testDrawImageJpeg.swf (with props) trunk/Graph/tests/data/compare/ezcGraphFlashDriverTest_testDrawImagePng.swf (with props) Removed: trunk/Graph/src/exceptions/flash_bitmap_boundings.php Modified: trunk/Graph/src/driver/flash.php trunk/Graph/src/exceptions/flash_bitmap_type.php trunk/Graph/tests/driver_flash_test.php Modified: trunk/Graph/src/driver/flash.php ============================================================================== --- trunk/Graph/src/driver/flash.php [iso-8859-1] (original) +++ trunk/Graph/src/driver/flash.php [iso-8859-1] Tue Dec 18 21:22:21 2007 @@ -889,8 +889,8 @@ * * @param mixed $file Image file * @param ezcGraphCoordinate $position Top left position - * @param mixed $width Width of image in destination image - * @param mixed $height Height of image in destination image + * @param float $width Width of image in destination image + * @param float $height Height of image in destination image * @return void */ public function drawImage( $file, ezcGraphCoordinate $position, $width, $height ) @@ -898,25 +898,36 @@ $movie = $this->getDocument(); $imageData = getimagesize( $file ); - if ( $imageData[0] !== $width || $imageData[1] !== $height ) - { - throw new ezcGraphFlashBitmapBoundingsException( $imageData[0], $imageData[1], $width, $height ); - } - - if ( $imageData[2] !== 2 ) + if ( ( $imageData[2] !== IMAGETYPE_JPEG ) && ( $imageData[2] !== IMAGETYPE_PNG ) ) { throw new ezcGraphFlashBitmapTypeException( $imageData[2] ); } - $image = new SWFBitmap( file_get_contents( 'http://kore.phpugdo.de/jpg.jpeg' ) ); - $object = $movie->add( $image ); - + // Try to create a new SWFBitmap object from provided file + $bitmap = new SWFBitmap( fopen( $file, 'rb' ) ); + + // Add the image to the movie + $object = $this->movie->add( $bitmap ); + + // Image size is calculated on the base of a tick size of 20, so + // that we need to transform this, to our tick size. + $factor = $this->modifyCoordinate( 1 ) / 20; + $object->scale( $factor, $factor ); + + // Scale by ratio of requested and original image size + $object->scale( + $width / $imageData[0], + $height / $imageData[1] + ); + + // Move object to the right position $object->moveTo( $this->modifyCoordinate( $position->x ), $this->modifyCoordinate( $position->y ) - ); + ); + + // Create, set and return unique ID $object->setName( $id = 'ezcGraphImage_'. $this->id++ ); - return $id; } Modified: trunk/Graph/src/exceptions/flash_bitmap_type.php ============================================================================== --- trunk/Graph/src/exceptions/flash_bitmap_type.php [iso-8859-1] (original) +++ trunk/Graph/src/exceptions/flash_bitmap_type.php [iso-8859-1] Tue Dec 18 21:22:21 2007 @@ -24,7 +24,7 @@ */ public function __construct() { - parent::__construct( "Flash can only read non interlaced JPEGs." ); + parent::__construct( "Flash can only read JPEGs and PNGs." ); } } Added: trunk/Graph/tests/data/compare/ezcGraphFlashDriverTest_testDrawImageJpeg.swf ============================================================================== Binary file - no diff available. Propchange: trunk/Graph/tests/data/compare/ezcGraphFlashDriverTest_testDrawImageJpeg.swf ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: trunk/Graph/tests/data/compare/ezcGraphFlashDriverTest_testDrawImagePng.swf ============================================================================== Binary file - no diff available. Propchange: trunk/Graph/tests/data/compare/ezcGraphFlashDriverTest_testDrawImagePng.swf ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Modified: trunk/Graph/tests/driver_flash_test.php ============================================================================== --- trunk/Graph/tests/driver_flash_test.php [iso-8859-1] (original) +++ trunk/Graph/tests/driver_flash_test.php [iso-8859-1] Tue Dec 18 21:22:21 2007 @@ -506,27 +506,6 @@ ); } - public function testDrawImageOutOfBoundings() - { - $filename = $this->tempDir . __FUNCTION__ . '.swf'; - - try - { - $return = $this->driver->drawImage( - $this->basePath . $this->testFiles['jpeg'], - new ezcGraphCoordinate( 10, 10 ), - 100, - 50 - ); - } - catch ( ezcGraphFlashBitmapBoundingsException $e ) - { - return true; - } - - $this->fail( 'Expected ezcGraphFlashBitmapBoundingsException.' ); - } - public function testDrawImageGif() { $filename = $this->tempDir . __FUNCTION__ . '.swf'; @@ -552,31 +531,27 @@ { $filename = $this->tempDir . __FUNCTION__ . '.swf'; - try - { - $return = $this->driver->drawImage( - $this->basePath . $this->testFiles['png'], - new ezcGraphCoordinate( 10, 10 ), - 177, - 100 - ); - } - catch ( ezcGraphFlashBitmapTypeException $e ) - { - return true; - } - - $this->fail( 'Expected ezcGraphFlashBitmapBoundingsException.' ); + $return = $this->driver->drawImage( + $this->basePath . $this->testFiles['png'], + new ezcGraphCoordinate( 10, 10 ), + 177, + 100 + ); + + $this->driver->render( $filename ); + + $this->swfCompare( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf' + ); } public function testDrawImageJpeg() { - $this->fail( 'Ends up in a recursive loop somehow caused by PHPUnits error handling and exception conversion.' ); - $filename = $this->tempDir . __FUNCTION__ . '.swf'; $this->driver->drawImage( - $this->basePath . $this->testFiles['non_interlaced'], + $this->basePath . $this->testFiles['jpeg'], new ezcGraphCoordinate( 10, 10 ), 177, 100 -- svn-components mailing list svn-components@lists.ez.no http://lists.ez.no/mailman/listinfo/svn-components