-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Allow renderer short-circuit if unable to render anything (#200)
The text renderer would previously throw in some circumstances if no font was available. With this patch, its `prepareRenderParams()` method can return `null` in these cases, aborting the render for that text element without causing a crash. This also simplifies RectRenderer, which doesn't need an "empty" state anymore.
- Loading branch information
Showing
8 changed files
with
58 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace SVG\Rasterization\Renderers; | ||
|
||
use AssertGD\GDSimilarityConstraint; | ||
use SVG\Rasterization\SVGRasterizer; | ||
|
||
/** | ||
* @requires extension gd | ||
* @covers \SVG\Rasterization\Renderers\TextRenderer | ||
* | ||
* @SuppressWarnings(PHPMD) | ||
*/ | ||
class TextRendererTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
public function testShouldNotFailWithoutRegisteredFont() | ||
{ | ||
$obj = new TextRenderer(); | ||
|
||
$context = $this->getMockForAbstractClass('\SVG\Nodes\SVGNode'); | ||
|
||
$rasterizer = new SVGRasterizer('40px', '80px', null, 4, 8); | ||
$obj->render($rasterizer, [ | ||
'x' => 10, | ||
'y' => 10, | ||
'fontFamily' => 'Roboto', | ||
'fontWeight' => 'normal', | ||
'fontStyle' => 'normal', | ||
'fontSize' => 16, | ||
'anchor' => 'middle', | ||
'text' => 'foo', | ||
], $context); | ||
$img = $rasterizer->finish(); | ||
|
||
$this->assertThat($img, new GDSimilarityConstraint('./tests/images/empty-4x8.png')); | ||
} | ||
} |