summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2006-10-13 10:19:40 +0000
committerKore Nordmann <github@kore-nordmann.de>2006-10-13 10:19:40 +0000
commite8d5613680eb883687d821a34fe2ad80914baee2 (patch)
treee8746b1da687c928e8b7aaed397072a14b437a99
parente61af065ecdd565683a54225911a2dd9e725acae (diff)
downloadzetacomponents-graph-e8d5613680eb883687d821a34fe2ad80914baee2.zip
zetacomponents-graph-e8d5613680eb883687d821a34fe2ad80914baee2.tar.gz
- Added first, not complete working, version of ming driver
# Image drawing causes not proper handled error, causing an inifinite loop in PHP # Font drawing causes Segmentation fault # Ming driver tests commented out for now in test suite
-rw-r--r--TODO1
-rw-r--r--src/driver/ming.php493
-rw-r--r--src/exceptions/invalid_font.php35
-rw-r--r--src/exceptions/ming_bitmap_boundings.php25
-rw-r--r--src/exceptions/ming_bitmap_type.php25
-rw-r--r--src/graph.php4
-rw-r--r--src/graph_autoload.php5
-rw-r--r--src/interfaces/axis_label_renderer.php1
-rw-r--r--src/interfaces/renderer.php2
-rw-r--r--src/options/font.php3
-rw-r--r--src/options/ming_driver.php66
-rw-r--r--tests/data/fdb_font.fdbbin0 -> 31365 bytes
-rw-r--r--tests/driver_ming_test.php1168
-rw-r--r--tests/suite.php3
14 files changed, 1829 insertions, 2 deletions
diff --git a/TODO b/TODO
index dd60f13..a1ad36b 100644
--- a/TODO
+++ b/TODO
@@ -6,3 +6,4 @@ Missing features:
- Radar charts
http://www.aditus.nu/jpgraph/img/gallery/radarlogex1.png
- Flash driver
+ - Cairo driver
diff --git a/src/driver/ming.php b/src/driver/ming.php
new file mode 100644
index 0000000..fa52ca2
--- /dev/null
+++ b/src/driver/ming.php
@@ -0,0 +1,493 @@
+<?php
+/**
+ * File containing the ezcGraphMingDriver class
+ *
+ * @package Graph
+ * @version //autogentag//
+ * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+/**
+ * Driver to create Flash4 (SWF) files as graph output.
+ *
+ * @package Graph
+ */
+
+class ezcGraphMingDriver extends ezcGraphDriver
+{
+ /**
+ * Flash movie
+ *
+ * @var SWFMovie
+ */
+ protected $movie;
+
+ /**
+ * Unique element id
+ *
+ * @var int
+ */
+ protected $id = 1;
+
+ /**
+ * Constructor
+ *
+ * @param array $options Default option array
+ * @return void
+ * @ignore
+ */
+ public function __construct( array $options = array() )
+ {
+ $this->options = new ezcGraphMingDriverOptions( $options );
+ }
+
+ public function getDocument()
+ {
+ if ( $this->movie === null )
+ {
+ $this->movie = new SWFMovie();
+ $this->movie->setDimension( $this->modifyCoordinate( $this->options->width ), $this->modifyCoordinate( $this->options->height ) );
+ $this->movie->setRate( 1 );
+ $this->movie->setBackground( 255, 255, 255 );
+ }
+
+ return $this->movie;
+ }
+
+ protected function setShapeColor( SWFShape $shape, ezcGraphColor $color, $thickness, $filled )
+ {
+ // @TODO: respect gradients
+ if ( $filled === false )
+ {
+ $shape->setLine( $this->modifyCoordinate( $thickness ), $color->red, $color->green, $color->blue, 255 - $color->alpha );
+ }
+ else
+ {
+ $fill = $shape->addFill( $color->red, $color->green, $color->blue );
+ $shape->setLeftFill( $fill );
+ }
+ }
+
+ protected function modifyCoordinate( $pointValue )
+ {
+ return $pointValue * 10;
+ }
+
+ /**
+ * Draws a single polygon.
+ *
+ * @param array $points Point array
+ * @param ezcGraphColor $color Polygon color
+ * @param mixed $filled Filled
+ * @param float $thickness Line thickness
+ * @return void
+ */
+ public function drawPolygon( array $points, ezcGraphColor $color, $filled = true, $thickness = 1 )
+ {
+ $movie = $this->getDocument();
+
+ $shape = new SWFShape();
+
+ $this->setShapeColor( $shape, $color, $thickness, $filled );
+
+ $lastPoint = end( $points );
+ $shape->movePenTo( $this->modifyCoordinate( $lastPoint->x ), $this->modifyCoordinate( $lastPoint->y ) );
+
+ foreach( $points as $point )
+ {
+ $shape->drawLineTo( $this->modifyCoordinate( $point->x ), $this->modifyCoordinate( $point->y ) );
+ }
+
+ $object = $movie->add( $shape );
+ $object->setName( $id = 'ezcGraphPolygon_' . $this->id++ );
+
+ return $id;
+ }
+
+ /**
+ * Draws a line
+ *
+ * @param ezcGraphCoordinate $start Start point
+ * @param ezcGraphCoordinate $end End point
+ * @param ezcGraphColor $color Line color
+ * @param float $thickness Line thickness
+ * @return void
+ */
+ public function drawLine( ezcGraphCoordinate $start, ezcGraphCoordinate $end, ezcGraphColor $color, $thickness = 1 )
+ {
+ $movie = $this->getDocument();
+
+ $shape = new SWFShape();
+
+ $this->setShapeColor( $shape, $color, $thickness, false );
+
+ $shape->movePenTo( $this->modifyCoordinate( $start->x ), $this->modifyCoordinate( $start->y ) );
+ $shape->drawLineTo( $this->modifyCoordinate( $end->x ), $this->modifyCoordinate( $end->y ) );
+
+ $object = $movie->add( $shape );
+ $object->setName( $id = 'ezcGraphLine_' . $this->id++ );
+
+ return $id;
+ }
+
+ /**
+ * Returns boundings of text depending on the available font extension
+ *
+ * @param float $size Textsize
+ * @param ezcGraphFontOptions $font Font
+ * @param string $text Text
+ * @return ezcGraphBoundings Boundings of text
+ */
+ protected function getTextBoundings( $size, ezcGraphFontOptions $font, $text )
+ {
+ $t = new SWFText();
+ $t->addString( $text );
+ $t->setHeight( $size );
+ $t->setFont( $font->path );
+
+ $boundings = new ezcGraphBoundings( 0, 0, $t->getWidth(), $size );
+
+ return $boundings;
+ }
+
+ /**
+ * Test if string fits in a box with given font size
+ *
+ * This method splits the text up into tokens and tries to wrap the text
+ * in an optimal way to fit in the Box defined by width and height.
+ *
+ * If the text fits into the box an array with lines is returned, which
+ * can be used to render the text later:
+ * array(
+ * // Lines
+ * array( 'word', 'word', .. ),
+ * )
+ * Otherwise the function will return false.
+ *
+ * @param string $string Text
+ * @param ezcGraphCoordinate $position Topleft position of the text box
+ * @param float $width Width of textbox
+ * @param float $height Height of textbox
+ * @param int $size Fontsize
+ * @return mixed Array with lines or false on failure
+ */
+ protected function testFitStringInTextBox( $string, ezcGraphCoordinate $position, $width, $height, $size )
+ {
+ // Tokenize String
+ $tokens = preg_split( '/\s+/', $string );
+
+ $lines = array( array() );
+ $line = 0;
+ foreach ( $tokens as $token )
+ {
+ // Add token to tested line
+ $selectedLine = $lines[$line];
+ $selectedLine[] = $token;
+
+ $boundings = $this->getTextBoundings( $size, $this->options->font, implode( ' ', $selectedLine ) );
+
+ // Check if line is too long
+ if ( $boundings->width > $width )
+ {
+ if ( count( $selectedLine ) == 1 )
+ {
+ // Return false if one single word does not fit into one line
+ return false;
+ }
+ else
+ {
+ // Put word in next line instead and reduce available height by used space
+ $lines[++$line][] = $token;
+ $height -= $size * ( 1 + $this->options->lineSpacing );
+ }
+ }
+ else
+ {
+ // Everything is ok - put token in this line
+ $lines[$line][] = $token;
+ }
+
+ // Return false if text exceeds vertical limit
+ if ( $size > $height )
+ {
+ return false;
+ }
+ }
+
+ // Check width of last line
+ $boundings = $this->getTextBoundings( $size, $this->options->font, implode( ' ', $lines[$line] ) );
+ if ( $boundings->width > $width )
+ {
+ return false;
+ }
+
+ // It seems to fit - return line array
+ return $lines;
+ }
+
+ /**
+ * Writes text in a box of desired size
+ *
+ * @param string $string Text
+ * @param ezcGraphCoordinate $position Top left position
+ * @param float $width Width of text box
+ * @param float $height Height of text box
+ * @param int $align Alignement of text
+ * @return void
+ */
+ public function drawTextBox( $string, ezcGraphCoordinate $position, $width, $height, $align )
+ {
+ if ( $this->options->font->type !== ezcGraph::PALM_FONT )
+ {
+ throw new ezcGraphInvalidFontTypeException( $this->options->font->type, __CLASS__ );
+ }
+
+ $padding = $this->options->font->padding + ( $this->options->font->border !== false ? $this->options->font->borderWidth : 0 );
+
+ $width -= $padding * 2;
+ $height -= $padding * 2;
+ $position->x += $padding;
+ $position->y += $padding;
+
+ // Try to get a font size for the text to fit into the box
+ $maxSize = min( $height, $this->options->font->maxFontSize );
+ $result = false;
+ for ( $size = $maxSize; $size >= $this->options->font->minFontSize; --$size )
+ {
+ $result = $this->testFitStringInTextBox( $string, $position, $width, $height, $size );
+ if ( $result !== false )
+ {
+ break;
+ }
+ }
+
+ if ( is_array( $result ) )
+ {
+ $this->options->font->minimalUsedFont = $size;
+
+ $this->strings[] = array(
+ 'text' => $result,
+ 'id' => $id = 'ezcGraphText_' . $this->id++,
+ 'position' => $position,
+ 'width' => $width,
+ 'height' => $height,
+ 'align' => $align,
+ 'font' => $this->options->font,
+ );
+ }
+ else
+ {
+ throw new ezcGraphFontRenderingException( $string, $this->options->font->minFontSize, $width, $height );
+ }
+
+ return $id;
+ }
+
+ /**
+ * Draws a sector of cirlce
+ *
+ * @param ezcGraphCoordinate $center Center of circle
+ * @param mixed $width Width
+ * @param mixed $height Height
+ * @param mixed $startAngle Start angle of circle sector
+ * @param mixed $endAngle End angle of circle sector
+ * @param ezcGraphColor $color Color
+ * @param mixed $filled Filled
+ * @return void
+ */
+ public function drawCircleSector( ezcGraphCoordinate $center, $width, $height, $startAngle, $endAngle, ezcGraphColor $color, $filled = true )
+ {
+ if ( $startAngle > $endAngle )
+ {
+ $tmp = $startAngle;
+ $startAngle = $endAngle;
+ $endAngle = $tmp;
+ }
+
+ $movie = $this->getDocument();
+
+ $shape = new SWFShape();
+ $this->setShapeColor( $shape, $color, 1, $filled );
+
+ $shape->movePenTo( $this->modifyCoordinate( $center->x ), $this->modifyCoordinate( $center->y ) );
+
+ // @TODO: User SWFShape::curveTo
+ for ( $angle = $startAngle; $angle <= $endAngle; $angle += $this->options->circleResolution )
+ {
+ $angle = min(
+ $angle,
+ $endAngle
+ );
+
+ $shape->drawLineTo(
+ $this->modifyCoordinate( $center->x + cos( deg2rad( $angle ) ) * $width / 2 ),
+ $this->modifyCoordinate( $center->y + sin( deg2rad( $angle ) ) * $height / 2 )
+ );
+ }
+
+ $shape->drawLineTo(
+ $this->modifyCoordinate( $center->x ),
+ $this->modifyCoordinate( $center->y )
+ );
+
+ $object = $movie->add( $shape );
+ $object->setName( $id = 'ezcGraphCircleSector_' . $this->id++ );
+
+ return $id;
+ }
+
+ /**
+ * Draws a circular arc
+ *
+ * @param ezcGraphCoordinate $center Center of ellipse
+ * @param integer $width Width of ellipse
+ * @param integer $height Height of ellipse
+ * @param integer $size Height of border
+ * @param float $startAngle Starting angle of circle sector
+ * @param float $endAngle Ending angle of circle sector
+ * @param ezcGraphColor $color Color of Border
+ * @return void
+ */
+ public function drawCircularArc( ezcGraphCoordinate $center, $width, $height, $size, $startAngle, $endAngle, ezcGraphColor $color, $filled = true )
+ {
+ if ( $startAngle > $endAngle )
+ {
+ $tmp = $startAngle;
+ $startAngle = $endAngle;
+ $endAngle = $tmp;
+ }
+
+ $movie = $this->getDocument();
+
+ $shape = new SWFShape();
+ $this->setShapeColor( $shape, $color, 1, $filled );
+
+ $shape->movePenTo(
+ $this->modifyCoordinate( $center->x + cos( deg2rad( $startAngle ) ) * $width / 2 ),
+ $this->modifyCoordinate( $center->y + sin( deg2rad( $startAngle ) ) * $height / 2 )
+ );
+
+ // @TODO: User SWFShape::curveTo
+ for ( $angle = $startAngle; $angle <= $endAngle; $angle += $this->options->circleResolution )
+ {
+ $angle = min(
+ $angle,
+ $endAngle
+ );
+
+ $shape->drawLineTo(
+ $this->modifyCoordinate( $center->x + cos( deg2rad( $angle ) ) * $width / 2 ),
+ $this->modifyCoordinate( $center->y + sin( deg2rad( $angle ) ) * $height / 2 + $size )
+ );
+ }
+
+ for ( $angle = $endAngle; $angle > $startAngle; $angle -= $this->options->circleResolution )
+ {
+ $angle = max(
+ $angle,
+ $startAngle
+ );
+
+ $shape->drawLineTo(
+ $this->modifyCoordinate( $center->x + cos( deg2rad( $angle ) ) * $width / 2 ),
+ $this->modifyCoordinate( $center->y + sin( deg2rad( $angle ) ) * $height / 2 )
+ );
+ }
+
+ $object = $movie->add( $shape );
+ $object->setName( $id = 'ezcGraphCircularArc_' . $this->id++ );
+
+ return $id;
+ }
+
+ /**
+ * Draw circle
+ *
+ * @param ezcGraphCoordinate $center Center of ellipse
+ * @param mixed $width Width of ellipse
+ * @param mixed $height height of ellipse
+ * @param ezcGraphColor $color Color
+ * @param mixed $filled Filled
+ * @return void
+ */
+ public function drawCircle( ezcGraphCoordinate $center, $width, $height, ezcGraphColor $color, $filled = true )
+ {
+ $movie = $this->getDocument();
+
+ $shape = new SWFShape();
+ $this->setShapeColor( $shape, $color, 1, $filled );
+
+ $shape->movePenTo(
+ $this->modifyCoordinate( $center->x + $width / 2 ),
+ $this->modifyCoordinate( $center->y )
+ );
+
+ // @TODO: User SWFShape::curveTo
+ for ( $angle = $this->options->circleResolution; $angle <= 360; $angle += $this->options->circleResolution )
+ {
+ $shape->drawLineTo(
+ $this->modifyCoordinate( $center->x + cos( deg2rad( $angle ) ) * $width / 2 ),
+ $this->modifyCoordinate( $center->y + sin( deg2rad( $angle ) ) * $height / 2 )
+ );
+ }
+
+ $object = $movie->add( $shape );
+ $object->setName( $id = 'ezcGraphCircle_' . $this->id++ );
+
+ return $id;
+ }
+
+ /**
+ * Draw an image
+ *
+ * The image will be inlined in the SVG document using data URL scheme. For
+ * this the mime type and base64 encoded file content will be merged to
+ * URL.
+ *
+ * @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
+ * @return void
+ */
+ public function drawImage( $file, ezcGraphCoordinate $position, $width, $height )
+ {
+ $movie = $this->getDocument();
+
+ $imageData = getimagesize( $file );
+ if ( $imageData[0] !== $width || $imageData[1] !== $height )
+ {
+ throw new ezcGraphMingBitmapBoundingsException( $imageData[0], $imageData[1], $width, $height );
+ }
+
+ if ( $imageData[2] !== 2 )
+ {
+ throw new ezcGraphMingBitmapTypeException( $imageData[2] );
+ }
+
+ $image = new SWFBitmap( file_get_contents( 'http://kore.phpugdo.de/jpg.jpeg' ) );
+ $object = $movie->add( $image );
+
+ $object->moveTo(
+ $this->modifyCoordinate( $position->x ),
+ $this->modifyCoordinate( $position->y )
+ );
+ $object->setName( $id = 'ezcGraphImage_'. $this->id++ );
+
+ return $id;
+ }
+
+ /**
+ * Finally save image
+ *
+ * @param string $file Destination filename
+ * @return void
+ */
+ public function render ( $file )
+ {
+ $movie = $this->getDocument();
+ $movie->save( $file, $this->options->compression );
+ }
+}
+
+?>
diff --git a/src/exceptions/invalid_font.php b/src/exceptions/invalid_font.php
new file mode 100644
index 0000000..8376c6f
--- /dev/null
+++ b/src/exceptions/invalid_font.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * File containing the ezcGraphInvalidFontTypeException class
+ *
+ * @package Graph
+ * @version //autogen//
+ * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+/**
+ * Exception thrown if font type cannot be rendered with one driver.
+ *
+ * @package Graph
+ * @version //autogen//
+ */
+class ezcGraphInvalidFontTypeException extends ezcGraphException
+{
+ public function __construct( $type, $driver )
+ {
+ $fontNames = array(
+ ezcGraph::TTF_FONT => 'True Type Font',
+ ezcGraph::PS_FONT => 'Postscript Type 1 font',
+ ezcGraph::PALM_FONT => 'Palm Font',
+ );
+
+ $fontName = ( isset( $fontNames[$type] )
+ ? $fontName = $fontNames[$type]
+ : 'Unknown'
+ );
+
+ parent::__construct( "Font type <{$fontName}> cannot be used with <{$driver}>." );
+ }
+}
+
+?>
diff --git a/src/exceptions/ming_bitmap_boundings.php b/src/exceptions/ming_bitmap_boundings.php
new file mode 100644
index 0000000..627246e
--- /dev/null
+++ b/src/exceptions/ming_bitmap_boundings.php
@@ -0,0 +1,25 @@
+<?php
+/**
+ * File containing the ezcGraphMingBitmapBoundingsException class
+ *
+ * @package Graph
+ * @version //autogen//
+ * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+/**
+ * Ming does not support bitmap scaling, so that this exceptions is thrown
+ * when an image does not have the requested size.
+ *
+ * @package Graph
+ * @version //autogen//
+ */
+class ezcGraphMingBitmapBoundingsException extends ezcGraphException
+{
+ public function __construct( $imageWidth, $imageHeight, $reqWidth, $reqHeight )
+ {
+ parent::__construct( "Ming does not support bitmap scaling, so that it is up to you to scale the image <$imageWidth> * <$imageHeight> to <$reqWidth> * <$reqHeight>." );
+ }
+}
+
+?>
diff --git a/src/exceptions/ming_bitmap_type.php b/src/exceptions/ming_bitmap_type.php
new file mode 100644
index 0000000..825a907
--- /dev/null
+++ b/src/exceptions/ming_bitmap_type.php
@@ -0,0 +1,25 @@
+<?php
+/**
+ * File containing the ezcGraphMingBitmapTypeException class
+ *
+ * @package Graph
+ * @version //autogen//
+ * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+/**
+ * Ming can only read non interlaced bitmaps. This exception is thrown for
+ * all other image types.
+ *
+ * @package Graph
+ * @version //autogen//
+ */
+class ezcGraphMingBitmapTypeException extends ezcGraphException
+{
+ public function __construct( $type )
+ {
+ parent::__construct( "Ming can only read non interlaced JPEGs." );
+ }
+}
+
+?>
diff --git a/src/graph.php b/src/graph.php
index ae6c74b..537bd36 100644
--- a/src/graph.php
+++ b/src/graph.php
@@ -106,6 +106,10 @@ class ezcGraph
* Font type definition. Used for Postscript Type 1 fonts.
*/
const PS_FONT = 2;
+ /**
+ * Font type definition. Used for Palm Format Fonts for Ming driver.
+ */
+ const PALM_FONT = 3;
}
?>
diff --git a/src/graph_autoload.php b/src/graph_autoload.php
index 2169d18..deb6f92 100644
--- a/src/graph_autoload.php
+++ b/src/graph_autoload.php
@@ -46,6 +46,7 @@ return array(
'ezcGraphDriver' => 'Graph/interfaces/driver.php',
'ezcGraphFontRenderingException' => 'Graph/exceptions/font_rendering.php',
'ezcGraphUnknownFontTypeException' => 'Graph/exceptions/font_type.php',
+ 'ezcGraphInvalidFontTypeException' => 'Graph/exceptions/invalid_font.php',
'ezcGraphDriverOptions' => 'Graph/options/driver.php',
'ezcGraphGdDriver' => 'Graph/driver/gd.php',
'ezcGraphGdDriverOptions' => 'Graph/options/gd_driver.php',
@@ -54,6 +55,10 @@ return array(
'ezcGraphSvgDriverOptions' => 'Graph/options/svg_driver.php',
'ezcGraphSvgDriverInvalidIdException' => 'Graph/exceptions/invalid_id.php',
'ezcGraphVerboseDriver' => 'Graph/driver/verbose.php',
+ 'ezcGraphMingDriver' => 'Graph/driver/ming.php',
+ 'ezcGraphMingDriverOptions' => 'Graph/options/ming_driver.php',
+ 'ezcGraphMingBitmapTypeException' => 'Graph/exceptions/ming_bitmap_type.php',
+ 'ezcGraphMingBitmapBoundingsException' => 'Graph/exceptions/ming_bitmap_boundings.php',
'ezcGraphPalette' => 'Graph/interfaces/palette.php',
'ezcGraphPaletteTango' => 'Graph/palette/tango.php',
diff --git a/src/interfaces/axis_label_renderer.php b/src/interfaces/axis_label_renderer.php
index acfc6e2..1a8e295 100644
--- a/src/interfaces/axis_label_renderer.php
+++ b/src/interfaces/axis_label_renderer.php
@@ -149,7 +149,6 @@ abstract class ezcGraphAxisLabelRenderer extends ezcBaseOptions
( $aDir->x != 0 ? $bStart->x / $aDir->x : 0 ) +
( $aDir->x != 0 ? $aStart->x / $aDir->x : 0 )
) / $denominator;
-
}
}
diff --git a/src/interfaces/renderer.php b/src/interfaces/renderer.php
index d43778d..1e1d2fc 100644
--- a/src/interfaces/renderer.php
+++ b/src/interfaces/renderer.php
@@ -82,7 +82,7 @@ abstract class ezcGraphRenderer
/**
* __get
*
- * @param mixed $propertyName
+ * @param string $propertyName
* @throws ezcBasePropertyNotFoundException
* If a the value for the property options is not an instance of
* @return mixed
diff --git a/src/options/font.php b/src/options/font.php
index 8991bb7..523687c 100644
--- a/src/options/font.php
+++ b/src/options/font.php
@@ -159,6 +159,9 @@ class ezcGraphFontOptions extends ezcBaseOptions
$parts = pathinfo( $this->properties['path'] );
switch ( strtolower( $parts['extension'] ) )
{
+ case 'fdb':
+ $this->properties['type'] = ezcGraph::PALM_FONT;
+ break;
case 'pfb':
$this->properties['type'] = ezcGraph::PS_FONT;
break;
diff --git a/src/options/ming_driver.php b/src/options/ming_driver.php
new file mode 100644
index 0000000..8efa9f2
--- /dev/null
+++ b/src/options/ming_driver.php
@@ -0,0 +1,66 @@
+<?php
+/**
+ * File containing the ezcGraphMingDriverOption class
+ *
+ * @package Graph
+ * @version //autogentag//
+ * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+/**
+ * Class containing the basic options for charts
+ *
+ * @property int $compression
+ * Compression level used for generated flash file
+ * @see http://php.net/manual/en/function.swfmovie.save.php
+ * @property float $circleResolution
+ * Resolution for circles, until I understand how to draw ellipses
+ * with SWFShape::curveTo()
+ *
+ * @package Graph
+ */
+class ezcGraphMingDriverOptions extends ezcGraphDriverOptions
+{
+ /**
+ * Constructor
+ *
+ * @param array $options Default option array
+ * @return void
+ * @ignore
+ */
+ public function __construct( array $options = array() )
+ {
+ $this->properties['compression'] = 9;
+ $this->properties['circleResolution'] = 1;
+
+ parent::__construct( $options );
+ }
+
+ /**
+ * Set an option value
+ *
+ * @param string $propertyName
+ * @param mixed $propertyValue
+ * @throws ezcBasePropertyNotFoundException
+ * If a property is not defined in this class
+ * @return void
+ * @ignore
+ */
+ public function __set( $propertyName, $propertyValue )
+ {
+ switch ( $propertyName )
+ {
+ case 'compression':
+ $this->properties['compression'] = max( 0, min( 9, (int) $propertyValue ) );
+ break;
+ case 'circleResolution':
+ $this->properties['circleResolution'] = (float) $propertyValue;
+ break;
+ default:
+ parent::__set( $propertyName, $propertyValue );
+ break;
+ }
+ }
+}
+
+?>
diff --git a/tests/data/fdb_font.fdb b/tests/data/fdb_font.fdb
new file mode 100644
index 0000000..5fefdcb
--- /dev/null
+++ b/tests/data/fdb_font.fdb
Binary files differ
diff --git a/tests/driver_ming_test.php b/tests/driver_ming_test.php
new file mode 100644
index 0000000..7f993c7
--- /dev/null
+++ b/tests/driver_ming_test.php
@@ -0,0 +1,1168 @@
+<?php
+/**
+ * ezcGraphMingDriverTest
+ *
+ * @package Graph
+ * @version //autogen//
+ * @subpackage Tests
+ * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+
+/**
+ * Tests for ezcGraph class.
+ *
+ * @package ImageAnalysis
+ * @subpackage Tests
+ */
+class ezcGraphMingDriverTest extends ezcTestCase
+{
+ protected $driver;
+
+ protected $tempDir;
+
+ protected $basePath;
+
+ protected $testFiles = array(
+ 'jpeg' => 'jpeg.jpg',
+ 'non_interlaced' => 'jpeg_non_interlaced.jpg',
+ 'png' => 'png.png',
+ 'gif' => 'gif.gif',
+ );
+
+ public static function suite()
+ {
+ return new PHPUnit_Framework_TestSuite( "ezcGraphMingDriverTest" );
+ }
+
+ protected function setUp()
+ {
+ static $i = 0;
+ $this->tempDir = $this->createTempDir( __CLASS__ . sprintf( '_%03d_', ++$i ) ) . '/';
+ $this->basePath = dirname( __FILE__ ) . '/data/';
+
+ $this->driver = new ezcGraphMingDriver();
+ $this->driver->options->width = 200;
+ $this->driver->options->height = 100;
+
+ $this->driver->options->font->path = $this->basePath . 'fdb_font.fdb';
+ }
+
+ protected function tearDown()
+ {
+ unset( $this->driver );
+ if ( !$this->hasFailed() )
+ {
+ $this->removeTempDir();
+ }
+ }
+
+ /**
+ * Compares a generated image with a stored file
+ *
+ * @param string $generated Filename of generated image
+ * @param string $compare Filename of stored image
+ * @return void
+ */
+ protected function compare( $generated, $compare )
+ {
+ $this->assertTrue(
+ file_exists( $generated ),
+ 'No image file has been created.'
+ );
+
+ $this->assertTrue(
+ file_exists( $compare ),
+ 'Comparision image does not exist.'
+ );
+
+ if ( md5_file( $generated ) !== md5_file( $compare ) )
+ {
+ // Adding a diff makes no sense here, because created XML uses
+ // only two lines
+ $this->fail( 'Rendered image is not correct.');
+ }
+ }
+
+ public function testDrawLine()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $this->driver->drawLine(
+ new ezcGraphCoordinate( 12, 45 ),
+ new ezcGraphCoordinate( 134, 12 ),
+ ezcGraphColor::fromHex( '#3465A4' )
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ public function testDrawPolygonThreePointsFilled()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $return = $this->driver->drawPolygon(
+ array(
+ new ezcGraphCoordinate( 45, 12 ),
+ new ezcGraphCoordinate( 122, 34 ),
+ new ezcGraphCoordinate( 12, 71 ),
+ ),
+ ezcGraphColor::fromHex( '#3465A4' ),
+ true
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+
+ $this->assertEquals(
+ 'ezcGraphPolygon_1',
+ $return,
+ 'Expected flash object id as return value.'
+ );
+ }
+
+ public function testDrawPolygonThreePointsNotFilled()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $this->driver->drawPolygon(
+ array(
+ new ezcGraphCoordinate( 45, 12 ),
+ new ezcGraphCoordinate( 122, 34 ),
+ new ezcGraphCoordinate( 12, 71 ),
+ ),
+ ezcGraphColor::fromHex( '#3465A4' ),
+ false
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ public function testDrawPolygonFivePoints()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $this->driver->drawPolygon(
+ array(
+ new ezcGraphCoordinate( 45, 12 ),
+ new ezcGraphCoordinate( 122, 34 ),
+ new ezcGraphCoordinate( 12, 71 ),
+ new ezcGraphCoordinate( 3, 45 ),
+ new ezcGraphCoordinate( 60, 32 ),
+ ),
+ ezcGraphColor::fromHex( '#3465A4' ),
+ true
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ public function testDrawCircleSectorAcute()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $return = $this->driver->drawCircleSector(
+ new ezcGraphCoordinate( 100, 50 ),
+ 80,
+ 40,
+ 12.5,
+ 25,
+ ezcGraphColor::fromHex( '#3465A4' )
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+
+ $this->assertEquals(
+ 'ezcGraphCircleSector_1',
+ $return,
+ 'Expected flash object id as return value.'
+ );
+ }
+
+ public function testDrawMultipleCircleSectors()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $angles = array( 10, 25, 45, 75, 110, 55 );
+
+ $startAngle = 0;
+ foreach ( $angles as $angle )
+ {
+ $this->driver->drawCircleSector(
+ new ezcGraphCoordinate( 100, 50 ),
+ 80,
+ 40,
+ $startAngle,
+ $startAngle += $angle,
+ ezcGraphColor::fromHex( '#3465A4' )
+ );
+ $startAngle += 5;
+ }
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ public function testDrawMultipleBigCircleSectors()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $angles = array( 135, 250 );
+
+ $startAngle = 5;
+ foreach ( $angles as $angle )
+ {
+ $this->driver->drawCircleSector(
+ new ezcGraphCoordinate( 100, 50 ),
+ 80,
+ 40,
+ $startAngle,
+ $startAngle += $angle,
+ ezcGraphColor::fromHex( '#3465A4' )
+ );
+ $startAngle += 5;
+ }
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ public function testDrawCircleSectorAcuteNonFilled()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $this->driver->drawCircleSector(
+ new ezcGraphCoordinate( 100, 50 ),
+ 80,
+ 40,
+ 12.5,
+ 45,
+ ezcGraphColor::fromHex( '#3465A4' ),
+ false
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ public function testDrawCircleSectorAcuteReverse()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $this->driver->drawCircleSector(
+ new ezcGraphCoordinate( 100, 50 ),
+ 80,
+ 40,
+ 25,
+ 12.5,
+ ezcGraphColor::fromHex( '#3465A4' )
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ public function testDrawCircleSectorObtuse()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $this->driver->drawCircleSector(
+ new ezcGraphCoordinate( 100, 50 ),
+ 80,
+ 40,
+ 25,
+ 273,
+ ezcGraphColor::fromHex( '#3465A4' )
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ public function testDrawCircularArcAcute()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $return = $this->driver->drawCircularArc(
+ new ezcGraphCoordinate( 100, 50 ),
+ 150,
+ 80,
+ 10,
+ 12.5,
+ 55,
+ ezcGraphColor::fromHex( '#3465A4' )
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+
+ $this->assertEquals(
+ 'ezcGraphCircularArc_1',
+ $return,
+ 'Expected flash object id as return value.'
+ );
+ }
+
+ public function testDrawCircularArcAcuteBorder()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $this->driver->drawCircularArc(
+ new ezcGraphCoordinate( 100, 50 ),
+ 150,
+ 80,
+ 10,
+ 12.5,
+ 55,
+ ezcGraphColor::fromHex( '#3465A4' ),
+ false
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ public function testDrawCircularArcAcuteReverse()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $this->driver->drawCircularArc(
+ new ezcGraphCoordinate( 100, 50 ),
+ 150,
+ 80,
+ 10,
+ 55,
+ 12.5,
+ ezcGraphColor::fromHex( '#3465A4' )
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ public function testDrawCircularArcObtuse()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $this->driver->drawCircularArc(
+ new ezcGraphCoordinate( 100, 50 ),
+ 150,
+ 80,
+ 10,
+ 25,
+ 300,
+ ezcGraphColor::fromHex( '#3465A4' )
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ public function testDrawCircleFilled()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $return = $this->driver->drawCircle(
+ new ezcGraphCoordinate( 100, 50 ),
+ 80,
+ 40,
+ ezcGraphColor::fromHex( '#3465A4' )
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+
+ $this->assertEquals(
+ 'ezcGraphCircle_1',
+ $return,
+ 'Expected flash object id as return value.'
+ );
+ }
+
+ public function testDrawCircleNonFilled()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $this->driver->drawCircle(
+ new ezcGraphCoordinate( 100, 50 ),
+ 80,
+ 40,
+ ezcGraphColor::fromHex( '#3465A4' ),
+ false
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ 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 ( ezcGraphMingBitmapBoundingsException $e )
+ {
+ return true;
+ }
+
+ $this->fail( 'Expected ezcGraphMingBitmapBoundingsException.' );
+ }
+
+ public function testDrawImageGif()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ try
+ {
+ $return = $this->driver->drawImage(
+ $this->basePath . $this->testFiles['gif'],
+ new ezcGraphCoordinate( 10, 10 ),
+ 150,
+ 100
+ );
+ }
+ catch ( ezcGraphMingBitmapTypeException $e )
+ {
+ return true;
+ }
+
+ $this->fail( 'Expected ezcGraphMingBitmapTypeException.' );
+ }
+
+ public function testDrawImagePng()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ try
+ {
+ $return = $this->driver->drawImage(
+ $this->basePath . $this->testFiles['png'],
+ new ezcGraphCoordinate( 10, 10 ),
+ 177,
+ 100
+ );
+ }
+ catch ( ezcGraphMingBitmapTypeException $e )
+ {
+ return true;
+ }
+
+ $this->fail( 'Expected ezcGraphMingBitmapBoundingsException.' );
+ }
+
+ 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'],
+ new ezcGraphCoordinate( 10, 10 ),
+ 177,
+ 100
+ );
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ public function testDrawTextBoxShortString()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $this->driver->drawPolygon(
+ array(
+ new ezcGraphCoordinate( 10, 10 ),
+ new ezcGraphCoordinate( 160, 10 ),
+ new ezcGraphCoordinate( 160, 80 ),
+ new ezcGraphCoordinate( 10, 80 ),
+ ),
+ ezcGraphColor::fromHex( '#eeeeec' ),
+ true
+ );
+ $return = $this->driver->drawTextBox(
+ 'Short',
+ new ezcGraphCoordinate( 10, 10 ),
+ 150,
+ 70,
+ ezcGraph::LEFT
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+
+ $this->assertEquals(
+ 'ezcGraphTextBox_2',
+ $return,
+ 'Expected flash object id as return value.'
+ );
+ }
+
+ public function testDrawTextBoxLongString()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $this->driver->drawPolygon(
+ array(
+ new ezcGraphCoordinate( 10, 10 ),
+ new ezcGraphCoordinate( 160, 10 ),
+ new ezcGraphCoordinate( 160, 80 ),
+ new ezcGraphCoordinate( 10, 80 ),
+ ),
+ ezcGraphColor::fromHex( '#eeeeec' ),
+ true
+ );
+ $this->driver->drawTextBox(
+ 'ThisIsAPrettyLongString',
+ new ezcGraphCoordinate( 10, 10 ),
+ 150,
+ 70,
+ ezcGraph::LEFT
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ public function testDrawTextBoxLongSpacedString()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $this->driver->drawPolygon(
+ array(
+ new ezcGraphCoordinate( 10, 10 ),
+ new ezcGraphCoordinate( 160, 10 ),
+ new ezcGraphCoordinate( 160, 80 ),
+ new ezcGraphCoordinate( 10, 80 ),
+ ),
+ ezcGraphColor::fromHex( '#eeeeec' ),
+ true
+ );
+ $this->driver->drawTextBox(
+ 'This Is A Pretty Long String',
+ new ezcGraphCoordinate( 10, 10 ),
+ 150,
+ 70,
+ ezcGraph::LEFT
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ public function testDrawTextBoxManualBreak()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $this->driver->drawPolygon(
+ array(
+ new ezcGraphCoordinate( 10, 10 ),
+ new ezcGraphCoordinate( 160, 10 ),
+ new ezcGraphCoordinate( 160, 80 ),
+ new ezcGraphCoordinate( 10, 80 ),
+ ),
+ ezcGraphColor::fromHex( '#eeeeec' ),
+ true
+ );
+ $this->driver->drawTextBox(
+ "New\nLine",
+ new ezcGraphCoordinate( 10, 10 ),
+ 150,
+ 70,
+ ezcGraph::LEFT
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ public function testDrawTextBoxStringSampleRight()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $this->driver->drawPolygon(
+ array(
+ new ezcGraphCoordinate( 20, 20 ),
+ new ezcGraphCoordinate( 110, 20 ),
+ new ezcGraphCoordinate( 110, 30 ),
+ new ezcGraphCoordinate( 20, 30 ),
+ ),
+ ezcGraphColor::fromHex( '#eeeeec' ),
+ true
+ );
+ $this->driver->drawTextBox(
+ 'sample 4',
+ new ezcGraphCoordinate( 21, 21 ),
+ 88,
+ 8,
+ ezcGraph::RIGHT
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ public function testDrawTextBoxStringRight()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $this->driver->drawPolygon(
+ array(
+ new ezcGraphCoordinate( 10, 10 ),
+ new ezcGraphCoordinate( 160, 10 ),
+ new ezcGraphCoordinate( 160, 80 ),
+ new ezcGraphCoordinate( 10, 80 ),
+ ),
+ ezcGraphColor::fromHex( '#eeeeec' ),
+ true
+ );
+ $this->driver->drawTextBox(
+ 'ThisIsAPrettyLongString',
+ new ezcGraphCoordinate( 10, 10 ),
+ 150,
+ 70,
+ ezcGraph::RIGHT
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ public function testDrawTextBoxLongSpacedStringRight()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $this->driver->drawPolygon(
+ array(
+ new ezcGraphCoordinate( 10, 10 ),
+ new ezcGraphCoordinate( 160, 10 ),
+ new ezcGraphCoordinate( 160, 80 ),
+ new ezcGraphCoordinate( 10, 80 ),
+ ),
+ ezcGraphColor::fromHex( '#eeeeec' ),
+ true
+ );
+ $this->driver->drawTextBox(
+ 'This Is A Pretty Long String',
+ new ezcGraphCoordinate( 10, 10 ),
+ 150,
+ 70,
+ ezcGraph::RIGHT
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ public function testDrawTextBoxStringCenter()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $this->driver->drawPolygon(
+ array(
+ new ezcGraphCoordinate( 10, 10 ),
+ new ezcGraphCoordinate( 160, 10 ),
+ new ezcGraphCoordinate( 160, 80 ),
+ new ezcGraphCoordinate( 10, 80 ),
+ ),
+ ezcGraphColor::fromHex( '#eeeeec' ),
+ true
+ );
+ $this->driver->drawTextBox(
+ 'ThisIsAPrettyLongString',
+ new ezcGraphCoordinate( 10, 10 ),
+ 150,
+ 70,
+ ezcGraph::CENTER
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ public function testDrawTextBoxLongSpacedStringCenter()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $this->driver->drawPolygon(
+ array(
+ new ezcGraphCoordinate( 10, 10 ),
+ new ezcGraphCoordinate( 160, 10 ),
+ new ezcGraphCoordinate( 160, 80 ),
+ new ezcGraphCoordinate( 10, 80 ),
+ ),
+ ezcGraphColor::fromHex( '#eeeeec' ),
+ true
+ );
+ $this->driver->drawTextBox(
+ 'This Is A Pretty Long String',
+ new ezcGraphCoordinate( 10, 10 ),
+ 150,
+ 70,
+ ezcGraph::CENTER
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ public function testDrawTextBoxStringRightBottom()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $this->driver->drawPolygon(
+ array(
+ new ezcGraphCoordinate( 10, 10 ),
+ new ezcGraphCoordinate( 160, 10 ),
+ new ezcGraphCoordinate( 160, 80 ),
+ new ezcGraphCoordinate( 10, 80 ),
+ ),
+ ezcGraphColor::fromHex( '#eeeeec' ),
+ true
+ );
+ $this->driver->drawTextBox(
+ 'ThisIsAPrettyLongString',
+ new ezcGraphCoordinate( 10, 10 ),
+ 150,
+ 70,
+ ezcGraph::RIGHT | ezcGraph::BOTTOM
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ public function testDrawTextBoxLongSpacedStringRightMiddle()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $this->driver->drawPolygon(
+ array(
+ new ezcGraphCoordinate( 10, 10 ),
+ new ezcGraphCoordinate( 160, 10 ),
+ new ezcGraphCoordinate( 160, 80 ),
+ new ezcGraphCoordinate( 10, 80 ),
+ ),
+ ezcGraphColor::fromHex( '#eeeeec' ),
+ true
+ );
+ $this->driver->drawTextBox(
+ 'This Is A Pretty Long String',
+ new ezcGraphCoordinate( 10, 10 ),
+ 150,
+ 70,
+ ezcGraph::RIGHT | ezcGraph::MIDDLE
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ public function testDrawTextBoxStringCenterMiddle()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $this->driver->drawPolygon(
+ array(
+ new ezcGraphCoordinate( 10, 10 ),
+ new ezcGraphCoordinate( 160, 10 ),
+ new ezcGraphCoordinate( 160, 80 ),
+ new ezcGraphCoordinate( 10, 80 ),
+ ),
+ ezcGraphColor::fromHex( '#eeeeec' ),
+ true
+ );
+ $this->driver->drawTextBox(
+ 'ThisIsAPrettyLongString',
+ new ezcGraphCoordinate( 10, 10 ),
+ 150,
+ 70,
+ ezcGraph::CENTER | ezcGraph::MIDDLE
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ public function testDrawTextBoxLongSpacedStringCenterBottom()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $this->driver->drawPolygon(
+ array(
+ new ezcGraphCoordinate( 10, 10 ),
+ new ezcGraphCoordinate( 160, 10 ),
+ new ezcGraphCoordinate( 160, 80 ),
+ new ezcGraphCoordinate( 10, 80 ),
+ ),
+ ezcGraphColor::fromHex( '#eeeeec' ),
+ true
+ );
+ $this->driver->drawTextBox(
+ 'This Is A Pretty Long String',
+ new ezcGraphCoordinate( 10, 10 ),
+ 150,
+ 70,
+ ezcGraph::CENTER | ezcGraph::BOTTOM
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ public function testDrawStringWithSpecialChars()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $this->driver->drawPolygon(
+ array(
+ new ezcGraphCoordinate( 47, 54 ),
+ new ezcGraphCoordinate( 47, 84 ),
+ new ezcGraphCoordinate( 99, 84 ),
+ new ezcGraphCoordinate( 99, 54 ),
+ ),
+ ezcGraphColor::fromHex( '#DDDDDD' ),
+ true
+ );
+ $this->driver->drawTextBox(
+ 'Safari (13.8%)',
+ new ezcGraphCoordinate( 47, 54 ),
+ 52,
+ 30,
+ ezcGraph::LEFT
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ public function testDrawTextWithTextShadow()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $this->driver->options->font->background = ezcGraphColor::fromHex( '#DDDDDD' );
+ $this->driver->options->font->textShadow = true;
+
+ $this->driver->drawTextBox(
+ 'Some test string',
+ new ezcGraphCoordinate( 10, 10 ),
+ 150,
+ 70,
+ ezcGraph::LEFT | ezcGraph::MIDDLE
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ public function testDrawTextWithCustomTextShadow()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $this->driver->options->font->background = ezcGraphColor::fromHex( '#DDDDDD' );
+ $this->driver->options->font->textShadow = true;
+ $this->driver->options->font->textShadowColor = '#888888';
+
+ $this->driver->drawTextBox(
+ 'Some test string',
+ new ezcGraphCoordinate( 10, 10 ),
+ 150,
+ 70,
+ ezcGraph::LEFT | ezcGraph::MIDDLE
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ public function testDrawTextWithBackground()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $this->driver->options->font->background = ezcGraphColor::fromHex( '#DDDDDD' );
+ $this->driver->options->font->minimizeBorder = false;
+
+ $this->driver->drawTextBox(
+ 'Some test string',
+ new ezcGraphCoordinate( 10, 10 ),
+ 150,
+ 70,
+ ezcGraph::LEFT | ezcGraph::MIDDLE
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ public function testDrawTextWithBorder()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $this->driver->options->font->border = ezcGraphColor::fromHex( '#555555' );
+ $this->driver->options->font->minimizeBorder = false;
+
+ $this->driver->drawTextBox(
+ 'Some test string',
+ new ezcGraphCoordinate( 10, 10 ),
+ 150,
+ 70,
+ ezcGraph::LEFT | ezcGraph::MIDDLE
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ public function testDrawTextWithMinimizedBorderAndBackgroundTopLeft()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $this->driver->options->font->border = ezcGraphColor::fromHex( '#555555' );
+ $this->driver->options->font->background = ezcGraphColor::fromHex( '#DDDDDD' );
+ $this->driver->options->font->minimizeBorder = true;
+ $this->driver->options->font->padding = 2;
+
+ $this->driver->drawTextBox(
+ 'Some test string',
+ new ezcGraphCoordinate( 10, 10 ),
+ 150,
+ 70,
+ ezcGraph::LEFT | ezcGraph::TOP
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ public function testDrawTextWithMinimizedBorderAndBackgroundMiddleCenter()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $this->driver->options->font->border = ezcGraphColor::fromHex( '#555555' );
+ $this->driver->options->font->background = ezcGraphColor::fromHex( '#DDDDDD' );
+ $this->driver->options->font->minimizeBorder = true;
+ $this->driver->options->font->padding = 2;
+
+ $this->driver->drawTextBox(
+ 'Some test string',
+ new ezcGraphCoordinate( 10, 10 ),
+ 150,
+ 70,
+ ezcGraph::CENTER | ezcGraph::MIDDLE
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ public function testDrawTextWithMinimizedBorderAndBackgroundBottomRight()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $this->driver->options->font->border = ezcGraphColor::fromHex( '#555555' );
+ $this->driver->options->font->background = ezcGraphColor::fromHex( '#DDDDDD' );
+ $this->driver->options->font->minimizeBorder = true;
+ $this->driver->options->font->padding = 2;
+
+ $this->driver->drawTextBox(
+ 'Some test string',
+ new ezcGraphCoordinate( 10, 10 ),
+ 150,
+ 70,
+ ezcGraph::RIGHT | ezcGraph::BOTTOM
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
+ public function testDrawTooLongTextException()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.png';
+
+ try
+ {
+ $this->driver->drawTextBox(
+ 'This is very long text which is not supposed to fit in the bounding box.',
+ new ezcGraphCoordinate( 10, 10 ),
+ 50,
+ 20,
+ ezcGraph::LEFT
+ );
+
+ $this->driver->render( $filename );
+ }
+ catch ( ezcGraphFontRenderingException $e )
+ {
+ return true;
+ }
+
+ $this->fail( 'Expected ezcGraphFontRenderingException.' );
+ }
+}
+
+?>
diff --git a/tests/suite.php b/tests/suite.php
index d75d7d3..157c868 100644
--- a/tests/suite.php
+++ b/tests/suite.php
@@ -29,6 +29,7 @@ require_once 'axis_exact_renderer_test.php';
require_once 'axis_centered_renderer_test.php';
require_once 'driver_gd_test.php';
require_once 'driver_svg_test.php';
+require_once 'driver_ming_test.php';
require_once 'font_test.php';
require_once 'palette_test.php';
require_once 'matrix_test.php';
@@ -65,6 +66,8 @@ class ezcGraphSuite extends PHPUnit_Framework_TestSuite
$this->addTest( ezcGraphAxisCenteredRendererTest::suite() );
$this->addTest( ezcGraphGdDriverTest::suite() );
$this->addTest( ezcGraphSvgDriverTest::suite() );
+ // Segfaults
+// $this->addTest( ezcGraphMingDriverTest::suite() );
$this->addTest( ezcGraphFontTest::suite() );
$this->addTest( ezcGraphTextTest::suite() );
$this->addTest( ezcGraphPaletteTest::suite() );
OpenPOWER on IntegriCloud