diff options
Diffstat (limited to 'srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer')
36 files changed, 3553 insertions, 0 deletions
diff --git a/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Color/Alpha.php b/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Color/Alpha.php new file mode 100644 index 0000000..3490252 --- /dev/null +++ b/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Color/Alpha.php @@ -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(); + } +} diff --git a/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Color/Cmyk.php b/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Color/Cmyk.php new file mode 100644 index 0000000..d6de390 --- /dev/null +++ b/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Color/Cmyk.php @@ -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(); + } +} diff --git a/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Color/ColorInterface.php b/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Color/ColorInterface.php new file mode 100644 index 0000000..b50d1ca --- /dev/null +++ b/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Color/ColorInterface.php @@ -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; +} diff --git a/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Color/Gray.php b/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Color/Gray.php new file mode 100644 index 0000000..acb986d --- /dev/null +++ b/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Color/Gray.php @@ -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; + } +} diff --git a/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Color/Rgb.php b/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Color/Rgb.php new file mode 100644 index 0000000..7935406 --- /dev/null +++ b/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Color/Rgb.php @@ -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)); + } +} diff --git a/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Eye/CompositeEye.php b/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Eye/CompositeEye.php new file mode 100644 index 0000000..a3e1909 --- /dev/null +++ b/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Eye/CompositeEye.php @@ -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(); + } +} diff --git a/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Eye/EyeInterface.php b/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Eye/EyeInterface.php new file mode 100644 index 0000000..ab68f3c --- /dev/null +++ b/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Eye/EyeInterface.php @@ -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; +} diff --git a/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Eye/ModuleEye.php b/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Eye/ModuleEye.php new file mode 100644 index 0000000..84f7d12 --- /dev/null +++ b/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Eye/ModuleEye.php @@ -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); + } +} diff --git a/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Eye/SimpleCircleEye.php b/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Eye/SimpleCircleEye.php new file mode 100644 index 0000000..64d54ee --- /dev/null +++ b/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Eye/SimpleCircleEye.php @@ -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() + ; + } +} diff --git a/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Eye/SquareEye.php b/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Eye/SquareEye.php new file mode 100644 index 0000000..a3892b4 --- /dev/null +++ b/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Eye/SquareEye.php @@ -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() + ; + } +} diff --git a/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Image/EpsImageBackEnd.php b/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Image/EpsImageBackEnd.php new file mode 100644 index 0000000..b581b54 --- /dev/null +++ b/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Renderer/Image/EpsImageBackEnd.php @@ -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; + |
