| 123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\librarys\Picqer\Barcode\Helpers;
- use app\librarys\Picqer\Barcode\Barcode;
- use app\librarys\Picqer\Barcode\BarcodeBar;
- /**
- * Convert binary barcode sequence string to Barcode representation.
- */
- class BinarySequenceConverter
- {
- public static function convert(string $code, string $sequence): Barcode
- {
- $barcode = new Barcode($code);
- $len = strlen($sequence);
- $barWidth = 0;
- for ($i = 0; $i < $len; ++$i) {
- $barWidth += 1;
- if (($i == ($len - 1)) || (($i < ($len - 1)) && ($sequence[$i] != $sequence[($i + 1)]))) {
- if ($sequence[$i] == '1') {
- $drawBar = true;
- } else {
- $drawBar = false;
- }
- $barcode->addBar(new BarcodeBar($barWidth, 1, $drawBar));
- $barWidth = 0;
- }
- }
- return $barcode;
- }
- }
|