vendor/endroid/qr-code/src/Writer/EpsWriter.php line 18

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Endroid\QrCode\Writer;
  4. use Endroid\QrCode\Bacon\MatrixFactory;
  5. use Endroid\QrCode\Label\LabelInterface;
  6. use Endroid\QrCode\Logo\LogoInterface;
  7. use Endroid\QrCode\QrCodeInterface;
  8. use Endroid\QrCode\Writer\Result\EpsResult;
  9. use Endroid\QrCode\Writer\Result\ResultInterface;
  10. final class EpsWriter implements WriterInterface
  11. {
  12.     public const DECIMAL_PRECISION 10;
  13.     public function write(QrCodeInterface $qrCodeLogoInterface $logo nullLabelInterface $label null, array $options = []): ResultInterface
  14.     {
  15.         $matrixFactory = new MatrixFactory();
  16.         $matrix $matrixFactory->create($qrCode);
  17.         $lines = [
  18.             '%!PS-Adobe-3.0 EPSF-3.0',
  19.             '%%BoundingBox: 0 0 '.$matrix->getOuterSize().' '.$matrix->getOuterSize(),
  20.             '/F { rectfill } def',
  21.             number_format($qrCode->getBackgroundColor()->getRed() / 1002'.'',').' '.number_format($qrCode->getBackgroundColor()->getGreen() / 1002'.'',').' '.number_format($qrCode->getBackgroundColor()->getBlue() / 1002'.'',').' setrgbcolor',
  22.             '0 0 '.$matrix->getOuterSize().' '.$matrix->getOuterSize().' F',
  23.             number_format($qrCode->getForegroundColor()->getRed() / 1002'.'',').' '.number_format($qrCode->getForegroundColor()->getGreen() / 1002'.'',').' '.number_format($qrCode->getForegroundColor()->getBlue() / 1002'.'',').' setrgbcolor',
  24.         ];
  25.         for ($rowIndex 0$rowIndex $matrix->getBlockCount(); ++$rowIndex) {
  26.             for ($columnIndex 0$columnIndex $matrix->getBlockCount(); ++$columnIndex) {
  27.                 if (=== $matrix->getBlockValue($matrix->getBlockCount() - $rowIndex$columnIndex)) {
  28.                     $x $matrix->getMarginLeft() + $matrix->getBlockSize() * $columnIndex;
  29.                     $y $matrix->getMarginLeft() + $matrix->getBlockSize() * $rowIndex;
  30.                     $lines[] = number_format($xself::DECIMAL_PRECISION'.''').' '.number_format($yself::DECIMAL_PRECISION'.''').' '.number_format($matrix->getBlockSize(), self::DECIMAL_PRECISION'.''').' '.number_format($matrix->getBlockSize(), self::DECIMAL_PRECISION'.''').' F';
  31.                 }
  32.             }
  33.         }
  34.         return new EpsResult($matrix$lines);
  35.     }
  36. }