PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.20
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.20
1.10.20 1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 All 164 releases
woocommerce-pos / vendor_prefixed / picqer / php-barcode-generator / src / BarcodeGeneratorSVG.php

BarcodeGeneratorSVG.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.20, at vendor_prefixed/picqer/php-barcode-generator/src/BarcodeGeneratorSVG.php

47 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WCPOS\Vendor\Picqer\Barcode;
4
5 class BarcodeGeneratorSVG extends BarcodeGenerator
6 {
7 /**
8 * Return a SVG string representation of barcode.
9 *
10 * @param $barcode (string) code to print
11 * @param BarcodeGenerator::TYPE_* $type (string) type of barcode
12 * @param $widthFactor (float) Minimum width of a single bar in user units.
13 * @param $height (float) Height of barcode in user units.
14 * @param $foregroundColor (string) Foreground color (in SVG format) for bar elements (background is transparent).
15 * @return string SVG code.
16 * @public
17 */
18 public function getBarcode(string $barcode, $type, float $widthFactor = 2, float $height = 30, string $foregroundColor = 'black') : string
19 {
20 $barcodeData = $this->getBarcodeData($barcode, $type);
21 // replace table for special characters
22 $repstr = ["\x00" => '', '&' => '&amp;', '<' => '&lt;', '>' => '&gt;'];
23 $width = \round($barcodeData->getWidth() * $widthFactor, 3);
24 $svg = '<?xml version="1.0" standalone="no" ?>' . \PHP_EOL;
25 $svg .= '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">' . \PHP_EOL;
26 $svg .= '<svg width="' . $width . '" height="' . $height . '" viewBox="0 0 ' . $width . ' ' . $height . '" version="1.1" xmlns="http://www.w3.org/2000/svg">' . \PHP_EOL;
27 $svg .= "\t" . '<desc>' . \strtr($barcodeData->getBarcode(), $repstr) . '</desc>' . \PHP_EOL;
28 $svg .= "\t" . '<g id="bars" fill="' . $foregroundColor . '" stroke="none">' . \PHP_EOL;
29 // print bars
30 $positionHorizontal = 0;
31 /** @var BarcodeBar $bar */
32 foreach ($barcodeData->getBars() as $bar) {
33 $barWidth = \round($bar->getWidth() * $widthFactor, 3);
34 $barHeight = \round($bar->getHeight() * $height / $barcodeData->getHeight(), 3);
35 if ($bar->isBar() && $barWidth > 0) {
36 $positionVertical = \round($bar->getPositionVertical() * $height / $barcodeData->getHeight(), 3);
37 // draw a vertical bar
38 $svg .= "\t\t" . '<rect x="' . $positionHorizontal . '" y="' . $positionVertical . '" width="' . $barWidth . '" height="' . $barHeight . '" />' . \PHP_EOL;
39 }
40 $positionHorizontal += $barWidth;
41 }
42 $svg .= "\t</g>" . \PHP_EOL;
43 $svg .= '</svg>' . \PHP_EOL;
44 return $svg;
45 }
46 }
47