Skip to content

Commit

Permalink
fixed svgFlatRenderer
Browse files Browse the repository at this point in the history
  • Loading branch information
liuggio committed Apr 20, 2015
1 parent f4aa2a2 commit 577f80c
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private function __construct($content, $format)
*/
public function __toString()
{
return $this->content;
return (string) $this->content;
}

/**
Expand All @@ -66,4 +66,5 @@ public function getFormat()
{
return $this->format;
}

}
54 changes: 53 additions & 1 deletion src/Render/SvgFlatRender.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class SvgFlatRender implements RenderInterface
{
const VENDOR_COLOR = '#555';
private $textSizeCalculator;

/*
private static $template = <<<EOF
<svg xmlns="http://www.w3.org/2000/svg" width="{{ totalWidth }}" height="20">
<linearGradient id="b" x2="0" y2="100%">
Expand All @@ -48,6 +48,58 @@ class SvgFlatRender implements RenderInterface
</svg>
EOF;
quasi ok
ù private static $template = <<<EOF
<svg xmlns="http://www.w3.org/2000/svg" width="{{ totalWidth }}" height="20">
<linearGradient id="smooth" x2="0" y2="100%">
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
<stop offset="1" stop-opacity=".1"/>
</linearGradient>
<mask id="round">
<rect width="{{ totalWidth }}" height="20" rx="3" fill="{{ vendorColor }}"/>
</mask>
<g mask="url(#round)">
<rect width="{{ vendorWidth }}" height="20" fill="#fff"/>
<rect x="{{ vendorWidth }}" width="{{ valueWidth }}" height="20" fill="{{ valueColor }}"/>
<rect width="{{ totalWidth }}" height="20" fill="url(#smooth)"/>
</g>
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
<text x="{{ vendorStartPosition }}" y="15" fill="#010101" fill-opacity=".3">{{ vendor }}</text>
<text x="{{ vendorStartPosition }}" y="14">{{ vendor }}</text>
<text x="{{ valueStartPosition }}" y="15" fill="#010101" fill-opacity=".3">{{ value }}</text>
<text x="{{ valueStartPosition }}" y="14">{{ value }}</text>
</g>
</svg>
EOF;
*/

private static $template = <<<EOF
<svg xmlns="http://www.w3.org/2000/svg" width="{{ totalWidth }}" height="20">
<linearGradient id="b" x2="0" y2="100%">
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
<stop offset="1" stop-opacity=".1"/>
</linearGradient>
<mask id="a">
<rect width="{{ totalWidth }}" height="20" rx="3" fill="#fff"/>
</mask>
<g mask="url(#a)">
<rect width="{{ vendorWidth }}" height="20" fill="#555"/>
<rect x="{{ vendorWidth }}" width="{{ valueWidth }}" height="20" fill="{{ valueColor }}"/>
<rect width="{{ totalWidth }}" height="20" fill="url(#b)"/>
</g>
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
<text x="{{ vendorStartPosition }}" y="15" fill="#010101" fill-opacity=".3">{{ vendor }}</text>
<text x="{{ vendorStartPosition }}" y="14">{{ vendor }}</text>
<text x="{{ valueStartPosition }}" y="15" fill="#010101" fill-opacity=".3">{{ value }}</text>
<text x="{{ valueStartPosition }}" y="14">{{ value }}</text>
</g>
</svg>
EOF;

/**
* Constructor.
*
Expand Down
10 changes: 7 additions & 3 deletions src/UI/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,18 @@ protected function execute(InputInterface $input, OutputInterface $output)

protected function flushImage(InputInterface $input, OutputInterface $output, $imageContent)
{
$output->write($imageContent);
$output->write((string) $imageContent);
$this->header = '';
}

protected function storeImage(InputInterface $input, OutputInterface $output, $path, $imageContent)
{
$this->printHeaderOnce($output);
$fp = fopen($path,"x"); // if file already exists warning is raised
try {
$fp = @fopen($path, "x");
} catch (\Exception $e) {
$fp = false;
}

if (false == $fp) {
throw new \Exception("Error on creating the file maybe file [$path] already exists?");
Expand All @@ -112,7 +116,7 @@ protected function storeImage(InputInterface $input, OutputInterface $output, $p
if ($written <1 || $written != strlen($imageContent)) {
throw new \Exception('Error on writing to file.');
}
fclose($fp);
@fclose($fp);

$output->write(sprintf('Image created at %s', $path));
}
Expand Down

0 comments on commit 577f80c

Please sign in to comment.