1 | <?php |
||
19 | class SvgWriter extends AbstractWriter |
||
20 | { |
||
21 | /** |
||
22 | * SvgWriter constructor. |
||
23 | */ |
||
24 | public function __construct() |
||
25 | { |
||
26 | parent::__construct(new Svg()); |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * @inheritdoc |
||
31 | */ |
||
32 | public function writeString(QrCodeInterface $qrCode) |
||
33 | { |
||
34 | /** @var Svg $renderer */ |
||
35 | $renderer = $this->renderer; |
||
36 | $renderer->setWidth($qrCode->getSize()); |
||
37 | $renderer->setHeight($qrCode->getSize()); |
||
38 | $renderer->setMargin(0); |
||
39 | $renderer->setForegroundColor($this->convertColor($qrCode->getForegroundColor())); |
||
40 | $renderer->setBackgroundColor($this->convertColor($qrCode->getBackgroundColor())); |
||
41 | $writer = new Writer($renderer); |
||
42 | |||
43 | $string = $writer->writeString( |
||
44 | $qrCode->getText(), |
||
45 | $qrCode->getEncoding(), |
||
46 | $this->convertErrorCorrectionLevel($qrCode->getErrorCorrectionLevel()) |
||
47 | ); |
||
48 | |||
49 | $string = $this->addMargin($string, $qrCode->getMargin(), $qrCode->getSize()); |
||
|
|||
50 | |||
51 | return $string; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @return string |
||
56 | */ |
||
57 | public function getContentType() |
||
61 | |||
62 | /** |
||
63 | * @param string $string |
||
64 | * @param int $margin |
||
65 | * @param int $size |
||
66 | * @return string |
||
67 | */ |
||
68 | protected function addMargin($string, $margin, $size) |
||
95 | } |
||
96 |