From 38f5bfd53c140586268394c3fce421858e7c710a Mon Sep 17 00:00:00 2001 From: Andrea Giannantonio Date: Thu, 5 Jan 2023 17:12:57 +0100 Subject: [PATCH] feat: social badge --- src/Calculator/Font/HelveticaNeue.svg | 597 ++++++++++++++++++++++ src/Calculator/Font/HelveticaNeueBold.svg | 563 ++++++++++++++++++++ src/Render/SvgSocialRender.php | 76 +++ src/Resources/templates/social.svg | 27 + src/UI/Command.php | 5 +- 5 files changed, 1267 insertions(+), 1 deletion(-) create mode 100644 src/Calculator/Font/HelveticaNeue.svg create mode 100644 src/Calculator/Font/HelveticaNeueBold.svg create mode 100644 src/Render/SvgSocialRender.php create mode 100644 src/Resources/templates/social.svg diff --git a/src/Calculator/Font/HelveticaNeue.svg b/src/Calculator/Font/HelveticaNeue.svg new file mode 100644 index 0000000..134a1d3 --- /dev/null +++ b/src/Calculator/Font/HelveticaNeue.svg @@ -0,0 +1,597 @@ + + + + +Created by FontForge 20200511 at Thu Aug 29 11:15:27 1996 + By convertio +Copyright (c) 1988, 1990 Adobe Systems Incorporated. All Rights Reserved.Helvetica is a registered trademark of Linotype AG and/or its subsidiaries. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Calculator/Font/HelveticaNeueBold.svg b/src/Calculator/Font/HelveticaNeueBold.svg new file mode 100644 index 0000000..b46e26b --- /dev/null +++ b/src/Calculator/Font/HelveticaNeueBold.svg @@ -0,0 +1,563 @@ + + + + +Created by FontForge 20200511 at Sat Sep 19 12:52:04 1998 + By convertio +Copyright (c) 1988, 1990 Adobe Systems Incorporated. All Rights Reserved.Helvetica is a registered trademark of Linotype AG and/or its subsidiaries. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Render/SvgSocialRender.php b/src/Render/SvgSocialRender.php new file mode 100644 index 0000000..c7c8f1e --- /dev/null +++ b/src/Render/SvgSocialRender.php @@ -0,0 +1,76 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace PUGX\Poser\Render; + +use PUGX\Poser\Badge; +use PUGX\Poser\Calculator\TextSizeCalculatorInterface; + +class SvgSocialRender extends LocalSvgRenderer +{ + public const VENDOR_TEXT_FONT = __DIR__ . '/../Calculator/Font/HelveticaNeue.svg'; + public const VALUE_TEXT_FONT = __DIR__ . '/../Calculator/Font/HelveticaNeueBold.svg'; + public const TEXT_FONT_SIZE = 10; + public const TEXT_FONT_COLOR = '#FFFFFF'; + public const TEXT_LETTER_SPACING = 0.1; + public const PADDING_X = 8; + public const ARROW_WIDTH = 6.5; + + 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 'social'; + } + + protected function getTemplateName(): string + { + return $this->getBadgeStyle(); + } + + protected function buildParameters(Badge $badge): array + { + $parameters = parent::buildParameters($badge); + + $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); + + $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['vendorStartPosition'] + \round(self::ARROW_WIDTH) + \round($parameters['valueWidth'] / 2); + + $parameters['vendorAndArrowWidth'] = $parameters['vendorWidth'] + self::ARROW_WIDTH; + $parameters['totalWidth'] = $parameters['vendorAndArrowWidth'] + $parameters['valueWidth']; + + return $parameters; + } +} diff --git a/src/Resources/templates/social.svg b/src/Resources/templates/social.svg new file mode 100644 index 0000000..ab13119 --- /dev/null +++ b/src/Resources/templates/social.svg @@ -0,0 +1,27 @@ + + {{ vendor }}: {{ value }} + + + + + + + + + + + + + + + + + diff --git a/src/UI/Command.php b/src/UI/Command.php index 568dc99..811ea95 100644 --- a/src/UI/Command.php +++ b/src/UI/Command.php @@ -8,6 +8,7 @@ use PUGX\Poser\Render\SvgFlatSquareRender; use PUGX\Poser\Render\SvgForTheBadgeRenderer; use PUGX\Poser\Render\SvgPlasticRender; +use PUGX\Poser\Render\SvgSocialRender; use PUGX\Poser\ValueObject\InputRequest; use Symfony\Component\Console\Command\Command as BaseCommand; use Symfony\Component\Console\Input\InputArgument; @@ -38,6 +39,7 @@ public function __construct(string $name = null) new SvgFlatRender(), new SvgFlatSquareRender(), new SvgForTheBadgeRenderer(), + new SvgSocialRender(), ]); $this->header = self::HEADER; } @@ -49,6 +51,7 @@ private function init(): void new SvgFlatRender(), new SvgFlatSquareRender(), new SvgForTheBadgeRenderer(), + new SvgSocialRender(), ]); $this->header = self::HEADER; } @@ -155,7 +158,7 @@ protected function storeImage(OutputInterface $output, string $path, string $ima } @\fclose($fp); - $output->write(\sprintf('Image created at %s', $path)); + $output->write(\sprintf('Image created at %s', $path) . \PHP_EOL); } protected function printHeaderOnce(OutputInterface $output): void