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