AbstractWriter.php
3 years ago
BinaryWriter.php
3 years ago
DebugWriter.php
3 years ago
EpsWriter.php
3 years ago
FpdfWriter.php
3 years ago
PngWriter.php
3 years ago
SvgWriter.php
3 years ago
WriterInterface.php
3 years ago
EpsWriter.php
51 lines
| 1 | <?php |
| 2 | |
| 3 | declare (strict_types=1); |
| 4 | /* |
| 5 | * (c) Jeroen van den Enden <info@endroid.nl> |
| 6 | * |
| 7 | * This source file is subject to the MIT license that is bundled |
| 8 | * with this source code in the file LICENSE. |
| 9 | */ |
| 10 | namespace WP2FA_Vendor\Endroid\QrCode\Writer; |
| 11 | |
| 12 | use WP2FA_Vendor\Endroid\QrCode\QrCodeInterface; |
| 13 | class EpsWriter extends AbstractWriter |
| 14 | { |
| 15 | public function writeString(QrCodeInterface $qrCode) : string |
| 16 | { |
| 17 | $data = $qrCode->getData(); |
| 18 | $epsData = []; |
| 19 | $epsData[] = '%!PS-Adobe-3.0 EPSF-3.0'; |
| 20 | $epsData[] = '%%BoundingBox: 0 0 ' . $data['outer_width'] . ' ' . $data['outer_height']; |
| 21 | $epsData[] = '/F { rectfill } def'; |
| 22 | $epsData[] = \number_format($qrCode->getBackgroundColor()['r'] / 100, 2, '.', ',') . ' ' . \number_format($qrCode->getBackgroundColor()['g'] / 100, 2, '.', ',') . ' ' . \number_format($qrCode->getBackgroundColor()['b'] / 100, 2, '.', ',') . ' setrgbcolor'; |
| 23 | $epsData[] = '0 0 ' . $data['outer_width'] . ' ' . $data['outer_height'] . ' F'; |
| 24 | $epsData[] = \number_format($qrCode->getForegroundColor()['r'] / 100, 2, '.', ',') . ' ' . \number_format($qrCode->getForegroundColor()['g'] / 100, 2, '.', ',') . ' ' . \number_format($qrCode->getForegroundColor()['b'] / 100, 2, '.', ',') . ' setrgbcolor'; |
| 25 | // Please note an EPS has a reversed Y axis compared to PNG and SVG |
| 26 | $data['matrix'] = \array_reverse($data['matrix']); |
| 27 | foreach ($data['matrix'] as $row => $values) { |
| 28 | foreach ($values as $column => $value) { |
| 29 | if (1 === $value) { |
| 30 | $x = $data['margin_left'] + $data['block_size'] * $column; |
| 31 | $y = $data['margin_left'] + $data['block_size'] * $row; |
| 32 | $epsData[] = $x . ' ' . $y . ' ' . $data['block_size'] . ' ' . $data['block_size'] . ' F'; |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | return \implode("\n", $epsData); |
| 37 | } |
| 38 | public static function getContentType() : string |
| 39 | { |
| 40 | return 'image/eps'; |
| 41 | } |
| 42 | public static function getSupportedExtensions() : array |
| 43 | { |
| 44 | return ['eps']; |
| 45 | } |
| 46 | public function getName() : string |
| 47 | { |
| 48 | return 'eps'; |
| 49 | } |
| 50 | } |
| 51 |