summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2008-05-03 18:29:35 +0000
committerKore Nordmann <github@kore-nordmann.de>2008-05-03 18:29:35 +0000
commit639d72f8b822bf105d9c8be01a4fa27452b7beee (patch)
tree3ab33bc6c147ed2eee3e23d08d03ebe4a0f6c534
parentcce8cbce35d5b21fcc2a9ccb7a62d398e7501594 (diff)
downloadzetacomponents-graph-639d72f8b822bf105d9c8be01a4fa27452b7beee.zip
zetacomponents-graph-639d72f8b822bf105d9c8be01a4fa27452b7beee.tar.gz
- Implemented feature #10829: Get resource from driver
-rw-r--r--ChangeLog1
-rw-r--r--src/driver/cairo.php28
-rw-r--r--src/driver/flash.php16
-rw-r--r--src/driver/gd.php26
-rw-r--r--src/driver/svg.php16
-rw-r--r--tests/driver_cairo_test.php24
-rw-r--r--tests/driver_flash_test.php19
-rw-r--r--tests/driver_gd_test.php20
-rw-r--r--tests/driver_svg_test.php19
9 files changed, 160 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 0617565..6afabc6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,7 @@
- Implemented feature #12382: Enhance line chart to allow invisible lines.
- Implemented feature #10957: Embed glyphs for exact SVG font width estimation
(Patch by Freddie Witherden)
+- Implemented feature #10829: Get resource from driver
- Fixed issue #12483: Average dataset does not work with a single value.
diff --git a/src/driver/cairo.php b/src/driver/cairo.php
index b5a4b24..dc69f4d 100644
--- a/src/driver/cairo.php
+++ b/src/driver/cairo.php
@@ -974,11 +974,37 @@ class ezcGraphCairoDriver extends ezcGraphDriver
* @param string $file Destination filename
* @return void
*/
- public function render ( $file )
+ public function render( $file )
{
$this->drawAllTexts();
cairo_surface_write_to_png( $this->surface, $file );
}
+
+ /**
+ * Get resource of rendered result
+ *
+ * Return the resource of the rendered result. You should not use this
+ * method before you called either renderToOutput() or render(), as the
+ * image may not be completely rendered until then.
+ *
+ * This method returns an array, containing the surface and the context in
+ * a structure like:
+ * <code>
+ * array(
+ * 'surface' => resource,
+ * 'context' => resource,
+ * )
+ * </code>
+ *
+ * @return array
+ */
+ public function getResource()
+ {
+ return array(
+ 'surface' => $this->surface,
+ 'context' => $this->context,
+ );
+ }
}
?>
diff --git a/src/driver/flash.php b/src/driver/flash.php
index 6f10d0a..9c40ada 100644
--- a/src/driver/flash.php
+++ b/src/driver/flash.php
@@ -947,12 +947,26 @@ class ezcGraphFlashDriver extends ezcGraphDriver
* @param string $file Destination filename
* @return void
*/
- public function render ( $file )
+ public function render( $file )
{
$this->drawAllTexts();
$movie = $this->getDocument();
$movie->save( $file, $this->options->compression );
}
+
+ /**
+ * Get resource of rendered result
+ *
+ * Return the resource of the rendered result. You should not use this
+ * method before you called either renderToOutput() or render(), as the
+ * image may not be completely rendered until then.
+ *
+ * @return SWFMovie
+ */
+ public function getResource()
+ {
+ return $this->movie;
+ }
}
?>
diff --git a/src/driver/gd.php b/src/driver/gd.php
index 8755961..8f8a7f7 100644
--- a/src/driver/gd.php
+++ b/src/driver/gd.php
@@ -89,7 +89,7 @@ class ezcGraphGdDriver extends ezcGraphDriver
*
* @var array
*/
- protected $psFontRessources = array();
+ protected $psFontResources = array();
/**
* Constructor
@@ -306,12 +306,12 @@ class ezcGraphGdDriver extends ezcGraphDriver
switch ( $font->type )
{
case ezcGraph::PS_FONT:
- if ( !isset( $this->psFontRessources[$font->path] ) )
+ if ( !isset( $this->psFontResources[$font->path] ) )
{
- $this->psFontRessources[$font->path] = imagePsLoadFont( $font->path );
+ $this->psFontResources[$font->path] = imagePsLoadFont( $font->path );
}
- $boundings = imagePsBBox( $text, $this->psFontRessources[$font->path], $size );
+ $boundings = imagePsBBox( $text, $this->psFontResources[$font->path], $size );
return new ezcGraphBoundings(
$boundings[0],
$boundings[1],
@@ -377,7 +377,7 @@ class ezcGraphGdDriver extends ezcGraphDriver
imagePsText(
$image,
$text,
- $this->psFontRessources[$path],
+ $this->psFontResources[$path],
$size,
$this->allocate( $color ),
1,
@@ -1115,7 +1115,7 @@ class ezcGraphGdDriver extends ezcGraphDriver
* @param string $file Destination filename
* @return void
*/
- public function render ( $file )
+ public function render( $file )
{
$destination = imagecreatetruecolor( $this->options->width, $this->options->height );
@@ -1190,6 +1190,20 @@ class ezcGraphGdDriver extends ezcGraphDriver
throw new ezcGraphGdDriverUnsupportedImageTypeException( $this->options->imageFormat );
}
}
+
+ /**
+ * Get resource of rendered result
+ *
+ * Return the resource of the rendered result. You should not use this
+ * method before you called either renderToOutput() or render(), as the
+ * image may not be completely rendered until then.
+ *
+ * @return resource
+ */
+ public function getResource()
+ {
+ return $this->image;
+ }
}
?>
diff --git a/src/driver/svg.php b/src/driver/svg.php
index 9a814f1..84fe267 100644
--- a/src/driver/svg.php
+++ b/src/driver/svg.php
@@ -1202,7 +1202,7 @@ class ezcGraphSvgDriver extends ezcGraphDriver
* @param string $file Destination filename
* @return void
*/
- public function render ( $file )
+ public function render( $file )
{
$this->createDocument();
$this->drawAllTexts();
@@ -1211,6 +1211,20 @@ class ezcGraphSvgDriver extends ezcGraphDriver
$this->font->addFontToDocument( $this->dom );
$this->dom->save( $file );
}
+
+ /**
+ * Get resource of rendered result
+ *
+ * Return the resource of the rendered result. You should not use this
+ * method before you called either renderToOutput() or render(), as the
+ * image may not be completely rendered until then.
+ *
+ * @return DOMDocument
+ */
+ public function getResource()
+ {
+ return $this->dom;
+ }
}
?>
diff --git a/tests/driver_cairo_test.php b/tests/driver_cairo_test.php
index 854c551..2b902fc 100644
--- a/tests/driver_cairo_test.php
+++ b/tests/driver_cairo_test.php
@@ -87,6 +87,30 @@ class ezcGraphCairoDriverTest extends ezcTestImageCase
);
}
+ public function testGetResource()
+ {
+ $this->driver->drawLine(
+ new ezcGraphCoordinate( 12, 45 ),
+ new ezcGraphCoordinate( 134, 12 ),
+ ezcGraphColor::fromHex( '#3465A4' )
+ );
+
+ ob_start();
+ // Suppress header already sent warning
+ @$this->driver->renderToOutput();
+ ob_end_clean();
+
+ $resource = $this->driver->getResource();
+ $this->assertSame(
+ 'resource',
+ gettype( $resource['surface'] )
+ );
+ $this->assertSame(
+ 'resource',
+ gettype( $resource['context'] )
+ );
+ }
+
public function testDrawLine()
{
$filename = $this->tempDir . __FUNCTION__ . '.png';
diff --git a/tests/driver_flash_test.php b/tests/driver_flash_test.php
index d1e48c1..2656531 100644
--- a/tests/driver_flash_test.php
+++ b/tests/driver_flash_test.php
@@ -81,6 +81,25 @@ class ezcGraphFlashDriverTest extends ezcGraphTestCase
);
}
+ public function testGetResource()
+ {
+ $this->driver->drawLine(
+ new ezcGraphCoordinate( 12, 45 ),
+ new ezcGraphCoordinate( 134, 12 ),
+ ezcGraphColor::fromHex( '#3465A4' )
+ );
+
+ ob_start();
+ // Suppress header already sent warning
+ @$this->driver->renderToOutput();
+ ob_end_clean();
+
+ $resource = $this->driver->getResource();
+ $this->assertTrue(
+ $resource instanceof SWFMovie
+ );
+ }
+
public function testDrawPolygonThreePointsFilled()
{
$filename = $this->tempDir . __FUNCTION__ . '.swf';
diff --git a/tests/driver_gd_test.php b/tests/driver_gd_test.php
index 70a0211..e01193a 100644
--- a/tests/driver_gd_test.php
+++ b/tests/driver_gd_test.php
@@ -92,6 +92,26 @@ class ezcGraphGdDriverTest extends ezcTestImageCase
);
}
+ public function testGetResource()
+ {
+ $this->driver->drawLine(
+ new ezcGraphCoordinate( 12, 45 ),
+ new ezcGraphCoordinate( 134, 12 ),
+ ezcGraphColor::fromHex( '#3465A4' )
+ );
+
+ ob_start();
+ // Suppress header already sent warning
+ @$this->driver->renderToOutput();
+ ob_end_clean();
+
+ $resource = $this->driver->getResource();
+ $this->assertEquals(
+ 'resource',
+ gettype( $resource )
+ );
+ }
+
public function testRenderJpegToOutput() {
$filename = $this->tempDir . __FUNCTION__ . '.jpeg';
diff --git a/tests/driver_svg_test.php b/tests/driver_svg_test.php
index 11874d1..3120e50 100644
--- a/tests/driver_svg_test.php
+++ b/tests/driver_svg_test.php
@@ -83,6 +83,25 @@ class ezcGraphSvgDriverTest extends ezcGraphTestCase
);
}
+ public function testGetResource()
+ {
+ $this->driver->drawLine(
+ new ezcGraphCoordinate( 12, 45 ),
+ new ezcGraphCoordinate( 134, 12 ),
+ ezcGraphColor::fromHex( '#3465A4' )
+ );
+
+ ob_start();
+ // Suppress header already sent warning
+ @$this->driver->renderToOutput();
+ ob_end_clean();
+
+ $resource = $this->driver->getResource();
+ $this->assertTrue(
+ $resource instanceof DOMDocument
+ );
+ }
+
public function testDrawLine()
{
$filename = $this->tempDir . __FUNCTION__ . '.svg';
OpenPOWER on IntegriCloud