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 / BarcodeGeneratorDynamicHTML.php

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

37 lines 1.8 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 BarcodeGeneratorDynamicHTML extends BarcodeGenerator
6 {
7 private const WIDTH_PRECISION = 6;
8 /**
9 * Return an HTML representation of barcode.
10 * This 'dynamic' version uses percentage based widths and heights, resulting in a vector-y qualitative result.
11 *
12 * @param string $barcode code to print
13 * @param BarcodeGenerator::TYPE_* $type (string) type of barcode
14 * @param string $foregroundColor Foreground color for bar elements as '#333' or 'orange' for example (background is transparent).
15 * @return string HTML code.
16 */
17 public function getBarcode(string $barcode, $type, string $foregroundColor = 'black') : string
18 {
19 $barcodeData = $this->getBarcodeData($barcode, $type);
20 $html = '<div style="font-size:0;position:relative;width:100%;height:100%">' . \PHP_EOL;
21 $positionHorizontal = 0;
22 /** @var BarcodeBar $bar */
23 foreach ($barcodeData->getBars() as $bar) {
24 $barWidth = $bar->getWidth() / $barcodeData->getWidth() * 100;
25 $barHeight = \round($bar->getHeight() / $barcodeData->getHeight() * 100, 3);
26 if ($bar->isBar() && $barWidth > 0) {
27 $positionVertical = \round($bar->getPositionVertical() / $barcodeData->getHeight() * 100, 3);
28 // draw a vertical bar
29 $html .= '<div style="background-color:' . $foregroundColor . ';width:' . \round($barWidth, self::WIDTH_PRECISION) . '%;height:' . $barHeight . '%;position:absolute;left:' . \round($positionHorizontal, self::WIDTH_PRECISION) . '%;top:' . $positionVertical . ($positionVertical > 0 ? '%' : '') . '">&nbsp;</div>' . \PHP_EOL;
30 }
31 $positionHorizontal += $barWidth;
32 }
33 $html .= '</div>' . \PHP_EOL;
34 return $html;
35 }
36 }
37