PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.18
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.18
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 / BarcodeGeneratorHTML.php

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

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