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 /src/driver | |
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
Diffstat (limited to 'src/driver')
-rw-r--r-- | src/driver/gd.php | 23 |
1 files changed, 20 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; } |