summaryrefslogtreecommitdiffstats
path: root/src/driver/svg.php
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2006-09-19 13:54:35 +0000
committerKore Nordmann <github@kore-nordmann.de>2006-09-19 13:54:35 +0000
commit07b3bbfeee01d2b73c3d5dd47f900c07edd09952 (patch)
tree2c2ad498720251ce46fc27b24835365dd9212f9e /src/driver/svg.php
parentfe13be6dac3b9a019cd4ee7a4e1b3272ef922871 (diff)
downloadzetacomponents-graph-07b3bbfeee01d2b73c3d5dd47f900c07edd09952.zip
zetacomponents-graph-07b3bbfeee01d2b73c3d5dd47f900c07edd09952.tar.gz
- Make better assumptions an character width in SVG driver
Diffstat (limited to 'src/driver/svg.php')
-rw-r--r--src/driver/svg.php24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/driver/svg.php b/src/driver/svg.php
index 9fa4e5c..13ac3b1 100644
--- a/src/driver/svg.php
+++ b/src/driver/svg.php
@@ -356,7 +356,7 @@ class ezcGraphSvgDriver extends ezcGraphDriver
$selectedLine[] = $token;
// Assume characters have the same width as height
- $strWidth = $size * strlen( implode( ' ', $selectedLine ) ) * $this->options->assumedCharacterWidth;
+ $strWidth = $this->getTextWidth( implode( ' ', $selectedLine ), $size );
// Check if line is too long
if ( $strWidth > $width )
@@ -387,7 +387,7 @@ class ezcGraphSvgDriver extends ezcGraphDriver
}
// Check width of last line
- $strWidth = $size * strlen( implode( ' ', $selectedLine ) ) * $this->options->assumedCharacterWidth;
+ $strWidth = $this->getTextWidth( implode( ' ', $selectedLine ), $size );
if ( $strWidth > $width ) {
return false;
}
@@ -441,6 +441,18 @@ class ezcGraphSvgDriver extends ezcGraphDriver
return $id;
}
+ protected function getTextWidth( $string, $size )
+ {
+ if ( is_numeric( $string ) )
+ {
+ return $size * strlen( $string ) * $this->options->assumedNumericCharacterWidth;
+ }
+ else
+ {
+ return $size * strlen( $string ) * $this->options->assumedTextCharacterWidth;
+ }
+ }
+
protected function drawAllTexts()
{
foreach ( $this->strings as $text )
@@ -473,7 +485,7 @@ class ezcGraphSvgDriver extends ezcGraphDriver
foreach ( $text['text'] as $line )
{
$string = implode( ' ', $line );
- if ( ( $strWidth = ( $size * strlen( $string ) * $this->options->assumedCharacterWidth ) ) > $width )
+ if ( ( $strWidth = $this->getTextWidth( $string, $size ) ) > $width )
{
$width = $strWidth;
}
@@ -568,13 +580,13 @@ class ezcGraphSvgDriver extends ezcGraphDriver
break;
case ( $text['align'] & ezcGraph::RIGHT ):
$position = new ezcGraphCoordinate(
- $text['position']->x + ( $text['width'] - $size * strlen( $string ) * $this->options->assumedCharacterWidth ),
+ $text['position']->x + ( $text['width'] - $this->getTextWidth( $string, $size ) ),
$text['position']->y + $yOffset
);
break;
case ( $text['align'] & ezcGraph::CENTER ):
$position = new ezcGraphCoordinate(
- $text['position']->x + ( ( $text['width'] - $size * strlen( $string ) * $this->options->assumedCharacterWidth ) / 2 ),
+ $text['position']->x + ( ( $text['width'] - $this->getTextWidth( $string, $size ) ) / 2 ),
$text['position']->y + $yOffset
);
break;
@@ -583,7 +595,7 @@ class ezcGraphSvgDriver extends ezcGraphDriver
$textNode = $this->dom->createElement( 'text', $string );
$textNode->setAttribute( 'id', $text['id'] );
$textNode->setAttribute( 'x', $position->x + $this->options->graphOffset->x );
- $textNode->setAttribute( 'text-length', ( $size * strlen( $string ) * $this->options->assumedCharacterWidth ) . 'px' );
+ $textNode->setAttribute( 'text-length', $this->getTextWidth( $string, $size ) . 'px' );
$textNode->setAttribute( 'y', $position->y + $this->options->graphOffset->y );
$textNode->setAttribute(
'style',
OpenPOWER on IntegriCloud