Skip to content

Commit 877fcb0

Browse files
authored
Merge pull request #142 from str4to/TypeCode32
Added Type code32
2 parents e25a030 + a875c84 commit 877fcb0

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

Readme.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ These barcode types are supported. All types support different character sets or
6565

6666
Most used types are TYPE_CODE_128 and TYPE_CODE_39. Because of the best scanner support, variable length and most chars supported.
6767

68+
- TYPE_CODE_32 (italian pharmaceutical code 'MINSAN')
6869
- TYPE_CODE_39
6970
- TYPE_CODE_39_CHECKSUM
7071
- TYPE_CODE_39E
@@ -118,4 +119,4 @@ file_put_contents('barcode.jpg', $generator->getBarcode('081231723897', $generat
118119
### Oneliner SVG output to disk
119120
```php
120121
file_put_contents('barcode.svg', (new Picqer\Barcode\BarcodeGeneratorSVG())->getBarcode('6825ME601', Picqer\Barcode\BarcodeGeneratorSVG::TYPE_KIX));
121-
```
122+
```

src/BarcodeGenerator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use Picqer\Barcode\Types\TypeCode128A;
3737
use Picqer\Barcode\Types\TypeCode128B;
3838
use Picqer\Barcode\Types\TypeCode128C;
39+
use Picqer\Barcode\Types\TypeCode32;
3940
use Picqer\Barcode\Types\TypeCode39;
4041
use Picqer\Barcode\Types\TypeCode39Checksum;
4142
use Picqer\Barcode\Types\TypeCode39Extended;
@@ -63,6 +64,7 @@
6364

6465
abstract class BarcodeGenerator
6566
{
67+
const TYPE_CODE_32 = 'C32';
6668
const TYPE_CODE_39 = 'C39';
6769
const TYPE_CODE_39_CHECKSUM = 'C39+';
6870
const TYPE_CODE_39E = 'C39E'; // CODE 39 EXTENDED
@@ -104,6 +106,9 @@ protected function getBarcodeData(string $code, string $type): Barcode
104106
protected function createDataBuilderForType(string $type)
105107
{
106108
switch (strtoupper($type)) {
109+
case self::TYPE_CODE_32:
110+
return new TypeCode32();
111+
107112
case self::TYPE_CODE_39:
108113
return new TypeCode39();
109114

src/Types/TypeCode32.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace Picqer\Barcode\Types;
4+
5+
use Picqer\Barcode\Barcode;
6+
7+
/*
8+
* CODE 32 - italian pharmaceutical
9+
* General-purpose code in very wide use world-wide
10+
*/
11+
class TypeCode32 extends TypeCode39
12+
{
13+
protected $conversionTable32 = [
14+
'0' => '0',
15+
'1' => '1',
16+
'2' => '2',
17+
'3' => '3',
18+
'4' => '4',
19+
'5' => '5',
20+
'6' => '6',
21+
'7' => '7',
22+
'8' => '8',
23+
'9' => '9',
24+
'10' => 'B',
25+
'11' => 'C',
26+
'12' => 'D',
27+
'13' => 'F',
28+
'14' => 'G',
29+
'15' => 'H',
30+
'16' => 'J',
31+
'17' => 'K',
32+
'18' => 'L',
33+
'19' => 'M',
34+
'20' => 'N',
35+
'21' => 'P',
36+
'22' => 'Q',
37+
'23' => 'R',
38+
'24' => 'S',
39+
'25' => 'T',
40+
'26' => 'U',
41+
'27' => 'V',
42+
'28' => 'W',
43+
'29' => 'X',
44+
'30' => 'Y',
45+
'31' => 'Z'
46+
];
47+
48+
public function getBarcodeData(string $code): Barcode
49+
{
50+
$code39 = '';
51+
$codeElab = $code;
52+
53+
for ($e = 5; $e >= 0; $e--) {
54+
$code39 .= $this->conversionTable32[intval($codeElab / pow(32,$e))];
55+
$codeElab = intval($codeElab % pow(32,$e));
56+
}
57+
58+
return parent::getBarcodeData($code39);
59+
}
60+
}

0 commit comments

Comments
 (0)