diff options
author | Kore Nordmann <github@kore-nordmann.de> | 2006-09-06 09:34:53 +0000 |
---|---|---|
committer | Kore Nordmann <github@kore-nordmann.de> | 2006-09-06 09:34:53 +0000 |
commit | b7b8d6da07309da4e16397f662a4e2db46c0869a (patch) | |
tree | a76a982bef0844f6d3d0eeb7089a7e8a5dfb2ee0 /tests | |
parent | 4e50ab6291dc2430ef9ce4cc42c100c021e1a3b0 (diff) | |
download | zetacomponents-graph-b7b8d6da07309da4e16397f662a4e2db46c0869a.zip zetacomponents-graph-b7b8d6da07309da4e16397f662a4e2db46c0869a.tar.gz |
- Enhanced font configuration
- Use Free Type 2 by default now, fallback to native ttf, if not available
- Use t1lib for PostScript Type1 fonts
- Throw an exception, if some texts could not be rendered with minimum font
size
Diffstat (limited to 'tests')
17 files changed, 226 insertions, 2 deletions
diff --git a/tests/data/compare/ezcGraphGdDriverTest_testDrawFreeTypeTTFText.png b/tests/data/compare/ezcGraphGdDriverTest_testDrawFreeTypeTTFText.png Binary files differnew file mode 100644 index 0000000..65b89f5 --- /dev/null +++ b/tests/data/compare/ezcGraphGdDriverTest_testDrawFreeTypeTTFText.png diff --git a/tests/data/compare/ezcGraphGdDriverTest_testDrawNativeTTFText.png b/tests/data/compare/ezcGraphGdDriverTest_testDrawNativeTTFText.png Binary files differnew file mode 100644 index 0000000..65b89f5 --- /dev/null +++ b/tests/data/compare/ezcGraphGdDriverTest_testDrawNativeTTFText.png diff --git a/tests/data/compare/ezcGraphGdDriverTest_testDrawPSText.png b/tests/data/compare/ezcGraphGdDriverTest_testDrawPSText.png Binary files differnew file mode 100644 index 0000000..85f9755 --- /dev/null +++ b/tests/data/compare/ezcGraphGdDriverTest_testDrawPSText.png diff --git a/tests/data/compare/ezcGraphGdDriverTest_testDrawSmallFreeTypeStringWithSpecialChars.png b/tests/data/compare/ezcGraphGdDriverTest_testDrawSmallFreeTypeStringWithSpecialChars.png Binary files differnew file mode 100644 index 0000000..66a593a --- /dev/null +++ b/tests/data/compare/ezcGraphGdDriverTest_testDrawSmallFreeTypeStringWithSpecialChars.png diff --git a/tests/data/compare/ezcGraphGdDriverTest_testDrawSmallNativeTTFStringWithSpecialChars.png b/tests/data/compare/ezcGraphGdDriverTest_testDrawSmallNativeTTFStringWithSpecialChars.png Binary files differnew file mode 100644 index 0000000..66a593a --- /dev/null +++ b/tests/data/compare/ezcGraphGdDriverTest_testDrawSmallNativeTTFStringWithSpecialChars.png diff --git a/tests/data/compare/ezcGraphGdDriverTest_testDrawSmallPsStringWithSpecialChars.png b/tests/data/compare/ezcGraphGdDriverTest_testDrawSmallPsStringWithSpecialChars.png Binary files differnew file mode 100644 index 0000000..81fc503 --- /dev/null +++ b/tests/data/compare/ezcGraphGdDriverTest_testDrawSmallPsStringWithSpecialChars.png diff --git a/tests/data/compare/ezcGraphGdDriverTest_testDrawStringWithSpecialChars.png b/tests/data/compare/ezcGraphGdDriverTest_testDrawStringWithSpecialChars.png Binary files differdeleted file mode 100644 index 41847bd..0000000 --- a/tests/data/compare/ezcGraphGdDriverTest_testDrawStringWithSpecialChars.png +++ /dev/null diff --git a/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxLongSpacedStringCenter.png b/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxLongSpacedStringCenter.png Binary files differindex 597c6ca..a53a6f7 100644 --- a/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxLongSpacedStringCenter.png +++ b/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxLongSpacedStringCenter.png diff --git a/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxLongSpacedStringCenterBottom.png b/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxLongSpacedStringCenterBottom.png Binary files differindex 9946a1e..288594b 100644 --- a/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxLongSpacedStringCenterBottom.png +++ b/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxLongSpacedStringCenterBottom.png diff --git a/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxLongSpacedStringRight.png b/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxLongSpacedStringRight.png Binary files differindex 96ba490..424d3cd 100644 --- a/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxLongSpacedStringRight.png +++ b/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxLongSpacedStringRight.png diff --git a/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxLongSpacedStringRightMiddle.png b/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxLongSpacedStringRightMiddle.png Binary files differindex 8bb1c2c..f823653 100644 --- a/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxLongSpacedStringRightMiddle.png +++ b/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxLongSpacedStringRightMiddle.png diff --git a/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxStringRight.png b/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxStringRight.png Binary files differindex 392c830..86882e7 100644 --- a/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxStringRight.png +++ b/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxStringRight.png diff --git a/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxStringRightBottom.png b/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxStringRightBottom.png Binary files differindex a304be2..9c1590e 100644 --- a/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxStringRightBottom.png +++ b/tests/data/compare/ezcGraphGdDriverTest_testDrawTextBoxStringRightBottom.png diff --git a/tests/data/compare/ezcGraphGdDriverTest_testSupersamplingDrawTextBoxShortString.png b/tests/data/compare/ezcGraphGdDriverTest_testSupersamplingDrawTextBoxShortString.png Binary files differindex 89d772b..0ebd2ba 100644 --- a/tests/data/compare/ezcGraphGdDriverTest_testSupersamplingDrawTextBoxShortString.png +++ b/tests/data/compare/ezcGraphGdDriverTest_testSupersamplingDrawTextBoxShortString.png diff --git a/tests/data/ps_font.pfb b/tests/data/ps_font.pfb Binary files differnew file mode 100644 index 0000000..130fac0 --- /dev/null +++ b/tests/data/ps_font.pfb diff --git a/tests/driver_gd_test.php b/tests/driver_gd_test.php index 30c4f22..0be109c 100644 --- a/tests/driver_gd_test.php +++ b/tests/driver_gd_test.php @@ -1271,10 +1271,47 @@ class ezcGraphGdDriverTest extends ezcImageTestCase ); } - public function testDrawStringWithSpecialChars() + public function testDrawSmallNativeTTFStringWithSpecialChars() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + $this->driver->options->forceNativeTTF = true; + + $this->driver->drawPolygon( + array( + new ezcGraphCoordinate( 47, 54 ), + new ezcGraphCoordinate( 47, 84 ), + new ezcGraphCoordinate( 99, 84 ), + new ezcGraphCoordinate( 99, 54 ), + ), + ezcGraphColor::fromHex( '#DDDDDD' ), + true + ); + $this->driver->drawTextBox( + 'Safari (13.8%)', + new ezcGraphCoordinate( 47, 54 ), + 52, + 30, + ezcGraph::LEFT + ); + + $this->driver->render( $filename ); + + $this->assertTrue( + file_exists( $filename ), + 'No image was generated.' + ); + + $this->assertImageSimilar( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.png', + 'Image does not look as expected.', + 10 + ); + } + + public function testDrawSmallFreeTypeStringWithSpecialChars() { $filename = $this->tempDir . __FUNCTION__ . '.png'; - $this->driver->options->supersampling = 2; $this->driver->drawPolygon( array( @@ -1305,9 +1342,156 @@ class ezcGraphGdDriverTest extends ezcImageTestCase $filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.png', 'Image does not look as expected.', + 10 + ); + } + + public function testDrawSmallPsStringWithSpecialChars() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + $this->driver->options->font->path = $this->basePath . 'ps_font.pfb'; + + $this->driver->drawPolygon( + array( + new ezcGraphCoordinate( 47, 54 ), + new ezcGraphCoordinate( 47, 84 ), + new ezcGraphCoordinate( 99, 84 ), + new ezcGraphCoordinate( 99, 54 ), + ), + ezcGraphColor::fromHex( '#DDDDDD' ), + true + ); + $this->driver->drawTextBox( + 'Safari (13.8%)', + new ezcGraphCoordinate( 47, 54 ), + 52, + 30, + ezcGraph::LEFT + ); + + $this->driver->render( $filename ); + + $this->assertTrue( + file_exists( $filename ), + 'No image was generated.' + ); + + $this->assertImageSimilar( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.png', + 'Image does not look as expected.', + 10 + ); + } + + public function testDrawNativeTTFText() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + $this->driver->options->font->path = $this->basePath . 'font.ttf'; + $this->driver->options->forceNativeTTF = true; + + $this->driver->drawTextBox( + 'Fontfiletest', + new ezcGraphCoordinate( 10, 10 ), + 150, + 70, + ezcGraph::LEFT + ); + + $this->driver->render( $filename ); + + $this->assertTrue( + file_exists( $filename ), + 'No image was generated.' + ); + + $this->assertImageSimilar( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.png', + 'Image does not look as expected.', + 2000 + ); + } + + public function testDrawFreeTypeTTFText() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + $this->driver->options->font->path = $this->basePath . 'font.ttf'; + + $this->driver->drawTextBox( + 'Fontfiletest', + new ezcGraphCoordinate( 10, 10 ), + 150, + 70, + ezcGraph::LEFT + ); + + $this->driver->render( $filename ); + + $this->assertTrue( + file_exists( $filename ), + 'No image was generated.' + ); + + $this->assertImageSimilar( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.png', + 'Image does not look as expected.', 2000 ); } + + public function testDrawPSText() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + $this->driver->options->font->path = $this->basePath . 'ps_font.pfb'; + + $this->driver->drawTextBox( + 'Fontfiletest', + new ezcGraphCoordinate( 10, 10 ), + 150, + 70, + ezcGraph::LEFT + ); + + $this->driver->render( $filename ); + + $this->assertTrue( + file_exists( $filename ), + 'No image was generated.' + ); + + $this->assertImageSimilar( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.png', + 'Image does not look as expected.', + 2000 + ); + } + + 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.' ); + } } ?> diff --git a/tests/font_test.php b/tests/font_test.php index 3e6ee6d..00a13df 100644 --- a/tests/font_test.php +++ b/tests/font_test.php @@ -145,6 +145,46 @@ class ezcGraphFontTest extends ezcTestCase 'Font face for legend has not changed.' ); } + + public function testTTFFontType() + { + $chart = new ezcGraphLineChart(); + $chart->options->font->path = $this->basePath . 'font.ttf'; + + $this->assertSame( + $chart->options->font->type, + ezcGraph::TTF_FONT, + 'Font type is not TTF.' + ); + } + + public function testPSFontType() + { + $chart = new ezcGraphLineChart(); + $chart->options->font->path = $this->basePath . 'ps_font.pfb'; + + $this->assertSame( + $chart->options->font->type, + ezcGraph::PS_FONT, + 'Font type is not TTF.' + ); + } + + public function testUnknownFontType() + { + $chart = new ezcGraphLineChart(); + + try + { + $chart->options->font->path = $this->basePath . 'ez.png'; + } + catch ( ezcGraphUnknownFontTypeException $e ) + { + return true; + } + + $this->fail( 'Expected ezcGraphUnknownFontTypeException.' ); + } } ?> |