Initial commit
This commit is contained in:
57
pma/vendor/bacon/bacon-qr-code/src/Renderer/Color/Alpha.php
vendored
Normal file
57
pma/vendor/bacon/bacon-qr-code/src/Renderer/Color/Alpha.php
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\Color;
|
||||
|
||||
use BaconQrCode\Exception;
|
||||
|
||||
final class Alpha implements ColorInterface
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $alpha;
|
||||
|
||||
/**
|
||||
* @var ColorInterface
|
||||
*/
|
||||
private $baseColor;
|
||||
|
||||
/**
|
||||
* @param int $alpha the alpha value, 0 to 100
|
||||
*/
|
||||
public function __construct(int $alpha, ColorInterface $baseColor)
|
||||
{
|
||||
if ($alpha < 0 || $alpha > 100) {
|
||||
throw new Exception\InvalidArgumentException('Alpha must be between 0 and 100');
|
||||
}
|
||||
|
||||
$this->alpha = $alpha;
|
||||
$this->baseColor = $baseColor;
|
||||
}
|
||||
|
||||
public function getAlpha() : int
|
||||
{
|
||||
return $this->alpha;
|
||||
}
|
||||
|
||||
public function getBaseColor() : ColorInterface
|
||||
{
|
||||
return $this->baseColor;
|
||||
}
|
||||
|
||||
public function toRgb() : Rgb
|
||||
{
|
||||
return $this->baseColor->toRgb();
|
||||
}
|
||||
|
||||
public function toCmyk() : Cmyk
|
||||
{
|
||||
return $this->baseColor->toCmyk();
|
||||
}
|
||||
|
||||
public function toGray() : Gray
|
||||
{
|
||||
return $this->baseColor->toGray();
|
||||
}
|
||||
}
|
||||
103
pma/vendor/bacon/bacon-qr-code/src/Renderer/Color/Cmyk.php
vendored
Normal file
103
pma/vendor/bacon/bacon-qr-code/src/Renderer/Color/Cmyk.php
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\Color;
|
||||
|
||||
use BaconQrCode\Exception;
|
||||
|
||||
final class Cmyk implements ColorInterface
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $cyan;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $magenta;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $yellow;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $black;
|
||||
|
||||
/**
|
||||
* @param int $cyan the cyan amount, 0 to 100
|
||||
* @param int $magenta the magenta amount, 0 to 100
|
||||
* @param int $yellow the yellow amount, 0 to 100
|
||||
* @param int $black the black amount, 0 to 100
|
||||
*/
|
||||
public function __construct(int $cyan, int $magenta, int $yellow, int $black)
|
||||
{
|
||||
if ($cyan < 0 || $cyan > 100) {
|
||||
throw new Exception\InvalidArgumentException('Cyan must be between 0 and 100');
|
||||
}
|
||||
|
||||
if ($magenta < 0 || $magenta > 100) {
|
||||
throw new Exception\InvalidArgumentException('Magenta must be between 0 and 100');
|
||||
}
|
||||
|
||||
if ($yellow < 0 || $yellow > 100) {
|
||||
throw new Exception\InvalidArgumentException('Yellow must be between 0 and 100');
|
||||
}
|
||||
|
||||
if ($black < 0 || $black > 100) {
|
||||
throw new Exception\InvalidArgumentException('Black must be between 0 and 100');
|
||||
}
|
||||
|
||||
$this->cyan = $cyan;
|
||||
$this->magenta = $magenta;
|
||||
$this->yellow = $yellow;
|
||||
$this->black = $black;
|
||||
}
|
||||
|
||||
public function getCyan() : int
|
||||
{
|
||||
return $this->cyan;
|
||||
}
|
||||
|
||||
public function getMagenta() : int
|
||||
{
|
||||
return $this->magenta;
|
||||
}
|
||||
|
||||
public function getYellow() : int
|
||||
{
|
||||
return $this->yellow;
|
||||
}
|
||||
|
||||
public function getBlack() : int
|
||||
{
|
||||
return $this->black;
|
||||
}
|
||||
|
||||
public function toRgb() : Rgb
|
||||
{
|
||||
$k = $this->black / 100;
|
||||
$c = (-$k * $this->cyan + $k * 100 + $this->cyan) / 100;
|
||||
$m = (-$k * $this->magenta + $k * 100 + $this->magenta) / 100;
|
||||
$y = (-$k * $this->yellow + $k * 100 + $this->yellow) / 100;
|
||||
|
||||
return new Rgb(
|
||||
(int) (-$c * 255 + 255),
|
||||
(int) (-$m * 255 + 255),
|
||||
(int) (-$y * 255 + 255)
|
||||
);
|
||||
}
|
||||
|
||||
public function toCmyk() : Cmyk
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function toGray() : Gray
|
||||
{
|
||||
return $this->toRgb()->toGray();
|
||||
}
|
||||
}
|
||||
22
pma/vendor/bacon/bacon-qr-code/src/Renderer/Color/ColorInterface.php
vendored
Normal file
22
pma/vendor/bacon/bacon-qr-code/src/Renderer/Color/ColorInterface.php
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\Color;
|
||||
|
||||
interface ColorInterface
|
||||
{
|
||||
/**
|
||||
* Converts the color to RGB.
|
||||
*/
|
||||
public function toRgb() : Rgb;
|
||||
|
||||
/**
|
||||
* Converts the color to CMYK.
|
||||
*/
|
||||
public function toCmyk() : Cmyk;
|
||||
|
||||
/**
|
||||
* Converts the color to gray.
|
||||
*/
|
||||
public function toGray() : Gray;
|
||||
}
|
||||
46
pma/vendor/bacon/bacon-qr-code/src/Renderer/Color/Gray.php
vendored
Normal file
46
pma/vendor/bacon/bacon-qr-code/src/Renderer/Color/Gray.php
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\Color;
|
||||
|
||||
use BaconQrCode\Exception;
|
||||
|
||||
final class Gray implements ColorInterface
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $gray;
|
||||
|
||||
/**
|
||||
* @param int $gray the gray value between 0 (black) and 100 (white)
|
||||
*/
|
||||
public function __construct(int $gray)
|
||||
{
|
||||
if ($gray < 0 || $gray > 100) {
|
||||
throw new Exception\InvalidArgumentException('Gray must be between 0 and 100');
|
||||
}
|
||||
|
||||
$this->gray = (int) $gray;
|
||||
}
|
||||
|
||||
public function getGray() : int
|
||||
{
|
||||
return $this->gray;
|
||||
}
|
||||
|
||||
public function toRgb() : Rgb
|
||||
{
|
||||
return new Rgb((int) ($this->gray * 2.55), (int) ($this->gray * 2.55), (int) ($this->gray * 2.55));
|
||||
}
|
||||
|
||||
public function toCmyk() : Cmyk
|
||||
{
|
||||
return new Cmyk(0, 0, 0, 100 - $this->gray);
|
||||
}
|
||||
|
||||
public function toGray() : Gray
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
88
pma/vendor/bacon/bacon-qr-code/src/Renderer/Color/Rgb.php
vendored
Normal file
88
pma/vendor/bacon/bacon-qr-code/src/Renderer/Color/Rgb.php
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\Color;
|
||||
|
||||
use BaconQrCode\Exception;
|
||||
|
||||
final class Rgb implements ColorInterface
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $red;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $green;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $blue;
|
||||
|
||||
/**
|
||||
* @param int $red the red amount of the color, 0 to 255
|
||||
* @param int $green the green amount of the color, 0 to 255
|
||||
* @param int $blue the blue amount of the color, 0 to 255
|
||||
*/
|
||||
public function __construct(int $red, int $green, int $blue)
|
||||
{
|
||||
if ($red < 0 || $red > 255) {
|
||||
throw new Exception\InvalidArgumentException('Red must be between 0 and 255');
|
||||
}
|
||||
|
||||
if ($green < 0 || $green > 255) {
|
||||
throw new Exception\InvalidArgumentException('Green must be between 0 and 255');
|
||||
}
|
||||
|
||||
if ($blue < 0 || $blue > 255) {
|
||||
throw new Exception\InvalidArgumentException('Blue must be between 0 and 255');
|
||||
}
|
||||
|
||||
$this->red = $red;
|
||||
$this->green = $green;
|
||||
$this->blue = $blue;
|
||||
}
|
||||
|
||||
public function getRed() : int
|
||||
{
|
||||
return $this->red;
|
||||
}
|
||||
|
||||
public function getGreen() : int
|
||||
{
|
||||
return $this->green;
|
||||
}
|
||||
|
||||
public function getBlue() : int
|
||||
{
|
||||
return $this->blue;
|
||||
}
|
||||
|
||||
public function toRgb() : Rgb
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function toCmyk() : Cmyk
|
||||
{
|
||||
$c = 1 - ($this->red / 255);
|
||||
$m = 1 - ($this->green / 255);
|
||||
$y = 1 - ($this->blue / 255);
|
||||
$k = min($c, $m, $y);
|
||||
|
||||
return new Cmyk(
|
||||
(int) (100 * ($c - $k) / (1 - $k)),
|
||||
(int) (100 * ($m - $k) / (1 - $k)),
|
||||
(int) (100 * ($y - $k) / (1 - $k)),
|
||||
(int) (100 * $k)
|
||||
);
|
||||
}
|
||||
|
||||
public function toGray() : Gray
|
||||
{
|
||||
return new Gray((int) (($this->red * 0.21 + $this->green * 0.71 + $this->blue * 0.07) / 2.55));
|
||||
}
|
||||
}
|
||||
38
pma/vendor/bacon/bacon-qr-code/src/Renderer/Eye/CompositeEye.php
vendored
Normal file
38
pma/vendor/bacon/bacon-qr-code/src/Renderer/Eye/CompositeEye.php
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\Eye;
|
||||
|
||||
use BaconQrCode\Renderer\Path\Path;
|
||||
|
||||
/**
|
||||
* Combines the style of two different eyes.
|
||||
*/
|
||||
final class CompositeEye implements EyeInterface
|
||||
{
|
||||
/**
|
||||
* @var EyeInterface
|
||||
*/
|
||||
private $externalEye;
|
||||
|
||||
/**
|
||||
* @var EyeInterface
|
||||
*/
|
||||
private $internalEye;
|
||||
|
||||
public function __construct(EyeInterface $externalEye, EyeInterface $internalEye)
|
||||
{
|
||||
$this->externalEye = $externalEye;
|
||||
$this->internalEye = $internalEye;
|
||||
}
|
||||
|
||||
public function getExternalPath() : Path
|
||||
{
|
||||
return $this->externalEye->getExternalPath();
|
||||
}
|
||||
|
||||
public function getInternalPath() : Path
|
||||
{
|
||||
return $this->externalEye->getInternalPath();
|
||||
}
|
||||
}
|
||||
26
pma/vendor/bacon/bacon-qr-code/src/Renderer/Eye/EyeInterface.php
vendored
Normal file
26
pma/vendor/bacon/bacon-qr-code/src/Renderer/Eye/EyeInterface.php
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\Eye;
|
||||
|
||||
use BaconQrCode\Renderer\Path\Path;
|
||||
|
||||
/**
|
||||
* Interface for describing the look of an eye.
|
||||
*/
|
||||
interface EyeInterface
|
||||
{
|
||||
/**
|
||||
* Returns the path of the external eye element.
|
||||
*
|
||||
* The path origin point (0, 0) must be anchored at the middle of the path.
|
||||
*/
|
||||
public function getExternalPath() : Path;
|
||||
|
||||
/**
|
||||
* Returns the path of the internal eye element.
|
||||
*
|
||||
* The path origin point (0, 0) must be anchored at the middle of the path.
|
||||
*/
|
||||
public function getInternalPath() : Path;
|
||||
}
|
||||
54
pma/vendor/bacon/bacon-qr-code/src/Renderer/Eye/ModuleEye.php
vendored
Normal file
54
pma/vendor/bacon/bacon-qr-code/src/Renderer/Eye/ModuleEye.php
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\Eye;
|
||||
|
||||
use BaconQrCode\Encoder\ByteMatrix;
|
||||
use BaconQrCode\Renderer\Module\ModuleInterface;
|
||||
use BaconQrCode\Renderer\Path\Path;
|
||||
|
||||
/**
|
||||
* Renders an eye based on a module renderer.
|
||||
*/
|
||||
final class ModuleEye implements EyeInterface
|
||||
{
|
||||
/**
|
||||
* @var ModuleInterface
|
||||
*/
|
||||
private $module;
|
||||
|
||||
public function __construct(ModuleInterface $module)
|
||||
{
|
||||
$this->module = $module;
|
||||
}
|
||||
|
||||
public function getExternalPath() : Path
|
||||
{
|
||||
$matrix = new ByteMatrix(7, 7);
|
||||
|
||||
for ($x = 0; $x < 7; ++$x) {
|
||||
$matrix->set($x, 0, 1);
|
||||
$matrix->set($x, 6, 1);
|
||||
}
|
||||
|
||||
for ($y = 1; $y < 6; ++$y) {
|
||||
$matrix->set(0, $y, 1);
|
||||
$matrix->set(6, $y, 1);
|
||||
}
|
||||
|
||||
return $this->module->createPath($matrix)->translate(-3.5, -3.5);
|
||||
}
|
||||
|
||||
public function getInternalPath() : Path
|
||||
{
|
||||
$matrix = new ByteMatrix(3, 3);
|
||||
|
||||
for ($x = 0; $x < 3; ++$x) {
|
||||
for ($y = 0; $y < 3; ++$y) {
|
||||
$matrix->set($x, $y, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->module->createPath($matrix)->translate(-1.5, -1.5);
|
||||
}
|
||||
}
|
||||
54
pma/vendor/bacon/bacon-qr-code/src/Renderer/Eye/SimpleCircleEye.php
vendored
Normal file
54
pma/vendor/bacon/bacon-qr-code/src/Renderer/Eye/SimpleCircleEye.php
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\Eye;
|
||||
|
||||
use BaconQrCode\Renderer\Path\Path;
|
||||
|
||||
/**
|
||||
* Renders the inner eye as a circle.
|
||||
*/
|
||||
final class SimpleCircleEye implements EyeInterface
|
||||
{
|
||||
/**
|
||||
* @var self|null
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public static function instance() : self
|
||||
{
|
||||
return self::$instance ?: self::$instance = new self();
|
||||
}
|
||||
|
||||
public function getExternalPath() : Path
|
||||
{
|
||||
return (new Path())
|
||||
->move(-3.5, -3.5)
|
||||
->line(3.5, -3.5)
|
||||
->line(3.5, 3.5)
|
||||
->line(-3.5, 3.5)
|
||||
->close()
|
||||
->move(-2.5, -2.5)
|
||||
->line(-2.5, 2.5)
|
||||
->line(2.5, 2.5)
|
||||
->line(2.5, -2.5)
|
||||
->close()
|
||||
;
|
||||
}
|
||||
|
||||
public function getInternalPath() : Path
|
||||
{
|
||||
return (new Path())
|
||||
->move(1.5, 0)
|
||||
->ellipticArc(1.5, 1.5, 0., false, true, 0., 1.5)
|
||||
->ellipticArc(1.5, 1.5, 0., false, true, -1.5, 0.)
|
||||
->ellipticArc(1.5, 1.5, 0., false, true, 0., -1.5)
|
||||
->ellipticArc(1.5, 1.5, 0., false, true, 1.5, 0.)
|
||||
->close()
|
||||
;
|
||||
}
|
||||
}
|
||||
53
pma/vendor/bacon/bacon-qr-code/src/Renderer/Eye/SquareEye.php
vendored
Normal file
53
pma/vendor/bacon/bacon-qr-code/src/Renderer/Eye/SquareEye.php
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\Eye;
|
||||
|
||||
use BaconQrCode\Renderer\Path\Path;
|
||||
|
||||
/**
|
||||
* Renders the eyes in their default square shape.
|
||||
*/
|
||||
final class SquareEye implements EyeInterface
|
||||
{
|
||||
/**
|
||||
* @var self|null
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public static function instance() : self
|
||||
{
|
||||
return self::$instance ?: self::$instance = new self();
|
||||
}
|
||||
|
||||
public function getExternalPath() : Path
|
||||
{
|
||||
return (new Path())
|
||||
->move(-3.5, -3.5)
|
||||
->line(3.5, -3.5)
|
||||
->line(3.5, 3.5)
|
||||
->line(-3.5, 3.5)
|
||||
->close()
|
||||
->move(-2.5, -2.5)
|
||||
->line(-2.5, 2.5)
|
||||
->line(2.5, 2.5)
|
||||
->line(2.5, -2.5)
|
||||
->close()
|
||||
;
|
||||
}
|
||||
|
||||
public function getInternalPath() : Path
|
||||
{
|
||||
return (new Path())
|
||||
->move(-1.5, -1.5)
|
||||
->line(1.5, -1.5)
|
||||
->line(1.5, 1.5)
|
||||
->line(-1.5, 1.5)
|
||||
->close()
|
||||
;
|
||||
}
|
||||
}
|
||||
376
pma/vendor/bacon/bacon-qr-code/src/Renderer/Image/EpsImageBackEnd.php
vendored
Normal file
376
pma/vendor/bacon/bacon-qr-code/src/Renderer/Image/EpsImageBackEnd.php
vendored
Normal file
@@ -0,0 +1,376 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\Image;
|
||||
|
||||
use BaconQrCode\Exception\RuntimeException;
|
||||
use BaconQrCode\Renderer\Color\Alpha;
|
||||
use BaconQrCode\Renderer\Color\Cmyk;
|
||||
use BaconQrCode\Renderer\Color\ColorInterface;
|
||||
use BaconQrCode\Renderer\Color\Gray;
|
||||
use BaconQrCode\Renderer\Color\Rgb;
|
||||
use BaconQrCode\Renderer\Path\Close;
|
||||
use BaconQrCode\Renderer\Path\Curve;
|
||||
use BaconQrCode\Renderer\Path\EllipticArc;
|
||||
use BaconQrCode\Renderer\Path\Line;
|
||||
use BaconQrCode\Renderer\Path\Move;
|
||||
use BaconQrCode\Renderer\Path\Path;
|
||||
use BaconQrCode\Renderer\RendererStyle\Gradient;
|
||||
use BaconQrCode\Renderer\RendererStyle\GradientType;
|
||||
|
||||
final class EpsImageBackEnd implements ImageBackEndInterface
|
||||
{
|
||||
private const PRECISION = 3;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $eps;
|
||||
|
||||
public function new(int $size, ColorInterface $backgroundColor) : void
|
||||
{
|
||||
$this->eps = "%!PS-Adobe-3.0 EPSF-3.0\n"
|
||||
. "%%Creator: BaconQrCode\n"
|
||||
. sprintf("%%%%BoundingBox: 0 0 %d %d \n", $size, $size)
|
||||
. "%%BeginProlog\n"
|
||||
. "save\n"
|
||||
. "50 dict begin\n"
|
||||
. "/q { gsave } bind def\n"
|
||||
. "/Q { grestore } bind def\n"
|
||||
. "/s { scale } bind def\n"
|
||||
. "/t { translate } bind def\n"
|
||||
. "/r { rotate } bind def\n"
|
||||
. "/n { newpath } bind def\n"
|
||||
. "/m { moveto } bind def\n"
|
||||
. "/l { lineto } bind def\n"
|
||||
. "/c { curveto } bind def\n"
|
||||
. "/z { closepath } bind def\n"
|
||||
. "/f { eofill } bind def\n"
|
||||
. "/rgb { setrgbcolor } bind def\n"
|
||||
. "/cmyk { setcmykcolor } bind def\n"
|
||||
. "/gray { setgray } bind def\n"
|
||||
. "%%EndProlog\n"
|
||||
. "1 -1 s\n"
|
||||
. sprintf("0 -%d t\n", $size);
|
||||
|
||||
if ($backgroundColor instanceof Alpha && 0 === $backgroundColor->getAlpha()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->eps .= wordwrap(
|
||||
'0 0 m'
|
||||
. sprintf(' %s 0 l', (string) $size)
|
||||
. sprintf(' %s %s l', (string) $size, (string) $size)
|
||||
. sprintf(' 0 %s l', (string) $size)
|
||||
. ' z'
|
||||
. ' ' .$this->getColorSetString($backgroundColor) . " f\n",
|
||||
75,
|
||||
"\n "
|
||||
);
|
||||
}
|
||||
|
||||
public function scale(float $size) : void
|
||||
{
|
||||
if (null === $this->eps) {
|
||||
throw new RuntimeException('No image has been started');
|
||||
}
|
||||
|
||||
$this->eps .= sprintf("%1\$s %1\$s s\n", round($size, self::PRECISION));
|
||||
}
|
||||
|
||||
public function translate(float $x, float $y) : void
|
||||
{
|
||||
if (null === $this->eps) {
|
||||
throw new RuntimeException('No image has been started');
|
||||
}
|
||||
|
||||
$this->eps .= sprintf("%s %s t\n", round($x, self::PRECISION), round($y, self::PRECISION));
|
||||
}
|
||||
|
||||
public function rotate(int $degrees) : void
|
||||
{
|
||||
if (null === $this->eps) {
|
||||
throw new RuntimeException('No image has been started');
|
||||
}
|
||||
|
||||
$this->eps .= sprintf("%d r\n", $degrees);
|
||||
}
|
||||
|
||||
public function push() : void
|
||||
{
|
||||
if (null === $this->eps) {
|
||||
throw new RuntimeException('No image has been started');
|
||||
}
|
||||
|
||||
$this->eps .= "q\n";
|
||||
}
|
||||
|
||||
public function pop() : void
|
||||
{
|
||||
if (null === $this->eps) {
|
||||
throw new RuntimeException('No image has been started');
|
||||
}
|
||||
|
||||
$this->eps .= "Q\n";
|
||||
}
|
||||
|
||||
public function drawPathWithColor(Path $path, ColorInterface $color) : void
|
||||
{
|
||||
if (null === $this->eps) {
|
||||
throw new RuntimeException('No image has been started');
|
||||
}
|
||||
|
||||
$fromX = 0;
|
||||
$fromY = 0;
|
||||
$this->eps .= wordwrap(
|
||||
'n '
|
||||
. $this->drawPathOperations($path, $fromX, $fromY)
|
||||
. ' ' . $this->getColorSetString($color) . " f\n",
|
||||
75,
|
||||
"\n "
|
||||
);
|
||||
}
|
||||
|
||||
public function drawPathWithGradient(
|
||||
Path $path,
|
||||
Gradient $gradient,
|
||||
float $x,
|
||||
float $y,
|
||||
float $width,
|
||||
float $height
|
||||
) : void {
|
||||
if (null === $this->eps) {
|
||||
throw new RuntimeException('No image has been started');
|
||||
}
|
||||
|
||||
$fromX = 0;
|
||||
$fromY = 0;
|
||||
$this->eps .= wordwrap(
|
||||
'q n ' . $this->drawPathOperations($path, $fromX, $fromY) . "\n",
|
||||
75,
|
||||
"\n "
|
||||
);
|
||||
|
||||
$this->createGradientFill($gradient, $x, $y, $width, $height);
|
||||
}
|
||||
|
||||
public function done() : string
|
||||
{
|
||||
if (null === $this->eps) {
|
||||
throw new RuntimeException('No image has been started');
|
||||
}
|
||||
|
||||
$this->eps .= "%%TRAILER\nend restore\n%%EOF";
|
||||
$blob = $this->eps;
|
||||
$this->eps = null;
|
||||
|
||||
return $blob;
|
||||
}
|
||||
|
||||
private function drawPathOperations(Iterable $ops, &$fromX, &$fromY) : string
|
||||
{
|
||||
$pathData = [];
|
||||
|
||||
foreach ($ops as $op) {
|
||||
switch (true) {
|
||||
case $op instanceof Move:
|
||||
$fromX = $toX = round($op->getX(), self::PRECISION);
|
||||
$fromY = $toY = round($op->getY(), self::PRECISION);
|
||||
$pathData[] = sprintf('%s %s m', $toX, $toY);
|
||||
break;
|
||||
|
||||
case $op instanceof Line:
|
||||
$fromX = $toX = round($op->getX(), self::PRECISION);
|
||||
$fromY = $toY = round($op->getY(), self::PRECISION);
|
||||
$pathData[] = sprintf('%s %s l', $toX, $toY);
|
||||
break;
|
||||
|
||||
case $op instanceof EllipticArc:
|
||||
$pathData[] = $this->drawPathOperations($op->toCurves($fromX, $fromY), $fromX, $fromY);
|
||||
break;
|
||||
|
||||
case $op instanceof Curve:
|
||||
$x1 = round($op->getX1(), self::PRECISION);
|
||||
$y1 = round($op->getY1(), self::PRECISION);
|
||||
$x2 = round($op->getX2(), self::PRECISION);
|
||||
$y2 = round($op->getY2(), self::PRECISION);
|
||||
$fromX = $x3 = round($op->getX3(), self::PRECISION);
|
||||
$fromY = $y3 = round($op->getY3(), self::PRECISION);
|
||||
$pathData[] = sprintf('%s %s %s %s %s %s c', $x1, $y1, $x2, $y2, $x3, $y3);
|
||||
break;
|
||||
|
||||
case $op instanceof Close:
|
||||
$pathData[] = 'z';
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new RuntimeException('Unexpected draw operation: ' . get_class($op));
|
||||
}
|
||||
}
|
||||
|
||||
return implode(' ', $pathData);
|
||||
}
|
||||
|
||||
private function createGradientFill(Gradient $gradient, float $x, float $y, float $width, float $height) : void
|
||||
{
|
||||
$startColor = $gradient->getStartColor();
|
||||
$endColor = $gradient->getEndColor();
|
||||
|
||||
if ($startColor instanceof Alpha) {
|
||||
$startColor = $startColor->getBaseColor();
|
||||
}
|
||||
|
||||
$startColorType = get_class($startColor);
|
||||
|
||||
if (! in_array($startColorType, [Rgb::class, Cmyk::class, Gray::class])) {
|
||||
$startColorType = Cmyk::class;
|
||||
$startColor = $startColor->toCmyk();
|
||||
}
|
||||
|
||||
if (get_class($endColor) !== $startColorType) {
|
||||
switch ($startColorType) {
|
||||
case Cmyk::class:
|
||||
$endColor = $endColor->toCmyk();
|
||||
break;
|
||||
|
||||
case Rgb::class:
|
||||
$endColor = $endColor->toRgb();
|
||||
break;
|
||||
|
||||
case Gray::class:
|
||||
$endColor = $endColor->toGray();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->eps .= "eoclip\n<<\n";
|
||||
|
||||
if ($gradient->getType() === GradientType::RADIAL()) {
|
||||
$this->eps .= " /ShadingType 3\n";
|
||||
} else {
|
||||
$this->eps .= " /ShadingType 2\n";
|
||||
}
|
||||
|
||||
$this->eps .= " /Extend [ true true ]\n"
|
||||
. " /AntiAlias true\n";
|
||||
|
||||
switch ($startColorType) {
|
||||
case Cmyk::class:
|
||||
$this->eps .= " /ColorSpace /DeviceCMYK\n";
|
||||
break;
|
||||
|
||||
case Rgb::class:
|
||||
$this->eps .= " /ColorSpace /DeviceRGB\n";
|
||||
break;
|
||||
|
||||
case Gray::class:
|
||||
$this->eps .= " /ColorSpace /DeviceGray\n";
|
||||
break;
|
||||
}
|
||||
|
||||
switch ($gradient->getType()) {
|
||||
case GradientType::HORIZONTAL():
|
||||
$this->eps .= sprintf(
|
||||
" /Coords [ %s %s %s %s ]\n",
|
||||
round($x, self::PRECISION),
|
||||
round($y, self::PRECISION),
|
||||
round($x + $width, self::PRECISION),
|
||||
round($y, self::PRECISION)
|
||||
);
|
||||
break;
|
||||
|
||||
case GradientType::VERTICAL():
|
||||
$this->eps .= sprintf(
|
||||
" /Coords [ %s %s %s %s ]\n",
|
||||
round($x, self::PRECISION),
|
||||
round($y, self::PRECISION),
|
||||
round($x, self::PRECISION),
|
||||
round($y + $height, self::PRECISION)
|
||||
);
|
||||
break;
|
||||
|
||||
case GradientType::DIAGONAL():
|
||||
$this->eps .= sprintf(
|
||||
" /Coords [ %s %s %s %s ]\n",
|
||||
round($x, self::PRECISION),
|
||||
round($y, self::PRECISION),
|
||||
round($x + $width, self::PRECISION),
|
||||
round($y + $height, self::PRECISION)
|
||||
);
|
||||
break;
|
||||
|
||||
case GradientType::INVERSE_DIAGONAL():
|
||||
$this->eps .= sprintf(
|
||||
" /Coords [ %s %s %s %s ]\n",
|
||||
round($x, self::PRECISION),
|
||||
round($y + $height, self::PRECISION),
|
||||
round($x + $width, self::PRECISION),
|
||||
round($y, self::PRECISION)
|
||||
);
|
||||
break;
|
||||
|
||||
case GradientType::RADIAL():
|
||||
$centerX = ($x + $width) / 2;
|
||||
$centerY = ($y + $height) / 2;
|
||||
|
||||
$this->eps .= sprintf(
|
||||
" /Coords [ %s %s 0 %s %s %s ]\n",
|
||||
round($centerX, self::PRECISION),
|
||||
round($centerY, self::PRECISION),
|
||||
round($centerX, self::PRECISION),
|
||||
round($centerY, self::PRECISION),
|
||||
round(max($width, $height) / 2, self::PRECISION)
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
$this->eps .= " /Function\n"
|
||||
. " <<\n"
|
||||
. " /FunctionType 2\n"
|
||||
. " /Domain [ 0 1 ]\n"
|
||||
. sprintf(" /C0 [ %s ]\n", $this->getColorString($startColor))
|
||||
. sprintf(" /C1 [ %s ]\n", $this->getColorString($endColor))
|
||||
. " /N 1\n"
|
||||
. " >>\n>>\nshfill\nQ\n";
|
||||
}
|
||||
|
||||
private function getColorSetString(ColorInterface $color) : string
|
||||
{
|
||||
if ($color instanceof Rgb) {
|
||||
return $this->getColorString($color) . ' rgb';
|
||||
}
|
||||
|
||||
if ($color instanceof Cmyk) {
|
||||
return $this->getColorString($color) . ' cmyk';
|
||||
}
|
||||
|
||||
if ($color instanceof Gray) {
|
||||
return $this->getColorString($color) . ' gray';
|
||||
}
|
||||
|
||||
return $this->getColorSetString($color->toCmyk());
|
||||
}
|
||||
|
||||
private function getColorString(ColorInterface $color) : string
|
||||
{
|
||||
if ($color instanceof Rgb) {
|
||||
return sprintf('%s %s %s', $color->getRed() / 255, $color->getGreen() / 255, $color->getBlue() / 255);
|
||||
}
|
||||
|
||||
if ($color instanceof Cmyk) {
|
||||
return sprintf(
|
||||
'%s %s %s %s',
|
||||
$color->getCyan() / 100,
|
||||
$color->getMagenta() / 100,
|
||||
$color->getYellow() / 100,
|
||||
$color->getBlack() / 100
|
||||
);
|
||||
}
|
||||
|
||||
if ($color instanceof Gray) {
|
||||
return sprintf('%s', $color->getGray() / 100);
|
||||
}
|
||||
|
||||
return $this->getColorString($color->toCmyk());
|
||||
}
|
||||
}
|
||||
87
pma/vendor/bacon/bacon-qr-code/src/Renderer/Image/ImageBackEndInterface.php
vendored
Normal file
87
pma/vendor/bacon/bacon-qr-code/src/Renderer/Image/ImageBackEndInterface.php
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\Image;
|
||||
|
||||
use BaconQrCode\Exception\RuntimeException;
|
||||
use BaconQrCode\Renderer\Color\ColorInterface;
|
||||
use BaconQrCode\Renderer\Path\Path;
|
||||
use BaconQrCode\Renderer\RendererStyle\Gradient;
|
||||
|
||||
/**
|
||||
* Interface for back ends able to to produce path based images.
|
||||
*/
|
||||
interface ImageBackEndInterface
|
||||
{
|
||||
/**
|
||||
* Starts a new image.
|
||||
*
|
||||
* If a previous image was already started, previous data get erased.
|
||||
*/
|
||||
public function new(int $size, ColorInterface $backgroundColor) : void;
|
||||
|
||||
/**
|
||||
* Transforms all following drawing operation coordinates by scaling them by a given factor.
|
||||
*
|
||||
* @throws RuntimeException if no image was started yet.
|
||||
*/
|
||||
public function scale(float $size) : void;
|
||||
|
||||
/**
|
||||
* Transforms all following drawing operation coordinates by translating them by a given amount.
|
||||
*
|
||||
* @throws RuntimeException if no image was started yet.
|
||||
*/
|
||||
public function translate(float $x, float $y) : void;
|
||||
|
||||
/**
|
||||
* Transforms all following drawing operation coordinates by rotating them by a given amount.
|
||||
*
|
||||
* @throws RuntimeException if no image was started yet.
|
||||
*/
|
||||
public function rotate(int $degrees) : void;
|
||||
|
||||
/**
|
||||
* Pushes the current coordinate transformation onto a stack.
|
||||
*
|
||||
* @throws RuntimeException if no image was started yet.
|
||||
*/
|
||||
public function push() : void;
|
||||
|
||||
/**
|
||||
* Pops the last coordinate transformation from a stack.
|
||||
*
|
||||
* @throws RuntimeException if no image was started yet.
|
||||
*/
|
||||
public function pop() : void;
|
||||
|
||||
/**
|
||||
* Draws a path with a given color.
|
||||
*
|
||||
* @throws RuntimeException if no image was started yet.
|
||||
*/
|
||||
public function drawPathWithColor(Path $path, ColorInterface $color) : void;
|
||||
|
||||
/**
|
||||
* Draws a path with a given gradient which spans the box described by the position and size.
|
||||
*
|
||||
* @throws RuntimeException if no image was started yet.
|
||||
*/
|
||||
public function drawPathWithGradient(
|
||||
Path $path,
|
||||
Gradient $gradient,
|
||||
float $x,
|
||||
float $y,
|
||||
float $width,
|
||||
float $height
|
||||
) : void;
|
||||
|
||||
/**
|
||||
* Ends the image drawing operation and returns the resulting blob.
|
||||
*
|
||||
* This should reset the state of the back end and thus this method should only be callable once per image.
|
||||
*
|
||||
* @throws RuntimeException if no image was started yet.
|
||||
*/
|
||||
public function done() : string;
|
||||
}
|
||||
339
pma/vendor/bacon/bacon-qr-code/src/Renderer/Image/ImagickImageBackEnd.php
vendored
Normal file
339
pma/vendor/bacon/bacon-qr-code/src/Renderer/Image/ImagickImageBackEnd.php
vendored
Normal file
@@ -0,0 +1,339 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\Image;
|
||||
|
||||
use BaconQrCode\Exception\RuntimeException;
|
||||
use BaconQrCode\Renderer\Color\Alpha;
|
||||
use BaconQrCode\Renderer\Color\Cmyk;
|
||||
use BaconQrCode\Renderer\Color\ColorInterface;
|
||||
use BaconQrCode\Renderer\Color\Gray;
|
||||
use BaconQrCode\Renderer\Color\Rgb;
|
||||
use BaconQrCode\Renderer\Path\Close;
|
||||
use BaconQrCode\Renderer\Path\Curve;
|
||||
use BaconQrCode\Renderer\Path\EllipticArc;
|
||||
use BaconQrCode\Renderer\Path\Line;
|
||||
use BaconQrCode\Renderer\Path\Move;
|
||||
use BaconQrCode\Renderer\Path\Path;
|
||||
use BaconQrCode\Renderer\RendererStyle\Gradient;
|
||||
use BaconQrCode\Renderer\RendererStyle\GradientType;
|
||||
use Imagick;
|
||||
use ImagickDraw;
|
||||
use ImagickPixel;
|
||||
|
||||
final class ImagickImageBackEnd implements ImageBackEndInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $imageFormat;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $compressionQuality;
|
||||
|
||||
/**
|
||||
* @var Imagick|null
|
||||
*/
|
||||
private $image;
|
||||
|
||||
/**
|
||||
* @var ImagickDraw|null
|
||||
*/
|
||||
private $draw;
|
||||
|
||||
/**
|
||||
* @var int|null
|
||||
*/
|
||||
private $gradientCount;
|
||||
|
||||
/**
|
||||
* @var TransformationMatrix[]|null
|
||||
*/
|
||||
private $matrices;
|
||||
|
||||
/**
|
||||
* @var int|null
|
||||
*/
|
||||
private $matrixIndex;
|
||||
|
||||
public function __construct(string $imageFormat = 'png', int $compressionQuality = 100)
|
||||
{
|
||||
if (! class_exists(Imagick::class)) {
|
||||
throw new RuntimeException('You need to install the imagick extension to use this back end');
|
||||
}
|
||||
|
||||
$this->imageFormat = $imageFormat;
|
||||
$this->compressionQuality = $compressionQuality;
|
||||
}
|
||||
|
||||
public function new(int $size, ColorInterface $backgroundColor) : void
|
||||
{
|
||||
$this->image = new Imagick();
|
||||
$this->image->newImage($size, $size, $this->getColorPixel($backgroundColor));
|
||||
$this->image->setImageFormat($this->imageFormat);
|
||||
$this->image->setCompressionQuality($this->compressionQuality);
|
||||
$this->draw = new ImagickDraw();
|
||||
$this->gradientCount = 0;
|
||||
$this->matrices = [new TransformationMatrix()];
|
||||
$this->matrixIndex = 0;
|
||||
}
|
||||
|
||||
public function scale(float $size) : void
|
||||
{
|
||||
if (null === $this->draw) {
|
||||
throw new RuntimeException('No image has been started');
|
||||
}
|
||||
|
||||
$this->draw->scale($size, $size);
|
||||
$this->matrices[$this->matrixIndex] = $this->matrices[$this->matrixIndex]
|
||||
->multiply(TransformationMatrix::scale($size));
|
||||
}
|
||||
|
||||
public function translate(float $x, float $y) : void
|
||||
{
|
||||
if (null === $this->draw) {
|
||||
throw new RuntimeException('No image has been started');
|
||||
}
|
||||
|
||||
$this->draw->translate($x, $y);
|
||||
$this->matrices[$this->matrixIndex] = $this->matrices[$this->matrixIndex]
|
||||
->multiply(TransformationMatrix::translate($x, $y));
|
||||
}
|
||||
|
||||
public function rotate(int $degrees) : void
|
||||
{
|
||||
if (null === $this->draw) {
|
||||
throw new RuntimeException('No image has been started');
|
||||
}
|
||||
|
||||
$this->draw->rotate($degrees);
|
||||
$this->matrices[$this->matrixIndex] = $this->matrices[$this->matrixIndex]
|
||||
->multiply(TransformationMatrix::rotate($degrees));
|
||||
}
|
||||
|
||||
public function push() : void
|
||||
{
|
||||
if (null === $this->draw) {
|
||||
throw new RuntimeException('No image has been started');
|
||||
}
|
||||
|
||||
$this->draw->push();
|
||||
$this->matrices[++$this->matrixIndex] = $this->matrices[$this->matrixIndex - 1];
|
||||
}
|
||||
|
||||
public function pop() : void
|
||||
{
|
||||
if (null === $this->draw) {
|
||||
throw new RuntimeException('No image has been started');
|
||||
}
|
||||
|
||||
$this->draw->pop();
|
||||
unset($this->matrices[$this->matrixIndex--]);
|
||||
}
|
||||
|
||||
public function drawPathWithColor(Path $path, ColorInterface $color) : void
|
||||
{
|
||||
if (null === $this->draw) {
|
||||
throw new RuntimeException('No image has been started');
|
||||
}
|
||||
|
||||
$this->draw->setFillColor($this->getColorPixel($color));
|
||||
$this->drawPath($path);
|
||||
}
|
||||
|
||||
public function drawPathWithGradient(
|
||||
Path $path,
|
||||
Gradient $gradient,
|
||||
float $x,
|
||||
float $y,
|
||||
float $width,
|
||||
float $height
|
||||
) : void {
|
||||
if (null === $this->draw) {
|
||||
throw new RuntimeException('No image has been started');
|
||||
}
|
||||
|
||||
$this->draw->setFillPatternURL('#' . $this->createGradientFill($gradient, $x, $y, $width, $height));
|
||||
$this->drawPath($path);
|
||||
}
|
||||
|
||||
public function done() : string
|
||||
{
|
||||
if (null === $this->draw) {
|
||||
throw new RuntimeException('No image has been started');
|
||||
}
|
||||
|
||||
$this->image->drawImage($this->draw);
|
||||
$blob = $this->image->getImageBlob();
|
||||
$this->draw->clear();
|
||||
$this->image->clear();
|
||||
$this->draw = null;
|
||||
$this->image = null;
|
||||
$this->gradientCount = null;
|
||||
|
||||
return $blob;
|
||||
}
|
||||
|
||||
private function drawPath(Path $path) : void
|
||||
{
|
||||
$this->draw->pathStart();
|
||||
|
||||
foreach ($path as $op) {
|
||||
switch (true) {
|
||||
case $op instanceof Move:
|
||||
$this->draw->pathMoveToAbsolute($op->getX(), $op->getY());
|
||||
break;
|
||||
|
||||
case $op instanceof Line:
|
||||
$this->draw->pathLineToAbsolute($op->getX(), $op->getY());
|
||||
break;
|
||||
|
||||
case $op instanceof EllipticArc:
|
||||
$this->draw->pathEllipticArcAbsolute(
|
||||
$op->getXRadius(),
|
||||
$op->getYRadius(),
|
||||
$op->getXAxisAngle(),
|
||||
$op->isLargeArc(),
|
||||
$op->isSweep(),
|
||||
$op->getX(),
|
||||
$op->getY()
|
||||
);
|
||||
break;
|
||||
|
||||
case $op instanceof Curve:
|
||||
$this->draw->pathCurveToAbsolute(
|
||||
$op->getX1(),
|
||||
$op->getY1(),
|
||||
$op->getX2(),
|
||||
$op->getY2(),
|
||||
$op->getX3(),
|
||||
$op->getY3()
|
||||
);
|
||||
break;
|
||||
|
||||
case $op instanceof Close:
|
||||
$this->draw->pathClose();
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new RuntimeException('Unexpected draw operation: ' . get_class($op));
|
||||
}
|
||||
}
|
||||
|
||||
$this->draw->pathFinish();
|
||||
}
|
||||
|
||||
private function createGradientFill(Gradient $gradient, float $x, float $y, float $width, float $height) : string
|
||||
{
|
||||
list($width, $height) = $this->matrices[$this->matrixIndex]->apply($x + $width, $y + $height);
|
||||
list($x, $y) = $this->matrices[$this->matrixIndex]->apply($x, $y);
|
||||
$width -= $x;
|
||||
$height -= $y;
|
||||
|
||||
$startColor = $this->getColorPixel($gradient->getStartColor())->getColorAsString();
|
||||
$endColor = $this->getColorPixel($gradient->getEndColor())->getColorAsString();
|
||||
$gradientImage = new Imagick();
|
||||
|
||||
switch ($gradient->getType()) {
|
||||
case GradientType::HORIZONTAL():
|
||||
$gradientImage->newPseudoImage((int) $height, (int) $width, sprintf(
|
||||
'gradient:%s-%s',
|
||||
$startColor,
|
||||
$endColor
|
||||
));
|
||||
$gradientImage->rotateImage('transparent', -90);
|
||||
break;
|
||||
|
||||
case GradientType::VERTICAL():
|
||||
$gradientImage->newPseudoImage((int) $width, (int) $height, sprintf(
|
||||
'gradient:%s-%s',
|
||||
$startColor,
|
||||
$endColor
|
||||
));
|
||||
break;
|
||||
|
||||
case GradientType::DIAGONAL():
|
||||
case GradientType::INVERSE_DIAGONAL():
|
||||
$gradientImage->newPseudoImage((int) ($width * sqrt(2)), (int) ($height * sqrt(2)), sprintf(
|
||||
'gradient:%s-%s',
|
||||
$startColor,
|
||||
$endColor
|
||||
));
|
||||
|
||||
if (GradientType::DIAGONAL() === $gradient->getType()) {
|
||||
$gradientImage->rotateImage('transparent', -45);
|
||||
} else {
|
||||
$gradientImage->rotateImage('transparent', -135);
|
||||
}
|
||||
|
||||
$rotatedWidth = $gradientImage->getImageWidth();
|
||||
$rotatedHeight = $gradientImage->getImageHeight();
|
||||
|
||||
$gradientImage->setImagePage($rotatedWidth, $rotatedHeight, 0, 0);
|
||||
$gradientImage->cropImage(
|
||||
intdiv($rotatedWidth, 2) - 2,
|
||||
intdiv($rotatedHeight, 2) - 2,
|
||||
intdiv($rotatedWidth, 4) + 1,
|
||||
intdiv($rotatedWidth, 4) + 1
|
||||
);
|
||||
break;
|
||||
|
||||
case GradientType::RADIAL():
|
||||
$gradientImage->newPseudoImage((int) $width, (int) $height, sprintf(
|
||||
'radial-gradient:%s-%s',
|
||||
$startColor,
|
||||
$endColor
|
||||
));
|
||||
break;
|
||||
}
|
||||
|
||||
$id = sprintf('g%d', ++$this->gradientCount);
|
||||
$this->draw->pushPattern($id, 0, 0, $x + $width, $y + $height);
|
||||
$this->draw->composite(Imagick::COMPOSITE_COPY, $x, $y, $width, $height, $gradientImage);
|
||||
$this->draw->popPattern();
|
||||
return $id;
|
||||
}
|
||||
|
||||
private function getColorPixel(ColorInterface $color) : ImagickPixel
|
||||
{
|
||||
$alpha = 100;
|
||||
|
||||
if ($color instanceof Alpha) {
|
||||
$alpha = $color->getAlpha();
|
||||
$color = $color->getBaseColor();
|
||||
}
|
||||
|
||||
if ($color instanceof Rgb) {
|
||||
return new ImagickPixel(sprintf(
|
||||
'rgba(%d, %d, %d, %F)',
|
||||
$color->getRed(),
|
||||
$color->getGreen(),
|
||||
$color->getBlue(),
|
||||
$alpha / 100
|
||||
));
|
||||
}
|
||||
|
||||
if ($color instanceof Cmyk) {
|
||||
return new ImagickPixel(sprintf(
|
||||
'cmyka(%d, %d, %d, %d, %F)',
|
||||
$color->getCyan(),
|
||||
$color->getMagenta(),
|
||||
$color->getYellow(),
|
||||
$color->getBlack(),
|
||||
$alpha / 100
|
||||
));
|
||||
}
|
||||
|
||||
if ($color instanceof Gray) {
|
||||
return new ImagickPixel(sprintf(
|
||||
'graya(%d%%, %F)',
|
||||
$color->getGray(),
|
||||
$alpha / 100
|
||||
));
|
||||
}
|
||||
|
||||
return $this->getColorPixel(new Alpha($alpha, $color->toRgb()));
|
||||
}
|
||||
}
|
||||
369
pma/vendor/bacon/bacon-qr-code/src/Renderer/Image/SvgImageBackEnd.php
vendored
Normal file
369
pma/vendor/bacon/bacon-qr-code/src/Renderer/Image/SvgImageBackEnd.php
vendored
Normal file
@@ -0,0 +1,369 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\Image;
|
||||
|
||||
use BaconQrCode\Exception\RuntimeException;
|
||||
use BaconQrCode\Renderer\Color\Alpha;
|
||||
use BaconQrCode\Renderer\Color\ColorInterface;
|
||||
use BaconQrCode\Renderer\Path\Close;
|
||||
use BaconQrCode\Renderer\Path\Curve;
|
||||
use BaconQrCode\Renderer\Path\EllipticArc;
|
||||
use BaconQrCode\Renderer\Path\Line;
|
||||
use BaconQrCode\Renderer\Path\Move;
|
||||
use BaconQrCode\Renderer\Path\Path;
|
||||
use BaconQrCode\Renderer\RendererStyle\Gradient;
|
||||
use BaconQrCode\Renderer\RendererStyle\GradientType;
|
||||
use XMLWriter;
|
||||
|
||||
final class SvgImageBackEnd implements ImageBackEndInterface
|
||||
{
|
||||
private const PRECISION = 3;
|
||||
|
||||
/**
|
||||
* @var XMLWriter|null
|
||||
*/
|
||||
private $xmlWriter;
|
||||
|
||||
/**
|
||||
* @var int[]|null
|
||||
*/
|
||||
private $stack;
|
||||
|
||||
/**
|
||||
* @var int|null
|
||||
*/
|
||||
private $currentStack;
|
||||
|
||||
/**
|
||||
* @var int|null
|
||||
*/
|
||||
private $gradientCount;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
if (! class_exists(XMLWriter::class)) {
|
||||
throw new RuntimeException('You need to install the libxml extension to use this back end');
|
||||
}
|
||||
}
|
||||
|
||||
public function new(int $size, ColorInterface $backgroundColor) : void
|
||||
{
|
||||
$this->xmlWriter = new XMLWriter();
|
||||
$this->xmlWriter->openMemory();
|
||||
|
||||
$this->xmlWriter->startDocument('1.0', 'UTF-8');
|
||||
$this->xmlWriter->startElement('svg');
|
||||
$this->xmlWriter->writeAttribute('xmlns', 'http://www.w3.org/2000/svg');
|
||||
$this->xmlWriter->writeAttribute('version', '1.1');
|
||||
$this->xmlWriter->writeAttribute('width', (string) $size);
|
||||
$this->xmlWriter->writeAttribute('height', (string) $size);
|
||||
$this->xmlWriter->writeAttribute('viewBox', '0 0 '. $size . ' ' . $size);
|
||||
|
||||
$this->gradientCount = 0;
|
||||
$this->currentStack = 0;
|
||||
$this->stack[0] = 0;
|
||||
|
||||
$alpha = 1;
|
||||
|
||||
if ($backgroundColor instanceof Alpha) {
|
||||
$alpha = $backgroundColor->getAlpha() / 100;
|
||||
}
|
||||
|
||||
if (0 === $alpha) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->xmlWriter->startElement('rect');
|
||||
$this->xmlWriter->writeAttribute('x', '0');
|
||||
$this->xmlWriter->writeAttribute('y', '0');
|
||||
$this->xmlWriter->writeAttribute('width', (string) $size);
|
||||
$this->xmlWriter->writeAttribute('height', (string) $size);
|
||||
$this->xmlWriter->writeAttribute('fill', $this->getColorString($backgroundColor));
|
||||
|
||||
if ($alpha < 1) {
|
||||
$this->xmlWriter->writeAttribute('fill-opacity', (string) $alpha);
|
||||
}
|
||||
|
||||
$this->xmlWriter->endElement();
|
||||
}
|
||||
|
||||
public function scale(float $size) : void
|
||||
{
|
||||
if (null === $this->xmlWriter) {
|
||||
throw new RuntimeException('No image has been started');
|
||||
}
|
||||
|
||||
$this->xmlWriter->startElement('g');
|
||||
$this->xmlWriter->writeAttribute(
|
||||
'transform',
|
||||
sprintf('scale(%s)', round($size, self::PRECISION))
|
||||
);
|
||||
++$this->stack[$this->currentStack];
|
||||
}
|
||||
|
||||
public function translate(float $x, float $y) : void
|
||||
{
|
||||
if (null === $this->xmlWriter) {
|
||||
throw new RuntimeException('No image has been started');
|
||||
}
|
||||
|
||||
$this->xmlWriter->startElement('g');
|
||||
$this->xmlWriter->writeAttribute(
|
||||
'transform',
|
||||
sprintf('translate(%s,%s)', round($x, self::PRECISION), round($y, self::PRECISION))
|
||||
);
|
||||
++$this->stack[$this->currentStack];
|
||||
}
|
||||
|
||||
public function rotate(int $degrees) : void
|
||||
{
|
||||
if (null === $this->xmlWriter) {
|
||||
throw new RuntimeException('No image has been started');
|
||||
}
|
||||
|
||||
$this->xmlWriter->startElement('g');
|
||||
$this->xmlWriter->writeAttribute('transform', sprintf('rotate(%d)', $degrees));
|
||||
++$this->stack[$this->currentStack];
|
||||
}
|
||||
|
||||
public function push() : void
|
||||
{
|
||||
if (null === $this->xmlWriter) {
|
||||
throw new RuntimeException('No image has been started');
|
||||
}
|
||||
|
||||
$this->xmlWriter->startElement('g');
|
||||
$this->stack[] = 1;
|
||||
++$this->currentStack;
|
||||
}
|
||||
|
||||
public function pop() : void
|
||||
{
|
||||
if (null === $this->xmlWriter) {
|
||||
throw new RuntimeException('No image has been started');
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $this->stack[$this->currentStack]; ++$i) {
|
||||
$this->xmlWriter->endElement();
|
||||
}
|
||||
|
||||
array_pop($this->stack);
|
||||
--$this->currentStack;
|
||||
}
|
||||
|
||||
public function drawPathWithColor(Path $path, ColorInterface $color) : void
|
||||
{
|
||||
if (null === $this->xmlWriter) {
|
||||
throw new RuntimeException('No image has been started');
|
||||
}
|
||||
|
||||
$alpha = 1;
|
||||
|
||||
if ($color instanceof Alpha) {
|
||||
$alpha = $color->getAlpha() / 100;
|
||||
}
|
||||
|
||||
$this->startPathElement($path);
|
||||
$this->xmlWriter->writeAttribute('fill', $this->getColorString($color));
|
||||
|
||||
if ($alpha < 1) {
|
||||
$this->xmlWriter->writeAttribute('fill-opacity', (string) $alpha);
|
||||
}
|
||||
|
||||
$this->xmlWriter->endElement();
|
||||
}
|
||||
|
||||
public function drawPathWithGradient(
|
||||
Path $path,
|
||||
Gradient $gradient,
|
||||
float $x,
|
||||
float $y,
|
||||
float $width,
|
||||
float $height
|
||||
) : void {
|
||||
if (null === $this->xmlWriter) {
|
||||
throw new RuntimeException('No image has been started');
|
||||
}
|
||||
|
||||
$gradientId = $this->createGradientFill($gradient, $x, $y, $width, $height);
|
||||
$this->startPathElement($path);
|
||||
$this->xmlWriter->writeAttribute('fill', 'url(#' . $gradientId . ')');
|
||||
$this->xmlWriter->endElement();
|
||||
}
|
||||
|
||||
public function done() : string
|
||||
{
|
||||
if (null === $this->xmlWriter) {
|
||||
throw new RuntimeException('No image has been started');
|
||||
}
|
||||
|
||||
foreach ($this->stack as $openElements) {
|
||||
for ($i = $openElements; $i > 0; --$i) {
|
||||
$this->xmlWriter->endElement();
|
||||
}
|
||||
}
|
||||
|
||||
$this->xmlWriter->endDocument();
|
||||
$blob = $this->xmlWriter->outputMemory(true);
|
||||
$this->xmlWriter = null;
|
||||
$this->stack = null;
|
||||
$this->currentStack = null;
|
||||
$this->gradientCount = null;
|
||||
|
||||
return $blob;
|
||||
}
|
||||
|
||||
private function startPathElement(Path $path) : void
|
||||
{
|
||||
$pathData = [];
|
||||
|
||||
foreach ($path as $op) {
|
||||
switch (true) {
|
||||
case $op instanceof Move:
|
||||
$pathData[] = sprintf(
|
||||
'M%s %s',
|
||||
round($op->getX(), self::PRECISION),
|
||||
round($op->getY(), self::PRECISION)
|
||||
);
|
||||
break;
|
||||
|
||||
case $op instanceof Line:
|
||||
$pathData[] = sprintf(
|
||||
'L%s %s',
|
||||
round($op->getX(), self::PRECISION),
|
||||
round($op->getY(), self::PRECISION)
|
||||
);
|
||||
break;
|
||||
|
||||
case $op instanceof EllipticArc:
|
||||
$pathData[] = sprintf(
|
||||
'A%s %s %s %u %u %s %s',
|
||||
round($op->getXRadius(), self::PRECISION),
|
||||
round($op->getYRadius(), self::PRECISION),
|
||||
round($op->getXAxisAngle(), self::PRECISION),
|
||||
$op->isLargeArc(),
|
||||
$op->isSweep(),
|
||||
round($op->getX(), self::PRECISION),
|
||||
round($op->getY(), self::PRECISION)
|
||||
);
|
||||
break;
|
||||
|
||||
case $op instanceof Curve:
|
||||
$pathData[] = sprintf(
|
||||
'C%s %s %s %s %s %s',
|
||||
round($op->getX1(), self::PRECISION),
|
||||
round($op->getY1(), self::PRECISION),
|
||||
round($op->getX2(), self::PRECISION),
|
||||
round($op->getY2(), self::PRECISION),
|
||||
round($op->getX3(), self::PRECISION),
|
||||
round($op->getY3(), self::PRECISION)
|
||||
);
|
||||
break;
|
||||
|
||||
case $op instanceof Close:
|
||||
$pathData[] = 'Z';
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new RuntimeException('Unexpected draw operation: ' . get_class($op));
|
||||
}
|
||||
}
|
||||
|
||||
$this->xmlWriter->startElement('path');
|
||||
$this->xmlWriter->writeAttribute('fill-rule', 'evenodd');
|
||||
$this->xmlWriter->writeAttribute('d', implode('', $pathData));
|
||||
}
|
||||
|
||||
private function createGradientFill(Gradient $gradient, float $x, float $y, float $width, float $height) : string
|
||||
{
|
||||
$this->xmlWriter->startElement('defs');
|
||||
|
||||
$startColor = $gradient->getStartColor();
|
||||
$endColor = $gradient->getEndColor();
|
||||
|
||||
if ($gradient->getType() === GradientType::RADIAL()) {
|
||||
$this->xmlWriter->startElement('radialGradient');
|
||||
} else {
|
||||
$this->xmlWriter->startElement('linearGradient');
|
||||
}
|
||||
|
||||
$this->xmlWriter->writeAttribute('gradientUnits', 'userSpaceOnUse');
|
||||
|
||||
switch ($gradient->getType()) {
|
||||
case GradientType::HORIZONTAL():
|
||||
$this->xmlWriter->writeAttribute('x1', (string) round($x, self::PRECISION));
|
||||
$this->xmlWriter->writeAttribute('y1', (string) round($y, self::PRECISION));
|
||||
$this->xmlWriter->writeAttribute('x2', (string) round($x + $width, self::PRECISION));
|
||||
$this->xmlWriter->writeAttribute('y2', (string) round($y, self::PRECISION));
|
||||
break;
|
||||
|
||||
case GradientType::VERTICAL():
|
||||
$this->xmlWriter->writeAttribute('x1', (string) round($x, self::PRECISION));
|
||||
$this->xmlWriter->writeAttribute('y1', (string) round($y, self::PRECISION));
|
||||
$this->xmlWriter->writeAttribute('x2', (string) round($x, self::PRECISION));
|
||||
$this->xmlWriter->writeAttribute('y2', (string) round($y + $height, self::PRECISION));
|
||||
break;
|
||||
|
||||
case GradientType::DIAGONAL():
|
||||
$this->xmlWriter->writeAttribute('x1', (string) round($x, self::PRECISION));
|
||||
$this->xmlWriter->writeAttribute('y1', (string) round($y, self::PRECISION));
|
||||
$this->xmlWriter->writeAttribute('x2', (string) round($x + $width, self::PRECISION));
|
||||
$this->xmlWriter->writeAttribute('y2', (string) round($y + $height, self::PRECISION));
|
||||
break;
|
||||
|
||||
case GradientType::INVERSE_DIAGONAL():
|
||||
$this->xmlWriter->writeAttribute('x1', (string) round($x, self::PRECISION));
|
||||
$this->xmlWriter->writeAttribute('y1', (string) round($y + $height, self::PRECISION));
|
||||
$this->xmlWriter->writeAttribute('x2', (string) round($x + $width, self::PRECISION));
|
||||
$this->xmlWriter->writeAttribute('y2', (string) round($y, self::PRECISION));
|
||||
break;
|
||||
|
||||
case GradientType::RADIAL():
|
||||
$this->xmlWriter->writeAttribute('cx', (string) round(($x + $width) / 2, self::PRECISION));
|
||||
$this->xmlWriter->writeAttribute('cy', (string) round(($y + $height) / 2, self::PRECISION));
|
||||
$this->xmlWriter->writeAttribute('r', (string) round(max($width, $height) / 2, self::PRECISION));
|
||||
break;
|
||||
}
|
||||
|
||||
$id = sprintf('g%d', ++$this->gradientCount);
|
||||
$this->xmlWriter->writeAttribute('id', $id);
|
||||
|
||||
$this->xmlWriter->startElement('stop');
|
||||
$this->xmlWriter->writeAttribute('offset', '0%');
|
||||
$this->xmlWriter->writeAttribute('stop-color', $this->getColorString($startColor));
|
||||
|
||||
if ($startColor instanceof Alpha) {
|
||||
$this->xmlWriter->writeAttribute('stop-opacity', $startColor->getAlpha());
|
||||
}
|
||||
|
||||
$this->xmlWriter->endElement();
|
||||
|
||||
$this->xmlWriter->startElement('stop');
|
||||
$this->xmlWriter->writeAttribute('offset', '100%');
|
||||
$this->xmlWriter->writeAttribute('stop-color', $this->getColorString($endColor));
|
||||
|
||||
if ($endColor instanceof Alpha) {
|
||||
$this->xmlWriter->writeAttribute('stop-opacity', $endColor->getAlpha());
|
||||
}
|
||||
|
||||
$this->xmlWriter->endElement();
|
||||
|
||||
$this->xmlWriter->endElement();
|
||||
$this->xmlWriter->endElement();
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
private function getColorString(ColorInterface $color) : string
|
||||
{
|
||||
$color = $color->toRgb();
|
||||
|
||||
return sprintf(
|
||||
'#%02x%02x%02x',
|
||||
$color->getRed(),
|
||||
$color->getGreen(),
|
||||
$color->getBlue()
|
||||
);
|
||||
}
|
||||
}
|
||||
68
pma/vendor/bacon/bacon-qr-code/src/Renderer/Image/TransformationMatrix.php
vendored
Normal file
68
pma/vendor/bacon/bacon-qr-code/src/Renderer/Image/TransformationMatrix.php
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\Image;
|
||||
|
||||
final class TransformationMatrix
|
||||
{
|
||||
/**
|
||||
* @var float[]
|
||||
*/
|
||||
private $values;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->values = [1, 0, 0, 1, 0, 0];
|
||||
}
|
||||
|
||||
public function multiply(self $other) : self
|
||||
{
|
||||
$matrix = new self();
|
||||
$matrix->values[0] = $this->values[0] * $other->values[0] + $this->values[2] * $other->values[1];
|
||||
$matrix->values[1] = $this->values[1] * $other->values[0] + $this->values[3] * $other->values[1];
|
||||
$matrix->values[2] = $this->values[0] * $other->values[2] + $this->values[2] * $other->values[3];
|
||||
$matrix->values[3] = $this->values[1] * $other->values[2] + $this->values[3] * $other->values[3];
|
||||
$matrix->values[4] = $this->values[0] * $other->values[4] + $this->values[2] * $other->values[5]
|
||||
+ $this->values[4];
|
||||
$matrix->values[5] = $this->values[1] * $other->values[4] + $this->values[3] * $other->values[5]
|
||||
+ $this->values[5];
|
||||
|
||||
return $matrix;
|
||||
}
|
||||
|
||||
public static function scale(float $size) : self
|
||||
{
|
||||
$matrix = new self();
|
||||
$matrix->values = [$size, 0, 0, $size, 0, 0];
|
||||
return $matrix;
|
||||
}
|
||||
|
||||
public static function translate(float $x, float $y) : self
|
||||
{
|
||||
$matrix = new self();
|
||||
$matrix->values = [1, 0, 0, 1, $x, $y];
|
||||
return $matrix;
|
||||
}
|
||||
|
||||
public static function rotate(int $degrees) : self
|
||||
{
|
||||
$matrix = new self();
|
||||
$rad = deg2rad($degrees);
|
||||
$matrix->values = [cos($rad), sin($rad), -sin($rad), cos($rad), 0, 0];
|
||||
return $matrix;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Applies this matrix onto a point and returns the resulting viewport point.
|
||||
*
|
||||
* @return float[]
|
||||
*/
|
||||
public function apply(float $x, float $y) : array
|
||||
{
|
||||
return [
|
||||
$x * $this->values[0] + $y * $this->values[2] + $this->values[4],
|
||||
$x * $this->values[1] + $y * $this->values[3] + $this->values[5],
|
||||
];
|
||||
}
|
||||
}
|
||||
152
pma/vendor/bacon/bacon-qr-code/src/Renderer/ImageRenderer.php
vendored
Normal file
152
pma/vendor/bacon/bacon-qr-code/src/Renderer/ImageRenderer.php
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer;
|
||||
|
||||
use BaconQrCode\Encoder\MatrixUtil;
|
||||
use BaconQrCode\Encoder\QrCode;
|
||||
use BaconQrCode\Exception\InvalidArgumentException;
|
||||
use BaconQrCode\Renderer\Image\ImageBackEndInterface;
|
||||
use BaconQrCode\Renderer\Path\Path;
|
||||
use BaconQrCode\Renderer\RendererStyle\EyeFill;
|
||||
use BaconQrCode\Renderer\RendererStyle\RendererStyle;
|
||||
|
||||
final class ImageRenderer implements RendererInterface
|
||||
{
|
||||
/**
|
||||
* @var RendererStyle
|
||||
*/
|
||||
private $rendererStyle;
|
||||
|
||||
/**
|
||||
* @var ImageBackEndInterface
|
||||
*/
|
||||
private $imageBackEnd;
|
||||
|
||||
public function __construct(RendererStyle $rendererStyle, ImageBackEndInterface $imageBackEnd)
|
||||
{
|
||||
$this->rendererStyle = $rendererStyle;
|
||||
$this->imageBackEnd = $imageBackEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidArgumentException if matrix width doesn't match height
|
||||
*/
|
||||
public function render(QrCode $qrCode) : string
|
||||
{
|
||||
$size = $this->rendererStyle->getSize();
|
||||
$margin = $this->rendererStyle->getMargin();
|
||||
$matrix = $qrCode->getMatrix();
|
||||
$matrixSize = $matrix->getWidth();
|
||||
|
||||
if ($matrixSize !== $matrix->getHeight()) {
|
||||
throw new InvalidArgumentException('Matrix must have the same width and height');
|
||||
}
|
||||
|
||||
$totalSize = $matrixSize + ($margin * 2);
|
||||
$moduleSize = $size / $totalSize;
|
||||
$fill = $this->rendererStyle->getFill();
|
||||
|
||||
$this->imageBackEnd->new($size, $fill->getBackgroundColor());
|
||||
$this->imageBackEnd->scale((float) $moduleSize);
|
||||
$this->imageBackEnd->translate((float) $margin, (float) $margin);
|
||||
|
||||
$module = $this->rendererStyle->getModule();
|
||||
$moduleMatrix = clone $matrix;
|
||||
MatrixUtil::removePositionDetectionPatterns($moduleMatrix);
|
||||
$modulePath = $this->drawEyes($matrixSize, $module->createPath($moduleMatrix));
|
||||
|
||||
if ($fill->hasGradientFill()) {
|
||||
$this->imageBackEnd->drawPathWithGradient(
|
||||
$modulePath,
|
||||
$fill->getForegroundGradient(),
|
||||
0,
|
||||
0,
|
||||
$matrixSize,
|
||||
$matrixSize
|
||||
);
|
||||
} else {
|
||||
$this->imageBackEnd->drawPathWithColor($modulePath, $fill->getForegroundColor());
|
||||
}
|
||||
|
||||
return $this->imageBackEnd->done();
|
||||
}
|
||||
|
||||
private function drawEyes(int $matrixSize, Path $modulePath) : Path
|
||||
{
|
||||
$fill = $this->rendererStyle->getFill();
|
||||
|
||||
$eye = $this->rendererStyle->getEye();
|
||||
$externalPath = $eye->getExternalPath();
|
||||
$internalPath = $eye->getInternalPath();
|
||||
|
||||
$modulePath = $this->drawEye(
|
||||
$externalPath,
|
||||
$internalPath,
|
||||
$fill->getTopLeftEyeFill(),
|
||||
3.5,
|
||||
3.5,
|
||||
0,
|
||||
$modulePath
|
||||
);
|
||||
$modulePath = $this->drawEye(
|
||||
$externalPath,
|
||||
$internalPath,
|
||||
$fill->getTopRightEyeFill(),
|
||||
$matrixSize - 3.5,
|
||||
3.5,
|
||||
90,
|
||||
$modulePath
|
||||
);
|
||||
$modulePath = $this->drawEye(
|
||||
$externalPath,
|
||||
$internalPath,
|
||||
$fill->getBottomLeftEyeFill(),
|
||||
3.5,
|
||||
$matrixSize - 3.5,
|
||||
-90,
|
||||
$modulePath
|
||||
);
|
||||
|
||||
return $modulePath;
|
||||
}
|
||||
|
||||
private function drawEye(
|
||||
Path $externalPath,
|
||||
Path $internalPath,
|
||||
EyeFill $fill,
|
||||
float $xTranslation,
|
||||
float $yTranslation,
|
||||
int $rotation,
|
||||
Path $modulePath
|
||||
) : Path {
|
||||
if ($fill->inheritsBothColors()) {
|
||||
return $modulePath
|
||||
->append($externalPath->translate($xTranslation, $yTranslation))
|
||||
->append($internalPath->translate($xTranslation, $yTranslation));
|
||||
}
|
||||
|
||||
$this->imageBackEnd->push();
|
||||
$this->imageBackEnd->translate($xTranslation, $yTranslation);
|
||||
|
||||
if (0 !== $rotation) {
|
||||
$this->imageBackEnd->rotate($rotation);
|
||||
}
|
||||
|
||||
if ($fill->inheritsExternalColor()) {
|
||||
$modulePath = $modulePath->append($externalPath->translate($xTranslation, $yTranslation));
|
||||
} else {
|
||||
$this->imageBackEnd->drawPathWithColor($externalPath, $fill->getExternalColor());
|
||||
}
|
||||
|
||||
if ($fill->inheritsInternalColor()) {
|
||||
$modulePath = $modulePath->append($internalPath->translate($xTranslation, $yTranslation));
|
||||
} else {
|
||||
$this->imageBackEnd->drawPathWithColor($internalPath, $fill->getInternalColor());
|
||||
}
|
||||
|
||||
$this->imageBackEnd->pop();
|
||||
|
||||
return $modulePath;
|
||||
}
|
||||
}
|
||||
63
pma/vendor/bacon/bacon-qr-code/src/Renderer/Module/DotsModule.php
vendored
Normal file
63
pma/vendor/bacon/bacon-qr-code/src/Renderer/Module/DotsModule.php
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\Module;
|
||||
|
||||
use BaconQrCode\Encoder\ByteMatrix;
|
||||
use BaconQrCode\Exception\InvalidArgumentException;
|
||||
use BaconQrCode\Renderer\Path\Path;
|
||||
|
||||
/**
|
||||
* Renders individual modules as dots.
|
||||
*/
|
||||
final class DotsModule implements ModuleInterface
|
||||
{
|
||||
public const LARGE = 1;
|
||||
public const MEDIUM = .8;
|
||||
public const SMALL = .6;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
private $size;
|
||||
|
||||
public function __construct(float $size)
|
||||
{
|
||||
if ($size <= 0 || $size > 1) {
|
||||
throw new InvalidArgumentException('Size must between 0 (exclusive) and 1 (inclusive)');
|
||||
}
|
||||
|
||||
$this->size = $size;
|
||||
}
|
||||
|
||||
public function createPath(ByteMatrix $matrix) : Path
|
||||
{
|
||||
$width = $matrix->getWidth();
|
||||
$height = $matrix->getHeight();
|
||||
$path = new Path();
|
||||
$halfSize = $this->size / 2;
|
||||
$margin = (1 - $this->size) / 2;
|
||||
|
||||
for ($y = 0; $y < $height; ++$y) {
|
||||
for ($x = 0; $x < $width; ++$x) {
|
||||
if (! $matrix->get($x, $y)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$pathX = $x + $margin;
|
||||
$pathY = $y + $margin;
|
||||
|
||||
$path = $path
|
||||
->move($pathX + $this->size, $pathY + $halfSize)
|
||||
->ellipticArc($halfSize, $halfSize, 0, false, true, $pathX + $halfSize, $pathY + $this->size)
|
||||
->ellipticArc($halfSize, $halfSize, 0, false, true, $pathX, $pathY + $halfSize)
|
||||
->ellipticArc($halfSize, $halfSize, 0, false, true, $pathX + $halfSize, $pathY)
|
||||
->ellipticArc($halfSize, $halfSize, 0, false, true, $pathX + $this->size, $pathY + $halfSize)
|
||||
->close()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
100
pma/vendor/bacon/bacon-qr-code/src/Renderer/Module/EdgeIterator/Edge.php
vendored
Normal file
100
pma/vendor/bacon/bacon-qr-code/src/Renderer/Module/EdgeIterator/Edge.php
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\Module\EdgeIterator;
|
||||
|
||||
final class Edge
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $positive;
|
||||
|
||||
/**
|
||||
* @var array<int[]>
|
||||
*/
|
||||
private $points = [];
|
||||
|
||||
/**
|
||||
* @var array<int[]>|null
|
||||
*/
|
||||
private $simplifiedPoints;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $minX = PHP_INT_MAX;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $minY = PHP_INT_MAX;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $maxX = -1;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $maxY = -1;
|
||||
|
||||
public function __construct(bool $positive)
|
||||
{
|
||||
$this->positive = $positive;
|
||||
}
|
||||
|
||||
public function addPoint(int $x, int $y) : void
|
||||
{
|
||||
$this->points[] = [$x, $y];
|
||||
$this->minX = min($this->minX, $x);
|
||||
$this->minY = min($this->minY, $y);
|
||||
$this->maxX = max($this->maxX, $x);
|
||||
$this->maxY = max($this->maxY, $y);
|
||||
}
|
||||
|
||||
public function isPositive() : bool
|
||||
{
|
||||
return $this->positive;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int[]>
|
||||
*/
|
||||
public function getPoints() : array
|
||||
{
|
||||
return $this->points;
|
||||
}
|
||||
|
||||
public function getMaxX() : int
|
||||
{
|
||||
return $this->maxX;
|
||||
}
|
||||
|
||||
public function getSimplifiedPoints() : array
|
||||
{
|
||||
if (null !== $this->simplifiedPoints) {
|
||||
return $this->simplifiedPoints;
|
||||
}
|
||||
|
||||
$points = [];
|
||||
$length = count($this->points);
|
||||
|
||||
for ($i = 0; $i < $length; ++$i) {
|
||||
$previousPoint = $this->points[(0 === $i ? $length : $i) - 1];
|
||||
$nextPoint = $this->points[($length - 1 === $i ? -1 : $i) + 1];
|
||||
$currentPoint = $this->points[$i];
|
||||
|
||||
if (($previousPoint[0] === $currentPoint[0] && $currentPoint[0] === $nextPoint[0])
|
||||
|| ($previousPoint[1] === $currentPoint[1] && $currentPoint[1] === $nextPoint[1])
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$points[] = $currentPoint;
|
||||
}
|
||||
|
||||
return $this->simplifiedPoints = $points;
|
||||
}
|
||||
}
|
||||
169
pma/vendor/bacon/bacon-qr-code/src/Renderer/Module/EdgeIterator/EdgeIterator.php
vendored
Normal file
169
pma/vendor/bacon/bacon-qr-code/src/Renderer/Module/EdgeIterator/EdgeIterator.php
vendored
Normal file
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\Module\EdgeIterator;
|
||||
|
||||
use BaconQrCode\Encoder\ByteMatrix;
|
||||
use IteratorAggregate;
|
||||
use Traversable;
|
||||
|
||||
/**
|
||||
* Edge iterator based on potrace.
|
||||
*/
|
||||
final class EdgeIterator implements IteratorAggregate
|
||||
{
|
||||
/**
|
||||
* @var int[]
|
||||
*/
|
||||
private $bytes = [];
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $size;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $width;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $height;
|
||||
|
||||
public function __construct(ByteMatrix $matrix)
|
||||
{
|
||||
$this->bytes = iterator_to_array($matrix->getBytes());
|
||||
$this->size = count($this->bytes);
|
||||
$this->width = $matrix->getWidth();
|
||||
$this->height = $matrix->getHeight();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Edge[]
|
||||
*/
|
||||
public function getIterator() : Traversable
|
||||
{
|
||||
$originalBytes = $this->bytes;
|
||||
$point = $this->findNext(0, 0);
|
||||
|
||||
while (null !== $point) {
|
||||
$edge = $this->findEdge($point[0], $point[1]);
|
||||
$this->xorEdge($edge);
|
||||
|
||||
yield $edge;
|
||||
|
||||
$point = $this->findNext($point[0], $point[1]);
|
||||
}
|
||||
|
||||
$this->bytes = $originalBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int[]|null
|
||||
*/
|
||||
private function findNext(int $x, int $y) : ?array
|
||||
{
|
||||
$i = $this->width * $y + $x;
|
||||
|
||||
while ($i < $this->size && 1 !== $this->bytes[$i]) {
|
||||
++$i;
|
||||
}
|
||||
|
||||
if ($i < $this->size) {
|
||||
return $this->pointOf($i);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function findEdge(int $x, int $y) : Edge
|
||||
{
|
||||
$edge = new Edge($this->isSet($x, $y));
|
||||
$startX = $x;
|
||||
$startY = $y;
|
||||
$dirX = 0;
|
||||
$dirY = 1;
|
||||
|
||||
while (true) {
|
||||
$edge->addPoint($x, $y);
|
||||
$x += $dirX;
|
||||
$y += $dirY;
|
||||
|
||||
if ($x === $startX && $y === $startY) {
|
||||
break;
|
||||
}
|
||||
|
||||
$left = $this->isSet($x + ($dirX + $dirY - 1 ) / 2, $y + ($dirY - $dirX - 1) / 2);
|
||||
$right = $this->isSet($x + ($dirX - $dirY - 1) / 2, $y + ($dirY + $dirX - 1) / 2);
|
||||
|
||||
if ($right && ! $left) {
|
||||
$tmp = $dirX;
|
||||
$dirX = -$dirY;
|
||||
$dirY = $tmp;
|
||||
} elseif ($right) {
|
||||
$tmp = $dirX;
|
||||
$dirX = -$dirY;
|
||||
$dirY = $tmp;
|
||||
} elseif (! $left) {
|
||||
$tmp = $dirX;
|
||||
$dirX = $dirY;
|
||||
$dirY = -$tmp;
|
||||
}
|
||||
}
|
||||
|
||||
return $edge;
|
||||
}
|
||||
|
||||
private function xorEdge(Edge $path) : void
|
||||
{
|
||||
$points = $path->getPoints();
|
||||
$y1 = $points[0][1];
|
||||
$length = count($points);
|
||||
$maxX = $path->getMaxX();
|
||||
|
||||
for ($i = 1; $i < $length; ++$i) {
|
||||
$y = $points[$i][1];
|
||||
|
||||
if ($y === $y1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$x = $points[$i][0];
|
||||
$minY = min($y1, $y);
|
||||
|
||||
for ($j = $x; $j < $maxX; ++$j) {
|
||||
$this->flip($j, $minY);
|
||||
}
|
||||
|
||||
$y1 = $y;
|
||||
}
|
||||
}
|
||||
|
||||
private function isSet(int $x, int $y) : bool
|
||||
{
|
||||
return (
|
||||
$x >= 0
|
||||
&& $x < $this->width
|
||||
&& $y >= 0
|
||||
&& $y < $this->height
|
||||
) && 1 === $this->bytes[$this->width * $y + $x];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int[]
|
||||
*/
|
||||
private function pointOf(int $i) : array
|
||||
{
|
||||
$y = intdiv($i, $this->width);
|
||||
return [$i - $y * $this->width, $y];
|
||||
}
|
||||
|
||||
private function flip(int $x, int $y) : void
|
||||
{
|
||||
$this->bytes[$this->width * $y + $x] = (
|
||||
$this->isSet($x, $y) ? 0 : 1
|
||||
);
|
||||
}
|
||||
}
|
||||
18
pma/vendor/bacon/bacon-qr-code/src/Renderer/Module/ModuleInterface.php
vendored
Normal file
18
pma/vendor/bacon/bacon-qr-code/src/Renderer/Module/ModuleInterface.php
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\Module;
|
||||
|
||||
use BaconQrCode\Encoder\ByteMatrix;
|
||||
use BaconQrCode\Renderer\Path\Path;
|
||||
|
||||
/**
|
||||
* Interface describing how modules should be rendered.
|
||||
*
|
||||
* A module always receives a byte matrix (with values either being 1 or 0). It returns a path, where the origin
|
||||
* coordinate (0, 0) equals the top left corner of the first matrix value.
|
||||
*/
|
||||
interface ModuleInterface
|
||||
{
|
||||
public function createPath(ByteMatrix $matrix) : Path;
|
||||
}
|
||||
129
pma/vendor/bacon/bacon-qr-code/src/Renderer/Module/RoundnessModule.php
vendored
Normal file
129
pma/vendor/bacon/bacon-qr-code/src/Renderer/Module/RoundnessModule.php
vendored
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\Module;
|
||||
|
||||
use BaconQrCode\Encoder\ByteMatrix;
|
||||
use BaconQrCode\Exception\InvalidArgumentException;
|
||||
use BaconQrCode\Renderer\Module\EdgeIterator\EdgeIterator;
|
||||
use BaconQrCode\Renderer\Path\Path;
|
||||
|
||||
/**
|
||||
* Rounds the corners of module groups.
|
||||
*/
|
||||
final class RoundnessModule implements ModuleInterface
|
||||
{
|
||||
public const STRONG = 1;
|
||||
public const MEDIUM = .5;
|
||||
public const SOFT = .25;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
private $intensity;
|
||||
|
||||
public function __construct(float $intensity)
|
||||
{
|
||||
if ($intensity <= 0 || $intensity > 1) {
|
||||
throw new InvalidArgumentException('Intensity must between 0 (exclusive) and 1 (inclusive)');
|
||||
}
|
||||
|
||||
$this->intensity = $intensity / 2;
|
||||
}
|
||||
|
||||
public function createPath(ByteMatrix $matrix) : Path
|
||||
{
|
||||
$path = new Path();
|
||||
|
||||
foreach (new EdgeIterator($matrix) as $edge) {
|
||||
$points = $edge->getSimplifiedPoints();
|
||||
$length = count($points);
|
||||
|
||||
$currentPoint = $points[0];
|
||||
$nextPoint = $points[1];
|
||||
$horizontal = ($currentPoint[1] === $nextPoint[1]);
|
||||
|
||||
if ($horizontal) {
|
||||
$right = $nextPoint[0] > $currentPoint[0];
|
||||
$path = $path->move(
|
||||
$currentPoint[0] + ($right ? $this->intensity : -$this->intensity),
|
||||
$currentPoint[1]
|
||||
);
|
||||
} else {
|
||||
$up = $nextPoint[0] < $currentPoint[0];
|
||||
$path = $path->move(
|
||||
$currentPoint[0],
|
||||
$currentPoint[1] + ($up ? -$this->intensity : $this->intensity)
|
||||
);
|
||||
}
|
||||
|
||||
for ($i = 1; $i <= $length; ++$i) {
|
||||
if ($i === $length) {
|
||||
$previousPoint = $points[$length - 1];
|
||||
$currentPoint = $points[0];
|
||||
$nextPoint = $points[1];
|
||||
} else {
|
||||
$previousPoint = $points[(0 === $i ? $length : $i) - 1];
|
||||
$currentPoint = $points[$i];
|
||||
$nextPoint = $points[($length - 1 === $i ? -1 : $i) + 1];
|
||||
}
|
||||
|
||||
$horizontal = ($previousPoint[1] === $currentPoint[1]);
|
||||
|
||||
if ($horizontal) {
|
||||
$right = $previousPoint[0] < $currentPoint[0];
|
||||
$up = $nextPoint[1] < $currentPoint[1];
|
||||
$sweep = ($up xor $right);
|
||||
|
||||
if ($this->intensity < 0.5
|
||||
|| ($right && $previousPoint[0] !== $currentPoint[0] - 1)
|
||||
|| (! $right && $previousPoint[0] - 1 !== $currentPoint[0])
|
||||
) {
|
||||
$path = $path->line(
|
||||
$currentPoint[0] + ($right ? -$this->intensity : $this->intensity),
|
||||
$currentPoint[1]
|
||||
);
|
||||
}
|
||||
|
||||
$path = $path->ellipticArc(
|
||||
$this->intensity,
|
||||
$this->intensity,
|
||||
0,
|
||||
false,
|
||||
$sweep,
|
||||
$currentPoint[0],
|
||||
$currentPoint[1] + ($up ? -$this->intensity : $this->intensity)
|
||||
);
|
||||
} else {
|
||||
$up = $previousPoint[1] > $currentPoint[1];
|
||||
$right = $nextPoint[0] > $currentPoint[0];
|
||||
$sweep = ! ($up xor $right);
|
||||
|
||||
if ($this->intensity < 0.5
|
||||
|| ($up && $previousPoint[1] !== $currentPoint[1] + 1)
|
||||
|| (! $up && $previousPoint[0] + 1 !== $currentPoint[0])
|
||||
) {
|
||||
$path = $path->line(
|
||||
$currentPoint[0],
|
||||
$currentPoint[1] + ($up ? $this->intensity : -$this->intensity)
|
||||
);
|
||||
}
|
||||
|
||||
$path = $path->ellipticArc(
|
||||
$this->intensity,
|
||||
$this->intensity,
|
||||
0,
|
||||
false,
|
||||
$sweep,
|
||||
$currentPoint[0] + ($right ? $this->intensity : -$this->intensity),
|
||||
$currentPoint[1]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$path = $path->close();
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
47
pma/vendor/bacon/bacon-qr-code/src/Renderer/Module/SquareModule.php
vendored
Normal file
47
pma/vendor/bacon/bacon-qr-code/src/Renderer/Module/SquareModule.php
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\Module;
|
||||
|
||||
use BaconQrCode\Encoder\ByteMatrix;
|
||||
use BaconQrCode\Renderer\Module\EdgeIterator\EdgeIterator;
|
||||
use BaconQrCode\Renderer\Path\Path;
|
||||
|
||||
/**
|
||||
* Groups modules together to a single path.
|
||||
*/
|
||||
final class SquareModule implements ModuleInterface
|
||||
{
|
||||
/**
|
||||
* @var self|null
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public static function instance() : self
|
||||
{
|
||||
return self::$instance ?: self::$instance = new self();
|
||||
}
|
||||
|
||||
public function createPath(ByteMatrix $matrix) : Path
|
||||
{
|
||||
$path = new Path();
|
||||
|
||||
foreach (new EdgeIterator($matrix) as $edge) {
|
||||
$points = $edge->getSimplifiedPoints();
|
||||
$length = count($points);
|
||||
$path = $path->move($points[0][0], $points[0][1]);
|
||||
|
||||
for ($i = 1; $i < $length; ++$i) {
|
||||
$path = $path->line($points[$i][0], $points[$i][1]);
|
||||
}
|
||||
|
||||
$path = $path->close();
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
29
pma/vendor/bacon/bacon-qr-code/src/Renderer/Path/Close.php
vendored
Normal file
29
pma/vendor/bacon/bacon-qr-code/src/Renderer/Path/Close.php
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\Path;
|
||||
|
||||
final class Close implements OperationInterface
|
||||
{
|
||||
/**
|
||||
* @var self|null
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public static function instance() : self
|
||||
{
|
||||
return self::$instance ?: self::$instance = new self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return self
|
||||
*/
|
||||
public function translate(float $x, float $y) : OperationInterface
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
92
pma/vendor/bacon/bacon-qr-code/src/Renderer/Path/Curve.php
vendored
Normal file
92
pma/vendor/bacon/bacon-qr-code/src/Renderer/Path/Curve.php
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\Path;
|
||||
|
||||
final class Curve implements OperationInterface
|
||||
{
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
private $x1;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
private $y1;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
private $x2;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
private $y2;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
private $x3;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
private $y3;
|
||||
|
||||
public function __construct(float $x1, float $y1, float $x2, float $y2, float $x3, float $y3)
|
||||
{
|
||||
$this->x1 = $x1;
|
||||
$this->y1 = $y1;
|
||||
$this->x2 = $x2;
|
||||
$this->y2 = $y2;
|
||||
$this->x3 = $x3;
|
||||
$this->y3 = $y3;
|
||||
}
|
||||
|
||||
public function getX1() : float
|
||||
{
|
||||
return $this->x1;
|
||||
}
|
||||
|
||||
public function getY1() : float
|
||||
{
|
||||
return $this->y1;
|
||||
}
|
||||
|
||||
public function getX2() : float
|
||||
{
|
||||
return $this->x2;
|
||||
}
|
||||
|
||||
public function getY2() : float
|
||||
{
|
||||
return $this->y2;
|
||||
}
|
||||
|
||||
public function getX3() : float
|
||||
{
|
||||
return $this->x3;
|
||||
}
|
||||
|
||||
public function getY3() : float
|
||||
{
|
||||
return $this->y3;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return self
|
||||
*/
|
||||
public function translate(float $x, float $y) : OperationInterface
|
||||
{
|
||||
return new self(
|
||||
$this->x1 + $x,
|
||||
$this->y1 + $y,
|
||||
$this->x2 + $x,
|
||||
$this->y2 + $y,
|
||||
$this->x3 + $x,
|
||||
$this->y3 + $y
|
||||
);
|
||||
}
|
||||
}
|
||||
278
pma/vendor/bacon/bacon-qr-code/src/Renderer/Path/EllipticArc.php
vendored
Normal file
278
pma/vendor/bacon/bacon-qr-code/src/Renderer/Path/EllipticArc.php
vendored
Normal file
@@ -0,0 +1,278 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\Path;
|
||||
|
||||
final class EllipticArc implements OperationInterface
|
||||
{
|
||||
private const ZERO_TOLERANCE = 1e-05;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
private $xRadius;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
private $yRadius;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
private $xAxisAngle;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $largeArc;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $sweep;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
private $x;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
private $y;
|
||||
|
||||
public function __construct(
|
||||
float $xRadius,
|
||||
float $yRadius,
|
||||
float $xAxisAngle,
|
||||
bool $largeArc,
|
||||
bool $sweep,
|
||||
float $x,
|
||||
float $y
|
||||
) {
|
||||
$this->xRadius = abs($xRadius);
|
||||
$this->yRadius = abs($yRadius);
|
||||
$this->xAxisAngle = $xAxisAngle % 360;
|
||||
$this->largeArc = $largeArc;
|
||||
$this->sweep = $sweep;
|
||||
$this->x = $x;
|
||||
$this->y = $y;
|
||||
}
|
||||
|
||||
public function getXRadius() : float
|
||||
{
|
||||
return $this->xRadius;
|
||||
}
|
||||
|
||||
public function getYRadius() : float
|
||||
{
|
||||
return $this->yRadius;
|
||||
}
|
||||
|
||||
public function getXAxisAngle() : float
|
||||
{
|
||||
return $this->xAxisAngle;
|
||||
}
|
||||
|
||||
public function isLargeArc() : bool
|
||||
{
|
||||
return $this->largeArc;
|
||||
}
|
||||
|
||||
public function isSweep() : bool
|
||||
{
|
||||
return $this->sweep;
|
||||
}
|
||||
|
||||
public function getX() : float
|
||||
{
|
||||
return $this->x;
|
||||
}
|
||||
|
||||
public function getY() : float
|
||||
{
|
||||
return $this->y;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return self
|
||||
*/
|
||||
public function translate(float $x, float $y) : OperationInterface
|
||||
{
|
||||
return new self(
|
||||
$this->xRadius,
|
||||
$this->yRadius,
|
||||
$this->xAxisAngle,
|
||||
$this->largeArc,
|
||||
$this->sweep,
|
||||
$this->x + $x,
|
||||
$this->y + $y
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the elliptic arc to multiple curves.
|
||||
*
|
||||
* Since not all image back ends support elliptic arcs, this method allows to convert the arc into multiple curves
|
||||
* resembling the same result.
|
||||
*
|
||||
* @see https://mortoray.com/2017/02/16/rendering-an-svg-elliptical-arc-as-bezier-curves/
|
||||
* @return array<Curve|Line>
|
||||
*/
|
||||
public function toCurves(float $fromX, float $fromY) : array
|
||||
{
|
||||
if (sqrt(($fromX - $this->x) ** 2 + ($fromY - $this->y) ** 2) < self::ZERO_TOLERANCE) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if ($this->xRadius < self::ZERO_TOLERANCE || $this->yRadius < self::ZERO_TOLERANCE) {
|
||||
return [new Line($this->x, $this->y)];
|
||||
}
|
||||
|
||||
return $this->createCurves($fromX, $fromY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Curve[]
|
||||
*/
|
||||
private function createCurves(float $fromX, $fromY) : array
|
||||
{
|
||||
$xAngle = deg2rad($this->xAxisAngle);
|
||||
list($centerX, $centerY, $radiusX, $radiusY, $startAngle, $deltaAngle) =
|
||||
$this->calculateCenterPointParameters($fromX, $fromY, $xAngle);
|
||||
|
||||
$s = $startAngle;
|
||||
$e = $s + $deltaAngle;
|
||||
$sign = ($e < $s) ? -1 : 1;
|
||||
$remain = abs($e - $s);
|
||||
$p1 = self::point($centerX, $centerY, $radiusX, $radiusY, $xAngle, $s);
|
||||
$curves = [];
|
||||
|
||||
while ($remain > self::ZERO_TOLERANCE) {
|
||||
$step = min($remain, pi() / 2);
|
||||
$signStep = $step * $sign;
|
||||
$p2 = self::point($centerX, $centerY, $radiusX, $radiusY, $xAngle, $s + $signStep);
|
||||
|
||||
$alphaT = tan($signStep / 2);
|
||||
$alpha = sin($signStep) * (sqrt(4 + 3 * $alphaT ** 2) - 1) / 3;
|
||||
$d1 = self::derivative($radiusX, $radiusY, $xAngle, $s);
|
||||
$d2 = self::derivative($radiusX, $radiusY, $xAngle, $s + $signStep);
|
||||
|
||||
$curves[] = new Curve(
|
||||
$p1[0] + $alpha * $d1[0],
|
||||
$p1[1] + $alpha * $d1[1],
|
||||
$p2[0] - $alpha * $d2[0],
|
||||
$p2[1] - $alpha * $d2[1],
|
||||
$p2[0],
|
||||
$p2[1]
|
||||
);
|
||||
|
||||
$s += $signStep;
|
||||
$remain -= $step;
|
||||
$p1 = $p2;
|
||||
}
|
||||
|
||||
return $curves;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float[]
|
||||
*/
|
||||
private function calculateCenterPointParameters(float $fromX, float $fromY, float $xAngle)
|
||||
{
|
||||
$rX = $this->xRadius;
|
||||
$rY = $this->yRadius;
|
||||
|
||||
// F.6.5.1
|
||||
$dx2 = ($fromX - $this->x) / 2;
|
||||
$dy2 = ($fromY - $this->y) / 2;
|
||||
$x1p = cos($xAngle) * $dx2 + sin($xAngle) * $dy2;
|
||||
$y1p = -sin($xAngle) * $dx2 + cos($xAngle) * $dy2;
|
||||
|
||||
// F.6.5.2
|
||||
$rxs = $rX ** 2;
|
||||
$rys = $rY ** 2;
|
||||
$x1ps = $x1p ** 2;
|
||||
$y1ps = $y1p ** 2;
|
||||
$cr = $x1ps / $rxs + $y1ps / $rys;
|
||||
|
||||
if ($cr > 1) {
|
||||
$s = sqrt($cr);
|
||||
$rX *= $s;
|
||||
$rY *= $s;
|
||||
$rxs = $rX ** 2;
|
||||
$rys = $rY ** 2;
|
||||
}
|
||||
|
||||
$dq = ($rxs * $y1ps + $rys * $x1ps);
|
||||
$pq = ($rxs * $rys - $dq) / $dq;
|
||||
$q = sqrt(max(0, $pq));
|
||||
|
||||
if ($this->largeArc === $this->sweep) {
|
||||
$q = -$q;
|
||||
}
|
||||
|
||||
$cxp = $q * $rX * $y1p / $rY;
|
||||
$cyp = -$q * $rY * $x1p / $rX;
|
||||
|
||||
// F.6.5.3
|
||||
$cx = cos($xAngle) * $cxp - sin($xAngle) * $cyp + ($fromX + $this->x) / 2;
|
||||
$cy = sin($xAngle) * $cxp + cos($xAngle) * $cyp + ($fromY + $this->y) / 2;
|
||||
|
||||
// F.6.5.5
|
||||
$theta = self::angle(1, 0, ($x1p - $cxp) / $rX, ($y1p - $cyp) / $rY);
|
||||
|
||||
// F.6.5.6
|
||||
$delta = self::angle(($x1p - $cxp) / $rX, ($y1p - $cyp) / $rY, (-$x1p - $cxp) / $rX, (-$y1p - $cyp) / $rY);
|
||||
$delta = fmod($delta, pi() * 2);
|
||||
|
||||
if (! $this->sweep) {
|
||||
$delta -= 2 * pi();
|
||||
}
|
||||
|
||||
return [$cx, $cy, $rX, $rY, $theta, $delta];
|
||||
}
|
||||
|
||||
private static function angle(float $ux, float $uy, float $vx, float $vy) : float
|
||||
{
|
||||
// F.6.5.4
|
||||
$dot = $ux * $vx + $uy * $vy;
|
||||
$length = sqrt($ux ** 2 + $uy ** 2) * sqrt($vx ** 2 + $vy ** 2);
|
||||
$angle = acos(min(1, max(-1, $dot / $length)));
|
||||
|
||||
if (($ux * $vy - $uy * $vx) < 0) {
|
||||
return -$angle;
|
||||
}
|
||||
|
||||
return $angle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float[]
|
||||
*/
|
||||
private static function point(
|
||||
float $centerX,
|
||||
float $centerY,
|
||||
float $radiusX,
|
||||
float $radiusY,
|
||||
float $xAngle,
|
||||
float $angle
|
||||
) : array {
|
||||
return [
|
||||
$centerX + $radiusX * cos($xAngle) * cos($angle) - $radiusY * sin($xAngle) * sin($angle),
|
||||
$centerY + $radiusX * sin($xAngle) * cos($angle) + $radiusY * cos($xAngle) * sin($angle),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float[]
|
||||
*/
|
||||
private static function derivative(float $radiusX, float $radiusY, float $xAngle, float $angle) : array
|
||||
{
|
||||
return [
|
||||
-$radiusX * cos($xAngle) * sin($angle) - $radiusY * sin($xAngle) * cos($angle),
|
||||
-$radiusX * sin($xAngle) * sin($angle) + $radiusY * cos($xAngle) * cos($angle),
|
||||
];
|
||||
}
|
||||
}
|
||||
41
pma/vendor/bacon/bacon-qr-code/src/Renderer/Path/Line.php
vendored
Normal file
41
pma/vendor/bacon/bacon-qr-code/src/Renderer/Path/Line.php
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\Path;
|
||||
|
||||
final class Line implements OperationInterface
|
||||
{
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
private $x;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
private $y;
|
||||
|
||||
public function __construct(float $x, float $y)
|
||||
{
|
||||
$this->x = $x;
|
||||
$this->y = $y;
|
||||
}
|
||||
|
||||
public function getX() : float
|
||||
{
|
||||
return $this->x;
|
||||
}
|
||||
|
||||
public function getY() : float
|
||||
{
|
||||
return $this->y;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return self
|
||||
*/
|
||||
public function translate(float $x, float $y) : OperationInterface
|
||||
{
|
||||
return new self($this->x + $x, $this->y + $y);
|
||||
}
|
||||
}
|
||||
41
pma/vendor/bacon/bacon-qr-code/src/Renderer/Path/Move.php
vendored
Normal file
41
pma/vendor/bacon/bacon-qr-code/src/Renderer/Path/Move.php
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\Path;
|
||||
|
||||
final class Move implements OperationInterface
|
||||
{
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
private $x;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
private $y;
|
||||
|
||||
public function __construct(float $x, float $y)
|
||||
{
|
||||
$this->x = $x;
|
||||
$this->y = $y;
|
||||
}
|
||||
|
||||
public function getX() : float
|
||||
{
|
||||
return $this->x;
|
||||
}
|
||||
|
||||
public function getY() : float
|
||||
{
|
||||
return $this->y;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return self
|
||||
*/
|
||||
public function translate(float $x, float $y) : OperationInterface
|
||||
{
|
||||
return new self($this->x + $x, $this->y + $y);
|
||||
}
|
||||
}
|
||||
12
pma/vendor/bacon/bacon-qr-code/src/Renderer/Path/OperationInterface.php
vendored
Normal file
12
pma/vendor/bacon/bacon-qr-code/src/Renderer/Path/OperationInterface.php
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\Path;
|
||||
|
||||
interface OperationInterface
|
||||
{
|
||||
/**
|
||||
* Translates the operation's coordinates.
|
||||
*/
|
||||
public function translate(float $x, float $y) : self;
|
||||
}
|
||||
106
pma/vendor/bacon/bacon-qr-code/src/Renderer/Path/Path.php
vendored
Normal file
106
pma/vendor/bacon/bacon-qr-code/src/Renderer/Path/Path.php
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\Path;
|
||||
|
||||
use IteratorAggregate;
|
||||
use Traversable;
|
||||
|
||||
/**
|
||||
* Internal Representation of a vector path.
|
||||
*/
|
||||
final class Path implements IteratorAggregate
|
||||
{
|
||||
/**
|
||||
* @var OperationInterface[]
|
||||
*/
|
||||
private $operations = [];
|
||||
|
||||
/**
|
||||
* Moves the drawing operation to a certain position.
|
||||
*/
|
||||
public function move(float $x, float $y) : self
|
||||
{
|
||||
$path = clone $this;
|
||||
$path->operations[] = new Move($x, $y);
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a line from the current position to another position.
|
||||
*/
|
||||
public function line(float $x, float $y) : self
|
||||
{
|
||||
$path = clone $this;
|
||||
$path->operations[] = new Line($x, $y);
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws an elliptic arc from the current position to another position.
|
||||
*/
|
||||
public function ellipticArc(
|
||||
float $xRadius,
|
||||
float $yRadius,
|
||||
float $xAxisRotation,
|
||||
bool $largeArc,
|
||||
bool $sweep,
|
||||
float $x,
|
||||
float $y
|
||||
) : self {
|
||||
$path = clone $this;
|
||||
$path->operations[] = new EllipticArc($xRadius, $yRadius, $xAxisRotation, $largeArc, $sweep, $x, $y);
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a curve from the current position to another position.
|
||||
*/
|
||||
public function curve(float $x1, float $y1, float $x2, float $y2, float $x3, float $y3) : self
|
||||
{
|
||||
$path = clone $this;
|
||||
$path->operations[] = new Curve($x1, $y1, $x2, $y2, $x3, $y3);
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes a sub-path.
|
||||
*/
|
||||
public function close() : self
|
||||
{
|
||||
$path = clone $this;
|
||||
$path->operations[] = Close::instance();
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends another path to this one.
|
||||
*/
|
||||
public function append(self $other) : self
|
||||
{
|
||||
$path = clone $this;
|
||||
$path->operations = array_merge($this->operations, $other->operations);
|
||||
return $path;
|
||||
}
|
||||
|
||||
public function translate(float $x, float $y) : self
|
||||
{
|
||||
$path = new self();
|
||||
|
||||
foreach ($this->operations as $operation) {
|
||||
$path->operations[] = $operation->translate($x, $y);
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return OperationInterface[]|Traversable
|
||||
*/
|
||||
public function getIterator() : Traversable
|
||||
{
|
||||
foreach ($this->operations as $operation) {
|
||||
yield $operation;
|
||||
}
|
||||
}
|
||||
}
|
||||
86
pma/vendor/bacon/bacon-qr-code/src/Renderer/PlainTextRenderer.php
vendored
Normal file
86
pma/vendor/bacon/bacon-qr-code/src/Renderer/PlainTextRenderer.php
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer;
|
||||
|
||||
use BaconQrCode\Encoder\QrCode;
|
||||
use BaconQrCode\Exception\InvalidArgumentException;
|
||||
|
||||
final class PlainTextRenderer implements RendererInterface
|
||||
{
|
||||
/**
|
||||
* UTF-8 full block (U+2588)
|
||||
*/
|
||||
private const FULL_BLOCK = "\xe2\x96\x88";
|
||||
|
||||
/**
|
||||
* UTF-8 upper half block (U+2580)
|
||||
*/
|
||||
private const UPPER_HALF_BLOCK = "\xe2\x96\x80";
|
||||
|
||||
/**
|
||||
* UTF-8 lower half block (U+2584)
|
||||
*/
|
||||
private const LOWER_HALF_BLOCK = "\xe2\x96\x84";
|
||||
|
||||
/**
|
||||
* UTF-8 no-break space (U+00A0)
|
||||
*/
|
||||
private const EMPTY_BLOCK = "\xc2\xa0";
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $margin;
|
||||
|
||||
public function __construct(int $margin = 2)
|
||||
{
|
||||
$this->margin = $margin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidArgumentException if matrix width doesn't match height
|
||||
*/
|
||||
public function render(QrCode $qrCode) : string
|
||||
{
|
||||
$matrix = $qrCode->getMatrix();
|
||||
$matrixSize = $matrix->getWidth();
|
||||
|
||||
if ($matrixSize !== $matrix->getHeight()) {
|
||||
throw new InvalidArgumentException('Matrix must have the same width and height');
|
||||
}
|
||||
|
||||
$rows = $matrix->getArray()->toArray();
|
||||
|
||||
if (0 !== $matrixSize % 2) {
|
||||
$rows[] = array_fill(0, $matrixSize, 0);
|
||||
}
|
||||
|
||||
$horizontalMargin = str_repeat(self::EMPTY_BLOCK, $this->margin);
|
||||
$result = str_repeat("\n", (int) ceil($this->margin / 2));
|
||||
|
||||
for ($i = 0; $i < $matrixSize; $i += 2) {
|
||||
$result .= $horizontalMargin;
|
||||
|
||||
$upperRow = $rows[$i];
|
||||
$lowerRow = $rows[$i + 1];
|
||||
|
||||
for ($j = 0; $j < $matrixSize; ++$j) {
|
||||
$upperBit = $upperRow[$j];
|
||||
$lowerBit = $lowerRow[$j];
|
||||
|
||||
if ($upperBit) {
|
||||
$result .= $lowerBit ? self::FULL_BLOCK : self::UPPER_HALF_BLOCK;
|
||||
} else {
|
||||
$result .= $lowerBit ? self::LOWER_HALF_BLOCK : self::EMPTY_BLOCK;
|
||||
}
|
||||
}
|
||||
|
||||
$result .= $horizontalMargin . "\n";
|
||||
}
|
||||
|
||||
$result .= str_repeat("\n", (int) ceil($this->margin / 2));
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
11
pma/vendor/bacon/bacon-qr-code/src/Renderer/RendererInterface.php
vendored
Normal file
11
pma/vendor/bacon/bacon-qr-code/src/Renderer/RendererInterface.php
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer;
|
||||
|
||||
use BaconQrCode\Encoder\QrCode;
|
||||
|
||||
interface RendererInterface
|
||||
{
|
||||
public function render(QrCode $qrCode) : string;
|
||||
}
|
||||
74
pma/vendor/bacon/bacon-qr-code/src/Renderer/RendererStyle/EyeFill.php
vendored
Normal file
74
pma/vendor/bacon/bacon-qr-code/src/Renderer/RendererStyle/EyeFill.php
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\RendererStyle;
|
||||
|
||||
use BaconQrCode\Exception\RuntimeException;
|
||||
use BaconQrCode\Renderer\Color\ColorInterface;
|
||||
|
||||
final class EyeFill
|
||||
{
|
||||
/**
|
||||
* @var ColorInterface|null
|
||||
*/
|
||||
private $externalColor;
|
||||
|
||||
/**
|
||||
* @var ColorInterface|null
|
||||
*/
|
||||
private $internalColor;
|
||||
|
||||
/**
|
||||
* @var self|null
|
||||
*/
|
||||
private static $inherit;
|
||||
|
||||
public function __construct(?ColorInterface $externalColor, ?ColorInterface $internalColor)
|
||||
{
|
||||
$this->externalColor = $externalColor;
|
||||
$this->internalColor = $internalColor;
|
||||
}
|
||||
|
||||
public static function uniform(ColorInterface $color) : self
|
||||
{
|
||||
return new self($color, $color);
|
||||
}
|
||||
|
||||
public static function inherit() : self
|
||||
{
|
||||
return self::$inherit ?: self::$inherit = new self(null, null);
|
||||
}
|
||||
|
||||
public function inheritsBothColors() : bool
|
||||
{
|
||||
return null === $this->externalColor && null === $this->internalColor;
|
||||
}
|
||||
|
||||
public function inheritsExternalColor() : bool
|
||||
{
|
||||
return null === $this->externalColor;
|
||||
}
|
||||
|
||||
public function inheritsInternalColor() : bool
|
||||
{
|
||||
return null === $this->internalColor;
|
||||
}
|
||||
|
||||
public function getExternalColor() : ColorInterface
|
||||
{
|
||||
if (null === $this->externalColor) {
|
||||
throw new RuntimeException('External eye color inherits foreground color');
|
||||
}
|
||||
|
||||
return $this->externalColor;
|
||||
}
|
||||
|
||||
public function getInternalColor() : ColorInterface
|
||||
{
|
||||
if (null === $this->internalColor) {
|
||||
throw new RuntimeException('Internal eye color inherits foreground color');
|
||||
}
|
||||
|
||||
return $this->internalColor;
|
||||
}
|
||||
}
|
||||
168
pma/vendor/bacon/bacon-qr-code/src/Renderer/RendererStyle/Fill.php
vendored
Normal file
168
pma/vendor/bacon/bacon-qr-code/src/Renderer/RendererStyle/Fill.php
vendored
Normal file
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\RendererStyle;
|
||||
|
||||
use BaconQrCode\Exception\RuntimeException;
|
||||
use BaconQrCode\Renderer\Color\ColorInterface;
|
||||
use BaconQrCode\Renderer\Color\Gray;
|
||||
|
||||
final class Fill
|
||||
{
|
||||
/**
|
||||
* @var ColorInterface
|
||||
*/
|
||||
private $backgroundColor;
|
||||
|
||||
/**
|
||||
* @var ColorInterface|null
|
||||
*/
|
||||
private $foregroundColor;
|
||||
|
||||
/**
|
||||
* @var Gradient|null
|
||||
*/
|
||||
private $foregroundGradient;
|
||||
|
||||
/**
|
||||
* @var EyeFill
|
||||
*/
|
||||
private $topLeftEyeFill;
|
||||
|
||||
/**
|
||||
* @var EyeFill
|
||||
*/
|
||||
private $topRightEyeFill;
|
||||
|
||||
/**
|
||||
* @var EyeFill
|
||||
*/
|
||||
private $bottomLeftEyeFill;
|
||||
|
||||
/**
|
||||
* @var self|null
|
||||
*/
|
||||
private static $default;
|
||||
|
||||
private function __construct(
|
||||
ColorInterface $backgroundColor,
|
||||
?ColorInterface $foregroundColor,
|
||||
?Gradient $foregroundGradient,
|
||||
EyeFill $topLeftEyeFill,
|
||||
EyeFill $topRightEyeFill,
|
||||
EyeFill $bottomLeftEyeFill
|
||||
) {
|
||||
$this->backgroundColor = $backgroundColor;
|
||||
$this->foregroundColor = $foregroundColor;
|
||||
$this->foregroundGradient = $foregroundGradient;
|
||||
$this->topLeftEyeFill = $topLeftEyeFill;
|
||||
$this->topRightEyeFill = $topRightEyeFill;
|
||||
$this->bottomLeftEyeFill = $bottomLeftEyeFill;
|
||||
}
|
||||
|
||||
public static function default() : self
|
||||
{
|
||||
return self::$default ?: self::$default = self::uniformColor(new Gray(100), new Gray(0));
|
||||
}
|
||||
|
||||
public static function withForegroundColor(
|
||||
ColorInterface $backgroundColor,
|
||||
ColorInterface $foregroundColor,
|
||||
EyeFill $topLeftEyeFill,
|
||||
EyeFill $topRightEyeFill,
|
||||
EyeFill $bottomLeftEyeFill
|
||||
) : self {
|
||||
return new self(
|
||||
$backgroundColor,
|
||||
$foregroundColor,
|
||||
null,
|
||||
$topLeftEyeFill,
|
||||
$topRightEyeFill,
|
||||
$bottomLeftEyeFill
|
||||
);
|
||||
}
|
||||
|
||||
public static function withForegroundGradient(
|
||||
ColorInterface $backgroundColor,
|
||||
Gradient $foregroundGradient,
|
||||
EyeFill $topLeftEyeFill,
|
||||
EyeFill $topRightEyeFill,
|
||||
EyeFill $bottomLeftEyeFill
|
||||
) : self {
|
||||
return new self(
|
||||
$backgroundColor,
|
||||
null,
|
||||
$foregroundGradient,
|
||||
$topLeftEyeFill,
|
||||
$topRightEyeFill,
|
||||
$bottomLeftEyeFill
|
||||
);
|
||||
}
|
||||
|
||||
public static function uniformColor(ColorInterface $backgroundColor, ColorInterface $foregroundColor) : self
|
||||
{
|
||||
return new self(
|
||||
$backgroundColor,
|
||||
$foregroundColor,
|
||||
null,
|
||||
EyeFill::inherit(),
|
||||
EyeFill::inherit(),
|
||||
EyeFill::inherit()
|
||||
);
|
||||
}
|
||||
|
||||
public static function uniformGradient(ColorInterface $backgroundColor, Gradient $foregroundGradient) : self
|
||||
{
|
||||
return new self(
|
||||
$backgroundColor,
|
||||
null,
|
||||
$foregroundGradient,
|
||||
EyeFill::inherit(),
|
||||
EyeFill::inherit(),
|
||||
EyeFill::inherit()
|
||||
);
|
||||
}
|
||||
|
||||
public function hasGradientFill() : bool
|
||||
{
|
||||
return null !== $this->foregroundGradient;
|
||||
}
|
||||
|
||||
public function getBackgroundColor() : ColorInterface
|
||||
{
|
||||
return $this->backgroundColor;
|
||||
}
|
||||
|
||||
public function getForegroundColor() : ColorInterface
|
||||
{
|
||||
if (null === $this->foregroundColor) {
|
||||
throw new RuntimeException('Fill uses a gradient, thus no foreground color is available');
|
||||
}
|
||||
|
||||
return $this->foregroundColor;
|
||||
}
|
||||
|
||||
public function getForegroundGradient() : Gradient
|
||||
{
|
||||
if (null === $this->foregroundGradient) {
|
||||
throw new RuntimeException('Fill uses a single color, thus no foreground gradient is available');
|
||||
}
|
||||
|
||||
return $this->foregroundGradient;
|
||||
}
|
||||
|
||||
public function getTopLeftEyeFill() : EyeFill
|
||||
{
|
||||
return $this->topLeftEyeFill;
|
||||
}
|
||||
|
||||
public function getTopRightEyeFill() : EyeFill
|
||||
{
|
||||
return $this->topRightEyeFill;
|
||||
}
|
||||
|
||||
public function getBottomLeftEyeFill() : EyeFill
|
||||
{
|
||||
return $this->bottomLeftEyeFill;
|
||||
}
|
||||
}
|
||||
46
pma/vendor/bacon/bacon-qr-code/src/Renderer/RendererStyle/Gradient.php
vendored
Normal file
46
pma/vendor/bacon/bacon-qr-code/src/Renderer/RendererStyle/Gradient.php
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\RendererStyle;
|
||||
|
||||
use BaconQrCode\Renderer\Color\ColorInterface;
|
||||
|
||||
final class Gradient
|
||||
{
|
||||
/**
|
||||
* @var ColorInterface
|
||||
*/
|
||||
private $startColor;
|
||||
|
||||
/**
|
||||
* @var ColorInterface
|
||||
*/
|
||||
private $endColor;
|
||||
|
||||
/**
|
||||
* @var GradientType
|
||||
*/
|
||||
private $type;
|
||||
|
||||
public function __construct(ColorInterface $startColor, ColorInterface $endColor, GradientType $type)
|
||||
{
|
||||
$this->startColor = $startColor;
|
||||
$this->endColor = $endColor;
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
public function getStartColor() : ColorInterface
|
||||
{
|
||||
return $this->startColor;
|
||||
}
|
||||
|
||||
public function getEndColor() : ColorInterface
|
||||
{
|
||||
return $this->endColor;
|
||||
}
|
||||
|
||||
public function getType() : GradientType
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
}
|
||||
22
pma/vendor/bacon/bacon-qr-code/src/Renderer/RendererStyle/GradientType.php
vendored
Normal file
22
pma/vendor/bacon/bacon-qr-code/src/Renderer/RendererStyle/GradientType.php
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\RendererStyle;
|
||||
|
||||
use DASPRiD\Enum\AbstractEnum;
|
||||
|
||||
/**
|
||||
* @method static self VERTICAL()
|
||||
* @method static self HORIZONTAL()
|
||||
* @method static self DIAGONAL()
|
||||
* @method static self INVERSE_DIAGONAL()
|
||||
* @method static self RADIAL()
|
||||
*/
|
||||
final class GradientType extends AbstractEnum
|
||||
{
|
||||
protected const VERTICAL = null;
|
||||
protected const HORIZONTAL = null;
|
||||
protected const DIAGONAL = null;
|
||||
protected const INVERSE_DIAGONAL = null;
|
||||
protected const RADIAL = null;
|
||||
}
|
||||
90
pma/vendor/bacon/bacon-qr-code/src/Renderer/RendererStyle/RendererStyle.php
vendored
Normal file
90
pma/vendor/bacon/bacon-qr-code/src/Renderer/RendererStyle/RendererStyle.php
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCode\Renderer\RendererStyle;
|
||||
|
||||
use BaconQrCode\Renderer\Eye\EyeInterface;
|
||||
use BaconQrCode\Renderer\Eye\ModuleEye;
|
||||
use BaconQrCode\Renderer\Module\ModuleInterface;
|
||||
use BaconQrCode\Renderer\Module\SquareModule;
|
||||
|
||||
final class RendererStyle
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $size;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $margin;
|
||||
|
||||
/**
|
||||
* @var ModuleInterface
|
||||
*/
|
||||
private $module;
|
||||
|
||||
/**
|
||||
* @var EyeInterface|null
|
||||
*/
|
||||
private $eye;
|
||||
|
||||
/**
|
||||
* @var Fill
|
||||
*/
|
||||
private $fill;
|
||||
|
||||
public function __construct(
|
||||
int $size,
|
||||
int $margin = 4,
|
||||
?ModuleInterface $module = null,
|
||||
?EyeInterface $eye = null,
|
||||
?Fill $fill = null
|
||||
) {
|
||||
$this->margin = $margin;
|
||||
$this->size = $size;
|
||||
$this->module = $module ?: SquareModule::instance();
|
||||
$this->eye = $eye ?: new ModuleEye($this->module);
|
||||
$this->fill = $fill ?: Fill::default();
|
||||
}
|
||||
|
||||
public function withSize(int $size) : self
|
||||
{
|
||||
$style = clone $this;
|
||||
$style->size = $size;
|
||||
return $style;
|
||||
}
|
||||
|
||||
public function withMargin(int $margin) : self
|
||||
{
|
||||
$style = clone $this;
|
||||
$style->margin = $margin;
|
||||
return $style;
|
||||
}
|
||||
|
||||
public function getSize() : int
|
||||
{
|
||||
return $this->size;
|
||||
}
|
||||
|
||||
public function getMargin() : int
|
||||
{
|
||||
return $this->margin;
|
||||
}
|
||||
|
||||
public function getModule() : ModuleInterface
|
||||
{
|
||||
return $this->module;
|
||||
}
|
||||
|
||||
public function getEye() : EyeInterface
|
||||
{
|
||||
return $this->eye;
|
||||
}
|
||||
|
||||
public function getFill() : Fill
|
||||
{
|
||||
return $this->fill;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user