summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog2
-rw-r--r--src/driver/flash.php41
-rw-r--r--src/driver/gd.php38
-rw-r--r--src/driver/svg.php10
-rw-r--r--src/interfaces/driver.php102
-rw-r--r--src/options/driver.php20
-rw-r--r--tests/data/compare/ezcGraphFlashDriverTest_testShortenStringMoreChars.swfbin0 -> 514 bytes
-rw-r--r--tests/data/compare/ezcGraphGdDriverTest_testShortenStringMoreChars.pngbin0 -> 599 bytes
-rw-r--r--tests/data/compare/ezcGraphSvgDriverTest_testShortenSingleChar.svg2
-rw-r--r--tests/data/compare/ezcGraphSvgDriverTest_testShortenStringFewChars.svg2
-rw-r--r--tests/data/compare/ezcGraphSvgDriverTest_testShortenStringManyWordsSplit.svg2
-rw-r--r--tests/data/compare/ezcGraphSvgDriverTest_testShortenStringMoreChars.svg2
-rw-r--r--tests/data/compare/ezcGraphSvgDriverTest_testShortenStringWordSplit.svg2
-rw-r--r--tests/driver_flash_test.php28
-rw-r--r--tests/driver_gd_test.php24
-rw-r--r--tests/driver_options_test.php47
-rw-r--r--tests/driver_svg_test.php148
17 files changed, 407 insertions, 63 deletions
diff --git a/ChangeLog b/ChangeLog
index 6c7038c..95946a6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -20,6 +20,8 @@
- Fixed issue #10846: Division by zero in polygon size reducement algorithm
for edges with an angle equals 0 degree.
- Fixed issue #10852: Fixed radar chart documentation
+- Fixed issue #10830: Automatically shorten labels if not enough space is
+ available
1.1beta1 - Monday 07 May 2007
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/driver/flash.php b/src/driver/flash.php
index 38c07a2..74de773 100644
--- a/src/driver/flash.php
+++ b/src/driver/flash.php
@@ -309,26 +309,33 @@ class ezcGraphFlashDriver extends ezcGraphDriver
$size = $this->modifyCoordinate( floor( ( $newsize = $size * ( $result ) ) >= $size ? $size - 1 : $newsize ) );
}
- if ( is_array( $result ) )
+ if ( !is_array( $result ) )
{
- $this->options->font->minimalUsedFont = $this->deModifyCoordinate( $size );
-
- $this->strings[] = array(
- 'text' => $result,
- 'id' => $id = 'ezcGraphTextBox_' . $this->id++,
- 'position' => $position,
- 'width' => $width,
- 'height' => $height,
- 'align' => $align,
- 'font' => $this->options->font,
- 'rotation' => $rotation,
- );
- }
- else
- {
- throw new ezcGraphFontRenderingException( $string, $this->options->font->minFontSize, $width, $height );
+ if ( ( $height >= $this->options->font->minFontSize ) &&
+ ( $this->options->autoShortenString ) )
+ {
+ $result = $this->tryFitShortenedString( $string, $position, $width, $height, $size = $this->modifyCoordinate( $this->options->font->minFontSize ) );
+ }
+ else
+ {
+ throw new ezcGraphFontRenderingException( $string, $this->options->font->minFontSize, $width, $height );
+ }
}
+
+ $this->options->font->minimalUsedFont = $this->deModifyCoordinate( $size );
+
+ $this->strings[] = array(
+ 'text' => $result,
+ 'id' => $id = 'ezcGraphTextBox_' . $this->id++,
+ 'position' => $position,
+ 'width' => $width,
+ 'height' => $height,
+ 'align' => $align,
+ 'font' => $this->options->font,
+ 'rotation' => $rotation,
+ );
+
return $id;
}
diff --git a/src/driver/gd.php b/src/driver/gd.php
index c398261..a3bea95 100644
--- a/src/driver/gd.php
+++ b/src/driver/gd.php
@@ -426,25 +426,31 @@ class ezcGraphGdDriver extends ezcGraphDriver
$size = floor( ( $newsize = $size * ( $result ) ) >= $size ? $size - 1 : $newsize );
}
- if ( is_array( $result ) )
+ if ( !is_array( $result ) )
{
- $this->options->font->minimalUsedFont = $size;
-
- $this->strings[] = array(
- 'text' => $result,
- 'position' => $position,
- 'width' => $width,
- 'height' => $height,
- 'align' => $align,
- 'font' => $this->options->font,
- 'rotation' => $rotation,
- );
- }
- else
- {
- throw new ezcGraphFontRenderingException( $string, $this->options->font->minFontSize, $width, $height );
+ if ( ( $height >= $this->options->font->minFontSize ) &&
+ ( $this->options->autoShortenString ) )
+ {
+ $result = $this->tryFitShortenedString( $string, $position, $width, $height, $size = $this->options->font->minFontSize );
+ }
+ else
+ {
+ throw new ezcGraphFontRenderingException( $string, $this->options->font->minFontSize, $width, $height );
+ }
}
+ $this->options->font->minimalUsedFont = $size;
+
+ $this->strings[] = array(
+ 'text' => $result,
+ 'position' => $position,
+ 'width' => $width,
+ 'height' => $height,
+ 'align' => $align,
+ 'font' => $this->options->font,
+ 'rotation' => $rotation,
+ );
+
return array(
clone $position,
new ezcGraphCoordinate( $position->x + $width, $position->y ),
diff --git a/src/driver/svg.php b/src/driver/svg.php
index bfbf95c..81e2aed 100644
--- a/src/driver/svg.php
+++ b/src/driver/svg.php
@@ -457,7 +457,15 @@ class ezcGraphSvgDriver extends ezcGraphDriver
if ( !is_array( $result ) )
{
- throw new ezcGraphFontRenderingException( $string, $this->options->font->minFontSize, $width, $height );
+ if ( ( $height >= $this->options->font->minFontSize ) &&
+ ( $this->options->autoShortenString ) )
+ {
+ $result = $this->tryFitShortenedString( $string, $position, $width, $height, $size = $this->options->font->minFontSize );
+ }
+ else
+ {
+ throw new ezcGraphFontRenderingException( $string, $this->options->font->minFontSize, $width, $height );
+ }
}
$this->options->font->minimalUsedFont = $size;
diff --git a/src/interfaces/driver.php b/src/interfaces/driver.php
index cb8857a..b9a55dd 100644
--- a/src/interfaces/driver.php
+++ b/src/interfaces/driver.php
@@ -498,6 +498,108 @@ abstract class ezcGraphDriver
}
/**
+ * If it is allow to shortened the string, this method tries to extract as
+ * many chars as possible to display a decent amount of characters.
+ *
+ * If no complete token (word) does fit, the largest possible amount of
+ * chars from the first word are taken. If the amount of chars is bigger
+ * then strlen( shortenedStringPostFix ) * 2 the last chars are replace by
+ * the postfix.
+ *
+ * If one complete word fits the box as many words are taken as possible
+ * including a appended shortenedStringPostFix.
+ *
+ * @param mixed $string
+ * @param ezcGraphCoordinate $position
+ * @param mixed $width
+ * @param mixed $height
+ * @param mixed $size
+ * @access protected
+ * @return void
+ */
+ protected function tryFitShortenedString( $string, ezcGraphCoordinate $position, $width, $height, $size )
+ {
+ $tokens = preg_split( '/\s+/', $string );
+
+ // Try to fit a complete word first
+ $boundings = $this->getTextBoundings(
+ $size,
+ $this->options->font,
+ reset( $tokens ) . ( $postfix = $this->options->autoShortenStringPostFix )
+ );
+
+ if ( $boundings->width > $width )
+ {
+ // Not even one word fits the box
+ $word = reset( $tokens );
+
+ // Test if first character fits the box
+ $boundigs = $this->getTextBoundings(
+ $size,
+ $this->options->font,
+ $hit = $word[0]
+ );
+
+ if ( $boundigs->width > $width )
+ {
+ // That is a really small box.
+ throw new ezcGraphFontRenderingException( $string, $size, $width, $height );
+ }
+
+ // Try to put more charactes in there
+ $postLength = strlen( $postfix );
+ $wordLength = strlen( $word );
+ for ( $i = 2; $i <= $wordLength; ++$i )
+ {
+ $string = substr( $word, 0, $i );
+ if ( strlen( $string ) > ( $postLength << 1 ) )
+ {
+ $string = substr( $string, 0, -$postLength ) . $postfix;
+ }
+
+ $boundigs = $this->getTextBoundings( $size, $this->options->font, $string );
+
+ if ( $boundigs->width < $width )
+ {
+ $hit = $string;
+ }
+ else
+ {
+ // Use last string which fit
+ break;
+ }
+ }
+ }
+ else
+ {
+ // Try to use as many words as possible
+ $hit = reset( $tokens );
+
+ for ( $i = 2; $i < count( $tokens ); ++$i )
+ {
+ $string = implode( ' ', array_slice( $tokens, 0, $i ) ) .
+ $postfix;
+
+ $boundings = $this->getTextBoundings( $size, $this->options->font, $string );
+
+ if ( $boundings->width <= $width )
+ {
+ $hit .= ' ' . $tokens[$i - 1];
+ }
+ else
+ {
+ // Use last valid hit
+ break;
+ }
+ }
+
+ $hit .= $postfix;
+ }
+
+ return array( array( $hit ) );
+ }
+
+ /**
* Writes text in a box of desired size
*
* @param string $string Text
diff --git a/src/options/driver.php b/src/options/driver.php
index eb353af..b967192 100644
--- a/src/options/driver.php
+++ b/src/options/driver.php
@@ -20,6 +20,10 @@
* Percent of font size used for line spacing
* @property int $font
* Font used in the graph.
+ * @property bool $autoShortenString
+ * Automatically shorten string if it does not fit into a box
+ * @property string $autoShortenStringPostFix
+ * String to append to shortened strings, if there is enough space
*
* @package Graph
*/
@@ -42,6 +46,9 @@ abstract class ezcGraphDriverOptions extends ezcBaseOptions
$this->properties['font'] = new ezcGraphFontOptions();
$this->properties['font']->color = ezcGraphColor::fromHex( '#000000' );
+ $this->properties['autoShortenString'] = true;
+ $this->properties['autoShortenStringPostFix'] = '..';
+
parent::__construct( $options );
}
@@ -106,6 +113,19 @@ abstract class ezcGraphDriverOptions extends ezcBaseOptions
throw new ezcBaseValueException( $propertyName, $propertyValue, 'ezcGraphFontOptions' );
}
break;
+ case 'autoShortenString':
+ if ( is_bool( $propertyValue ) )
+ {
+ $this->properties['autoShortenString'] = $propertyValue;
+ }
+ else
+ {
+ throw new ezcBaseValueException( $propertyName, $propertyValue, 'boolean' );
+ }
+ break;
+ case 'autoShortenStringPostFix':
+ $this->properties['autoShortenStringPostFix'] = (string) $propertyValue;
+ break;
default:
throw new ezcBasePropertyNotFoundException( $propertyName );
break;
diff --git a/tests/data/compare/ezcGraphFlashDriverTest_testShortenStringMoreChars.swf b/tests/data/compare/ezcGraphFlashDriverTest_testShortenStringMoreChars.swf
new file mode 100644
index 0000000..4ace166
--- /dev/null
+++ b/tests/data/compare/ezcGraphFlashDriverTest_testShortenStringMoreChars.swf
Binary files differ
diff --git a/tests/data/compare/ezcGraphGdDriverTest_testShortenStringMoreChars.png b/tests/data/compare/ezcGraphGdDriverTest_testShortenStringMoreChars.png
new file mode 100644
index 0000000..5df0996
--- /dev/null
+++ b/tests/data/compare/ezcGraphGdDriverTest_testShortenStringMoreChars.png
Binary files differ
diff --git a/tests/data/compare/ezcGraphSvgDriverTest_testShortenSingleChar.svg b/tests/data/compare/ezcGraphSvgDriverTest_testShortenSingleChar.svg
new file mode 100644
index 0000000..6f62296
--- /dev/null
+++ b/tests/data/compare/ezcGraphSvgDriverTest_testShortenSingleChar.svg
@@ -0,0 +1,2 @@
+<?xml version="1.0"?>
+<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" version="1.0" id="ezcGraph"><defs/><g id="ezcGraphChart" color-rendering="optimizeQuality" shape-rendering="geometricPrecision" text-rendering="optimizeLegibility"><g id="ezcGraphTextBox_1"><path d=" M 9.5000,17.0000 L 9.5000,9.5000 L 14.1800,9.5000 L 14.1800,17.0000 L 9.5000,17.0000 z " style="fill: #ffffff; fill-opacity: 0.00; stroke: none;" id="ezcGraphPolygon_2"/><text id="ezcGraphTextBox_1_text" x="10.0000" text-length="3.1800px" y="15.1000" style="font-size: 6px; font-family: sans-serif; fill: #000000; fill-opacity: 1.00; stroke: none;">T</text></g></g></svg>
diff --git a/tests/data/compare/ezcGraphSvgDriverTest_testShortenStringFewChars.svg b/tests/data/compare/ezcGraphSvgDriverTest_testShortenStringFewChars.svg
new file mode 100644
index 0000000..0670328
--- /dev/null
+++ b/tests/data/compare/ezcGraphSvgDriverTest_testShortenStringFewChars.svg
@@ -0,0 +1,2 @@
+<?xml version="1.0"?>
+<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" version="1.0" id="ezcGraph"><defs/><g id="ezcGraphChart" color-rendering="optimizeQuality" shape-rendering="geometricPrecision" text-rendering="optimizeLegibility"><g id="ezcGraphTextBox_1"><path d=" M 9.5000,17.0000 L 9.5000,9.5000 L 17.3600,9.5000 L 17.3600,17.0000 L 9.5000,17.0000 z " style="fill: #ffffff; fill-opacity: 0.00; stroke: none;" id="ezcGraphPolygon_2"/><text id="ezcGraphTextBox_1_text" x="10.0000" text-length="6.3600px" y="15.1000" style="font-size: 6px; font-family: sans-serif; fill: #000000; fill-opacity: 1.00; stroke: none;">Te</text></g></g></svg>
diff --git a/tests/data/compare/ezcGraphSvgDriverTest_testShortenStringManyWordsSplit.svg b/tests/data/compare/ezcGraphSvgDriverTest_testShortenStringManyWordsSplit.svg
new file mode 100644
index 0000000..28b0bf9
--- /dev/null
+++ b/tests/data/compare/ezcGraphSvgDriverTest_testShortenStringManyWordsSplit.svg
@@ -0,0 +1,2 @@
+<?xml version="1.0"?>
+<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" version="1.0" id="ezcGraph"><defs/><g id="ezcGraphChart" color-rendering="optimizeQuality" shape-rendering="geometricPrecision" text-rendering="optimizeLegibility"><g id="ezcGraphTextBox_1"><path d=" M 9.5000,17.0000 L 9.5000,9.5000 L 65.0600,9.5000 L 65.0600,17.0000 L 9.5000,17.0000 z " style="fill: #ffffff; fill-opacity: 0.00; stroke: none;" id="ezcGraphPolygon_2"/><text id="ezcGraphTextBox_1_text" x="10.0000" text-length="54.0600px" y="15.1000" style="font-size: 6px; font-family: sans-serif; fill: #000000; fill-opacity: 1.00; stroke: none;">foo bar foo bar..</text></g></g></svg>
diff --git a/tests/data/compare/ezcGraphSvgDriverTest_testShortenStringMoreChars.svg b/tests/data/compare/ezcGraphSvgDriverTest_testShortenStringMoreChars.svg
new file mode 100644
index 0000000..91b7aa6
--- /dev/null
+++ b/tests/data/compare/ezcGraphSvgDriverTest_testShortenStringMoreChars.svg
@@ -0,0 +1,2 @@
+<?xml version="1.0"?>
+<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" version="1.0" id="ezcGraph"><defs/><g id="ezcGraphChart" color-rendering="optimizeQuality" shape-rendering="geometricPrecision" text-rendering="optimizeLegibility"><g id="ezcGraphTextBox_1"><path d=" M 9.5000,17.0000 L 9.5000,9.5000 L 33.2600,9.5000 L 33.2600,17.0000 L 9.5000,17.0000 z " style="fill: #ffffff; fill-opacity: 0.00; stroke: none;" id="ezcGraphPolygon_2"/><text id="ezcGraphTextBox_1_text" x="10.0000" text-length="22.2600px" y="15.1000" style="font-size: 6px; font-family: sans-serif; fill: #000000; fill-opacity: 1.00; stroke: none;">Tests..</text></g></g></svg>
diff --git a/tests/data/compare/ezcGraphSvgDriverTest_testShortenStringWordSplit.svg b/tests/data/compare/ezcGraphSvgDriverTest_testShortenStringWordSplit.svg
new file mode 100644
index 0000000..1feb931
--- /dev/null
+++ b/tests/data/compare/ezcGraphSvgDriverTest_testShortenStringWordSplit.svg
@@ -0,0 +1,2 @@
+<?xml version="1.0"?>
+<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" version="1.0" id="ezcGraph"><defs/><g id="ezcGraphChart" color-rendering="optimizeQuality" shape-rendering="geometricPrecision" text-rendering="optimizeLegibility"><g id="ezcGraphTextBox_1"><path d=" M 9.5000,17.0000 L 9.5000,9.5000 L 49.1600,9.5000 L 49.1600,17.0000 L 9.5000,17.0000 z " style="fill: #ffffff; fill-opacity: 0.00; stroke: none;" id="ezcGraphPolygon_2"/><text id="ezcGraphTextBox_1_text" x="10.0000" text-length="38.1600px" y="15.1000" style="font-size: 6px; font-family: sans-serif; fill: #000000; fill-opacity: 1.00; stroke: none;">Teststring..</text></g></g></svg>
diff --git a/tests/driver_flash_test.php b/tests/driver_flash_test.php
index 409475f..d9b4287 100644
--- a/tests/driver_flash_test.php
+++ b/tests/driver_flash_test.php
@@ -1274,15 +1274,15 @@ class ezcGraphFlashDriverTest extends ezcGraphTestCase
public function testDrawTooLongTextException()
{
- $filename = $this->tempDir . __FUNCTION__ . '.png';
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
try
{
$this->driver->drawTextBox(
- 'This is very long text which is not supposed to fit in the bounding box.',
+ 'Teststring foo',
new ezcGraphCoordinate( 10, 10 ),
- 50,
- 20,
+ 1,
+ 6,
ezcGraph::LEFT
);
@@ -1296,6 +1296,26 @@ class ezcGraphFlashDriverTest extends ezcGraphTestCase
$this->fail( 'Expected ezcGraphFontRenderingException.' );
}
+ public function testShortenStringMoreChars()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.swf';
+
+ $this->driver->drawTextBox(
+ 'Teststring foo',
+ new ezcGraphCoordinate( 10, 10 ),
+ 24,
+ 6,
+ ezcGraph::LEFT
+ );
+
+ $this->driver->render( $filename );
+
+ $this->swfCompare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'
+ );
+ }
+
public function testDrawCircleRadialFill()
{
$filename = $this->tempDir . __FUNCTION__ . '.swf';
diff --git a/tests/driver_gd_test.php b/tests/driver_gd_test.php
index a11d38d..07690c0 100644
--- a/tests/driver_gd_test.php
+++ b/tests/driver_gd_test.php
@@ -1934,7 +1934,7 @@ class ezcGraphGdDriverTest extends ezcTestImageCase
$this->driver->drawTextBox(
'This is very long text which is not supposed to fit in the bounding box.',
new ezcGraphCoordinate( 10, 10 ),
- 50,
+ 1,
20,
ezcGraph::LEFT
);
@@ -2225,6 +2225,28 @@ class ezcGraphGdDriverTest extends ezcTestImageCase
);
}
+ public function testShortenStringMoreChars()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.png';
+
+ $this->driver->drawTextBox(
+ 'Teststring foo',
+ new ezcGraphCoordinate( 10, 10 ),
+ 24,
+ 6,
+ ezcGraph::LEFT
+ );
+
+ $this->driver->render( $filename );
+
+ $this->assertImageSimilar(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.png',
+ 'Image does not look as expected.',
+ 2000
+ );
+ }
+
public function testDrawJpeg()
{
$filename = $this->tempDir . __FUNCTION__ . '.jpg';
diff --git a/tests/driver_options_test.php b/tests/driver_options_test.php
index 705ade6..e544648 100644
--- a/tests/driver_options_test.php
+++ b/tests/driver_options_test.php
@@ -171,6 +171,53 @@ class ezcGraphDriverOptionsTest extends ezcTestImageCase
$this->fail( 'Expected ezcBaseValueException.' );
}
+ public function testDriverOptionsPropertyAutoShortenString()
+ {
+ $options = new ezcGraphSvgDriverOptions();
+
+ $this->assertSame(
+ true,
+ $options->autoShortenString,
+ 'Wrong default value for property autoShortenString in class ezcGraphDriverOptions'
+ );
+
+ $options->autoShortenString = false;
+ $this->assertSame(
+ false,
+ $options->autoShortenString,
+ 'Setting property value did not work for property autoShortenString in class ezcGraphDriverOptions'
+ );
+
+ try
+ {
+ $options->autoShortenString = 42;
+ }
+ catch ( ezcBaseValueException $e )
+ {
+ return true;
+ }
+
+ $this->fail( 'Expected ezcBaseValueException.' );
+ }
+
+ public function testDriverOptionsPropertyAutoShortenStringPostFix()
+ {
+ $options = new ezcGraphSvgDriverOptions();
+
+ $this->assertSame(
+ '..',
+ $options->autoShortenStringPostFix,
+ 'Wrong default value for property autoShortenStringPostFix in class ezcGraphDriverOptions'
+ );
+
+ $options->autoShortenStringPostFix = ' ...';
+ $this->assertSame(
+ ' ...',
+ $options->autoShortenStringPostFix,
+ 'Setting property value did not work for property autoShortenStringPostFix in class ezcGraphDriverOptions'
+ );
+ }
+
public function testPropertyNotFoundException()
{
$options = new ezcGraphSvgDriverOptions();
diff --git a/tests/driver_svg_test.php b/tests/driver_svg_test.php
index 67e0096..e9dffa8 100644
--- a/tests/driver_svg_test.php
+++ b/tests/driver_svg_test.php
@@ -1433,30 +1433,6 @@ class ezcGraphSvgDriverTest extends ezcGraphTestCase
);
}
- 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.' );
- }
-
public function testSvgDriverOptionsPropertyAssumedNumericCharacterWidth()
{
$options = new ezcGraphSvgDriverOptions();
@@ -1816,5 +1792,129 @@ class ezcGraphSvgDriverTest extends ezcGraphTestCase
$this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
);
}
+
+ public function testShortenStringFailure()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.svg';
+
+ try
+ {
+ $this->driver->drawTextBox(
+ 'Test string',
+ new ezcGraphCoordinate( 10, 10 ),
+ 1,
+ 6,
+ ezcGraph::LEFT
+ );
+
+ $this->driver->render( $filename );
+ }
+ catch ( ezcGraphFontRenderingException $e )
+ {
+ return true;
+ }
+
+ $this->fail( 'Expected ezcGraphFontRenderingException.' );
+ }
+
+ public function testShortenSingleChar()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.svg';
+
+ $this->driver->drawTextBox(
+ 'Teststring foo',
+ new ezcGraphCoordinate( 10, 10 ),
+ 4,
+ 6,
+ ezcGraph::LEFT
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
+ );
+ }
+
+ public function testShortenStringFewChars()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.svg';
+
+ $this->driver->drawTextBox(
+ 'Teststring foo',
+ new ezcGraphCoordinate( 10, 10 ),
+ 8,
+ 6,
+ ezcGraph::LEFT
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
+ );
+ }
+
+ public function testShortenStringMoreChars()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.svg';
+
+ $this->driver->drawTextBox(
+ 'Teststring foo',
+ new ezcGraphCoordinate( 10, 10 ),
+ 24,
+ 6,
+ ezcGraph::LEFT
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
+ );
+ }
+
+ public function testShortenStringWordSplit()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.svg';
+
+ $this->driver->drawTextBox(
+ 'Teststring foo',
+ new ezcGraphCoordinate( 10, 10 ),
+ 40,
+ 6,
+ ezcGraph::LEFT
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
+ );
+ }
+
+ public function testShortenStringManyWordsSplit()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.svg';
+
+ $this->driver->drawTextBox(
+ 'foo bar foo bar foo bar foo bar',
+ new ezcGraphCoordinate( 10, 10 ),
+ 60,
+ 6,
+ ezcGraph::LEFT
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
+ );
+ }
}
?>
OpenPOWER on IntegriCloud