-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from ricardoboss/master
Added SvgForTheBadgeRenderer
- Loading branch information
Showing
8 changed files
with
24,816 additions
and
15 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,78 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the badge-poser package. | ||
* | ||
* (c) PUGX <http://pugx.github.io/> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace PUGX\Poser\Render; | ||
|
||
use EasySVG; | ||
use PUGX\Poser\Badge; | ||
use PUGX\Poser\Calculator\TextSizeCalculatorInterface; | ||
|
||
class SvgForTheBadgeRenderer extends LocalSvgRenderer | ||
{ | ||
public const VENDOR_TEXT_FONT = __DIR__ . '/../Calculator/Font/Verdana.svg'; | ||
public const VALUE_TEXT_FONT = __DIR__ . '/../Calculator/Font/Verdana-Bold.svg'; | ||
public const TEXT_FONT_SIZE = 10; | ||
public const TEXT_FONT_COLOR = '#FFFFFF'; | ||
public const TEXT_LETTER_SPACING = 0.1; | ||
public const PADDING_X = 10; | ||
|
||
private EasySVG $easy; | ||
|
||
public function __construct( | ||
?EasySVG $easySVG = null, | ||
?TextSizeCalculatorInterface $textSizeCalculator = null, | ||
?string $templatesDirectory = null | ||
) { | ||
parent::__construct($textSizeCalculator, $templatesDirectory); | ||
|
||
if (null === $easySVG) { | ||
$easySVG = new EasySVG(); | ||
} | ||
|
||
$this->easy = $easySVG; | ||
} | ||
|
||
public function getBadgeStyle(): string | ||
{ | ||
return 'for-the-badge'; | ||
} | ||
|
||
protected function getTemplateName(): string | ||
{ | ||
return $this->getBadgeStyle(); | ||
} | ||
|
||
protected function buildParameters(Badge $badge): array | ||
{ | ||
$parameters = parent::buildParameters($badge); | ||
|
||
$parameters['vendor'] = \mb_strtoupper($parameters['vendor']); | ||
$parameters['value'] = \mb_strtoupper($parameters['value']); | ||
|
||
$this->easy->clearSVG(); | ||
$this->easy->setLetterSpacing(self::TEXT_LETTER_SPACING); | ||
$this->easy->setFont(self::VENDOR_TEXT_FONT, self::TEXT_FONT_SIZE, self::TEXT_FONT_COLOR); | ||
$vendorDimensions = $this->easy->textDimensions($parameters['vendor']); | ||
$parameters['vendorWidth'] = $vendorDimensions[0] + 2 * self::PADDING_X; | ||
$parameters['vendorStartPosition'] = \round($parameters['vendorWidth'] / 2, 1) + 1; | ||
|
||
$this->easy->clearSVG(); | ||
$this->easy->setLetterSpacing(self::TEXT_LETTER_SPACING); | ||
$this->easy->setFont(self::VALUE_TEXT_FONT, self::TEXT_FONT_SIZE, self::TEXT_FONT_COLOR); | ||
$valueDimensions = $this->easy->textDimensions($parameters['value']); | ||
$parameters['valueWidth'] = $valueDimensions[0] + 2 * self::PADDING_X; | ||
$parameters['valueStartPosition'] = $parameters['vendorWidth'] + \round($parameters['valueWidth'] / 2, 1) - 1; | ||
|
||
$parameters['totalWidth'] = $parameters['valueWidth'] + $parameters['vendorWidth']; | ||
|
||
return $parameters; | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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