Author: Kore Nordmann Date: 2007-04-05 11:06:26 +0200 (Thu, 05 Apr 2007) New Revision: 4808
Log: - Got rotated texts working with all GD font renderers Added: trunk/Graph/tests/data/compare/ezcGraphGdDriverTest_testDrawRotatedTextWithMinimizedBorderAndBackgroundTopLeft.png trunk/Graph/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxShortNativeTTFStringRotated10Degrees.png trunk/Graph/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxShortNativeTTFStringRotated340Degrees.png trunk/Graph/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxShortNativeTTFStringRotated45Degrees.png trunk/Graph/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxShortPSStringRotated10Degrees.png trunk/Graph/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxShortPSStringRotated340Degrees.png trunk/Graph/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxShortPSStringRotated45Degrees.png trunk/Graph/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxShortStringRotated10Degrees.png trunk/Graph/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxShortStringRotated340Degrees.png trunk/Graph/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxShortStringRotated45Degrees.png Modified: trunk/Graph/src/driver/gd.php trunk/Graph/tests/driver_gd_test.php Modified: trunk/Graph/src/driver/gd.php =================================================================== --- trunk/Graph/src/driver/gd.php 2007-04-04 14:22:02 UTC (rev 4807) +++ trunk/Graph/src/driver/gd.php 2007-04-05 09:06:26 UTC (rev 4808) @@ -318,11 +318,25 @@ * @param ezcGraphColor $color Font color * @param ezcGraphCoordinate $position Position * @param float $size Textsize - * @param ezcGraphColor $color Textcolor + * @param ezcGraphRotation $rotation + * * @return void */ - protected function renderText( $image, $text, $type, $path, ezcGraphColor $color, ezcGraphCoordinate $position, $size ) + protected function renderText( $image, $text, $type, $path, ezcGraphColor $color, ezcGraphCoordinate $position, $size, ezcGraphRotation $rotation = null ) { + if ( $rotation !== null ) + { + // Rotation is relative to top left point of text and not relative + // to the bounding coordinate system + $rotation = new ezcGraphRotation( + $rotation->getRotation(), + new ezcGraphCoordinate( + $rotation->getCenter()->x - $position->x, + $rotation->getCenter()->y - $position->y + ) + ); + } + switch ( $type ) { case ezcGraph::PS_FONT: @@ -333,8 +347,14 @@ $size, $this->allocate( $color ), 1, - $position->x, - $position->y + $position->x + + ( $rotation === null ? 0 : $rotation->get( 0, 2 ) ), + $position->y + + ( $rotation === null ? 0 : $rotation->get( 1, 2 ) ), + 0, + 0, + ( $rotation === null ? 0 : -$rotation->getRotation() ), + 4 ); break; case ezcGraph::TTF_FONT: @@ -344,9 +364,11 @@ imageFtText( $image, $size, - 0, - $position->x, - $position->y, + ( $rotation === null ? 0 : -$rotation->getRotation() ), + $position->x + + ( $rotation === null ? 0 : $rotation->get( 0, 2 ) ), + $position->y + + ( $rotation === null ? 0 : $rotation->get( 1, 2 ) ), $this->allocate( $color ), $path, $text @@ -356,9 +378,11 @@ imageTtfText( $image, $size, - 0, - $position->x, - $position->y, + ( $rotation === null ? 0 : -$rotation->getRotation() ), + $position->x + + ( $rotation === null ? 0 : $rotation->get( 0, 2 ) ), + $position->y + + ( $rotation === null ? 0 : $rotation->get( 1, 2 ) ), $this->allocate( $color ), $path, $text @@ -413,6 +437,7 @@ 'height' => $height, 'align' => $align, 'font' => $this->options->font, + 'rotation' => $rotation, ); } else @@ -539,6 +564,14 @@ ); } + if ( $text['rotation'] !== null ) + { + foreach ( $borderPolygonArray as $nr => $point ) + { + $borderPolygonArray[$nr] = $text['rotation']->transformCoordinate( $point ); + } + } + if ( $text['font']->background !== false ) { $this->drawPolygon( @@ -587,6 +620,25 @@ break; } + // Calculate relative modification of rotation center point + if ( $text['rotation'] !== null ) + { + $rotation = new ezcGraphRotation( + $text['rotation']->getRotation(), + new ezcGraphCoordinate( + $text['rotation']->getCenter()->x + + $position->x - $text['position']->x, + $text['rotation']->getCenter()->y + + $position->y - $text['position']->y + ) + ); + $rotation = $text['rotation']; + } + else + { + $rotation = null; + } + // Optionally draw text shadow if ( $text['font']->textShadow === true ) { @@ -600,7 +652,8 @@ $position->x + $text['font']->textShadowOffset, $position->y + $text['font']->textShadowOffset ), - $size + $size, + $rotation ); } @@ -612,7 +665,8 @@ $text['font']->path, $text['font']->color, $position, - $size + $size, + $rotation ); $text['position']->y += $size * $this->options->lineSpacing; Added: trunk/Graph/tests/data/compare/ezcGraphGdDriverTest_testDrawRotatedTextWithMinimizedBorderAndBackgroundTopLeft.png =================================================================== (Binary files differ) Property changes on: trunk/Graph/tests/data/compare/ezcGraphGdDriverTest_testDrawRotatedTextWithMinimizedBorderAndBackgroundTopLeft.png ___________________________________________________________________ Name: svn:mime-type + image/png Added: trunk/Graph/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxShortNativeTTFStringRotated10Degrees.png =================================================================== (Binary files differ) Property changes on: trunk/Graph/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxShortNativeTTFStringRotated10Degrees.png ___________________________________________________________________ Name: svn:mime-type + image/png Added: trunk/Graph/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxShortNativeTTFStringRotated340Degrees.png =================================================================== (Binary files differ) Property changes on: trunk/Graph/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxShortNativeTTFStringRotated340Degrees.png ___________________________________________________________________ Name: svn:mime-type + image/png Added: trunk/Graph/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxShortNativeTTFStringRotated45Degrees.png =================================================================== (Binary files differ) Property changes on: trunk/Graph/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxShortNativeTTFStringRotated45Degrees.png ___________________________________________________________________ Name: svn:mime-type + image/png Added: trunk/Graph/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxShortPSStringRotated10Degrees.png =================================================================== (Binary files differ) Property changes on: trunk/Graph/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxShortPSStringRotated10Degrees.png ___________________________________________________________________ Name: svn:mime-type + image/png Added: trunk/Graph/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxShortPSStringRotated340Degrees.png =================================================================== (Binary files differ) Property changes on: trunk/Graph/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxShortPSStringRotated340Degrees.png ___________________________________________________________________ Name: svn:mime-type + image/png Added: trunk/Graph/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxShortPSStringRotated45Degrees.png =================================================================== (Binary files differ) Property changes on: trunk/Graph/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxShortPSStringRotated45Degrees.png ___________________________________________________________________ Name: svn:mime-type + image/png Added: trunk/Graph/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxShortStringRotated10Degrees.png =================================================================== (Binary files differ) Property changes on: trunk/Graph/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxShortStringRotated10Degrees.png ___________________________________________________________________ Name: svn:mime-type + image/png Added: trunk/Graph/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxShortStringRotated340Degrees.png =================================================================== (Binary files differ) Property changes on: trunk/Graph/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxShortStringRotated340Degrees.png ___________________________________________________________________ Name: svn:mime-type + image/png Added: trunk/Graph/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxShortStringRotated45Degrees.png =================================================================== (Binary files differ) Property changes on: trunk/Graph/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxShortStringRotated45Degrees.png ___________________________________________________________________ Name: svn:mime-type + image/png Modified: trunk/Graph/tests/driver_gd_test.php =================================================================== --- trunk/Graph/tests/driver_gd_test.php 2007-04-04 14:22:02 UTC (rev 4807) +++ trunk/Graph/tests/driver_gd_test.php 2007-04-05 09:06:26 UTC (rev 4808) @@ -724,6 +724,264 @@ ); } + public function testDrawTextBoxShortStringRotated10Degrees() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + + $this->driver->options->font->border = ezcGraphColor::fromHex( '#555555' ); + $this->driver->options->font->background = ezcGraphColor::fromHex( '#DDDDDD' ); + $this->driver->options->font->minimizeBorder = true; + $this->driver->options->font->padding = 2; + + $return = $this->driver->drawTextBox( + 'Short', + new ezcGraphCoordinate( 10, 10 ), + 150, + 70, + ezcGraph::LEFT, + new ezcGraphRotation( 10 ) + ); + + $this->driver->render( $filename ); + + $this->assertImageSimilar( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.png', + 'Image does not look as expected.', + 2000 + ); + } + + public function testDrawTextBoxShortPSStringRotated10Degrees() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + + $this->driver->options->font->border = ezcGraphColor::fromHex( '#555555' ); + $this->driver->options->font->background = ezcGraphColor::fromHex( '#DDDDDD' ); + $this->driver->options->font->minimizeBorder = true; + $this->driver->options->font->padding = 2; + + $return = $this->driver->drawTextBox( + 'Short', + new ezcGraphCoordinate( 10, 10 ), + 150, + 70, + ezcGraph::LEFT, + new ezcGraphRotation( 10 ) + ); + + $this->driver->options->font->path = $this->basePath . 'ps_font.pfb'; + $this->driver->render( $filename ); + + $this->assertImageSimilar( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.png', + 'Image does not look as expected.', + 2000 + ); + } + + public function testDrawTextBoxShortNativeTTFStringRotated10Degrees() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + + $this->driver->options->font->border = ezcGraphColor::fromHex( '#555555' ); + $this->driver->options->font->background = ezcGraphColor::fromHex( '#DDDDDD' ); + $this->driver->options->font->minimizeBorder = true; + $this->driver->options->font->padding = 2; + + $return = $this->driver->drawTextBox( + 'Short', + new ezcGraphCoordinate( 10, 10 ), + 150, + 70, + ezcGraph::LEFT, + new ezcGraphRotation( 10 ) + ); + + $this->driver->options->forceNativeTTF = true; + $this->driver->render( $filename ); + + $this->assertImageSimilar( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.png', + 'Image does not look as expected.', + 2000 + ); + } + + public function testDrawTextBoxShortStringRotated45Degrees() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + + $this->driver->options->font->border = ezcGraphColor::fromHex( '#555555' ); + $this->driver->options->font->background = ezcGraphColor::fromHex( '#DDDDDD' ); + $this->driver->options->font->minimizeBorder = true; + $this->driver->options->font->padding = 2; + + $return = $this->driver->drawTextBox( + 'Short', + new ezcGraphCoordinate( 10, 10 ), + 150, + 70, + ezcGraph::LEFT, + new ezcGraphRotation( 45, new ezcGraphCoordinate( 100, 50 ) ) + ); + + $this->driver->render( $filename ); + + $this->assertImageSimilar( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.png', + 'Image does not look as expected.', + 2000 + ); + } + + public function testDrawTextBoxShortPSStringRotated45Degrees() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + + $this->driver->options->font->border = ezcGraphColor::fromHex( '#555555' ); + $this->driver->options->font->background = ezcGraphColor::fromHex( '#DDDDDD' ); + $this->driver->options->font->minimizeBorder = true; + $this->driver->options->font->padding = 2; + + $return = $this->driver->drawTextBox( + 'Short', + new ezcGraphCoordinate( 10, 10 ), + 150, + 70, + ezcGraph::LEFT, + new ezcGraphRotation( 45, new ezcGraphCoordinate( 100, 50 ) ) + ); + + $this->driver->options->font->path = $this->basePath . 'ps_font.pfb'; + $this->driver->render( $filename ); + + $this->assertImageSimilar( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.png', + 'Image does not look as expected.', + 2000 + ); + } + + public function testDrawTextBoxShortNativeTTFStringRotated45Degrees() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + + $this->driver->options->font->border = ezcGraphColor::fromHex( '#555555' ); + $this->driver->options->font->background = ezcGraphColor::fromHex( '#DDDDDD' ); + $this->driver->options->font->minimizeBorder = true; + $this->driver->options->font->padding = 2; + + $return = $this->driver->drawTextBox( + 'Short', + new ezcGraphCoordinate( 10, 10 ), + 150, + 70, + ezcGraph::LEFT, + new ezcGraphRotation( 45, new ezcGraphCoordinate( 100, 50 ) ) + ); + + $this->driver->options->forceNativeTTF = true; + $this->driver->render( $filename ); + + $this->assertImageSimilar( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.png', + 'Image does not look as expected.', + 2000 + ); + } + + public function testDrawTextBoxShortStringRotated340Degrees() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + + $this->driver->options->font->border = ezcGraphColor::fromHex( '#555555' ); + $this->driver->options->font->background = ezcGraphColor::fromHex( '#DDDDDD' ); + $this->driver->options->font->minimizeBorder = true; + $this->driver->options->font->padding = 2; + + $return = $this->driver->drawTextBox( + 'Short', + new ezcGraphCoordinate( 10, 10 ), + 150, + 70, + ezcGraph::LEFT, + new ezcGraphRotation( 340, new ezcGraphCoordinate( 200, 100 ) ) + ); + + $this->driver->render( $filename ); + + $this->assertImageSimilar( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.png', + 'Image does not look as expected.', + 2000 + ); + } + + public function testDrawTextBoxShortPSStringRotated340Degrees() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + + $this->driver->options->font->border = ezcGraphColor::fromHex( '#555555' ); + $this->driver->options->font->background = ezcGraphColor::fromHex( '#DDDDDD' ); + $this->driver->options->font->minimizeBorder = true; + $this->driver->options->font->padding = 2; + + $return = $this->driver->drawTextBox( + 'Short', + new ezcGraphCoordinate( 10, 10 ), + 150, + 70, + ezcGraph::LEFT, + new ezcGraphRotation( 340, new ezcGraphCoordinate( 200, 100 ) ) + ); + + $this->driver->options->font->path = $this->basePath . 'ps_font.pfb'; + $this->driver->render( $filename ); + + $this->assertImageSimilar( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.png', + 'Image does not look as expected.', + 2000 + ); + } + + public function testDrawTextBoxShortNativeTTFStringRotated340Degrees() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + + $this->driver->options->font->border = ezcGraphColor::fromHex( '#555555' ); + $this->driver->options->font->background = ezcGraphColor::fromHex( '#DDDDDD' ); + $this->driver->options->font->minimizeBorder = true; + $this->driver->options->font->padding = 2; + + $return = $this->driver->drawTextBox( + 'Short', + new ezcGraphCoordinate( 10, 10 ), + 150, + 70, + ezcGraph::LEFT, + new ezcGraphRotation( 340, new ezcGraphCoordinate( 200, 100 ) ) + ); + + $this->driver->options->forceNativeTTF = true; + $this->driver->render( $filename ); + + $this->assertImageSimilar( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.png', + 'Image does not look as expected.', + 2000 + ); + } + public function testDrawTextBoxLongString() { $filename = $this->tempDir . __FUNCTION__ . '.png'; @@ -1865,6 +2123,34 @@ ); } + public function testDrawRotatedTextWithMinimizedBorderAndBackgroundTopLeft() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + + $this->driver->options->font->border = ezcGraphColor::fromHex( '#555555' ); + $this->driver->options->font->background = ezcGraphColor::fromHex( '#DDDDDD' ); + $this->driver->options->font->minimizeBorder = true; + $this->driver->options->font->padding = 2; + + $this->driver->drawTextBox( + 'Some test string', + new ezcGraphCoordinate( 10, 10 ), + 150, + 70, + ezcGraph::LEFT | ezcGraph::TOP, + new ezcGraphRotation( 15 ) + ); + + $this->driver->render( $filename ); + + $this->assertImageSimilar( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.png', + 'Image does not look as expected.', + 2000 + ); + } + public function testDrawTextWithMinimizedBorderAndBackgroundMiddleCenter() { $filename = $this->tempDir . __FUNCTION__ . '.png'; -- svn-components mailing list svn-components@lists.ez.no http://lists.ez.no/mailman/listinfo/svn-components