diff options
author | Kore Nordmann <github@kore-nordmann.de> | 2006-06-02 10:04:10 +0000 |
---|---|---|
committer | Kore Nordmann <github@kore-nordmann.de> | 2006-06-02 10:04:10 +0000 |
commit | 9f913f9636f28383deea7c5885be484087b1e625 (patch) | |
tree | 7c5ae91e4f5467f1bbd6c265a9a52ed49b10781a | |
parent | a76468ade84e9b6d7f72bac87b2db60e4e631a4f (diff) | |
download | zetacomponents-graph-9f913f9636f28383deea7c5885be484087b1e625.zip zetacomponents-graph-9f913f9636f28383deea7c5885be484087b1e625.tar.gz |
- Added tests for vertical alignement
- Added support for vertical alignement to GD driver
-rw-r--r-- | src/driver/gd.php | 23 | ||||
-rw-r--r-- | src/graph.php | 1 | ||||
-rw-r--r-- | tests/driver_gd_test.php | 104 |
3 files changed, 125 insertions, 3 deletions
diff --git a/src/driver/gd.php b/src/driver/gd.php index 1df035d..e0e4912 100644 --- a/src/driver/gd.php +++ b/src/driver/gd.php @@ -219,6 +219,23 @@ class ezcGraphGdDriver extends ezcGraphDriver if ( is_array( $result ) ) { + $completeHeight = count( $result ) * $size + ( count( $result ) - 1 ) * $this->options->lineSpacing; + + // Calculate y offset for vertical alignement + switch ( true ) + { + case ( $align & ezcGraph::BOTTOM ): + $yOffset = $height - $completeHeight; + break; + case ( $align & ezcGraph::MIDDLE ): + $yOffset = ( $height - $completeHeight ) / 2; + break; + case ( $align & ezcGraph::TOP ): + default: + $yOffset = 0; + break; + } + // Render text with evaluated font size foreach ( $result as $line ) { @@ -229,13 +246,13 @@ class ezcGraphGdDriver extends ezcGraphDriver switch ( true ) { case ( $align & ezcGraph::LEFT ): - imagettftext( $image, $size, 0, $position->x, $position->y, $drawColor, $this->options->font, $string ); + imagettftext( $image, $size, 0, $position->x, $position->y + $yOffset, $drawColor, $this->options->font, $string ); break; case ( $align & ezcGraph::RIGHT ): - imagettftext( $image, $size, 0, $position->x + ( $width - $boundings[2] ), $position->y, $drawColor, $this->options->font, $string ); + imagettftext( $image, $size, 0, $position->x + ( $width - $boundings[2] ), $position->y + $yOffset, $drawColor, $this->options->font, $string ); break; case ( $align & ezcGraph::CENTER ): - imagettftext( $image, $size, 0, $position->x + ( ( $width - $boundings[2] ) / 2 ), $position->y, $drawColor, $this->options->font, $string ); + imagettftext( $image, $size, 0, $position->x + ( ( $width - $boundings[2] ) / 2 ), $position->y + $yOffset, $drawColor, $this->options->font, $string ); break; } diff --git a/src/graph.php b/src/graph.php index 12bb946..03ee3fe 100644 --- a/src/graph.php +++ b/src/graph.php @@ -25,6 +25,7 @@ class ezcGraph const LEFT = 4; const RIGHT = 8; const CENTER = 16; + const MIDDLE = 32; static protected $chartTypes = array( 'pie' => 'ezcGraphPieChart', diff --git a/tests/driver_gd_test.php b/tests/driver_gd_test.php index 3a3bde4..8cf78d2 100644 --- a/tests/driver_gd_test.php +++ b/tests/driver_gd_test.php @@ -645,6 +645,110 @@ class ezcGraphGdDriverTest extends ezcTestCase 'Incorrect image rendered.' ); } + + public function testDrawTextBoxStringRightBottom() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + + $this->driver->drawTextBox( + 'ThisIsAPrettyLongString', + new ezcGraphCoordinate( 10, 10 ), + 150, + 70, + ezcGraph::RIGHT | ezcGraph::BOTTOM + ); + + $this->driver->render( $filename ); + + $this->assertTrue( + file_exists( $filename ), + 'No image was generated.' + ); + + $this->assertEquals( + 'f257787cc53cb20466bab58ec5bddc5d', + md5_file( $filename ), + 'Incorrect image rendered.' + ); + } + + public function testDrawTextBoxLongSpacedStringRightMiddle() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + + $this->driver->drawTextBox( + 'This Is A Pretty Long String', + new ezcGraphCoordinate( 10, 10 ), + 150, + 70, + ezcGraph::RIGHT | ezcGraph::MIDDLE + ); + + $this->driver->render( $filename ); + + $this->assertTrue( + file_exists( $filename ), + 'No image was generated.' + ); + + $this->assertEquals( + '57b4feb5bd595f5719ad1cda3549c935', + md5_file( $filename ), + 'Incorrect image rendered.' + ); + } + + public function testDrawTextBoxStringCenterMiddle() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + + $this->driver->drawTextBox( + 'ThisIsAPrettyLongString', + new ezcGraphCoordinate( 10, 10 ), + 150, + 70, + ezcGraph::CENTER | ezcGraph::MIDDLE + ); + + $this->driver->render( $filename ); + + $this->assertTrue( + file_exists( $filename ), + 'No image was generated.' + ); + + $this->assertEquals( + 'df03a60c93f3003b3c3c1b0b7989c41f', + md5_file( $filename ), + 'Incorrect image rendered.' + ); + } + + public function testDrawTextBoxLongSpacedStringCenterBottom() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + + $this->driver->drawTextBox( + 'This Is A Pretty Long String', + new ezcGraphCoordinate( 10, 10 ), + 150, + 70, + ezcGraph::CENTER | ezcGraph::BOTTOM + ); + + $this->driver->render( $filename ); + + $this->assertTrue( + file_exists( $filename ), + 'No image was generated.' + ); + + $this->assertEquals( + 'd7e02054f05b72e6a051d9cbd35638c8', + md5_file( $filename ), + 'Incorrect image rendered.' + ); + } } ?> |