summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2007-12-18 20:08:00 +0000
committerKore Nordmann <github@kore-nordmann.de>2007-12-18 20:08:00 +0000
commita55d1470ea82f1edbef879e5b83dda530c3428b5 (patch)
tree2a90c6a8cc5e198c1771bcc507dad9935e002dab
parent8f5e0af2d66d1b73d841486b7c4f587967ec4152 (diff)
downloadzetacomponents-graph-a55d1470ea82f1edbef879e5b83dda530c3428b5.zip
zetacomponents-graph-a55d1470ea82f1edbef879e5b83dda530c3428b5.tar.gz
- Completed cairo driver
-rw-r--r--src/driver/cairo.php32
-rw-r--r--tests/data/compare/ezcGraphCairoDriverTest_testDrawTextBoxShortStringRotated340Degrees.pngbin0 -> 7281 bytes
-rw-r--r--tests/data/compare/ezcGraphCairoDriverTest_testDrawTextBoxShortStringRotated45Degrees.pngbin0 -> 4482 bytes
-rw-r--r--tests/suite.php2
4 files changed, 25 insertions, 9 deletions
diff --git a/src/driver/cairo.php b/src/driver/cairo.php
index 94263e9..f507bf5 100644
--- a/src/driver/cairo.php
+++ b/src/driver/cairo.php
@@ -377,24 +377,35 @@ class ezcGraphCairoDriver extends ezcGraphDriver
// Store current state of context
cairo_save( $this->context );
-
+ cairo_move_to( $this->context, 0, 0 );
if ( $rotation !== null )
{
- cairo_rotate( $this->context, deg2rad( $rotation->getRotation() ) );
- cairo_move_to( $this->context,
- $position->x + $rotation->get( 0, 1 ),
- $position->y + $rotation->get( 0, 2 ) - $size * .15
+ // Move to the center
+ cairo_translate( $this->context,
+ $rotation->getCenter()->x,
+ $rotation->getCenter()->y
+ );
+ // Rotate around text center
+ cairo_rotate( $this->context,
+ deg2rad( $rotation->getRotation() )
+ );
+ // Center the text
+ cairo_translate( $this->context,
+ $position->x - $rotation->getCenter()->x,
+ $position->y - $rotation->getCenter()->y - $size * .15
);
} else {
- cairo_move_to( $this->context,
+ cairo_translate( $this->context,
$position->x,
$position->y - $size * .15
);
}
+ cairo_new_path( $this->context );
$this->getStyle( $color, true );
cairo_show_text( $this->context, $text );
+ cairo_stroke( $this->context );
// Restore state of context
cairo_restore( $this->context );
@@ -419,6 +430,8 @@ class ezcGraphCairoDriver extends ezcGraphDriver
*/
protected function drawAllTexts()
{
+ $this->initiliazeSurface();
+
foreach ( $this->strings as $text )
{
$size = $text['font']->minimalUsedFont;
@@ -457,15 +470,16 @@ class ezcGraphCairoDriver extends ezcGraphDriver
switch ( true )
{
- case ( $text['align'] & ezcGraph::LEFT ):
- $xOffset = 0;
- break;
case ( $text['align'] & ezcGraph::CENTER ):
$xOffset = ( $text['width'] - $width ) / 2;
break;
case ( $text['align'] & ezcGraph::RIGHT ):
$xOffset = $text['width'] - $width;
break;
+ case ( $text['align'] & ezcGraph::LEFT ):
+ default:
+ $xOffset = 0;
+ break;
}
$borderPolygonArray = array(
diff --git a/tests/data/compare/ezcGraphCairoDriverTest_testDrawTextBoxShortStringRotated340Degrees.png b/tests/data/compare/ezcGraphCairoDriverTest_testDrawTextBoxShortStringRotated340Degrees.png
new file mode 100644
index 0000000..8e460c4
--- /dev/null
+++ b/tests/data/compare/ezcGraphCairoDriverTest_testDrawTextBoxShortStringRotated340Degrees.png
Binary files differ
diff --git a/tests/data/compare/ezcGraphCairoDriverTest_testDrawTextBoxShortStringRotated45Degrees.png b/tests/data/compare/ezcGraphCairoDriverTest_testDrawTextBoxShortStringRotated45Degrees.png
new file mode 100644
index 0000000..cdaa79a
--- /dev/null
+++ b/tests/data/compare/ezcGraphCairoDriverTest_testDrawTextBoxShortStringRotated45Degrees.png
Binary files differ
diff --git a/tests/suite.php b/tests/suite.php
index e7efa91..40df038 100644
--- a/tests/suite.php
+++ b/tests/suite.php
@@ -25,6 +25,7 @@ require_once 'dataset_test.php';
require_once 'date_axis_test.php';
require_once 'driver_flash_test.php';
require_once 'driver_gd_test.php';
+require_once 'driver_cairo_test.php';
require_once 'driver_options_test.php';
require_once 'driver_svg_test.php';
require_once 'element_options_test.php';
@@ -79,6 +80,7 @@ class ezcGraphSuite extends PHPUnit_Framework_TestSuite
$this->addTest( ezcGraphFlashDriverTest::suite() );
$this->addTest( ezcGraphFontTest::suite() );
$this->addTest( ezcGraphGdDriverTest::suite() );
+ $this->addTest( ezcGraphCairoDriverTest::suite() );
$this->addTest( ezcGraphImageMapTest::suite() );
$this->addTest( ezcGraphLabeledAxisTest::suite() );
$this->addTest( ezcGraphLegendTest::suite() );
OpenPOWER on IntegriCloud