├── RELEASE ├── VERSION ├── resources ├── debian │ ├── compat │ ├── source │ │ └── format │ ├── rules │ ├── changelog │ ├── copyright │ └── control ├── phpmd │ ├── design.xml │ └── codesize.xml ├── autoload.php └── rpm │ └── rpm.spec ├── .github └── FUNDING.yml ├── .gitignore ├── phpcompatinfo.json ├── phpunit.xml.dist ├── src ├── Exception.php ├── Type │ ├── Linear.php │ ├── Square.php │ ├── Linear │ │ ├── Raw.php │ │ ├── Msi.php │ │ ├── CodeThreeNine.php │ │ ├── StandardTwoOfFive.php │ │ ├── InterleavedTwoOfFive.php │ │ ├── CodeThreeNineExt.php │ │ ├── CodeThreeNineCheck.php │ │ ├── Planet.php │ │ ├── UpcA.php │ │ ├── KlantIndex.php │ │ ├── CodeOneTwoEight │ │ │ ├── A.php │ │ │ ├── B.php │ │ │ └── C.php │ │ ├── Pharma.php │ │ ├── EanEight.php │ │ ├── EanFive.php │ │ ├── ImbPre.php │ │ ├── PharmaTwoTracks.php │ │ ├── Codabar.php │ │ ├── Postnet.php │ │ ├── StandardTwoOfFiveCheck.php │ │ ├── MsiCheck.php │ │ ├── EanTwo.php │ │ ├── InterleavedTwoOfFiveCheck.php │ │ ├── CodeOneOne.php │ │ ├── UpcE.php │ │ ├── EanOneThree.php │ │ └── RoyalMailFourCc.php │ ├── Square │ │ ├── Raw.php │ │ ├── Datamatrix │ │ │ └── ErrorCorrection.php │ │ └── QrCode │ │ │ ├── InputItem.php │ │ │ ├── MaskNum.php │ │ │ ├── Estimate.php │ │ │ └── SpecRs.php │ ├── Raw.php │ └── Convert.php └── Barcode.php ├── test ├── Square │ └── RawTest.php ├── Linear │ ├── EanTwoTest.php │ ├── EanFiveTest.php │ ├── PharmaTwoTracksTest.php │ ├── RawTest.php │ ├── EanEightTest.php │ ├── PharmaTest.php │ ├── MsiTest.php │ ├── InterleavedTwoOfFiveTest.php │ ├── StandardTwoOfFiveTest.php │ ├── CodeThreeNineExtTest.php │ ├── CodeThreeNineCheckTest.php │ ├── KlantIndexTest.php │ ├── PlanetTest.php │ ├── CodabarTest.php │ ├── UpcATest.php │ ├── InterleavedTwoOfFiveCheckTest.php │ ├── CodeThreeNineTest.php │ ├── StandardTwoOfFiveCheckTest.php │ ├── MsiCheckTest.php │ ├── CodeThreeNineExtCheckTest.php │ ├── PostnetTest.php │ ├── RoyalMailFourCcTest.php │ ├── EanOneThreeTest.php │ ├── CodeOneTwoEight │ │ ├── BTest.php │ │ ├── ATest.php │ │ └── CTest.php │ ├── ImbPreTest.php │ ├── CodeOneOneTest.php │ ├── CodeNineThreeTest.php │ ├── UpcETest.php │ └── ImbTest.php └── TestStrings.php ├── composer.json ├── .travis.yml └── example └── index.php /RELEASE: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 1.16.1 2 | -------------------------------------------------------------------------------- /resources/debian/compat: -------------------------------------------------------------------------------- 1 | 9 2 | -------------------------------------------------------------------------------- /resources/debian/source/format: -------------------------------------------------------------------------------- 1 | 3.0 (quilt) 2 | -------------------------------------------------------------------------------- /resources/debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | %: 3 | dh $@ 4 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | custom: ['https://www.paypal.com/cgi-bin/webscr?cmd=_donations¤cy_code=GBP&business=paypal@tecnick.com&item_name=donation%20for%20tc-lib-barcode%20project'] 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | composer.lock 2 | vendor 3 | target 4 | phpunit.xml 5 | **/auth.json 6 | **/.vagrant 7 | **/nbproject 8 | **/.idea 9 | **/.DS_Store 10 | **/.#* 11 | **/._* 12 | **/*.tmp 13 | **/*.bak 14 | **/temp.php 15 | example/test.php 16 | -------------------------------------------------------------------------------- /resources/debian/changelog: -------------------------------------------------------------------------------- 1 | ~#PKGNAME#~ (~#VERSION#~-~#RELEASE#~) UNRELEASED; urgency=low 2 | 3 | * Please check the 4 | https://github.com/~#VENDOR#~/~#PROJECT#~ 5 | commit history 6 | 7 | -- Nicola Asuni ~#DATE#~ 8 | -------------------------------------------------------------------------------- /phpcompatinfo.json: -------------------------------------------------------------------------------- 1 | { 2 | "source-providers": [ 3 | { 4 | "in": "src as source", 5 | "exclude": "vendor", 6 | "name": "/\\.(php)$/" 7 | } 8 | ], 9 | "plugins": [ 10 | ], 11 | "analysers": [ 12 | ], 13 | "services": [ 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | ./test 15 | 16 | 17 | 18 | 19 | src 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /resources/phpmd/design.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | Created with the PHP Coding Standard Generator. http://edorian.github.com/php-coding-standard-generator/ 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /resources/autoload.php: -------------------------------------------------------------------------------- 1 | 11 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 12 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 13 | * @link https://github.com/tecnickcom/tc-lib-barcode 14 | * 15 | * This file is part of tc-lib-barcode software library. 16 | */ 17 | spl_autoload_register( 18 | function ($class) { 19 | $prefix = 'Com\\Tecnick\\'; 20 | $len = strlen($prefix); 21 | if (strncmp($prefix, $class, $len) !== 0) { 22 | return; 23 | } 24 | $relative_class = substr($class, $len); 25 | $file = dirname(__DIR__).'/'.str_replace('\\', '/', $relative_class).'.php'; 26 | if (file_exists($file)) { 27 | require $file; 28 | } 29 | } 30 | ); 31 | -------------------------------------------------------------------------------- /resources/debian/copyright: -------------------------------------------------------------------------------- 1 | Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | Upstream-Name: ~#PROJECT#~ 3 | Source: https://github.com/~#VENDOR#~/~#PROJECT#~ 4 | 5 | Files: * 6 | Copyright: Copyright 2001-2017 Nicola Asuni 7 | License: LGPL-3 8 | 9 | License: LGPL-3 10 | This program is free software: you can redistribute it and/or modify 11 | it under the terms of the GNU Lesser General Public License as 12 | published by the Free Software Foundation, either version 3 of the 13 | License, or (at your option) any later version. 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see or 20 | /usr/share/common-licenses/LGPL-3 21 | -------------------------------------------------------------------------------- /src/Exception.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode; 17 | 18 | /** 19 | * Com\Tecnick\Barcode\Exception 20 | * 21 | * Custom Exception class 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class Exception extends \Exception 32 | { 33 | } 34 | -------------------------------------------------------------------------------- /resources/debian/control: -------------------------------------------------------------------------------- 1 | Source: ~#PKGNAME#~ 2 | Maintainer: Nicola Asuni 3 | Section: php 4 | Priority: optional 5 | Build-Depends: debhelper (>= 9) 6 | Standards-Version: 3.9.7 7 | Homepage: https://github.com/~#VENDOR#~/~#PROJECT#~ 8 | Vcs-Git: https://github.com/~#VENDOR#~/~#PROJECT#~.git 9 | 10 | Package: ~#PKGNAME#~ 11 | Provides: php-~#PROJECT#~ 12 | Architecture: all 13 | Depends: php (>= 5.4.0), php-bcmath, php-date, php-gd, php-tecnickcom-tc-lib-color (<< 2.0.0), php-tecnickcom-tc-lib-color (>= 1.12.15), ${misc:Depends} 14 | Description: PHP Barcode library 15 | This library includes PHP classes to generate linear 16 | and bidimensional barcodes: 17 | CODE 39, ANSI MH10.8M-1983, USD-3, 3 of 9, CODE 93, 18 | USS-93, Standard 2 of 5, Interleaved 2 of 5, CODE 128 A/B/C, 19 | 2 and 5 Digits UPC-Based Extension, EAN 8, EAN 13, UPC-A, 20 | UPC-E, MSI, POSTNET, PLANET, RMS4CC (Royal Mail 4-state Customer Code), 21 | CBC (Customer Bar Code), KIX (Klant index - Customer index), 22 | Intelligent Mail Barcode, Onecode, USPS-B-3200, CODABAR, CODE 11, 23 | PHARMACODE, PHARMACODE TWO-TRACKS, Datamatrix ECC200, QR-Code, PDF417. 24 | -------------------------------------------------------------------------------- /src/Type/Linear.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type; 17 | 18 | /** 19 | * Com\Tecnick\Barcode\Type\Linear 20 | * 21 | * Barcode type class 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | abstract class Linear extends \Com\Tecnick\Barcode\Type 32 | { 33 | /** 34 | * Barcode type 35 | * 36 | * @var string 37 | */ 38 | protected $type = 'linear'; 39 | } 40 | -------------------------------------------------------------------------------- /src/Type/Square.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type; 17 | 18 | /** 19 | * Com\Tecnick\Barcode\Type\Square 20 | * 21 | * Barcode type class 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | abstract class Square extends \Com\Tecnick\Barcode\Type 32 | { 33 | /** 34 | * Barcode type 35 | * 36 | * @var string 37 | */ 38 | protected $type = 'square'; 39 | } 40 | -------------------------------------------------------------------------------- /resources/phpmd/codesize.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | Created with the PHP Coding Standard Generator. http://edorian.github.com/php-coding-standard-generator/ 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/Type/Linear/Raw.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Linear; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | 20 | /** 21 | * Com\Tecnick\Barcode\Type\Linear\Raw 22 | * 23 | * Raw Barcode type class 24 | * RAW MODE (comma-separated rows) 25 | * 26 | * @since 2015-02-21 27 | * @category Library 28 | * @package Barcode 29 | * @author Nicola Asuni 30 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 31 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 32 | * @link https://github.com/tecnickcom/tc-lib-barcode 33 | */ 34 | class Raw extends \Com\Tecnick\Barcode\Type\Raw 35 | { 36 | /** 37 | * Barcode type 38 | * 39 | * @var string 40 | */ 41 | protected $type = 'linear'; 42 | 43 | /** 44 | * Barcode format 45 | * 46 | * @var string 47 | */ 48 | protected $format = 'LRAW'; 49 | } 50 | -------------------------------------------------------------------------------- /src/Type/Square/Raw.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Square; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | 20 | /** 21 | * Com\Tecnick\Barcode\Type\Square\Raw 22 | * 23 | * Raw Barcode type class 24 | * RAW MODE (comma-separated rows) 25 | * 26 | * @since 2015-02-21 27 | * @category Library 28 | * @package Barcode 29 | * @author Nicola Asuni 30 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 31 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 32 | * @link https://github.com/tecnickcom/tc-lib-barcode 33 | */ 34 | class Raw extends \Com\Tecnick\Barcode\Type\Raw 35 | { 36 | /** 37 | * Barcode type 38 | * 39 | * @var string 40 | */ 41 | protected $type = 'square'; 42 | 43 | /** 44 | * Barcode format 45 | * 46 | * @var string 47 | */ 48 | protected $format = 'SRAW'; 49 | } 50 | -------------------------------------------------------------------------------- /src/Type/Linear/Msi.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Linear; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | 20 | /** 21 | * Com\Tecnick\Barcode\Type\Linear\Msi; 22 | * 23 | * Msi Barcode type class 24 | * MSI (Variation of Plessey code) 25 | * 26 | * @since 2015-02-21 27 | * @category Library 28 | * @package Barcode 29 | * @author Nicola Asuni 30 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 31 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 32 | * @link https://github.com/tecnickcom/tc-lib-barcode 33 | */ 34 | class Msi extends \Com\Tecnick\Barcode\Type\Linear\MsiCheck 35 | { 36 | /** 37 | * Barcode format 38 | * 39 | * @var string 40 | */ 41 | protected $format = 'MSI'; 42 | 43 | /** 44 | * Format code 45 | */ 46 | protected function formatCode() 47 | { 48 | $this->extcode = $this->code; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Type/Linear/CodeThreeNine.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Linear; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | 20 | /** 21 | * Com\Tecnick\Barcode\CodeThreeNine 22 | * 23 | * CodeThreeNine Barcode type class 24 | * CODE 39 25 | * 26 | * @since 2015-02-21 27 | * @category Library 28 | * @package Barcode 29 | * @author Nicola Asuni 30 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 31 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 32 | * @link https://github.com/tecnickcom/tc-lib-barcode 33 | */ 34 | class CodeThreeNine extends \Com\Tecnick\Barcode\Type\Linear\CodeThreeNineExtCheck 35 | { 36 | /** 37 | * Barcode format 38 | * 39 | * @var string 40 | */ 41 | protected $format = 'C39'; 42 | 43 | /** 44 | * Format code 45 | */ 46 | protected function formatCode() 47 | { 48 | $this->extcode = '*'.strtoupper($this->code).'*'; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /test/Square/RawTest.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Test\Square; 17 | 18 | use PHPUnit\Framework\TestCase; 19 | 20 | /** 21 | * Barcode class test 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class RawTest extends TestCase 32 | { 33 | protected $obj = null; 34 | 35 | public function setUp() 36 | { 37 | //$this->markTestSkipped(); // skip this test 38 | $this->obj = new \Com\Tecnick\Barcode\Barcode; 39 | } 40 | 41 | public function testGetGrid() 42 | { 43 | $bobj = $this->obj->getBarcodeObj('SRAW', '0101,1010,1100,0011'); 44 | $grid = $bobj->getGrid(); 45 | $expected = "0101\n1010\n1100\n0011\n"; 46 | $this->assertEquals($expected, $grid); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Type/Linear/StandardTwoOfFive.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Linear; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | 20 | /** 21 | * Com\Tecnick\Barcode\Type\Linear\StandardTwoOfFive; 22 | * 23 | * StandardTwoOfFive Barcode type class 24 | * Standard 2 of 5 25 | * 26 | * @since 2015-02-21 27 | * @category Library 28 | * @package Barcode 29 | * @author Nicola Asuni 30 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 31 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 32 | * @link https://github.com/tecnickcom/tc-lib-barcode 33 | */ 34 | class StandardTwoOfFive extends \Com\Tecnick\Barcode\Type\Linear\StandardTwoOfFiveCheck 35 | { 36 | /** 37 | * Barcode format 38 | * 39 | * @var string 40 | */ 41 | protected $format = 'S25'; 42 | 43 | /** 44 | * Format code 45 | */ 46 | protected function formatCode() 47 | { 48 | $this->extcode = $this->code; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Type/Linear/InterleavedTwoOfFive.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Linear; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | 20 | /** 21 | * Com\Tecnick\Barcode\Type\Linear\InterleavedTwoOfFive; 22 | * 23 | * InterleavedTwoOfFive Barcode type class 24 | * Interleaved 2 of 5 25 | * 26 | * @since 2015-02-21 27 | * @category Library 28 | * @package Barcode 29 | * @author Nicola Asuni 30 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 31 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 32 | * @link https://github.com/tecnickcom/tc-lib-barcode 33 | */ 34 | class InterleavedTwoOfFive extends \Com\Tecnick\Barcode\Type\Linear\InterleavedTwoOfFiveCheck 35 | { 36 | /** 37 | * Barcode format 38 | * 39 | * @var string 40 | */ 41 | protected $format = 'I25'; 42 | 43 | /** 44 | * Format code 45 | */ 46 | protected function formatCode() 47 | { 48 | $this->extcode = $this->code; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /test/Linear/EanTwoTest.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Test\Linear; 17 | 18 | use PHPUnit\Framework\TestCase; 19 | 20 | /** 21 | * Barcode class test 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class EanTwoTest extends TestCase 32 | { 33 | protected $obj = null; 34 | 35 | public function setUp() 36 | { 37 | //$this->markTestSkipped(); // skip this test 38 | $this->obj = new \Com\Tecnick\Barcode\Barcode; 39 | } 40 | 41 | public function testGetGrid() 42 | { 43 | $bobj = $this->obj->getBarcodeObj( 44 | 'EAN2', 45 | '12' 46 | ); 47 | $grid = $bobj->getGrid(); 48 | $expected = "10110011001010010011\n"; 49 | $this->assertEquals($expected, $grid); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Type/Linear/CodeThreeNineExt.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Linear; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | 20 | /** 21 | * Com\Tecnick\Barcode\CodeThreeNineExt 22 | * 23 | * CodeThreeNineExt Barcode type class 24 | * CODE 39 EXTENDED 25 | * 26 | * @since 2015-02-21 27 | * @category Library 28 | * @package Barcode 29 | * @author Nicola Asuni 30 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 31 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 32 | * @link https://github.com/tecnickcom/tc-lib-barcode 33 | */ 34 | class CodeThreeNineExt extends \Com\Tecnick\Barcode\Type\Linear\CodeThreeNineExtCheck 35 | { 36 | /** 37 | * Barcode format 38 | * 39 | * @var string 40 | */ 41 | protected $format = 'C39E'; 42 | 43 | /** 44 | * Format code 45 | */ 46 | protected function formatCode() 47 | { 48 | $this->extcode = '*'.$this->getExtendCode(strtoupper($this->code)).'*'; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /test/Linear/EanFiveTest.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Test\Linear; 17 | 18 | use PHPUnit\Framework\TestCase; 19 | 20 | /** 21 | * Barcode class test 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class EanFiveTest extends TestCase 32 | { 33 | protected $obj = null; 34 | 35 | public function setUp() 36 | { 37 | //$this->markTestSkipped(); // skip this test 38 | $this->obj = new \Com\Tecnick\Barcode\Barcode; 39 | } 40 | 41 | public function testGetGrid() 42 | { 43 | $bobj = $this->obj->getBarcodeObj( 44 | 'EAN5', 45 | '12345' 46 | ); 47 | $grid = $bobj->getGrid(); 48 | $expected = "10110110011010010011010100001010100011010110001\n"; 49 | $this->assertEquals($expected, $grid); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /test/Linear/PharmaTwoTracksTest.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Test\Linear; 17 | 18 | use PHPUnit\Framework\TestCase; 19 | 20 | /** 21 | * Barcode class test 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class PharmaTwoTracksTest extends TestCase 32 | { 33 | protected $obj = null; 34 | 35 | public function setUp() 36 | { 37 | //$this->markTestSkipped(); // skip this test 38 | $this->obj = new \Com\Tecnick\Barcode\Barcode; 39 | } 40 | 41 | public function testGetGrid() 42 | { 43 | $bobj = $this->obj->getBarcodeObj('PHARMA2T', '0123456789'); 44 | $grid = $bobj->getGrid(); 45 | $expected = "101000001010100010001010001000101\n000010101010001010101000100010001\n"; 46 | $this->assertEquals($expected, $grid); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Type/Linear/CodeThreeNineCheck.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Linear; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | 20 | /** 21 | * Com\Tecnick\Barcode\CodeThreeNineCheck 22 | * 23 | * CodeThreeNineCheck Barcode type class 24 | * CODE 39 + CHECKSUM 25 | * 26 | * @since 2015-02-21 27 | * @category Library 28 | * @package Barcode 29 | * @author Nicola Asuni 30 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 31 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 32 | * @link https://github.com/tecnickcom/tc-lib-barcode 33 | */ 34 | class CodeThreeNineCheck extends \Com\Tecnick\Barcode\Type\Linear\CodeThreeNineExtCheck 35 | { 36 | /** 37 | * Barcode format 38 | * 39 | * @var string 40 | */ 41 | protected $format = 'C39+'; 42 | 43 | /** 44 | * Format code 45 | */ 46 | protected function formatCode() 47 | { 48 | $code = strtoupper($this->code); 49 | $this->extcode = '*'.$code.$this->getChecksum($code).'*'; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /test/Linear/RawTest.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Test\Linear; 17 | 18 | use PHPUnit\Framework\TestCase; 19 | 20 | /** 21 | * Barcode class test 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class RawTest extends TestCase 32 | { 33 | protected $obj = null; 34 | 35 | public function setUp() 36 | { 37 | //$this->markTestSkipped(); // skip this test 38 | $this->obj = new \Com\Tecnick\Barcode\Barcode; 39 | } 40 | 41 | public function testGetGrid() 42 | { 43 | $bobj = $this->obj->getBarcodeObj( 44 | 'LRAW', 45 | '01001100011100001111,10110011100011110000' 46 | ); 47 | $grid = $bobj->getGrid(); 48 | $expected = "01001100011100001111\n10110011100011110000\n"; 49 | $this->assertEquals($expected, $grid); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /test/Linear/EanEightTest.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Test\Linear; 17 | 18 | use PHPUnit\Framework\TestCase; 19 | 20 | /** 21 | * Barcode class test 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class EanEightTest extends TestCase 32 | { 33 | protected $obj = null; 34 | 35 | public function setUp() 36 | { 37 | //$this->markTestSkipped(); // skip this test 38 | $this->obj = new \Com\Tecnick\Barcode\Barcode; 39 | } 40 | 41 | public function testGetGrid() 42 | { 43 | $bobj = $this->obj->getBarcodeObj( 44 | 'EAN8', 45 | '1234567' 46 | ); 47 | $grid = $bobj->getGrid(); 48 | $expected = "1010011001001001101111010100011010101001110101000010001001110010101\n"; 49 | $this->assertEquals($expected, $grid); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /test/Linear/PharmaTest.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Test\Linear; 17 | 18 | use PHPUnit\Framework\TestCase; 19 | 20 | /** 21 | * Barcode class test 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class PharmaTest extends TestCase 32 | { 33 | protected $obj = null; 34 | 35 | public function setUp() 36 | { 37 | //$this->markTestSkipped(); // skip this test 38 | $this->obj = new \Com\Tecnick\Barcode\Barcode; 39 | } 40 | 41 | public function testGetGrid() 42 | { 43 | $bobj = $this->obj->getBarcodeObj('PHARMA', '0123456789'); 44 | $grid = $bobj->getGrid(); 45 | $expected = "111001110010011100100111001110010011100111001110011100100" 46 | ."1001110011100100111001001001001110010011100111001\n"; 47 | $this->assertEquals($expected, $grid); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /test/Linear/MsiTest.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Test\Linear; 17 | 18 | use PHPUnit\Framework\TestCase; 19 | 20 | /** 21 | * Barcode class test 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class MsiTest extends TestCase 32 | { 33 | protected $obj = null; 34 | 35 | public function setUp() 36 | { 37 | //$this->markTestSkipped(); // skip this test 38 | $this->obj = new \Com\Tecnick\Barcode\Barcode; 39 | } 40 | 41 | public function testGetGrid() 42 | { 43 | $bobj = $this->obj->getBarcodeObj('MSI', '0123456789'); 44 | $grid = $bobj->getGrid(); 45 | $expected = "110100100100100100100100110100100110100100100110110100110100" 46 | ."1001001101001101001101101001001101101101101001001001101001001101001\n"; 47 | $this->assertEquals($expected, $grid); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /test/Linear/InterleavedTwoOfFiveTest.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Test\Linear; 17 | 18 | use PHPUnit\Framework\TestCase; 19 | 20 | /** 21 | * Barcode class test 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class InterleavedTwoOfFiveTest extends TestCase 32 | { 33 | protected $obj = null; 34 | 35 | public function setUp() 36 | { 37 | //$this->markTestSkipped(); // skip this test 38 | $this->obj = new \Com\Tecnick\Barcode\Barcode; 39 | } 40 | 41 | public function testGetGrid() 42 | { 43 | $bobj = $this->obj->getBarcodeObj( 44 | 'I25', 45 | '0123456789' 46 | ); 47 | $grid = $bobj->getGrid(); 48 | $expected = "101010010110110100100110010101101001011001011010110110100100110100101100101101\n"; 49 | $this->assertEquals($expected, $grid); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /test/Linear/StandardTwoOfFiveTest.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Test\Linear; 17 | 18 | use PHPUnit\Framework\TestCase; 19 | 20 | /** 21 | * Barcode class test 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class StandardTwoOfFiveTest extends TestCase 32 | { 33 | protected $obj = null; 34 | 35 | public function setUp() 36 | { 37 | //$this->markTestSkipped(); // skip this test 38 | $this->obj = new \Com\Tecnick\Barcode\Barcode; 39 | } 40 | 41 | public function testGetGrid() 42 | { 43 | $bobj = $this->obj->getBarcodeObj('S25', '0123456789'); 44 | $grid = $bobj->getGrid(); 45 | $expected = '111011101010101110111010111010101011101011101010111011101110101010101011101011101110101110101010' 46 | .'111011101010101010111011101110101011101010111010111010111010111'."\n"; 47 | $this->assertEquals($expected, $grid); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Type/Linear/Planet.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Linear; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | 20 | /** 21 | * Com\Tecnick\Barcode\Type\Linear\Planet; 22 | * 23 | * Planet Barcode type class 24 | * PLANET 25 | * 26 | * @since 2015-02-21 27 | * @category Library 28 | * @package Barcode 29 | * @author Nicola Asuni 30 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 31 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 32 | * @link https://github.com/tecnickcom/tc-lib-barcode 33 | */ 34 | class Planet extends \Com\Tecnick\Barcode\Type\Linear\Postnet 35 | { 36 | /** 37 | * Barcode format 38 | * 39 | * @var string 40 | */ 41 | protected $format = 'PLANET'; 42 | 43 | /** 44 | * Map characters to barcodes 45 | * 46 | * @var array 47 | */ 48 | protected $chbar = array( 49 | '0' => '11222', 50 | '1' => '22211', 51 | '2' => '22121', 52 | '3' => '22112', 53 | '4' => '21221', 54 | '5' => '21212', 55 | '6' => '21122', 56 | '7' => '12221', 57 | '8' => '12212', 58 | '9' => '12122' 59 | ); 60 | } 61 | -------------------------------------------------------------------------------- /src/Type/Linear/UpcA.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Linear; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | 20 | /** 21 | * Com\Tecnick\Barcode\Type\Linear\UpcA; 22 | * 23 | * UpcA Barcode type class 24 | * UPC-A 25 | * 26 | * @since 2015-02-21 27 | * @category Library 28 | * @package Barcode 29 | * @author Nicola Asuni 30 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 31 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 32 | * @link https://github.com/tecnickcom/tc-lib-barcode 33 | */ 34 | class UpcA extends \Com\Tecnick\Barcode\Type\Linear\EanOneThree 35 | { 36 | /** 37 | * Barcode format 38 | * 39 | * @var string 40 | */ 41 | protected $format = 'UPCA'; 42 | 43 | /** 44 | * Fixed code length 45 | * 46 | * @var int 47 | */ 48 | protected $code_length = 12; 49 | 50 | /** 51 | * Format the code 52 | */ 53 | protected function formatCode() 54 | { 55 | $code = str_pad($this->code, ($this->code_length - 1), '0', STR_PAD_LEFT); 56 | $code .= $this->getChecksum($code); 57 | ++$this->code_length; 58 | $this->extcode = '0'.$code; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /test/Linear/CodeThreeNineExtTest.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Test\Linear; 17 | 18 | use PHPUnit\Framework\TestCase; 19 | 20 | /** 21 | * Barcode class test 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class CodeThreeNineExtTest extends TestCase 32 | { 33 | protected $obj = null; 34 | 35 | public function setUp() 36 | { 37 | //$this->markTestSkipped(); // skip this test 38 | $this->obj = new \Com\Tecnick\Barcode\Barcode; 39 | } 40 | 41 | public function testGetGrid() 42 | { 43 | $bobj = $this->obj->getBarcodeObj('C39E', '0123456789'); 44 | $grid = $bobj->getGrid(); 45 | $expected = "10001011101110101010001110111010111010001010111010111000101011101110111000101010101000" 46 | ."111010111011101000111010101011100011101010101000101110111011101000101110101011100010111010100" 47 | ."010111011101\n"; 48 | $this->assertEquals($expected, $grid); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /test/Linear/CodeThreeNineCheckTest.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Test\Linear; 17 | 18 | use PHPUnit\Framework\TestCase; 19 | 20 | /** 21 | * Barcode class test 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class CodeThreeNineCheckTest extends TestCase 32 | { 33 | protected $obj = null; 34 | 35 | public function setUp() 36 | { 37 | //$this->markTestSkipped(); // skip this test 38 | $this->obj = new \Com\Tecnick\Barcode\Barcode; 39 | } 40 | 41 | public function testGetGrid() 42 | { 43 | $bobj = $this->obj->getBarcodeObj('C39+', '0123456789'); 44 | $grid = $bobj->getGrid(); 45 | $expected = "10001011101110101010001110111010111010001010111010111000101011101110111000101010101000" 46 | ."111010111011101000111010101011100011101010101000101110111011101000101110101011100010111010101" 47 | ."1100010101110100010111011101\n"; 48 | $this->assertEquals($expected, $grid); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /test/Linear/KlantIndexTest.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Test\Linear; 17 | 18 | use PHPUnit\Framework\TestCase; 19 | 20 | /** 21 | * Barcode class test 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class KlantIndexTest extends TestCase 32 | { 33 | protected $obj = null; 34 | 35 | public function setUp() 36 | { 37 | //$this->markTestSkipped(); // skip this test 38 | $this->obj = new \Com\Tecnick\Barcode\Barcode; 39 | } 40 | 41 | public function testGetGrid() 42 | { 43 | $bobj = $this->obj->getBarcodeObj('KIX', '0123456789'); 44 | $grid = $bobj->getGrid(); 45 | $expected = "00001010000010100000101000001010000010100000101000100010001000100010001000100010\n" 46 | ."10101010101010101010101010101010101010101010101010101010101010101010101010101010\n" 47 | ."00001010001000100010100010000010100010001010000000001010001000100010100010000010\n"; 48 | $this->assertEquals($expected, $grid); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /test/Linear/PlanetTest.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Test\Linear; 17 | 18 | use PHPUnit\Framework\TestCase; 19 | 20 | /** 21 | * Barcode class test 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class PlanetTest extends TestCase 32 | { 33 | protected $obj = null; 34 | 35 | public function setUp() 36 | { 37 | //$this->markTestSkipped(); // skip this test 38 | $this->obj = new \Com\Tecnick\Barcode\Barcode; 39 | } 40 | 41 | public function testGetGrid() 42 | { 43 | $bobj = $this->obj->getBarcodeObj('PLANET', '0123456789'); 44 | $grid = $bobj->getGrid(); 45 | $expected = "100000101010101010000010100010001010000010100010100010" 46 | ."00100010100000101000101010000010100010001000101010001000101\n" 47 | ."1010101010101010101010101010101010101010101010101010101010101" 48 | ."0101010101010101010101010101010101010101010101010101\n"; 49 | $this->assertEquals($expected, $grid); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Type/Linear/KlantIndex.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Linear; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | 20 | /** 21 | * Com\Tecnick\Barcode\Type\Linear\KlantIndex; 22 | * 23 | * KlantIndex Barcode type class 24 | * KIX (Klant index - Customer index) 25 | * 26 | * @since 2015-02-21 27 | * @category Library 28 | * @package Barcode 29 | * @author Nicola Asuni 30 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 31 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 32 | * @link https://github.com/tecnickcom/tc-lib-barcode 33 | */ 34 | class KlantIndex extends \Com\Tecnick\Barcode\Type\Linear\RoyalMailFourCc 35 | { 36 | /** 37 | * Barcode format 38 | * 39 | * @var string 40 | */ 41 | protected $format = 'KIX'; 42 | 43 | /** 44 | * Format code 45 | */ 46 | protected function formatCode() 47 | { 48 | $this->extcode = strtoupper($this->code); 49 | } 50 | 51 | /** 52 | * Get the bars array 53 | * 54 | * @throws BarcodeException in case of error 55 | */ 56 | protected function setBars() 57 | { 58 | $this->ncols = 0; 59 | $this->nrows = 3; 60 | $this->bars = array(); 61 | $this->getCoreBars(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /test/Linear/CodabarTest.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Test\Linear; 17 | 18 | use PHPUnit\Framework\TestCase; 19 | 20 | /** 21 | * Barcode class test 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class CodabarTest extends TestCase 32 | { 33 | protected $obj = null; 34 | 35 | public function setUp() 36 | { 37 | //$this->markTestSkipped(); // skip this test 38 | $this->obj = new \Com\Tecnick\Barcode\Barcode; 39 | } 40 | 41 | public function testGetGrid() 42 | { 43 | $bobj = $this->obj->getBarcodeObj('CODABAR', '0123456789'); 44 | $grid = $bobj->getGrid(); 45 | $expected = "10110010010101010011010101100101010010110110010101010110" 46 | ."10010110101001010010101101001011010100110101011010010101011001001\n"; 47 | $this->assertEquals($expected, $grid); 48 | } 49 | 50 | /** 51 | * @expectedException \Com\Tecnick\Barcode\Exception 52 | */ 53 | public function testInvalidInput() 54 | { 55 | $this->obj->getBarcodeObj('CODABAR', chr(218)); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Type/Linear/CodeOneTwoEight/A.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Linear\CodeOneTwoEight; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | 20 | /** 21 | * Com\Tecnick\Barcode\Type\Linear\CodeOneTwoEight\A; 22 | * 23 | * CodeOneTwoEightA Barcode type class 24 | * CODE 128 A 25 | * 26 | * @since 2015-02-21 27 | * @category Library 28 | * @package Barcode 29 | * @author Nicola Asuni 30 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 31 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 32 | * @link https://github.com/tecnickcom/tc-lib-barcode 33 | */ 34 | class A extends \Com\Tecnick\Barcode\Type\Linear\CodeOneTwoEight 35 | { 36 | /** 37 | * Barcode format 38 | * 39 | * @var string 40 | */ 41 | protected $format = 'C128A'; 42 | 43 | /** 44 | * Get the code point array 45 | * 46 | * @throws BarcodeException in case of error 47 | */ 48 | protected function getCodeData() 49 | { 50 | $code = $this->code; 51 | // array of symbols 52 | $code_data = array(); 53 | // length of the code 54 | $len = strlen($code); 55 | $startid = 103; 56 | $this->getCodeDataA($code_data, $code, $len); 57 | return $this->finalizeCodeData($code_data, $startid); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Type/Linear/CodeOneTwoEight/B.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Linear\CodeOneTwoEight; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | 20 | /** 21 | * Com\Tecnick\Barcode\Type\Linear\CodeOneTwoEight\B; 22 | * 23 | * CodeOneTwoEightB Barcode type class 24 | * CODE 128 B 25 | * 26 | * @since 2015-02-21 27 | * @category Library 28 | * @package Barcode 29 | * @author Nicola Asuni 30 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 31 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 32 | * @link https://github.com/tecnickcom/tc-lib-barcode 33 | */ 34 | class B extends \Com\Tecnick\Barcode\Type\Linear\CodeOneTwoEight 35 | { 36 | /** 37 | * Barcode format 38 | * 39 | * @var string 40 | */ 41 | protected $format = 'C128B'; 42 | 43 | /** 44 | * Get the code point array 45 | * 46 | * @throws BarcodeException in case of error 47 | */ 48 | protected function getCodeData() 49 | { 50 | $code = $this->code; 51 | // array of symbols 52 | $code_data = array(); 53 | // length of the code 54 | $len = strlen($code); 55 | $startid = 104; 56 | $this->getCodeDataB($code_data, $code, $len); 57 | return $this->finalizeCodeData($code_data, $startid); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /test/Linear/UpcATest.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Test\Linear; 17 | 18 | use PHPUnit\Framework\TestCase; 19 | 20 | /** 21 | * Barcode class test 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class UpcATest extends TestCase 32 | { 33 | protected $obj = null; 34 | 35 | public function setUp() 36 | { 37 | //$this->markTestSkipped(); // skip this test 38 | $this->obj = new \Com\Tecnick\Barcode\Barcode; 39 | } 40 | 41 | public function testGetGrid() 42 | { 43 | $bobj = $this->obj->getBarcodeObj('UPCA', '0123456789'); 44 | $grid = $bobj->getGrid(); 45 | $expected = "10100011010001101001100100100110111101010001101010100111010100001000100100100011101001001110101\n"; 46 | $this->assertEquals($expected, $grid); 47 | 48 | $bobj = $this->obj->getBarcodeObj('UPCA', '012345678912'); 49 | $grid = $bobj->getGrid(); 50 | $expected = "10100011010011001001001101111010100011011000101010101000010001001001000111010011001101101100101\n"; 51 | $this->assertEquals($expected, $grid); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /test/Linear/InterleavedTwoOfFiveCheckTest.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Test\Linear; 17 | 18 | use PHPUnit\Framework\TestCase; 19 | 20 | /** 21 | * Barcode class test 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class InterleavedTwoOfFiveCheckTest extends TestCase 32 | { 33 | protected $obj = null; 34 | 35 | public function setUp() 36 | { 37 | //$this->markTestSkipped(); // skip this test 38 | $this->obj = new \Com\Tecnick\Barcode\Barcode; 39 | } 40 | 41 | public function testGetGrid() 42 | { 43 | $bobj = $this->obj->getBarcodeObj( 44 | 'I25+', 45 | '0123456789' 46 | ); 47 | $grid = $bobj->getGrid(); 48 | $expected = "10101010110011001011010010101100110110100101001101001100101010010101100110100110100110101101\n"; 49 | $this->assertEquals($expected, $grid); 50 | } 51 | 52 | /** 53 | * @expectedException \Com\Tecnick\Barcode\Exception 54 | */ 55 | public function testInvalidInput() 56 | { 57 | $this->obj->getBarcodeObj('I25+', 'GHI'); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Type/Linear/CodeOneTwoEight/C.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Linear\CodeOneTwoEight; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | 20 | /** 21 | * Com\Tecnick\Barcode\Type\Linear\CodeOneTwoEight\C; 22 | * 23 | * CodeOneTwoEightC Barcode type class 24 | * CODE 128 C 25 | * 26 | * @since 2015-02-21 27 | * @category Library 28 | * @package Barcode 29 | * @author Nicola Asuni 30 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 31 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 32 | * @link https://github.com/tecnickcom/tc-lib-barcode 33 | */ 34 | class C extends \Com\Tecnick\Barcode\Type\Linear\CodeOneTwoEight 35 | { 36 | /** 37 | * Barcode format 38 | * 39 | * @var string 40 | */ 41 | protected $format = 'C128C'; 42 | 43 | /** 44 | * Get the code point array 45 | * 46 | * @throws BarcodeException in case of error 47 | */ 48 | protected function getCodeData() 49 | { 50 | $code = $this->code; 51 | // array of symbols 52 | $code_data = array(); 53 | 54 | $startid = 105; 55 | if (ord($code[0]) == 241) { 56 | $code_data[] = 102; 57 | $code = substr($code, 1); 58 | } 59 | $this->getCodeDataC($code_data, $code); 60 | return $this->finalizeCodeData($code_data, $startid); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /test/Linear/CodeThreeNineTest.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Test\Linear; 17 | 18 | use PHPUnit\Framework\TestCase; 19 | 20 | /** 21 | * Barcode class test 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class CodeThreeNineTest extends TestCase 32 | { 33 | protected $obj = null; 34 | 35 | public function setUp() 36 | { 37 | //$this->markTestSkipped(); // skip this test 38 | $this->obj = new \Com\Tecnick\Barcode\Barcode; 39 | } 40 | 41 | public function testGetGrid() 42 | { 43 | $bobj = $this->obj->getBarcodeObj('C39', '0123456789'); 44 | $grid = $bobj->getGrid(); 45 | $expected = "10001011101110101010001110111010111010001010111010111000101011101110" 46 | ."111000101010101000111010111011101000111010101011100011101010101000101110111" 47 | ."011101000101110101011100010111010100010111011101\n"; 48 | $this->assertEquals($expected, $grid); 49 | } 50 | 51 | /** 52 | * @expectedException \Com\Tecnick\Barcode\Exception 53 | */ 54 | public function testInvalidInput() 55 | { 56 | $this->obj->getBarcodeObj('C39', chr(218)); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /test/Linear/StandardTwoOfFiveCheckTest.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Test\Linear; 17 | 18 | use PHPUnit\Framework\TestCase; 19 | 20 | /** 21 | * Barcode class test 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class StandardTwoOfFiveCheckTest extends TestCase 32 | { 33 | protected $obj = null; 34 | 35 | public function setUp() 36 | { 37 | //$this->markTestSkipped(); // skip this test 38 | $this->obj = new \Com\Tecnick\Barcode\Barcode; 39 | } 40 | 41 | public function testGetGrid() 42 | { 43 | $bobj = $this->obj->getBarcodeObj('S25+', '0123456789'); 44 | $grid = $bobj->getGrid(); 45 | $expected = '111011101010101110111010101011101110101110101010111010111010101110111011101010101010111010' 46 | .'1110111010111010101011101110101010101011101110111010101110101011101011101011101011101010111010111'."\n"; 47 | $this->assertEquals($expected, $grid); 48 | } 49 | 50 | /** 51 | * @expectedException \Com\Tecnick\Barcode\Exception 52 | */ 53 | public function testInvalidInput() 54 | { 55 | $this->obj->getBarcodeObj('S25+', '}{'); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /test/Linear/MsiCheckTest.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Test\Linear; 17 | 18 | use PHPUnit\Framework\TestCase; 19 | 20 | /** 21 | * Barcode class test 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class MsiCheckTest extends TestCase 32 | { 33 | protected $obj = null; 34 | 35 | public function setUp() 36 | { 37 | //$this->markTestSkipped(); // skip this test 38 | $this->obj = new \Com\Tecnick\Barcode\Barcode; 39 | } 40 | 41 | public function testGetGrid() 42 | { 43 | $bobj = $this->obj->getBarcodeObj('MSI+', '0123456789ABCDEF'); 44 | $grid = $bobj->getGrid(); 45 | $expected = "110100100100100100100100110100100110100100100110110100110100100100110100110100110110100" 46 | ."1001101101101101001001001101001001101101001101001101001101101101101001001101101001101101101101" 47 | ."001101101101101001001001101001\n"; 48 | $this->assertEquals($expected, $grid); 49 | } 50 | 51 | /** 52 | * @expectedException \Com\Tecnick\Barcode\Exception 53 | */ 54 | public function testInvalidInput() 55 | { 56 | $this->obj->getBarcodeObj('MSI+', 'GHI'); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Type/Linear/Pharma.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Linear; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | 20 | /** 21 | * Com\Tecnick\Barcode\Type\Linear\Pharma; 22 | * 23 | * Pharma Barcode type class 24 | * PHARMACODE 25 | * 26 | * @since 2015-02-21 27 | * @category Library 28 | * @package Barcode 29 | * @author Nicola Asuni 30 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 31 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 32 | * @link https://github.com/tecnickcom/tc-lib-barcode 33 | */ 34 | class Pharma extends \Com\Tecnick\Barcode\Type\Linear 35 | { 36 | /** 37 | * Barcode format 38 | * 39 | * @var string 40 | */ 41 | protected $format = 'PHARMA'; 42 | 43 | /** 44 | * Get the bars array 45 | * 46 | * @throws BarcodeException in case of error 47 | */ 48 | protected function setBars() 49 | { 50 | $seq = ''; 51 | $code = intval($this->code); 52 | while ($code > 0) { 53 | if (($code % 2) == 0) { 54 | $seq .= '11100'; 55 | $code -= 2; 56 | } else { 57 | $seq .= '100'; 58 | $code -= 1; 59 | } 60 | $code /= 2; 61 | } 62 | $seq = substr($seq, 0, -2); 63 | $seq = strrev($seq); 64 | $this->processBinarySequence($seq); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tecnickcom/tc-lib-barcode", 3 | "description": "PHP library to generate linear and bidimensional barcodes", 4 | "type": "library", 5 | "homepage": "http://www.tecnick.com", 6 | "license": "LGPL-3.0", 7 | "keywords": [ 8 | "tc-lib-barcode", 9 | "barcode", 10 | "CODE 39", 11 | "ANSI MH10.8M-1983", 12 | "USD-3", 13 | "3 of 9", 14 | "CODE 93", 15 | "USS-93", 16 | "Standard 2 of 5", 17 | "Interleaved 2 of 5", 18 | "CODE 128 A B C", 19 | "UPC", 20 | "EAN 8", 21 | "EAN 13", 22 | "UPC-A", 23 | "UPC-E", 24 | "MSI", 25 | "POSTNET", 26 | "PLANET", 27 | "RMS4CC", 28 | "Royal Mail", 29 | "CBC", 30 | "KIX", 31 | "Klant", 32 | "Intelligent Mail Barcode", 33 | "Onecode", 34 | "USPS-B-3200", 35 | "CODABAR", 36 | "CODE 11", 37 | "PHARMACODE", 38 | "PHARMACODE TWO-TRACKS", 39 | "Datamatrix", 40 | "ECC200", 41 | "QR-Code", 42 | "PDF417" 43 | ], 44 | "authors": [ 45 | { 46 | "name": "Nicola Asuni", 47 | "email": "info@tecnick.com", 48 | "role": "lead" 49 | } 50 | ], 51 | "require": { 52 | "php": ">=5.4", 53 | "ext-bcmath": "*", 54 | "ext-date": "*", 55 | "ext-gd": "*", 56 | "ext-pcre": "*", 57 | "tecnickcom/tc-lib-color": "^1.12.15" 58 | }, 59 | "require-dev": { 60 | "apigen/apigen": "^2.8.1 || ^4.1.2", 61 | "bartlett/php-compatinfo": "^4.5.2 || ^5.0.10 || ^5.0.12", 62 | "pdepend/pdepend": "^2.5.2", 63 | "phploc/phploc": "^2.1 || ^3.0 || ^4.0", 64 | "phpmd/phpmd": "^2.6.0", 65 | "phpunit/phpunit": "^4.8 || ^5.7 || ^6.5 || ^7.1", 66 | "sebastian/phpcpd": "^2.0 || ^3.0 || ^4.0", 67 | "squizlabs/php_codesniffer": "^2.8.0 || ^3.2.0" 68 | }, 69 | "autoload": { 70 | "psr-4": { 71 | "Com\\Tecnick\\Barcode\\": "src" 72 | } 73 | }, 74 | "autoload-dev": { 75 | "psr-4": { 76 | "Test\\": "test" 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /test/Linear/CodeThreeNineExtCheckTest.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Test\Linear; 17 | 18 | use PHPUnit\Framework\TestCase; 19 | 20 | /** 21 | * Barcode class test 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class CodeThreeNineExtCheckTest extends TestCase 32 | { 33 | protected $obj = null; 34 | 35 | public function setUp() 36 | { 37 | //$this->markTestSkipped(); // skip this test 38 | $this->obj = new \Com\Tecnick\Barcode\Barcode; 39 | } 40 | 41 | public function testGetGrid() 42 | { 43 | $bobj = $this->obj->getBarcodeObj('C39E+', '0123456789'); 44 | $grid = $bobj->getGrid(); 45 | $expected = "10001011101110101010001110111010111010001010111010111000101011101110111000101010101000" 46 | ."111010111011101000111010101011100011101010101000101110111011101000101110101011100010111010101" 47 | ."1100010101110100010111011101\n"; 48 | $this->assertEquals($expected, $grid); 49 | } 50 | 51 | /** 52 | * @expectedException \Com\Tecnick\Barcode\Exception 53 | */ 54 | public function testInvalidInput() 55 | { 56 | $this->obj->getBarcodeObj('C39E+', chr(218)); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /test/Linear/PostnetTest.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Test\Linear; 17 | 18 | use PHPUnit\Framework\TestCase; 19 | 20 | /** 21 | * Barcode class test 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class PostnetTest extends TestCase 32 | { 33 | protected $obj = null; 34 | 35 | public function setUp() 36 | { 37 | //$this->markTestSkipped(); // skip this test 38 | $this->obj = new \Com\Tecnick\Barcode\Barcode; 39 | } 40 | 41 | public function testGetGrid() 42 | { 43 | $bobj = $this->obj->getBarcodeObj('POSTNET', '0123456789'); 44 | $grid = $bobj->getGrid(); 45 | $expected = "101010000000000000101000001000100000101000001000001000" 46 | ."10001000001010000010000000101000001000100010000000100010001\n" 47 | ."1010101010101010101010101010101010101010101010101010101010101" 48 | ."0101010101010101010101010101010101010101010101010101\n"; 49 | $this->assertEquals($expected, $grid); 50 | } 51 | 52 | /** 53 | * @expectedException \Com\Tecnick\Barcode\Exception 54 | */ 55 | public function testInvalidInput() 56 | { 57 | $this->obj->getBarcodeObj('POSTNET', '}{'); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /test/Linear/RoyalMailFourCcTest.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Test\Linear; 17 | 18 | use PHPUnit\Framework\TestCase; 19 | 20 | /** 21 | * Barcode class test 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class RoyalMailFourCcTest extends TestCase 32 | { 33 | protected $obj = null; 34 | 35 | public function setUp() 36 | { 37 | //$this->markTestSkipped(); // skip this test 38 | $this->obj = new \Com\Tecnick\Barcode\Barcode; 39 | } 40 | 41 | public function testGetGrid() 42 | { 43 | $bobj = $this->obj->getBarcodeObj('RMS4CC', '0123456789'); 44 | $grid = $bobj->getGrid(); 45 | $expected = "1000001010000010100000101000001010000010100000101000100010001000100010001000100010001000101\n" 46 | ."1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101\n" 47 | ."0000001010001000100010100010000010100010001010000000001010001000100010100010000010000010101\n"; 48 | $this->assertEquals($expected, $grid); 49 | } 50 | 51 | /** 52 | * @expectedException \Com\Tecnick\Barcode\Exception 53 | */ 54 | public function testInvalidInput() 55 | { 56 | $this->obj->getBarcodeObj('RMS4CC', '}{'); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /test/Linear/EanOneThreeTest.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Test\Linear; 17 | 18 | use PHPUnit\Framework\TestCase; 19 | 20 | /** 21 | * Barcode class test 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class EanOneThreeTest extends TestCase 32 | { 33 | protected $obj = null; 34 | 35 | public function setUp() 36 | { 37 | //$this->markTestSkipped(); // skip this test 38 | $this->obj = new \Com\Tecnick\Barcode\Barcode; 39 | } 40 | 41 | public function testGetGrid() 42 | { 43 | $bobj = $this->obj->getBarcodeObj('EAN13', '0123456789'); 44 | $grid = $bobj->getGrid(); 45 | $expected = "10100011010001101001100100100110111101010001101010100111010100001000100100100011101001001110101\n"; 46 | $this->assertEquals($expected, $grid); 47 | 48 | $this->assertEquals('0001234567895', $bobj->getExtendedCode()); 49 | } 50 | 51 | /** 52 | * @expectedException \Com\Tecnick\Barcode\Exception 53 | */ 54 | public function testInvalidInput() 55 | { 56 | $this->obj->getBarcodeObj('EAN13', '}{'); 57 | } 58 | 59 | /** 60 | * @expectedException \Com\Tecnick\Barcode\Exception 61 | */ 62 | public function testInvalidLength() 63 | { 64 | $this->obj->getBarcodeObj('EAN13', '1111111111111'); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /resources/rpm/rpm.spec: -------------------------------------------------------------------------------- 1 | # SPEC file 2 | 3 | %global c_vendor %{_vendor} 4 | %global gh_owner %{_owner} 5 | %global gh_project %{_project} 6 | 7 | Name: %{_package} 8 | Version: %{_version} 9 | Release: %{_release}%{?dist} 10 | Summary: PHP library to generate linear and bidimensional barcodes 11 | 12 | Group: Development/Libraries 13 | License: LGPLv3+ 14 | URL: https://github.com/%{gh_owner}/%{gh_project} 15 | 16 | BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-%(%{__id_u} -n) 17 | BuildArch: noarch 18 | 19 | Requires: php(language) >= 5.4.0 20 | Requires: php-composer(%{c_vendor}/tc-lib-color) < 2.0.0 21 | Requires: php-composer(%{c_vendor}/tc-lib-color) >= 1.12.15 22 | Requires: php-bcmath 23 | Requires: php-date 24 | Requires: php-gd 25 | Requires: php-pcre 26 | 27 | Provides: php-composer(%{c_vendor}/%{gh_project}) = %{version} 28 | Provides: php-%{gh_project} = %{version} 29 | 30 | %description 31 | PHP classes to generate linear and bidimensional barcodes: 32 | CODE 39, ANSI MH10.8M-1983, USD-3, 3 of 9, CODE 93, USS-93, 33 | Standard 2 of 5, Interleaved 2 of 5, CODE 128 A/B/C, 34 | 2 and 5 Digits UPC-Based Extension, EAN 8, EAN 13, UPC-A, 35 | UPC-E, MSI, POSTNET, PLANET, RMS4CC (Royal Mail 4-state Customer Code), 36 | CBC (Customer Bar Code), KIX (Klant index - Customer index), 37 | Intelligent Mail Barcode, Onecode, USPS-B-3200, CODABAR, CODE 11, 38 | PHARMACODE, PHARMACODE TWO-TRACKS, Datamatrix ECC200, QR-Code, PDF417. 39 | 40 | Optional dependency: php-pecl-imagick 41 | 42 | %build 43 | (cd %{_current_directory} && make build) 44 | 45 | %install 46 | rm -rf $RPM_BUILD_ROOT 47 | (cd %{_current_directory} && make install DESTDIR=$RPM_BUILD_ROOT) 48 | 49 | %clean 50 | rm -rf $RPM_BUILD_ROOT 51 | (cd %{_current_directory} && make clean) 52 | 53 | %files 54 | %attr(-,root,root) %{_libpath} 55 | %attr(-,root,root) %{_docpath} 56 | %docdir %{_docpath} 57 | #%config(noreplace) %{_configpath}* 58 | 59 | %changelog 60 | * Tue Jul 02 2015 Nicola Asuni 1.2.0-1 61 | - Changed package name, add provides section 62 | * Tue Feb 24 2015 Nicola Asuni 1.0.0-1 63 | - Initial Commit 64 | -------------------------------------------------------------------------------- /src/Type/Linear/EanEight.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Linear; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | 20 | /** 21 | * Com\Tecnick\Barcode\Type\Linear\EanEight; 22 | * 23 | * EanEight Barcode type class 24 | * EAN 8 25 | * 26 | * @since 2015-02-21 27 | * @category Library 28 | * @package Barcode 29 | * @author Nicola Asuni 30 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 31 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 32 | * @link https://github.com/tecnickcom/tc-lib-barcode 33 | */ 34 | class EanEight extends \Com\Tecnick\Barcode\Type\Linear\EanOneThree 35 | { 36 | /** 37 | * Barcode format 38 | * 39 | * @var string 40 | */ 41 | protected $format = 'EAN8'; 42 | 43 | /** 44 | * Fixed code length 45 | * 46 | * @var int 47 | */ 48 | protected $code_length = 8; 49 | 50 | /** 51 | * Get the bars array 52 | * 53 | * @throws BarcodeException in case of error 54 | */ 55 | protected function setBars() 56 | { 57 | $this->formatCode(); 58 | $seq = '101'; // left guard bar 59 | $half_len = intval(ceil($this->code_length / 2)); 60 | for ($pos = 0; $pos < $half_len; ++$pos) { 61 | $seq .= $this->chbar['A'][$this->extcode[$pos]]; 62 | } 63 | $seq .= '01010'; // center guard bar 64 | for ($pos = $half_len; $pos < $this->code_length; ++$pos) { 65 | $seq .= $this->chbar['C'][$this->extcode[$pos]]; 66 | } 67 | $seq .= '101'; // right guard bar 68 | $this->processBinarySequence($seq); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | sudo: false 4 | 5 | branches: 6 | except: 7 | - release 8 | 9 | branches: 10 | only: 11 | - master 12 | - develop 13 | 14 | php: 15 | - 5.6 16 | - 7.0 17 | - 7.1 18 | - 7.2 19 | - 7.3 20 | - 7.4 21 | - hhvm-3.18 22 | - hhvm-nightly 23 | - nightly 24 | 25 | matrix: 26 | allow_failures: 27 | - php: hhvm-nightly 28 | - php: nightly 29 | include: 30 | - os: linux 31 | dist: trusty 32 | language: php 33 | php: 5.4 34 | 35 | addons: 36 | apt: 37 | packages: 38 | - devscripts 39 | - fakeroot 40 | - debhelper 41 | - pkg-config 42 | - alien 43 | - rpm 44 | - dh-make 45 | - imagemagick 46 | 47 | before_install: 48 | - composer self-update 49 | - if [ -n "$GH_TOKEN" ]; then git config --global github.token ${GH_TOKEN} && composer config github-oauth.github.com ${GH_TOKEN}; fi; 50 | - if [ -n "$GH_USER" ]; then git config --global github.user ${GH_USER}; fi; 51 | - if [[ "$TRAVIS_PHP_VERSION" != "nightly" ]] && [[ "$TRAVIS_PHP_VERSION" != "5.3" ]] && [[ "$TRAVIS_PHP_VERSION" != "hhvm" ]] && [[ "$TRAVIS_PHP_VERSION" != "hhvm-3.18" ]] && [[ "$TRAVIS_PHP_VERSION" != "hhvm-nightly" ]] && [[ "$TRAVIS_PHP_VERSION" != "7.2" ]]; then printf "\n" | pecl install imagick-beta -v; fi; 52 | 53 | before_script: 54 | - composer install --no-interaction 55 | - if [ "$TRAVIS_PHP_VERSION" = "7.2" ]; then composer require php-coveralls/php-coveralls --no-interaction; fi 56 | 57 | script: 58 | - make qa_all 59 | - make report 60 | 61 | after_failure: 62 | - cat ./target/logs/junit.xml 63 | - cat ./target/report/phpcpd.txt 64 | 65 | after_success: 66 | - cat ./target/report/phploc.txt 67 | - cat ./target/report/phpcompatinfo.txt 68 | - "echo 'coverage_clover: target/coverage/coverage.xml' >> .coveralls.yml" 69 | - "echo 'json_path: target/coverage/coveralls-upload.json' >> .coveralls.yml" 70 | - if [ "$TRAVIS_PHP_VERSION" = "7.2" ]; then php vendor/php-coveralls/php-coveralls/bin/php-coveralls -v; fi; 71 | - if [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PHP_VERSION" = "7.2" ] && [ -n "$BT_APIUSER" ]; then make bintray APIUSER=${BT_APIUSER} APIKEY=${BT_APIKEY}; fi; 72 | -------------------------------------------------------------------------------- /test/Linear/CodeOneTwoEight/BTest.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Test\Linear\CodeOneTwoEight; 17 | 18 | use PHPUnit\Framework\TestCase; 19 | 20 | /** 21 | * Barcode class test 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class BTest extends TestCase 32 | { 33 | protected $obj = null; 34 | 35 | public function setUp() 36 | { 37 | //$this->markTestSkipped(); // skip this test 38 | $this->obj = new \Com\Tecnick\Barcode\Barcode; 39 | } 40 | 41 | public function testGetGrid() 42 | { 43 | $bobj = $this->obj->getBarcodeObj('C128B', '0123456789'); 44 | $grid = $bobj->getGrid(); 45 | $expected = "11010010000100111011001001110011011001110010110010111001100100111011011100" 46 | ."10011001110100111011011101110100110011100101100110000101001100011101011\n"; 47 | $this->assertEquals($expected, $grid); 48 | 49 | $bobj = $this->obj->getBarcodeObj('C128B', chr(241).'01234567891'); 50 | $grid = $bobj->getGrid(); 51 | $expected = "11010010000111101011101001110110010011100110110011100101100101110011001001" 52 | ."110110111001001100111010011101101110111010011001110010110010011100110100001100101100011101011\n"; 53 | $this->assertEquals($expected, $grid); 54 | } 55 | 56 | /** 57 | * @expectedException \Com\Tecnick\Barcode\Exception 58 | */ 59 | public function testInvalidInput() 60 | { 61 | $this->obj->getBarcodeObj('C128B', chr(246).'01234567891'); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /test/Linear/ImbPreTest.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Test\Linear; 17 | 18 | use PHPUnit\Framework\TestCase; 19 | 20 | /** 21 | * Barcode class test 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class ImbPreTest extends TestCase 32 | { 33 | protected $obj = null; 34 | 35 | public function setUp() 36 | { 37 | //$this->markTestSkipped(); // skip this test 38 | $this->obj = new \Com\Tecnick\Barcode\Barcode; 39 | } 40 | 41 | public function testGetGrid() 42 | { 43 | $bobj = $this->obj->getBarcodeObj( 44 | 'IMBPRE', 45 | 'fatdfatdfatdfatdfatdfatdfatdfatdfatdfatdfatdfatdfatdfatdfatdfatdf' 46 | ); 47 | $grid = $bobj->getGrid(); 48 | $expected = "101000001010000010100000101000001010000010100000101000001010" 49 | ."000010100000101000001010000010100000101000001010000010100000101000001\n" 50 | ."1010101010101010101010101010101010101010101010101010101010101010101" 51 | ."01010101010101010101010101010101010101010101010101010101010101\n" 52 | ."1000001010000010100000101000001010000010100000101000001010000010100" 53 | ."00010100000101000001010000010100000101000001010000010100000101\n"; 54 | $this->assertEquals($expected, $grid); 55 | } 56 | 57 | /** 58 | * @expectedException \Com\Tecnick\Barcode\Exception 59 | */ 60 | public function testInvalidInput() 61 | { 62 | $this->obj->getBarcodeObj('IMBPRE', 'fatd'); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /test/Linear/CodeOneOneTest.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Test\Linear; 17 | 18 | use PHPUnit\Framework\TestCase; 19 | 20 | /** 21 | * Barcode class test 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class CodeOneOneTest extends TestCase 32 | { 33 | protected $obj = null; 34 | 35 | public function setUp() 36 | { 37 | //$this->markTestSkipped(); // skip this test 38 | $this->obj = new \Com\Tecnick\Barcode\Barcode; 39 | } 40 | 41 | public function testGetGrid() 42 | { 43 | $bobj = $this->obj->getBarcodeObj('CODE11', '0123456789'); 44 | $grid = $bobj->getGrid(); 45 | $expected = "10110010101011011010110100101101100101010110110110" 46 | ."11010100110101010011011010010110101010101101011001\n"; 47 | $this->assertEquals($expected, $grid); 48 | 49 | $bobj = $this->obj->getBarcodeObj('CODE11', '123-456-789'); 50 | $grid = $bobj->getGrid(); 51 | $expected = "10110010110101101001011011001010101101010110110110110" 52 | ."10100110101011010101001101101001011010101101101011010101011001\n"; 53 | $this->assertEquals($expected, $grid); 54 | 55 | $bobj = $this->obj->getBarcodeObj('CODE11', '-'); 56 | $grid = $bobj->getGrid(); 57 | $expected = "10110010101101010110101011001\n"; 58 | $this->assertEquals($expected, $grid); 59 | } 60 | 61 | /** 62 | * @expectedException \Com\Tecnick\Barcode\Exception 63 | */ 64 | public function testInvalidInput() 65 | { 66 | $this->obj->getBarcodeObj('CODE11', chr(255)); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Type/Linear/EanFive.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Linear; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | 20 | /** 21 | * Com\Tecnick\Barcode\Type\Linear\EanFive; 22 | * 23 | * EanFive Barcode type class 24 | * EAN 5-Digits UPC-Based Extension 25 | * 26 | * @since 2015-02-21 27 | * @category Library 28 | * @package Barcode 29 | * @author Nicola Asuni 30 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 31 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 32 | * @link https://github.com/tecnickcom/tc-lib-barcode 33 | */ 34 | class EanFive extends \Com\Tecnick\Barcode\Type\Linear\EanTwo 35 | { 36 | /** 37 | * Barcode format 38 | * 39 | * @var string 40 | */ 41 | protected $format = 'EAN5'; 42 | 43 | /** 44 | * Fixed code length 45 | * 46 | * @var int 47 | */ 48 | protected $code_length = 5; 49 | 50 | /** 51 | * Map parities 52 | * 53 | * @var array 54 | */ 55 | protected $parities = array( 56 | '0' => array('B','B','A','A','A'), 57 | '1' => array('B','A','B','A','A'), 58 | '2' => array('B','A','A','B','A'), 59 | '3' => array('B','A','A','A','B'), 60 | '4' => array('A','B','B','A','A'), 61 | '5' => array('A','A','B','B','A'), 62 | '6' => array('A','A','A','B','B'), 63 | '7' => array('A','B','A','B','A'), 64 | '8' => array('A','B','A','A','B'), 65 | '9' => array('A','A','B','A','B') 66 | ); 67 | 68 | /** 69 | * Calculate checksum 70 | * 71 | * @param $code (string) code to represent. 72 | * 73 | * @return char checksum. 74 | */ 75 | protected function getChecksum($code) 76 | { 77 | return (((3 * (intval($code[0]) + intval($code[2]) + intval($code[4]))) 78 | + (9 * (intval($code[1]) + intval($code[3])))) % 10); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /test/Linear/CodeNineThreeTest.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Test\Linear; 17 | 18 | use PHPUnit\Framework\TestCase; 19 | 20 | /** 21 | * Barcode class test 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class CodeNineThreeTest extends TestCase 32 | { 33 | protected $obj = null; 34 | 35 | public function setUp() 36 | { 37 | //$this->markTestSkipped(); // skip this test 38 | $this->obj = new \Com\Tecnick\Barcode\Barcode; 39 | } 40 | 41 | public function testGetGrid() 42 | { 43 | $bobj = $this->obj->getBarcodeObj('C93', '0123456789'); 44 | $grid = $bobj->getGrid(); 45 | $expected = "101011110100010100101001000101000100101000010100101000100" 46 | ."1001001001000101010100001000100101000010101001011001001100101010111101\n"; 47 | $this->assertEquals($expected, $grid); 48 | 49 | 50 | $bobj = $this->obj->getBarcodeObj('C93', '012345678901234567890123456789'); 51 | $grid = $bobj->getGrid(); 52 | $expected = "10101111010001010010100100010100010010100001010010100010010010010010001010101" 53 | ."000010001001010000101010001010010100100010100010010100001010010100010010010010010001" 54 | ."010101000010001001010000101010001010010100100010100010010100001010010100010010010010" 55 | ."01000101010100001000100101000010101001001001001010001010111101\n"; 56 | $this->assertEquals($expected, $grid); 57 | } 58 | 59 | /** 60 | * @expectedException \Com\Tecnick\Barcode\Exception 61 | */ 62 | public function testInvalidInput() 63 | { 64 | $this->obj->getBarcodeObj('C93', chr(255)); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /test/Linear/CodeOneTwoEight/ATest.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Test\Linear\CodeOneTwoEight; 17 | 18 | use PHPUnit\Framework\TestCase; 19 | 20 | /** 21 | * Barcode class test 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class ATest extends TestCase 32 | { 33 | protected $obj = null; 34 | 35 | public function setUp() 36 | { 37 | //$this->markTestSkipped(); // skip this test 38 | $this->obj = new \Com\Tecnick\Barcode\Barcode; 39 | } 40 | 41 | public function testGetGrid() 42 | { 43 | $bobj = $this->obj->getBarcodeObj('C128A', 'ABCDEFG'); 44 | $grid = $bobj->getGrid(); 45 | $expected = "110100001001010001100010001011000100010001101011000100010001101000100011000101101" 46 | ."0001000100110010001100011101011\n"; 47 | $this->assertEquals($expected, $grid); 48 | 49 | $bobj = $this->obj->getBarcodeObj('C128A', '0123456789'); 50 | $grid = $bobj->getGrid(); 51 | $expected = "110100001001001110110010011100110110011100101100101110011001001110110111001001100" 52 | ."1110100111011011101110100110011100101100111101110101100011101011\n"; 53 | $this->assertEquals($expected, $grid); 54 | 55 | $bobj = $this->obj->getBarcodeObj('C128A', chr(241).'01234567891'); 56 | $grid = $bobj->getGrid(); 57 | $expected = "110100001001111010111010011101100100111001101100111001011001011100110010011101101" 58 | ."11001001100111010011101101110111010011001110010110010011100110100001101001100011101011\n"; 59 | $this->assertEquals($expected, $grid); 60 | } 61 | 62 | /** 63 | * @expectedException \Com\Tecnick\Barcode\Exception 64 | */ 65 | public function testInvalidInput() 66 | { 67 | $this->obj->getBarcodeObj('C128A', chr(246).'01234567891'); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/Type/Linear/ImbPre.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Linear; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | 20 | /** 21 | * Com\Tecnick\Barcode\Type\Linear\ImbPre; 22 | * 23 | * ImbPre Barcode type class 24 | * IMB - Intelligent Mail Barcode pre-processed (USPS-B-3200) 25 | * 26 | * @since 2015-02-21 27 | * @category Library 28 | * @package Barcode 29 | * @author Nicola Asuni 30 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 31 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 32 | * @link https://github.com/tecnickcom/tc-lib-barcode 33 | */ 34 | class ImbPre extends \Com\Tecnick\Barcode\Type\Linear 35 | { 36 | /** 37 | * Barcode format 38 | * 39 | * @var string 40 | */ 41 | protected $format = 'IMBPRE'; 42 | 43 | /** 44 | * Get the bars array 45 | * 46 | * @throws BarcodeException in case of error 47 | */ 48 | protected function setBars() 49 | { 50 | $code = strtolower($this->code); 51 | if (preg_match('/^[fadt]{65}$/', $code) != 1) { 52 | throw new BarcodeException('Invalid character sequence'); 53 | } 54 | $this->ncols = 0; 55 | $this->nrows = 3; 56 | $this->bars = array(); 57 | for ($pos = 0; $pos < 65; ++$pos) { 58 | switch ($code[$pos]) { 59 | case 'f': 60 | // full bar 61 | $this->bars[] = array($this->ncols, 0, 1, 3); 62 | break; 63 | case 'a': 64 | // ascender 65 | $this->bars[] = array($this->ncols, 0, 1, 2); 66 | break; 67 | case 'd': 68 | // descender 69 | $this->bars[] = array($this->ncols, 1, 1, 2); 70 | break; 71 | case 't': 72 | // tracker (short) 73 | $this->bars[] = array($this->ncols, 1, 1, 1); 74 | break; 75 | } 76 | $this->ncols += 2; 77 | } 78 | --$this->ncols; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/Type/Linear/PharmaTwoTracks.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Linear; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | 20 | /** 21 | * Com\Tecnick\Barcode\Type\Linear\PharmaTwoTracks; 22 | * 23 | * PharmaTwoTracks Barcode type class 24 | * PHARMACODE TWO-TRACKS 25 | * 26 | * @since 2015-02-21 27 | * @category Library 28 | * @package Barcode 29 | * @author Nicola Asuni 30 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 31 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 32 | * @link https://github.com/tecnickcom/tc-lib-barcode 33 | */ 34 | class PharmaTwoTracks extends \Com\Tecnick\Barcode\Type\Linear 35 | { 36 | /** 37 | * Barcode format 38 | * 39 | * @var string 40 | */ 41 | protected $format = 'PHARMA2T'; 42 | 43 | /** 44 | * Get the bars array 45 | * 46 | * @throws BarcodeException in case of error 47 | */ 48 | protected function setBars() 49 | { 50 | $seq = ''; 51 | $code = intval($this->code); 52 | 53 | do { 54 | switch ($code % 3) { 55 | case 0: 56 | $seq .= '3'; 57 | $code = (($code - 3) / 3); 58 | break; 59 | case 1: 60 | $seq .= '1'; 61 | $code = (($code - 1) / 3); 62 | break; 63 | case 2: 64 | $seq .= '2'; 65 | $code = (($code - 2) / 3); 66 | } 67 | } while ($code != 0); 68 | 69 | $seq = strrev($seq); 70 | $this->ncols = 0; 71 | $this->nrows = 2; 72 | $this->bars = array(); 73 | $len = strlen($seq); 74 | for ($pos = 0; $pos < $len; ++$pos) { 75 | switch ($seq[$pos]) { 76 | case '1': 77 | $this->bars[] = array($this->ncols, 1, 1, 1); 78 | break; 79 | case '2': 80 | $this->bars[] = array($this->ncols, 0, 1, 1); 81 | break; 82 | case '3': 83 | $this->bars[] = array($this->ncols, 0, 1, 2); 84 | break; 85 | } 86 | $this->ncols += 2; 87 | } 88 | --$this->ncols; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/Type/Raw.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | 20 | /** 21 | * Com\Tecnick\Barcode\Type\Raw 22 | * 23 | * Raw Barcode type class 24 | * RAW MODE (comma-separated rows) 25 | * 26 | * @since 2015-02-21 27 | * @category Library 28 | * @package Barcode 29 | * @author Nicola Asuni 30 | * @copyright 2015-2016 Nicola Asuni - Tecnick.com LTD 31 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 32 | * @link https://github.com/tecnickcom/tc-lib-barcode 33 | */ 34 | class Raw extends \Com\Tecnick\Barcode\Type 35 | { 36 | /** 37 | * Get the pre-formatted code 38 | * 39 | * @return string 40 | */ 41 | protected function getCodeRows() 42 | { 43 | if (is_array($this->code)) { 44 | return $this->code; 45 | } 46 | // remove spaces and newlines 47 | $code = preg_replace('/[\s]*/s', '', $this->code); 48 | // remove trailing brackets or commas 49 | $code = preg_replace('/^[\[,]+/', '', $code); 50 | $code = preg_replace('/[\],]+$/', '', $code); 51 | // convert bracket -separated to comma-separated 52 | $code = preg_replace('/[\]][\[]$/', ',', $code); 53 | return explode(',', $code); 54 | } 55 | 56 | /** 57 | * Get the bars array 58 | * 59 | * @throws BarcodeException in case of error 60 | */ 61 | protected function setBars() 62 | { 63 | $rows = $this->getCodeRows(); 64 | if (empty($rows)) { 65 | throw new BarcodeException('Empty input string'); 66 | } 67 | $this->nrows = count($rows); 68 | if (is_array($rows[0])) { 69 | $this->ncols = count($rows[0]); 70 | } else { 71 | $this->ncols = strlen($rows[0]); 72 | } 73 | if (empty($this->ncols)) { 74 | throw new BarcodeException('Empty columns'); 75 | } 76 | $this->bars = array(); 77 | foreach ($rows as $posy => $row) { 78 | if (!is_array($row)) { 79 | $row = str_split($row, 1); 80 | } 81 | $prevcol = ''; 82 | $bar_width = 0; 83 | $row[] = '0'; 84 | for ($posx = 0; $posx <= $this->ncols; ++$posx) { 85 | if ($row[$posx] != $prevcol) { 86 | if ($prevcol == '1') { 87 | $this->bars[] = array(($posx - $bar_width), $posy, $bar_width, 1); 88 | } 89 | $bar_width = 0; 90 | } 91 | ++$bar_width; 92 | $prevcol = $row[$posx]; 93 | } 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /test/Linear/CodeOneTwoEight/CTest.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Test\Linear\CodeOneTwoEight; 17 | 18 | use PHPUnit\Framework\TestCase; 19 | 20 | /** 21 | * Barcode class test 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class CTest extends TestCase 32 | { 33 | protected $obj = null; 34 | 35 | public function setUp() 36 | { 37 | //$this->markTestSkipped(); // skip this test 38 | $this->obj = new \Com\Tecnick\Barcode\Barcode; 39 | } 40 | 41 | public function testGetGrid() 42 | { 43 | $bobj = $this->obj->getBarcodeObj('C128C', '0123456789'); 44 | $grid = $bobj->getGrid(); 45 | $expected = "110100111001100110110011101101110101110110001000010110011011011110100001101001100011101011\n"; 46 | $this->assertEquals($expected, $grid); 47 | 48 | $bobj = $this->obj->getBarcodeObj('C128C', chr(241).'0123456789'); 49 | $grid = $bobj->getGrid(); 50 | $expected = "11010011100111101011101100110110011101101110101110110001000010110011011011110111101101101100" 51 | ."011101011\n"; 52 | $this->assertEquals($expected, $grid); 53 | 54 | $bobj = $this->obj->getBarcodeObj('C128C', chr(241).'00123456780000000001'); 55 | $grid = $bobj->getGrid(); 56 | $expected = "11010011100111101011101101100110010110011100100010110001110001011011000010100110110011001101" 57 | ."1001100110110011001101100110011001101100100010011001100011101011\n"; 58 | $this->assertEquals($expected, $grid); 59 | 60 | $bobj = $this->obj->getBarcodeObj('C128C', chr(241).'42029651'.chr(241).'9405510200864168997758'); 61 | $grid = $bobj->getGrid(); 62 | $expected = "11010011100111101011101011011100011001100110101111000101101110100011110101110100010111101000" 63 | ."100110011011101000110011001101101100110011110100100110001000101000010011010111011110111101110101110" 64 | ."1100010111100101001100011101011\n"; 65 | $this->assertEquals($expected, $grid); 66 | } 67 | 68 | /** 69 | * @expectedException \Com\Tecnick\Barcode\Exception 70 | */ 71 | public function testInvalidLength() 72 | { 73 | $this->obj->getBarcodeObj('C128C', '12345678901'); 74 | } 75 | 76 | /** 77 | * @expectedException \Com\Tecnick\Barcode\Exception 78 | */ 79 | public function testInvalidChar() 80 | { 81 | $this->obj->getBarcodeObj('C128C', '1A2345678901'); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/Type/Linear/Codabar.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Linear; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | 20 | /** 21 | * Com\Tecnick\Barcode\Type\Linear\Codabar; 22 | * 23 | * Codabar Barcode type class 24 | * 25 | * @since 2015-02-21 26 | * @category Library 27 | * @package Barcode 28 | * @author Nicola Asuni 29 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 30 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 31 | * @link https://github.com/tecnickcom/tc-lib-barcode 32 | */ 33 | class Codabar extends \Com\Tecnick\Barcode\Type\Linear 34 | { 35 | /** 36 | * Barcode format 37 | * 38 | * @var string 39 | */ 40 | protected $format = 'CODABAR'; 41 | 42 | /** 43 | * Map characters to barcodes 44 | * 45 | * @var array 46 | */ 47 | protected $chbar = array( 48 | '0' => '11111221', 49 | '1' => '11112211', 50 | '2' => '11121121', 51 | '3' => '22111111', 52 | '4' => '11211211', 53 | '5' => '21111211', 54 | '6' => '12111121', 55 | '7' => '12112111', 56 | '8' => '12211111', 57 | '9' => '21121111', 58 | '-' => '11122111', 59 | '$' => '11221111', 60 | ':' => '21112121', 61 | '/' => '21211121', 62 | '.' => '21212111', 63 | '+' => '11222221', 64 | 'A' => '11221211', 65 | 'B' => '12121121', 66 | 'C' => '11121221', 67 | 'D' => '11122211' 68 | ); 69 | 70 | /** 71 | * Format code 72 | */ 73 | protected function formatCode() 74 | { 75 | $this->extcode = 'A'.strtoupper($this->code).'A'; 76 | } 77 | 78 | /** 79 | * Get the bars array 80 | * 81 | * @return array 82 | * 83 | * @throws BarcodeException in case of error 84 | */ 85 | protected function setBars() 86 | { 87 | $this->ncols = 0; 88 | $this->nrows = 1; 89 | $this->bars = array(); 90 | $this->formatCode(); 91 | $clen = strlen($this->extcode); 92 | for ($chr = 0; $chr < $clen; ++$chr) { 93 | $char = $this->extcode[$chr]; 94 | if (!isset($this->chbar[$char])) { 95 | throw new BarcodeException('Invalid character: chr('.ord($char).')'); 96 | } 97 | for ($pos = 0; $pos < 8; ++$pos) { 98 | $bar_width = intval($this->chbar[$char][$pos]); 99 | if (($pos % 2) == 0) { 100 | $this->bars[] = array($this->ncols, 0, $bar_width, 1); 101 | } 102 | $this->ncols += $bar_width; 103 | } 104 | } 105 | --$this->ncols; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/Type/Linear/Postnet.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Linear; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | 20 | /** 21 | * Com\Tecnick\Barcode\Type\Linear\Postnet; 22 | * 23 | * Postnet Barcode type class 24 | * POSTNET 25 | * 26 | * @since 2015-02-21 27 | * @category Library 28 | * @package Barcode 29 | * @author Nicola Asuni 30 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 31 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 32 | * @link https://github.com/tecnickcom/tc-lib-barcode 33 | */ 34 | class Postnet extends \Com\Tecnick\Barcode\Type\Linear 35 | { 36 | /** 37 | * Barcode format 38 | * 39 | * @var string 40 | */ 41 | protected $format = 'POSTNET'; 42 | 43 | /** 44 | * Map characters to barcodes 45 | * 46 | * @var array 47 | */ 48 | protected $chbar = array( 49 | '0' => '22111', 50 | '1' => '11122', 51 | '2' => '11212', 52 | '3' => '11221', 53 | '4' => '12112', 54 | '5' => '12121', 55 | '6' => '12211', 56 | '7' => '21112', 57 | '8' => '21121', 58 | '9' => '21211' 59 | ); 60 | 61 | /** 62 | * Calculate the checksum. 63 | * 64 | * @param $code (string) code to represent. 65 | * 66 | * @return char checksum. 67 | */ 68 | protected function getChecksum($code) 69 | { 70 | $sum = 0; 71 | $len = strlen($code); 72 | for ($pos = 0; $pos < $len; ++$pos) { 73 | $sum += intval($code[$pos]); 74 | } 75 | $check = ($sum % 10); 76 | if ($check > 0) { 77 | $check = (10 - $check); 78 | } 79 | return $check; 80 | } 81 | 82 | /** 83 | * Format code 84 | */ 85 | protected function formatCode() 86 | { 87 | $code = preg_replace('/[-\s]+/', '', $this->code); 88 | $this->extcode = $code.$this->getChecksum($code); 89 | } 90 | 91 | /** 92 | * Get the bars array 93 | * 94 | * @return array 95 | * 96 | * @throws BarcodeException in case of error 97 | */ 98 | protected function setBars() 99 | { 100 | $this->ncols = 0; 101 | $this->nrows = 2; 102 | $this->bars = array(); 103 | $this->formatCode(); 104 | $clen = strlen($this->extcode); 105 | // start bar 106 | $this->bars[] = array($this->ncols, 0, 1, 2); 107 | $this->ncols += 2; 108 | for ($chr = 0; $chr < $clen; ++$chr) { 109 | $char = $this->extcode[$chr]; 110 | if (!isset($this->chbar[$char])) { 111 | throw new BarcodeException('Invalid character: chr('.ord($char).')'); 112 | } 113 | for ($pos = 0; $pos < 5; ++$pos) { 114 | $bar_height = intval($this->chbar[$char][$pos]); 115 | $this->bars[] = array($this->ncols, floor(1 / $bar_height), 1, $bar_height); 116 | $this->ncols += 2; 117 | } 118 | } 119 | // end bar 120 | $this->bars[] = array($this->ncols, 0, 1, 2); 121 | ++$this->ncols; 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /src/Type/Linear/StandardTwoOfFiveCheck.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Linear; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | 20 | /** 21 | * Com\Tecnick\Barcode\Type\Linear\StandardTwoOfFiveCheck; 22 | * 23 | * StandardTwoOfFiveCheck Barcode type class 24 | * Standard 2 of 5 + CHECKSUM 25 | * 26 | * @since 2015-02-21 27 | * @category Library 28 | * @package Barcode 29 | * @author Nicola Asuni 30 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 31 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 32 | * @link https://github.com/tecnickcom/tc-lib-barcode 33 | */ 34 | class StandardTwoOfFiveCheck extends \Com\Tecnick\Barcode\Type\Linear 35 | { 36 | /** 37 | * Barcode format 38 | * 39 | * @var string 40 | */ 41 | protected $format = 'S25+'; 42 | 43 | /** 44 | * Map characters to barcodes 45 | * 46 | * @var array 47 | */ 48 | protected $chbar = array( 49 | '0' => '10101110111010', 50 | '1' => '11101010101110', 51 | '2' => '10111010101110', 52 | '3' => '11101110101010', 53 | '4' => '10101110101110', 54 | '5' => '11101011101010', 55 | '6' => '10111011101010', 56 | '7' => '10101011101110', 57 | '8' => '11101010111010', 58 | '9' => '10111010111010' 59 | ); 60 | 61 | /** 62 | * Calculate the checksum 63 | * 64 | * @param $code (string) code to represent. 65 | * 66 | * @return char checksum. 67 | */ 68 | protected function getChecksum($code) 69 | { 70 | $clen = strlen($code); 71 | $sum = 0; 72 | for ($idx = 0; $idx < $clen; $idx+=2) { 73 | $sum += intval($code[$idx]); 74 | } 75 | $sum *= 3; 76 | for ($idx = 1; $idx < $clen; $idx+=2) { 77 | $sum += intval($code[$idx]); 78 | } 79 | $check = $sum % 10; 80 | if ($check > 0) { 81 | $check = (10 - $check); 82 | } 83 | return $check; 84 | } 85 | 86 | /** 87 | * Format code 88 | */ 89 | protected function formatCode() 90 | { 91 | $this->extcode = $this->code.$this->getChecksum($this->code); 92 | } 93 | 94 | /** 95 | * Get the bars array 96 | * 97 | * @return array 98 | * 99 | * @throws BarcodeException in case of error 100 | */ 101 | protected function setBars() 102 | { 103 | $this->formatCode(); 104 | if ((strlen($this->extcode) % 2) != 0) { 105 | // add leading zero if code-length is odd 106 | $this->extcode = '0'.$this->extcode; 107 | } 108 | $seq = '1110111010'; 109 | $clen = strlen($this->extcode); 110 | for ($idx = 0; $idx < $clen; ++$idx) { 111 | $digit = $this->extcode[$idx]; 112 | if (!isset($this->chbar[$digit])) { 113 | throw new BarcodeException('Invalid character: chr('.ord($digit).')'); 114 | } 115 | $seq .= $this->chbar[$digit]; 116 | } 117 | $seq .= '111010111'; 118 | $this->processBinarySequence($seq); 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/Type/Linear/MsiCheck.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2020 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Linear; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | 20 | /** 21 | * Com\Tecnick\Barcode\Type\Linear\MsiCheck; 22 | * 23 | * MsiCheck Barcode type class 24 | * MSI + CHECKSUM (modulo 11) 25 | * 26 | * @since 2015-02-21 27 | * @category Library 28 | * @package Barcode 29 | * @author Nicola Asuni 30 | * @copyright 2010-2020 Nicola Asuni - Tecnick.com LTD 31 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 32 | * @link https://github.com/tecnickcom/tc-lib-barcode 33 | */ 34 | class MsiCheck extends \Com\Tecnick\Barcode\Type\Linear 35 | { 36 | /** 37 | * Barcode format 38 | * 39 | * @var string 40 | */ 41 | protected $format = 'MSI+'; 42 | 43 | /** 44 | * Map characters to barcodes 45 | * 46 | * @var array 47 | */ 48 | protected $chbar = array( 49 | '0' => '100100100100', 50 | '1' => '100100100110', 51 | '2' => '100100110100', 52 | '3' => '100100110110', 53 | '4' => '100110100100', 54 | '5' => '100110100110', 55 | '6' => '100110110100', 56 | '7' => '100110110110', 57 | '8' => '110100100100', 58 | '9' => '110100100110', 59 | 'A' => '110100110100', 60 | 'B' => '110100110110', 61 | 'C' => '110110100100', 62 | 'D' => '110110100110', 63 | 'E' => '110110110100', 64 | 'F' => '110110110110' 65 | ); 66 | 67 | /** 68 | * Calculate the checksum 69 | * 70 | * @param $code (string) code to represent. 71 | * 72 | * @return char checksum. 73 | */ 74 | protected function getChecksum($code) 75 | { 76 | $clen = strlen($code); 77 | $pix = 2; 78 | $check = 0; 79 | for ($pos = ($clen - 1); $pos >= 0; --$pos) { 80 | $hex = $code[$pos]; 81 | if (!ctype_xdigit($hex)) { 82 | continue; 83 | } 84 | $check += (hexdec($hex) * $pix); 85 | ++$pix; 86 | if ($pix > 7) { 87 | $pix = 2; 88 | } 89 | } 90 | $check %= 11; 91 | if ($check > 0) { 92 | $check = (11 - $check); 93 | } 94 | return $check; 95 | } 96 | 97 | /** 98 | * Format code 99 | */ 100 | protected function formatCode() 101 | { 102 | $this->extcode = $this->code.$this->getChecksum($this->code); 103 | } 104 | 105 | /** 106 | * Get the bars array 107 | * 108 | * @return array 109 | * 110 | * @throws BarcodeException in case of error 111 | */ 112 | protected function setBars() 113 | { 114 | $this->formatCode(); 115 | $seq = '110'; // left guard 116 | $clen = strlen($this->extcode); 117 | for ($pos = 0; $pos < $clen; ++$pos) { 118 | $digit = $this->extcode[$pos]; 119 | if (!isset($this->chbar[$digit])) { 120 | throw new BarcodeException('Invalid character: chr('.ord($digit).')'); 121 | } 122 | $seq .= $this->chbar[$digit]; 123 | } 124 | $seq .= '1001'; // right guard 125 | $this->processBinarySequence($seq); 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /src/Type/Linear/EanTwo.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Linear; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | 20 | /** 21 | * Com\Tecnick\Barcode\Type\Linear\EanTwo; 22 | * 23 | * EanTwo Barcode type class 24 | * EAN 2-Digits UPC-Based Extension 25 | * 26 | * @since 2015-02-21 27 | * @category Library 28 | * @package Barcode 29 | * @author Nicola Asuni 30 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 31 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 32 | * @link https://github.com/tecnickcom/tc-lib-barcode 33 | */ 34 | class EanTwo extends \Com\Tecnick\Barcode\Type\Linear 35 | { 36 | /** 37 | * Barcode format 38 | * 39 | * @var string 40 | */ 41 | protected $format = 'EAN2'; 42 | 43 | /** 44 | * Fixed code length 45 | * 46 | * @var int 47 | */ 48 | protected $code_length = 2; 49 | 50 | /** 51 | * Map characters to barcodes 52 | * 53 | * @var array 54 | */ 55 | protected $chbar = array( 56 | 'A' => array( // left odd parity 57 | '0'=>'0001101', 58 | '1'=>'0011001', 59 | '2'=>'0010011', 60 | '3'=>'0111101', 61 | '4'=>'0100011', 62 | '5'=>'0110001', 63 | '6'=>'0101111', 64 | '7'=>'0111011', 65 | '8'=>'0110111', 66 | '9'=>'0001011' 67 | ), 68 | 'B' => array( // left even parity 69 | '0'=>'0100111', 70 | '1'=>'0110011', 71 | '2'=>'0011011', 72 | '3'=>'0100001', 73 | '4'=>'0011101', 74 | '5'=>'0111001', 75 | '6'=>'0000101', 76 | '7'=>'0010001', 77 | '8'=>'0001001', 78 | '9'=>'0010111' 79 | ) 80 | ); 81 | 82 | /** 83 | * Map parities 84 | * 85 | * @var array 86 | */ 87 | protected $parities = array( 88 | '0' => array('A','A'), 89 | '1' => array('A','B'), 90 | '2' => array('B','A'), 91 | '3' => array('B','B') 92 | ); 93 | 94 | /** 95 | * Calculate checksum 96 | * 97 | * @param $code (string) code to represent. 98 | * 99 | * @return char checksum. 100 | */ 101 | protected function getChecksum($code) 102 | { 103 | return (intval($code) % 4); 104 | } 105 | 106 | /** 107 | * Format code 108 | */ 109 | protected function formatCode() 110 | { 111 | $this->extcode = str_pad($this->code, $this->code_length, '0', STR_PAD_LEFT); 112 | } 113 | 114 | /** 115 | * Get the bars array 116 | * 117 | * @throws BarcodeException in case of error 118 | */ 119 | protected function setBars() 120 | { 121 | $this->formatCode(); 122 | $chk = $this->getChecksum($this->extcode); 123 | $parity = $this->parities[$chk]; 124 | $seq = '1011'; // left guard bar 125 | $seq .= $this->chbar[$parity[0]][$this->extcode[0]]; 126 | $len = strlen($this->extcode); 127 | for ($pos = 1; $pos < $len; ++$pos) { 128 | $seq .= '01'; // separator 129 | $seq .= $this->chbar[$parity[$pos]][$this->extcode[$pos]]; 130 | } 131 | $this->processBinarySequence($seq); 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/Type/Linear/InterleavedTwoOfFiveCheck.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Linear; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | 20 | /** 21 | * Com\Tecnick\Barcode\Type\Linear\InterleavedTwoOfFiveCheck; 22 | * 23 | * InterleavedTwoOfFiveCheck Barcode type class 24 | * Interleaved 2 of 5 + CHECKSUM 25 | * 26 | * @since 2015-02-21 27 | * @category Library 28 | * @package Barcode 29 | * @author Nicola Asuni 30 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 31 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 32 | * @link https://github.com/tecnickcom/tc-lib-barcode 33 | */ 34 | class InterleavedTwoOfFiveCheck extends \Com\Tecnick\Barcode\Type\Linear\StandardTwoOfFiveCheck 35 | { 36 | /** 37 | * Barcode format 38 | * 39 | * @var string 40 | */ 41 | protected $format = 'I25+'; 42 | 43 | /** 44 | * Map characters to barcodes 45 | * 46 | * @var array 47 | */ 48 | protected $chbar = array( 49 | '0' => '11221', 50 | '1' => '21112', 51 | '2' => '12112', 52 | '3' => '22111', 53 | '4' => '11212', 54 | '5' => '21211', 55 | '6' => '12211', 56 | '7' => '11122', 57 | '8' => '21121', 58 | '9' => '12121', 59 | 'A' => '11', 60 | 'Z' => '21' 61 | ); 62 | 63 | /** 64 | * Format code 65 | */ 66 | protected function formatCode() 67 | { 68 | $this->extcode = $this->code.$this->getChecksum($this->code); 69 | } 70 | 71 | /** 72 | * Get the bars array 73 | * 74 | * @return array 75 | * 76 | * @throws BarcodeException in case of error 77 | */ 78 | protected function setBars() 79 | { 80 | $this->formatCode(); 81 | if ((strlen($this->extcode) % 2) != 0) { 82 | // add leading zero if code-length is odd 83 | $this->extcode = '0'.$this->extcode; 84 | } 85 | // add start and stop codes 86 | $this->extcode = 'AA'.strtolower($this->extcode).'ZA'; 87 | $this->ncols = 0; 88 | $this->nrows = 1; 89 | $this->bars = array(); 90 | $clen = strlen($this->extcode); 91 | for ($idx = 0; $idx < $clen; $idx = ($idx + 2)) { 92 | $char_bar = $this->extcode[$idx]; 93 | $char_space = $this->extcode[($idx + 1)]; 94 | if ((!isset($this->chbar[$char_bar])) || (!isset($this->chbar[$char_space]))) { 95 | throw new BarcodeException('Invalid character sequence: '.$char_bar.$char_space); 96 | } 97 | // create a bar-space sequence 98 | $seq = ''; 99 | $chrlen = strlen($this->chbar[$char_bar]); 100 | for ($pos = 0; $pos < $chrlen; ++$pos) { 101 | $seq .= $this->chbar[$char_bar][$pos].$this->chbar[$char_space][$pos]; 102 | } 103 | $seqlen = strlen($seq); 104 | for ($pos = 0; $pos < $seqlen; ++$pos) { 105 | $bar_width = intval($seq[$pos]); 106 | if ((($pos % 2) == 0) && ($bar_width > 0)) { 107 | $this->bars[] = array($this->ncols, 0, $bar_width, 1); 108 | } 109 | $this->ncols += $bar_width; 110 | } 111 | } 112 | --$this->ncols; 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/Type/Linear/CodeOneOne.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Linear; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | 20 | /** 21 | * Com\Tecnick\Barcode\Type\Linear\CodeOneOne; 22 | * 23 | * CodeOneOne Barcode type class 24 | * CODE 11 25 | * 26 | * @since 2015-02-21 27 | * @category Library 28 | * @package Barcode 29 | * @author Nicola Asuni 30 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 31 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 32 | * @link https://github.com/tecnickcom/tc-lib-barcode 33 | */ 34 | class CodeOneOne extends \Com\Tecnick\Barcode\Type\Linear 35 | { 36 | /** 37 | * Barcode format 38 | * 39 | * @var string 40 | */ 41 | protected $format = 'CODE11'; 42 | 43 | /** 44 | * Map characters to barcodes 45 | * 46 | * @var array 47 | */ 48 | protected $chbar = array( 49 | '0' => '111121', 50 | '1' => '211121', 51 | '2' => '121121', 52 | '3' => '221111', 53 | '4' => '112121', 54 | '5' => '212111', 55 | '6' => '122111', 56 | '7' => '111221', 57 | '8' => '211211', 58 | '9' => '211111', 59 | '-' => '112111', 60 | 'S' => '112211' 61 | ); 62 | 63 | /** 64 | * Calculate the checksum. 65 | * 66 | * @param $code (string) code to represent. 67 | * 68 | * @return char checksum. 69 | */ 70 | protected function getChecksum($code) 71 | { 72 | $len = strlen($code); 73 | // calculate check digit C 74 | $ptr = 1; 75 | $ccheck = 0; 76 | for ($pos = ($len - 1); $pos >= 0; --$pos) { 77 | $digit = $code[$pos]; 78 | if ($digit == '-') { 79 | $dval = 10; 80 | } else { 81 | $dval = intval($digit); 82 | } 83 | $ccheck += ($dval * $ptr); 84 | ++$ptr; 85 | if ($ptr > 10) { 86 | $ptr = 1; 87 | } 88 | } 89 | $ccheck %= 11; 90 | if ($ccheck == 10) { 91 | $ccheck = '-'; 92 | } 93 | if ($len <= 10) { 94 | return $ccheck; 95 | } 96 | // calculate check digit K 97 | $code .= $ccheck; 98 | $ptr = 1; 99 | $kcheck = 0; 100 | for ($pos = $len; $pos >= 0; --$pos) { 101 | $digit = $code[$pos]; 102 | if ($digit == '-') { 103 | $dval = 10; 104 | } else { 105 | $dval = intval($digit); 106 | } 107 | $kcheck += ($dval * $ptr); 108 | ++$ptr; 109 | if ($ptr > 9) { 110 | $ptr = 1; 111 | } 112 | } 113 | $kcheck %= 11; 114 | return $ccheck.$kcheck; 115 | } 116 | 117 | /** 118 | * Format code 119 | */ 120 | protected function formatCode() 121 | { 122 | $this->extcode = 'S'.$this->code.$this->getChecksum($this->code).'S'; 123 | } 124 | 125 | /** 126 | * Get the bars array 127 | * 128 | * @return array 129 | * 130 | * @throws BarcodeException in case of error 131 | */ 132 | protected function setBars() 133 | { 134 | $this->ncols = 0; 135 | $this->nrows = 1; 136 | $this->bars = array(); 137 | $this->formatCode(); 138 | $clen = strlen($this->extcode); 139 | for ($chr = 0; $chr < $clen; ++$chr) { 140 | $char = $this->extcode[$chr]; 141 | if (!isset($this->chbar[$char])) { 142 | throw new BarcodeException('Invalid character: chr('.ord($char).')'); 143 | } 144 | for ($pos = 0; $pos < 6; ++$pos) { 145 | $bar_width = intval($this->chbar[$char][$pos]); 146 | if ((($pos % 2) == 0) && ($bar_width > 0)) { 147 | $this->bars[] = array($this->ncols, 0, $bar_width, 1); 148 | } 149 | $this->ncols += $bar_width; 150 | } 151 | } 152 | --$this->ncols; 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /test/Linear/UpcETest.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Test\Linear; 17 | 18 | use PHPUnit\Framework\TestCase; 19 | 20 | /** 21 | * Barcode class test 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2015-2019 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class UpcETest extends TestCase 32 | { 33 | protected $obj = null; 34 | 35 | public function setUp() 36 | { 37 | //$this->markTestSkipped(); // skip this test 38 | $this->obj = new \Com\Tecnick\Barcode\Barcode; 39 | } 40 | 41 | public function testGetGrid() 42 | { 43 | $bobj = $this->obj->getBarcodeObj('UPCE', '725270'); 44 | $grid = $bobj->getGrid(); 45 | $expected = "101001000100100110110001001101101110110100111010101\n"; 46 | $this->assertEquals($expected, $grid); 47 | 48 | $bobj = $this->obj->getBarcodeObj('UPCE', '725271'); 49 | $grid = $bobj->getGrid(); 50 | $expected = "101001000100100110111001001001101110110110011010101\n"; 51 | $this->assertEquals($expected, $grid); 52 | 53 | $bobj = $this->obj->getBarcodeObj('UPCE', '725272'); 54 | $grid = $bobj->getGrid(); 55 | $expected = "101001000100100110111001001001100100010010011010101\n"; 56 | $this->assertEquals($expected, $grid); 57 | 58 | $bobj = $this->obj->getBarcodeObj('UPCE', '725273'); 59 | $grid = $bobj->getGrid(); 60 | $expected = "101001000100100110110001001101101110110100001010101\n"; 61 | $this->assertEquals($expected, $grid); 62 | 63 | $bobj = $this->obj->getBarcodeObj('UPCE', '725274'); 64 | $grid = $bobj->getGrid(); 65 | $expected = "101001000100100110110001001101100100010100011010101\n"; 66 | $this->assertEquals($expected, $grid); 67 | 68 | $bobj = $this->obj->getBarcodeObj('UPCE', '725275'); 69 | $grid = $bobj->getGrid(); 70 | $expected = "101001000100100110111001001101101110110110001010101\n"; 71 | $this->assertEquals($expected, $grid); 72 | 73 | $bobj = $this->obj->getBarcodeObj('UPCE', '725276'); 74 | $grid = $bobj->getGrid(); 75 | $expected = "101001000100110110110001001101101110110101111010101\n"; 76 | $this->assertEquals($expected, $grid); 77 | 78 | $bobj = $this->obj->getBarcodeObj('UPCE', '725277'); 79 | $grid = $bobj->getGrid(); 80 | $expected = "101001000100100110111001001001101110110010001010101\n"; 81 | $this->assertEquals($expected, $grid); 82 | 83 | $bobj = $this->obj->getBarcodeObj('UPCE', '725278'); 84 | $grid = $bobj->getGrid(); 85 | $expected = "101001000100100110110001001101100100010110111010101\n"; 86 | $this->assertEquals($expected, $grid); 87 | 88 | $bobj = $this->obj->getBarcodeObj('UPCE', '725279'); 89 | $grid = $bobj->getGrid(); 90 | $expected = "101001000100110110110001001001100100010001011010101\n"; 91 | $this->assertEquals($expected, $grid); 92 | 93 | $bobj = $this->obj->getBarcodeObj('UPCE', '0123456789'); 94 | $grid = $bobj->getGrid(); 95 | $expected = "101010011100110010010011010000100111010001011010101\n"; 96 | $this->assertEquals($expected, $grid); 97 | 98 | $bobj = $this->obj->getBarcodeObj('UPCE', '012345678912'); 99 | $grid = $bobj->getGrid(); 100 | $expected = "101011001100110110111101010001101110010011001010101\n"; 101 | $this->assertEquals($expected, $grid); 102 | 103 | $bobj = $this->obj->getBarcodeObj('UPCE', '4210000526'); 104 | $grid = $bobj->getGrid(); 105 | $expected = "101001110100100110111001001101101011110011001010101\n"; 106 | $this->assertEquals($expected, $grid); 107 | 108 | $bobj = $this->obj->getBarcodeObj('UPCE', '4240000526'); 109 | $grid = $bobj->getGrid(); 110 | $expected = "101001110100110110100011001101101011110111101010101\n"; 111 | $this->assertEquals($expected, $grid); 112 | 113 | $bobj = $this->obj->getBarcodeObj('UPCE', '4241000526'); 114 | $grid = $bobj->getGrid(); 115 | $expected = "101001110100100110011101001100101011110011101010101\n"; 116 | $this->assertEquals($expected, $grid); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/Type/Square/Datamatrix/ErrorCorrection.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Square\Datamatrix; 17 | 18 | /** 19 | * Com\Tecnick\Barcode\Type\Square\Datamatrix\ErrorCorrection 20 | * 21 | * Error correction methods and other utilities for Datamatrix Barcode type class 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class ErrorCorrection 32 | { 33 | /** 34 | * Product of two numbers in a Power-of-Two Galois Field 35 | * 36 | * @param int $numa First number to multiply. 37 | * @param int $numb Second number to multiply. 38 | * @param array $log Log table. 39 | * @param array $alog Anti-Log table. 40 | * @param array $ngf Number of Factors of the Reed-Solomon polynomial. 41 | * 42 | * @return int product 43 | */ 44 | protected function getGFProduct($numa, $numb, $log, $alog, $ngf) 45 | { 46 | if (($numa == 0) || ($numb == 0)) { 47 | return 0; 48 | } 49 | return ($alog[($log[$numa] + $log[$numb]) % ($ngf - 1)]); 50 | } 51 | 52 | /** 53 | * Add error correction codewords to data codewords array (ANNEX E). 54 | * 55 | * @param array $wdc Array of datacodewords. 56 | * @param int $nbk Number of blocks. 57 | * @param int $ncw Number of data codewords per block. 58 | * @param int $ncc Number of correction codewords per block. 59 | * @param int $ngf Number of fields on log/antilog table (power of 2). 60 | * @param int $vpp The value of its prime modulus polynomial (301 for ECC200). 61 | * 62 | * @return array data codewords + error codewords 63 | */ 64 | public function getErrorCorrection($wdc, $nbk, $ncw, $ncc, $ngf = 256, $vpp = 301) 65 | { 66 | // generate the log ($log) and antilog ($alog) tables 67 | $log = array(0); 68 | $alog = array(1); 69 | $this->genLogs($log, $alog, $ngf, $vpp); 70 | 71 | // generate the polynomial coefficients (c) 72 | $plc = array_fill(0, ($ncc + 1), 0); 73 | $plc[0] = 1; 74 | for ($i = 1; $i <= $ncc; ++$i) { 75 | $plc[$i] = $plc[($i-1)]; 76 | for ($j = ($i - 1); $j >= 1; --$j) { 77 | $plc[$j] = $plc[($j - 1)] ^ $this->getGFProduct($plc[$j], $alog[$i], $log, $alog, $ngf); 78 | } 79 | $plc[0] = $this->getGFProduct($plc[0], $alog[$i], $log, $alog, $ngf); 80 | } 81 | ksort($plc); 82 | 83 | // total number of data codewords 84 | $num_wd = ($nbk * $ncw); 85 | // total number of error codewords 86 | $num_we = ($nbk * $ncc); 87 | // for each block 88 | for ($b = 0; $b < $nbk; ++$b) { 89 | // create interleaved data block 90 | $block = array(); 91 | for ($n = $b; $n < $num_wd; $n += $nbk) { 92 | $block[] = $wdc[$n]; 93 | } 94 | // initialize error codewords 95 | $wec = array_fill(0, ($ncc + 1), 0); 96 | // calculate error correction codewords for this block 97 | for ($i = 0; $i < $ncw; ++$i) { 98 | $ker = ($wec[0] ^ $block[$i]); 99 | for ($j = 0; $j < $ncc; ++$j) { 100 | $wec[$j] = ($wec[($j + 1)] ^ $this->getGFProduct($ker, $plc[($ncc - $j - 1)], $log, $alog, $ngf)); 101 | } 102 | } 103 | // add error codewords at the end of data codewords 104 | $j = 0; 105 | for ($i = $b; $i < $num_we; $i += $nbk) { 106 | $wdc[($num_wd + $i)] = $wec[$j]; 107 | ++$j; 108 | } 109 | } 110 | // reorder codewords 111 | ksort($wdc); 112 | return $wdc; 113 | } 114 | 115 | /** 116 | * Generate the log ($log) and antilog ($alog) tables 117 | * 118 | * @param array $log Log table 119 | * @param arrya $alog Anti-Log table 120 | * @param int $ngf Number of fields on log/antilog table (power of 2). 121 | * @param int $vpp The value of its prime modulus polynomial (301 for ECC200). 122 | */ 123 | protected function genLogs(&$log, &$alog, $ngf, $vpp) 124 | { 125 | for ($i = 1; $i < $ngf; ++$i) { 126 | $alog[$i] = ($alog[($i - 1)] * 2); 127 | if ($alog[$i] >= $ngf) { 128 | $alog[$i] ^= $vpp; 129 | } 130 | $log[$alog[$i]] = $i; 131 | } 132 | ksort($log); 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /src/Type/Square/QrCode/InputItem.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Square\QrCode; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | use \Com\Tecnick\Barcode\Type\Square\QrCode\Data; 20 | 21 | /** 22 | * Com\Tecnick\Barcode\Type\Square\QrCode\InputItem 23 | * 24 | * @since 2015-02-21 25 | * @category Library 26 | * @package Barcode 27 | * @author Nicola Asuni 28 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 29 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 30 | * @link https://github.com/tecnickcom/tc-lib-barcode 31 | */ 32 | abstract class InputItem extends \Com\Tecnick\Barcode\Type\Square\QrCode\Estimate 33 | { 34 | /** 35 | * Append data to an input object. 36 | * The data is copied and appended to the input object. 37 | * 38 | * @param array $items Input items 39 | * @param int $mode Encoding mode. 40 | * @param int $size Size of data (byte). 41 | * @param array $data Array of input data. 42 | * 43 | * @return array items 44 | */ 45 | public function appendNewInputItem($items, $mode, $size, $data) 46 | { 47 | $newitem = $this->newInputItem($mode, $size, $data); 48 | if (!empty($newitem)) { 49 | $items[] = $newitem; 50 | } 51 | return $items; 52 | } 53 | 54 | /** 55 | * newInputItem 56 | * 57 | * @param int $mode Encoding mode. 58 | * @param int $size Size of data (byte). 59 | * @param array $data Array of input data. 60 | * @param array $bstream Binary stream 61 | * 62 | * @return array input item 63 | */ 64 | protected function newInputItem($mode, $size, $data, $bstream = null) 65 | { 66 | $setData = array_slice($data, 0, $size); 67 | if (count($setData) < $size) { 68 | $setData = array_merge($setData, array_fill(0, ($size - count($setData)), 0)); 69 | } 70 | if (!$this->check($mode, $size, $setData)) { 71 | throw new BarcodeException('Invalid input item'); 72 | } 73 | return array( 74 | 'mode' => $mode, 75 | 'size' => $size, 76 | 'data' => $setData, 77 | 'bstream' => $bstream, 78 | ); 79 | } 80 | 81 | /** 82 | * Validate the input data. 83 | * 84 | * @param int $mode Encoding mode. 85 | * @param int $size Size of data (byte). 86 | * @param array $data Data to validate 87 | * 88 | * @return boolean true in case of valid data, false otherwise 89 | */ 90 | protected function check($mode, $size, $data) 91 | { 92 | if ($size <= 0) { 93 | return false; 94 | } 95 | switch ($mode) { 96 | case Data::$encodingModes['NM']: 97 | return $this->checkModeNum($size, $data); 98 | case Data::$encodingModes['AN']: 99 | return $this->checkModeAn($size, $data); 100 | case Data::$encodingModes['KJ']: 101 | return $this->checkModeKanji($size, $data); 102 | case Data::$encodingModes['8B']: 103 | return true; 104 | case Data::$encodingModes['ST']: 105 | return true; 106 | } 107 | return false; 108 | } 109 | 110 | /** 111 | * checkModeNum 112 | * 113 | * @param int $size 114 | * @param int $data 115 | * 116 | * @return boolean true or false 117 | */ 118 | protected function checkModeNum($size, $data) 119 | { 120 | for ($idx = 0; $idx < $size; ++$idx) { 121 | if ((ord($data[$idx]) < ord('0')) || (ord($data[$idx]) > ord('9'))) { 122 | return false; 123 | } 124 | } 125 | return true; 126 | } 127 | 128 | /** 129 | * checkModeAn 130 | * 131 | * @param int $size 132 | * @param int $data 133 | * 134 | * @return boolean true or false 135 | */ 136 | protected function checkModeAn($size, $data) 137 | { 138 | for ($idx = 0; $idx < $size; ++$idx) { 139 | if ($this->lookAnTable(ord($data[$idx])) == -1) { 140 | return false; 141 | } 142 | } 143 | return true; 144 | } 145 | 146 | /** 147 | * checkModeKanji 148 | * 149 | * @param int $size 150 | * @param int $data 151 | * 152 | * @return boolean true or false 153 | */ 154 | protected function checkModeKanji($size, $data) 155 | { 156 | if ($size & 1) { 157 | return false; 158 | } 159 | for ($idx = 0; $idx < $size; $idx += 2) { 160 | $val = (ord($data[$idx]) << 8) | ord($data[($idx + 1)]); 161 | if (($val < 0x8140) || (($val > 0x9ffc) && ($val < 0xe040)) || ($val > 0xebbf)) { 162 | return false; 163 | } 164 | } 165 | return true; 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /src/Type/Square/QrCode/MaskNum.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Square\QrCode; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | use \Com\Tecnick\Barcode\Type\Square\QrCode\Data; 20 | 21 | /** 22 | * Com\Tecnick\Barcode\Type\Square\QrCode\MaskNum 23 | * 24 | * @since 2015-02-21 25 | * @category Library 26 | * @package Barcode 27 | * @author Nicola Asuni 28 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 29 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 30 | * @link https://github.com/tecnickcom/tc-lib-barcode 31 | */ 32 | abstract class MaskNum 33 | { 34 | /** 35 | * Make Mask Number 36 | * 37 | * @param int $maskNo Mask number 38 | * @param int $width Width 39 | * @param int $frame Frame 40 | * @param int $mask Mask 41 | * 42 | * @return int mask number 43 | */ 44 | protected function makeMaskNo($maskNo, $width, $frame, &$mask) 45 | { 46 | $bnum = 0; 47 | $bitMask = $this->generateMaskNo($maskNo, $width, $frame); 48 | $mask = $frame; 49 | for ($ypos = 0; $ypos < $width; ++$ypos) { 50 | for ($xpos = 0; $xpos < $width; ++$xpos) { 51 | if ($bitMask[$ypos][$xpos] == 1) { 52 | $mask[$ypos][$xpos] = chr(ord($frame[$ypos][$xpos]) ^ ((int)($bitMask[$ypos][$xpos]))); 53 | } 54 | $bnum += (int)(ord($mask[$ypos][$xpos]) & 1); 55 | } 56 | } 57 | return $bnum; 58 | } 59 | 60 | /** 61 | * Return bit mask 62 | * 63 | * @param int $maskNo Mask number 64 | * @param int $width Width 65 | * @param array $frame Frame 66 | * 67 | * @return array bit mask 68 | */ 69 | protected function generateMaskNo($maskNo, $width, $frame) 70 | { 71 | $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); 72 | for ($ypos = 0; $ypos < $width; ++$ypos) { 73 | for ($xpos = 0; $xpos < $width; ++$xpos) { 74 | if (ord($frame[$ypos][$xpos]) & 0x80) { 75 | $bitMask[$ypos][$xpos] = 0; 76 | } else { 77 | $maskFunc = call_user_func(array($this, 'mask'.$maskNo), $xpos, $ypos); 78 | $bitMask[$ypos][$xpos] = (($maskFunc == 0) ? 1 : 0); 79 | } 80 | } 81 | } 82 | return $bitMask; 83 | } 84 | 85 | /** 86 | * Mask 0 87 | * 88 | * @param int $xpos X position 89 | * @param int $ypos Y position 90 | * 91 | * @return int mask 92 | */ 93 | protected function mask0($xpos, $ypos) 94 | { 95 | return (($xpos + $ypos) & 1); 96 | } 97 | 98 | /** 99 | * Mask 1 100 | * 101 | * @param int $xpos X position 102 | * @param int $ypos Y position 103 | * 104 | * @return int mask 105 | */ 106 | protected function mask1($xpos, $ypos) 107 | { 108 | $xpos = null; 109 | return ($ypos & 1); 110 | } 111 | 112 | /** 113 | * Mask 2 114 | * 115 | * @param int $xpos X position 116 | * @param int $ypos Y position 117 | * 118 | * @return int mask 119 | */ 120 | protected function mask2($xpos, $ypos) 121 | { 122 | $ypos = null; 123 | return ($xpos % 3); 124 | } 125 | 126 | /** 127 | * Mask 3 128 | * 129 | * @param int $xpos X position 130 | * @param int $ypos Y position 131 | * 132 | * @return int mask 133 | */ 134 | protected function mask3($xpos, $ypos) 135 | { 136 | return (($xpos + $ypos) % 3); 137 | } 138 | 139 | /** 140 | * Mask 4 141 | * 142 | * @param int $xpos X position 143 | * @param int $ypos Y position 144 | * 145 | * @return int mask 146 | */ 147 | protected function mask4($xpos, $ypos) 148 | { 149 | return ((((int)($ypos / 2)) + ((int)($xpos / 3))) & 1); 150 | } 151 | 152 | /** 153 | * Mask 5 154 | * 155 | * @param int $xpos X position 156 | * @param int $ypos Y position 157 | * 158 | * @return int mask 159 | */ 160 | protected function mask5($xpos, $ypos) 161 | { 162 | return ((($xpos * $ypos) & 1) + ($xpos * $ypos) % 3); 163 | } 164 | 165 | /** 166 | * Mask 6 167 | * 168 | * @param int $xpos X position 169 | * @param int $ypos Y position 170 | * 171 | * @return int mask 172 | */ 173 | protected function mask6($xpos, $ypos) 174 | { 175 | return (((($xpos * $ypos) & 1) + ($xpos * $ypos) % 3) & 1); 176 | } 177 | 178 | /** 179 | * Mask 7 180 | * 181 | * @param int $xpos X position 182 | * @param int $ypos Y position 183 | * 184 | * @return int mask 185 | */ 186 | protected function mask7($xpos, $ypos) 187 | { 188 | return (((($xpos * $ypos) % 3) + (($xpos + $ypos) & 1)) & 1); 189 | } 190 | } 191 | -------------------------------------------------------------------------------- /src/Type/Square/QrCode/Estimate.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Square\QrCode; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | use \Com\Tecnick\Barcode\Type\Square\QrCode\Data; 20 | 21 | /** 22 | * Com\Tecnick\Barcode\Type\Square\QrCode\Estimate 23 | * 24 | * @since 2015-02-21 25 | * @category Library 26 | * @package Barcode 27 | * @author Nicola Asuni 28 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 29 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 30 | * @link https://github.com/tecnickcom/tc-lib-barcode 31 | */ 32 | abstract class Estimate 33 | { 34 | /** 35 | * estimateBitsModeNum 36 | * 37 | * @param int $size 38 | * 39 | * @return int number of bits 40 | */ 41 | public function estimateBitsModeNum($size) 42 | { 43 | $wdt = (int)($size / 3); 44 | $bits = ($wdt * 10); 45 | switch ($size - ($wdt * 3)) { 46 | case 1: 47 | $bits += 4; 48 | break; 49 | case 2: 50 | $bits += 7; 51 | break; 52 | } 53 | return $bits; 54 | } 55 | 56 | /** 57 | * estimateBitsModeAn 58 | * 59 | * @param int $size 60 | * 61 | * @return int number of bits 62 | */ 63 | public function estimateBitsModeAn($size) 64 | { 65 | $bits = (int)($size * 5.5); // (size / 2 ) * 11 66 | if ($size & 1) { 67 | $bits += 6; 68 | } 69 | return $bits; 70 | } 71 | 72 | /** 73 | * estimateBitsMode8 74 | * 75 | * @param int $size 76 | * 77 | * @return int number of bits 78 | */ 79 | public function estimateBitsMode8($size) 80 | { 81 | return (int)($size * 8); 82 | } 83 | 84 | /** 85 | * estimateBitsModeKanji 86 | * 87 | * @param int $size 88 | * 89 | * @return int number of bits 90 | */ 91 | public function estimateBitsModeKanji($size) 92 | { 93 | return (int)($size * 6.5); // (size / 2 ) * 13 94 | } 95 | 96 | /** 97 | * Estimate version 98 | * 99 | * @param array $items 100 | * @param int $level 101 | * 102 | * @return int version 103 | */ 104 | public function estimateVersion($items, $level) 105 | { 106 | $version = 0; 107 | $prev = 0; 108 | do { 109 | $prev = $version; 110 | $bits = $this->estimateBitStreamSize($items, $prev); 111 | $version = $this->getMinimumVersion((int)(($bits + 7) / 8), $level); 112 | if ($version < 0) { 113 | return -1; 114 | } 115 | } while ($version > $prev); 116 | return $version; 117 | } 118 | 119 | /** 120 | * Return a version number that satisfies the input code length. 121 | * 122 | * @param int $size Input code length (bytes) 123 | * @param int $level Error correction level 124 | * 125 | * @return int version number 126 | * 127 | * @throws BarcodeException 128 | */ 129 | protected function getMinimumVersion($size, $level) 130 | { 131 | for ($idx = 1; $idx <= Data::QRSPEC_VERSION_MAX; ++$idx) { 132 | $words = (Data::$capacity[$idx][Data::QRCAP_WORDS] - Data::$capacity[$idx][Data::QRCAP_EC][$level]); 133 | if ($words >= $size) { 134 | return $idx; 135 | } 136 | } 137 | throw new BarcodeException( 138 | 'The size of input data is greater than Data::QR capacity, try to lower the error correction mode' 139 | ); 140 | } 141 | 142 | /** 143 | * estimateBitStreamSize 144 | * 145 | * @param array $items 146 | * @param int $version 147 | * 148 | * @return int bits 149 | */ 150 | protected function estimateBitStreamSize($items, $version) 151 | { 152 | $bits = 0; 153 | if ($version == 0) { 154 | $version = 1; 155 | } 156 | foreach ($items as $item) { 157 | switch ($item['mode']) { 158 | case Data::$encodingModes['NM']: 159 | $bits = $this->estimateBitsModeNum($item['size']); 160 | break; 161 | case Data::$encodingModes['AN']: 162 | $bits = $this->estimateBitsModeAn($item['size']); 163 | break; 164 | case Data::$encodingModes['8B']: 165 | $bits = $this->estimateBitsMode8($item['size']); 166 | break; 167 | case Data::$encodingModes['KJ']: 168 | $bits = $this->estimateBitsModeKanji($item['size']); 169 | break; 170 | case Data::$encodingModes['ST']: 171 | return Data::STRUCTURE_HEADER_BITS; 172 | default: 173 | return 0; 174 | } 175 | $len = $this->getLengthIndicator($item['mode'], $version); 176 | $mod = 1 << $len; 177 | $num = (int)(($item['size'] + $mod - 1) / $mod); 178 | $bits += $num * (4 + $len); 179 | } 180 | return $bits; 181 | } 182 | } 183 | -------------------------------------------------------------------------------- /src/Type/Linear/UpcE.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2019 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Linear; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | 20 | /** 21 | * Com\Tecnick\Barcode\Type\Linear\UpcE; 22 | * 23 | * UpcE Barcode type class 24 | * UPC-E 25 | * 26 | * UPC-E is a variation of UPC-A which allows for a more compact barcode by eliminating "extra" zeros. 27 | * Since the resulting UPC-E barcode is about half the size as an UPC-A barcode, UPC-E is generally used on products 28 | * with very small packaging where a full UPC-A barcode couldn't reasonably fit. 29 | * 30 | * @since 2015-02-21 31 | * @category Library 32 | * @package Barcode 33 | * @author Nicola Asuni 34 | * @copyright 2010-2019 Nicola Asuni - Tecnick.com LTD 35 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 36 | * @link https://github.com/tecnickcom/tc-lib-barcode 37 | */ 38 | class UpcE extends \Com\Tecnick\Barcode\Type\Linear\UpcA 39 | { 40 | /** 41 | * Barcode format 42 | * 43 | * @var string 44 | */ 45 | protected $format = 'UPCE'; 46 | 47 | /** 48 | * Fixed code length 49 | * 50 | * @var int 51 | */ 52 | protected $code_length = 12; 53 | 54 | /** 55 | * Map parities 56 | * 57 | * @var array 58 | */ 59 | protected $parities = array( 60 | 0 => array( 61 | '0' => array('B','B','B','A','A','A'), 62 | '1' => array('B','B','A','B','A','A'), 63 | '2' => array('B','B','A','A','B','A'), 64 | '3' => array('B','B','A','A','A','B'), 65 | '4' => array('B','A','B','B','A','A'), 66 | '5' => array('B','A','A','B','B','A'), 67 | '6' => array('B','A','A','A','B','B'), 68 | '7' => array('B','A','B','A','B','A'), 69 | '8' => array('B','A','B','A','A','B'), 70 | '9' => array('B','A','A','B','A','B') 71 | ), 72 | 1 => array( 73 | '0' => array('A','A','A','B','B','B'), 74 | '1' => array('A','A','B','A','B','B'), 75 | '2' => array('A','A','B','B','A','B'), 76 | '3' => array('A','A','B','B','B','A'), 77 | '4' => array('A','B','A','A','B','B'), 78 | '5' => array('A','B','B','A','A','B'), 79 | '6' => array('A','B','B','B','A','A'), 80 | '7' => array('A','B','A','B','A','B'), 81 | '8' => array('A','B','A','B','B','A'), 82 | '9' => array('A','B','B','A','B','A') 83 | ) 84 | ); 85 | 86 | /** 87 | * Convert UPC-E code to UPC-A 88 | * 89 | * @param string $code Code to convert. 90 | * 91 | * @return string 92 | */ 93 | protected function convertUpceToUpca($code) 94 | { 95 | if ($code[5] < 3) { 96 | return '0'.$code[0].$code[1].$code[5].'0000'.$code[2].$code[3].$code[4]; 97 | } 98 | if ($code[5] == 3) { 99 | return '0'.$code[0].$code[1].$code[2].'00000'.$code[3].$code[4]; 100 | } 101 | if ($code[5] == 4) { 102 | return '0'.$code[0].$code[1].$code[2].$code[3].'00000'.$code[4]; 103 | } 104 | return '0'.$code[0].$code[1].$code[2].$code[3].$code[4].'0000'.$code[5]; 105 | } 106 | 107 | /** 108 | * Convert UPC-A code to UPC-E 109 | * 110 | * @param string $code Code to convert. 111 | * 112 | * @return string 113 | */ 114 | protected function convertUpcaToUpce($code) 115 | { 116 | $tmp = substr($code, 4, 3); 117 | if (($tmp == '000') || ($tmp == '100') || ($tmp == '200')) { 118 | // manufacturer code ends in 000, 100, or 200 119 | return substr($code, 2, 2).substr($code, 9, 3).substr($code, 4, 1); 120 | } 121 | $tmp = substr($code, 5, 2); 122 | if ($tmp == '00') { 123 | // manufacturer code ends in 00 124 | return substr($code, 2, 3).substr($code, 10, 2).'3'; 125 | } 126 | $tmp = substr($code, 6, 1); 127 | if ($tmp == '0') { 128 | // manufacturer code ends in 0 129 | return substr($code, 2, 4).substr($code, 11, 1).'4'; 130 | } 131 | // manufacturer code does not end in zero 132 | return substr($code, 2, 5).substr($code, 11, 1); 133 | } 134 | 135 | /** 136 | * Format the code 137 | */ 138 | protected function formatCode() 139 | { 140 | $code = $this->code; 141 | if (strlen($code) == 6) { 142 | $code = $this->convertUpceToUpca($code); 143 | } 144 | $code = str_pad($code, ($this->code_length - 1), '0', STR_PAD_LEFT); 145 | $code .= $this->getChecksum($code); 146 | ++$this->code_length; 147 | $this->extcode = '0'.$code; 148 | } 149 | 150 | /** 151 | * Get the bars array 152 | * 153 | * @throws BarcodeException in case of error 154 | */ 155 | protected function setBars() 156 | { 157 | $this->formatCode(); 158 | $upce_code = $this->convertUpcaToUpce($this->extcode); 159 | $seq = '101'; // left guard bar 160 | $parity = $this->parities[$this->extcode[1]][$this->check]; 161 | for ($pos = 0; $pos < 6; ++$pos) { 162 | $seq .= $this->chbar[$parity[$pos]][$upce_code[$pos]]; 163 | } 164 | $seq .= '010101'; // right guard bar 165 | $this->processBinarySequence($seq); 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /src/Type/Linear/EanOneThree.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Linear; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | 20 | /** 21 | * Com\Tecnick\Barcode\Type\Linear\EanOneThree; 22 | * 23 | * EanOneThree Barcode type class 24 | * EAN 13 25 | * 26 | * @since 2015-02-21 27 | * @category Library 28 | * @package Barcode 29 | * @author Nicola Asuni 30 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 31 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 32 | * @link https://github.com/tecnickcom/tc-lib-barcode 33 | */ 34 | class EanOneThree extends \Com\Tecnick\Barcode\Type\Linear 35 | { 36 | /** 37 | * Barcode format 38 | * 39 | * @var string 40 | */ 41 | protected $format = 'EAN13'; 42 | 43 | /** 44 | * Fixed code length 45 | * 46 | * @var int 47 | */ 48 | protected $code_length = 13; 49 | 50 | /** 51 | * Check digit 52 | * 53 | * @var int 54 | */ 55 | protected $check = ''; 56 | 57 | /** 58 | * Map characters to barcodes 59 | * 60 | * @var array 61 | */ 62 | protected $chbar = array( 63 | 'A' => array( // left odd parity 64 | '0' => '0001101', 65 | '1' => '0011001', 66 | '2' => '0010011', 67 | '3' => '0111101', 68 | '4' => '0100011', 69 | '5' => '0110001', 70 | '6' => '0101111', 71 | '7' => '0111011', 72 | '8' => '0110111', 73 | '9' => '0001011' 74 | ), 75 | 'B' => array( // left even parity 76 | '0' => '0100111', 77 | '1' => '0110011', 78 | '2' => '0011011', 79 | '3' => '0100001', 80 | '4' => '0011101', 81 | '5' => '0111001', 82 | '6' => '0000101', 83 | '7' => '0010001', 84 | '8' => '0001001', 85 | '9' => '0010111' 86 | ), 87 | 'C' => array( // right 88 | '0' => '1110010', 89 | '1' => '1100110', 90 | '2' => '1101100', 91 | '3' => '1000010', 92 | '4' => '1011100', 93 | '5' => '1001110', 94 | '6' => '1010000', 95 | '7' => '1000100', 96 | '8' => '1001000', 97 | '9' => '1110100' 98 | ) 99 | ); 100 | 101 | /** 102 | * Map parities 103 | * 104 | * @var array 105 | */ 106 | protected $parities = array( 107 | '0' => 'AAAAAA', 108 | '1' => 'AABABB', 109 | '2' => 'AABBAB', 110 | '3' => 'AABBBA', 111 | '4' => 'ABAABB', 112 | '5' => 'ABBAAB', 113 | '6' => 'ABBBAA', 114 | '7' => 'ABABAB', 115 | '8' => 'ABABBA', 116 | '9' => 'ABBABA' 117 | ); 118 | 119 | /** 120 | * Calculate checksum 121 | * 122 | * @param $code (string) code to represent. 123 | * 124 | * @return char checksum. 125 | * 126 | * @throws BarcodeException in case of error 127 | */ 128 | protected function getChecksum($code) 129 | { 130 | $data_len = ($this->code_length - 1); 131 | $code_len = strlen($code); 132 | $sum_a = 0; 133 | for ($pos = 1; $pos < $data_len; $pos += 2) { 134 | $sum_a += $code[$pos]; 135 | } 136 | if ($this->code_length > 12) { 137 | $sum_a *= 3; 138 | } 139 | $sum_b = 0; 140 | for ($pos = 0; $pos < $data_len; $pos += 2) { 141 | $sum_b += ($code[$pos]); 142 | } 143 | if ($this->code_length < 13) { 144 | $sum_b *= 3; 145 | } 146 | $this->check = ($sum_a + $sum_b) % 10; 147 | if ($this->check > 0) { 148 | $this->check = (10 - $this->check); 149 | } 150 | if ($code_len == $data_len) { 151 | // add check digit 152 | return $this->check; 153 | } elseif ($this->check !== intval($code[$data_len])) { 154 | // wrong check digit 155 | throw new BarcodeException('Invalid check digit: '.$this->check); 156 | } 157 | return ''; 158 | } 159 | 160 | /** 161 | * Format code 162 | */ 163 | protected function formatCode() 164 | { 165 | $code = str_pad($this->code, ($this->code_length - 1), '0', STR_PAD_LEFT); 166 | $this->extcode = $code.$this->getChecksum($code); 167 | } 168 | 169 | /** 170 | * Get the bars array 171 | * 172 | * @throws BarcodeException in case of error 173 | */ 174 | protected function setBars() 175 | { 176 | if (!is_numeric($this->code)) { 177 | throw new BarcodeException('Input code must be a number'); 178 | } 179 | $this->formatCode(); 180 | $seq = '101'; // left guard bar 181 | $half_len = intval(ceil($this->code_length / 2)); 182 | $parity = $this->parities[$this->extcode[0]]; 183 | for ($pos = 1; $pos < $half_len; ++$pos) { 184 | $seq .= $this->chbar[$parity[($pos - 1)]][$this->extcode[$pos]]; 185 | } 186 | $seq .= '01010'; // center guard bar 187 | for ($pos = $half_len; $pos < $this->code_length; ++$pos) { 188 | $seq .= $this->chbar['C'][$this->extcode[$pos]]; 189 | } 190 | $seq .= '101'; // right guard bar 191 | $this->processBinarySequence($seq); 192 | } 193 | } 194 | -------------------------------------------------------------------------------- /src/Type/Convert.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | use \Com\Tecnick\Color\Exception as ColorException; 20 | 21 | /** 22 | * Com\Tecnick\Barcode\Type\Convert 23 | * 24 | * Barcode Convert class 25 | * 26 | * @since 2015-02-21 27 | * @category Library 28 | * @package Barcode 29 | * @author Nicola Asuni 30 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 31 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 32 | * @link https://github.com/tecnickcom/tc-lib-barcode 33 | */ 34 | abstract class Convert 35 | { 36 | /** 37 | * Import a binary sequence of comma-separated 01 strings 38 | * 39 | * @param string $code Code to process 40 | */ 41 | protected function processBinarySequence($code) 42 | { 43 | $raw = new \Com\Tecnick\Barcode\Type\Raw($code, $this->width, $this->height); 44 | $data = $raw->getArray(); 45 | $this->ncols = $data['ncols']; 46 | $this->nrows = $data['nrows']; 47 | $this->bars = $data['bars']; 48 | } 49 | 50 | /** 51 | * Convert large integer number to hexadecimal representation. 52 | * 53 | * @param string $number Number to convert (as string) 54 | * 55 | * @return string hexadecimal representation 56 | */ 57 | protected function convertDecToHex($number) 58 | { 59 | if ($number == 0) { 60 | return '00'; 61 | } 62 | $hex = array(); 63 | while ($number > 0) { 64 | array_push($hex, strtoupper(dechex(bcmod($number, '16')))); 65 | $number = bcdiv($number, '16', 0); 66 | } 67 | $hex = array_reverse($hex); 68 | return implode($hex); 69 | } 70 | 71 | /** 72 | * Convert large hexadecimal number to decimal representation (string). 73 | * 74 | * @param string $hex Hexadecimal number to convert (as string) 75 | * 76 | * @return string hexadecimal representation 77 | */ 78 | protected function convertHexToDec($hex) 79 | { 80 | $dec = 0; 81 | $bitval = 1; 82 | $len = strlen($hex); 83 | for ($pos = ($len - 1); $pos >= 0; --$pos) { 84 | $dec = bcadd($dec, bcmul(hexdec($hex[$pos]), $bitval)); 85 | $bitval = bcmul($bitval, 16); 86 | } 87 | return $dec; 88 | } 89 | 90 | /** 91 | * Get a raw barcode grid array 92 | * 93 | * @param string $space_char Character or string to use for filling empty spaces 94 | * @param string $bar_char Character or string to use for filling bars 95 | * 96 | * @return array 97 | */ 98 | public function getGridArray($space_char = '0', $bar_char = '1') 99 | { 100 | $raw = array_fill(0, $this->nrows, array_fill(0, $this->ncols, $space_char)); 101 | foreach ($this->bars as $bar) { 102 | if (($bar[2] > 0) && ($bar[3] > 0)) { 103 | for ($vert = 0; $vert < $bar[3]; ++$vert) { 104 | for ($horiz = 0; $horiz < $bar[2]; ++$horiz) { 105 | $raw[($bar[1] + $vert)][($bar[0] + $horiz)] = $bar_char; 106 | } 107 | } 108 | } 109 | } 110 | return $raw; 111 | } 112 | 113 | /** 114 | * Returns the bars array ordered by columns 115 | * 116 | * @return array 117 | */ 118 | protected function getRotatedBarArray() 119 | { 120 | $grid = $this->getGridArray(); 121 | $cols = call_user_func_array('array_map', array(-1 => null) + $grid); 122 | $bars = array(); 123 | foreach ($cols as $posx => $col) { 124 | $prevrow = ''; 125 | $bar_height = 0; 126 | $col[] = '0'; 127 | for ($posy = 0; $posy <= $this->nrows; ++$posy) { 128 | if ($col[$posy] != $prevrow) { 129 | if ($prevrow == '1') { 130 | $bars[] = array($posx, ($posy - $bar_height), 1, $bar_height); 131 | } 132 | $bar_height = 0; 133 | } 134 | ++$bar_height; 135 | $prevrow = $col[$posy]; 136 | } 137 | } 138 | return $bars; 139 | } 140 | 141 | /** 142 | * Get the adjusted rectangular coordinates (x1,y1,x2,y2) for the specified bar 143 | * 144 | * @param array Raw bar coordinates 145 | * 146 | * @return array Bar coordinates 147 | */ 148 | protected function getBarRectXYXY($bar) 149 | { 150 | return array( 151 | ($this->padding['L'] + ($bar[0] * $this->width_ratio)), 152 | ($this->padding['T'] + ($bar[1] * $this->height_ratio)), 153 | ($this->padding['L'] + (($bar[0] + $bar[2]) * $this->width_ratio) - 1), 154 | ($this->padding['T'] + (($bar[1] + $bar[3]) * $this->height_ratio) - 1) 155 | ); 156 | } 157 | 158 | /** 159 | * Get the adjusted rectangular coordinates (x,y,w,h) for the specified bar 160 | * 161 | * @param array Raw bar coordinates 162 | * 163 | * @return array Bar coordinates 164 | */ 165 | protected function getBarRectXYWH($bar) 166 | { 167 | return array( 168 | ($this->padding['L'] + ($bar[0] * $this->width_ratio)), 169 | ($this->padding['T'] + ($bar[1] * $this->height_ratio)), 170 | ($bar[2] * $this->width_ratio), 171 | ($bar[3] * $this->height_ratio) 172 | ); 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /src/Type/Square/QrCode/SpecRs.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Square\QrCode; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | use \Com\Tecnick\Barcode\Type\Square\QrCode\Data; 20 | 21 | /** 22 | * Com\Tecnick\Barcode\Type\Square\QrCode\SpecRs 23 | * 24 | * @since 2015-02-21 25 | * @category Library 26 | * @package Barcode 27 | * @author Nicola Asuni 28 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 29 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 30 | * @link https://github.com/tecnickcom/tc-lib-barcode 31 | */ 32 | abstract class SpecRs 33 | { 34 | /** 35 | * Return block number 0 36 | * 37 | * @param array $spec 38 | * 39 | * @return int value 40 | */ 41 | public function rsBlockNum($spec) 42 | { 43 | return ($spec[0] + $spec[3]); 44 | } 45 | 46 | /** 47 | * Return block number 1 48 | * 49 | * @param array $spec 50 | * 51 | * @return int value 52 | */ 53 | public function rsBlockNum1($spec) 54 | { 55 | return $spec[0]; 56 | } 57 | 58 | /** 59 | * Return data codes 1 60 | * 61 | * @param array $spec 62 | * 63 | * @return int value 64 | */ 65 | public function rsDataCodes1($spec) 66 | { 67 | return $spec[1]; 68 | } 69 | 70 | /** 71 | * Return ecc codes 1 72 | * 73 | * @param array $spec 74 | * 75 | * @return int value 76 | */ 77 | public function rsEccCodes1($spec) 78 | { 79 | return $spec[2]; 80 | } 81 | 82 | /** 83 | * Return block number 2 84 | * 85 | * @param array $spec 86 | * 87 | * @return int value 88 | */ 89 | public function rsBlockNum2($spec) 90 | { 91 | return $spec[3]; 92 | } 93 | 94 | /** 95 | * Return data codes 2 96 | * 97 | * @param array $spec 98 | * 99 | * @return int value 100 | */ 101 | public function rsDataCodes2($spec) 102 | { 103 | return $spec[4]; 104 | } 105 | 106 | /** 107 | * Return ecc codes 2 108 | * 109 | * @param array $spec 110 | * 111 | * @return int value 112 | */ 113 | public function rsEccCodes2($spec) 114 | { 115 | return $spec[2]; 116 | } 117 | 118 | /** 119 | * Return data length 120 | * 121 | * @param array $spec 122 | * 123 | * @return int value 124 | */ 125 | public function rsDataLength($spec) 126 | { 127 | return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]); 128 | } 129 | 130 | /** 131 | * Return ecc length 132 | * 133 | * @param array $spec 134 | * 135 | * @return int value 136 | */ 137 | public function rsEccLength($spec) 138 | { 139 | return ($spec[0] + $spec[3]) * $spec[2]; 140 | } 141 | 142 | /** 143 | * Return a copy of initialized frame. 144 | * 145 | * @param int $version Version 146 | * 147 | * @return Array of unsigned char. 148 | */ 149 | public function createFrame($version) 150 | { 151 | $width = Data::$capacity[$version][Data::QRCAP_WIDTH]; 152 | $frameLine = str_repeat("\0", $width); 153 | $frame = array_fill(0, $width, $frameLine); 154 | // Finder pattern 155 | $frame = $this->putFinderPattern($frame, 0, 0); 156 | $frame = $this->putFinderPattern($frame, $width - 7, 0); 157 | $frame = $this->putFinderPattern($frame, 0, $width - 7); 158 | // Separator 159 | $yOffset = $width - 7; 160 | for ($ypos = 0; $ypos < 7; ++$ypos) { 161 | $frame[$ypos][7] = "\xc0"; 162 | $frame[$ypos][$width - 8] = "\xc0"; 163 | $frame[$yOffset][7] = "\xc0"; 164 | ++$yOffset; 165 | } 166 | $setPattern = str_repeat("\xc0", 8); 167 | $frame = $this->qrstrset($frame, 0, 7, $setPattern); 168 | $frame = $this->qrstrset($frame, $width-8, 7, $setPattern); 169 | $frame = $this->qrstrset($frame, 0, $width - 8, $setPattern); 170 | // Format info 171 | $setPattern = str_repeat("\x84", 9); 172 | $frame = $this->qrstrset($frame, 0, 8, $setPattern); 173 | $frame = $this->qrstrset($frame, $width - 8, 8, $setPattern, 8); 174 | $yOffset = $width - 8; 175 | for ($ypos = 0; $ypos < 8; ++$ypos, ++$yOffset) { 176 | $frame[$ypos][8] = "\x84"; 177 | $frame[$yOffset][8] = "\x84"; 178 | } 179 | // Timing pattern 180 | $wdo = $width - 15; 181 | for ($idx = 1; $idx < $wdo; ++$idx) { 182 | $frame[6][(7 + $idx)] = chr(0x90 | ($idx & 1)); 183 | $frame[(7 + $idx)][6] = chr(0x90 | ($idx & 1)); 184 | } 185 | // Alignment pattern 186 | $frame = $this->putAlignmentPattern($version, $frame, $width); 187 | // Version information 188 | if ($version >= 7) { 189 | $vinf = $this->getVersionPattern($version); 190 | $val = $vinf; 191 | for ($xpos = 0; $xpos < 6; ++$xpos) { 192 | for ($ypos = 0; $ypos < 3; ++$ypos) { 193 | $frame[(($width - 11) + $ypos)][$xpos] = chr(0x88 | ($val & 1)); 194 | $val = $val >> 1; 195 | } 196 | } 197 | $val = $vinf; 198 | for ($ypos = 0; $ypos < 6; ++$ypos) { 199 | for ($xpos = 0; $xpos < 3; ++$xpos) { 200 | $frame[$ypos][($xpos + ($width - 11))] = chr(0x88 | ($val & 1)); 201 | $val = $val >> 1; 202 | } 203 | } 204 | } 205 | // and a little bit... 206 | $frame[$width - 8][8] = "\x81"; 207 | return $frame; 208 | } 209 | } 210 | -------------------------------------------------------------------------------- /test/Linear/ImbTest.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Test\Linear; 17 | 18 | use PHPUnit\Framework\TestCase; 19 | 20 | /** 21 | * Barcode class test 22 | * 23 | * @since 2015-02-21 24 | * @category Library 25 | * @package Barcode 26 | * @author Nicola Asuni 27 | * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD 28 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 29 | * @link https://github.com/tecnickcom/tc-lib-barcode 30 | */ 31 | class ImbTest extends TestCase 32 | { 33 | protected $obj = null; 34 | 35 | public function setUp() 36 | { 37 | //$this->markTestSkipped(); // skip this test 38 | $this->obj = new \Com\Tecnick\Barcode\Barcode; 39 | } 40 | 41 | public function testGetGrid() 42 | { 43 | $bobj = $this->obj->getBarcodeObj('IMB', '00000-'); 44 | $grid = $bobj->getGrid(); 45 | $expected = "100000101010001000101000101000000010000010100010001010100000" 46 | ."100010001000000010101000001010101000100000000000100010001000100000001\n" 47 | ."1010101010101010101010101010101010101010101010101010101010101010101" 48 | ."01010101010101010101010101010101010101010101010101010101010101\n" 49 | ."0000101000000010000010001000000000101010000010000000001000101010001" 50 | ."01010001010001010000010101000101000101000000000001000001000100\n"; 51 | $this->assertEquals($expected, $grid); 52 | 53 | $bobj = $this->obj->getBarcodeObj('IMB', '0123456789'); 54 | $grid = $bobj->getGrid(); 55 | $expected = "001010100010101000100010001010101010001000001000101010001010" 56 | ."101010100000000000000010101000000010001010100010001000101010001000001\n" 57 | ."1010101010101010101010101010101010101010101010101010101010101010101" 58 | ."01010101010101010101010101010101010101010101010101010101010101\n" 59 | ."1010101010101000001010000010101000000000000010100010001010000000000" 60 | ."00010100000100010001000001010101000001010000010101010100010101\n"; 61 | $this->assertEquals($expected, $grid); 62 | 63 | $bobj = $this->obj->getBarcodeObj('IMB', '01234567094987654321-01234567891'); 64 | $grid = $bobj->getGrid(); 65 | $expected = "10100000101000100000100000101000101000100000000010101000000000000000101010001" 66 | ."0000000001010100000000000100010101010001000001010001\n" 67 | ."101010101010101010101010101010101010101010101010101010101010101010101010101010101010" 68 | ."101010101010101010101010101010101010101010101\n" 69 | ."000010001010101000100010000000100000001010001010000000101000100000100010001000101010" 70 | ."001010101010000000001010000000101000100000100\n"; 71 | $this->assertEquals($expected, $grid); 72 | 73 | $bobj = $this->obj->getBarcodeObj('IMB', '01234567094987654321-012345678'); 74 | $grid = $bobj->getGrid(); 75 | $expected = "10001000001010000000000010100000100000101010001000100010000010101010000010001" 76 | ."0001000000000000000100000001000100010000000101000101\n" 77 | ."101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010" 78 | ."101010101010101010101010101010101\n" 79 | ."001010000000101000000000100000000010000000000010001000000010000000101010001000000000100010000010" 80 | ."101000100000001000100010101000100\n"; 81 | $this->assertEquals($expected, $grid); 82 | 83 | $bobj = $this->obj->getBarcodeObj('IMB', '01234567094987654321-01234'); 84 | $grid = $bobj->getGrid(); 85 | $expected = "00000010101000000000100000001000100000000010001000101010001010000000100010101" 86 | ."0100000001000101010100000100000001010000000000010100\n" 87 | ."101010101010101010101010101010101010101010101010101010101010101010101010101010101010" 88 | ."101010101010101010101010101010101010101010101\n" 89 | ."100000001000101000001000100010001010001010001000100010001010000010101000000000101000" 90 | ."000010100000000010101000101000101010001010100\n"; 91 | $this->assertEquals($expected, $grid); 92 | 93 | $bobj = $this->obj->getBarcodeObj('IMB', '01234567094987654321-'); 94 | $grid = $bobj->getGrid(); 95 | $expected = "10000010100000000000100000101000000000000010000000101000001010001000100010101" 96 | ."0101000100010101010100000101000001010001000100000000\n" 97 | ."101010101010101010101010101010101010101010101010101010101010101010101010101010101010" 98 | ."101010101010101010101010101010101010101010101\n" 99 | ."000000100000001000000010000000000010001000000000100010101010001010101000101010101000" 100 | ."000010000000000010101000100000101000101000100\n"; 101 | $this->assertEquals($expected, $grid); 102 | 103 | $bobj = $this->obj->getBarcodeObj('IMB', '01234567094987654321-01234567891'); 104 | $grid = $bobj->getGrid(); 105 | $expected = "10100000101000100000100000101000101000100000000010101000000000000000101010001" 106 | ."0000000001010100000000000100010101010001000001010001\n" 107 | ."101010101010101010101010101010101010101010101010101010101010101010101010101010101010" 108 | ."101010101010101010101010101010101010101010101\n" 109 | ."000010001010101000100010000000100000001010001010000000101000100000100010001000101010" 110 | ."001010101010000000001010000000101000100000100\n"; 111 | $this->assertEquals($expected, $grid); 112 | } 113 | 114 | /** 115 | * @expectedException \Com\Tecnick\Barcode\Exception 116 | */ 117 | public function testInvalidRoutingCode() 118 | { 119 | $this->obj->getBarcodeObj('IMB', '01234567094987654321-1'); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/Barcode.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | 20 | /** 21 | * Com\Tecnick\Barcode\Barcode 22 | * 23 | * Barcode Barcode class 24 | * 25 | * @since 2015-02-21 26 | * @category Library 27 | * @package Barcode 28 | * @author Nicola Asuni 29 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 30 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 31 | * @link https://github.com/tecnickcom/tc-lib-barcode 32 | */ 33 | class Barcode 34 | { 35 | /** 36 | * Array containing the map between the barcode type and correspondent class 37 | * 38 | * @var array 39 | */ 40 | protected static $typeclass = array( 41 | 'C128A' => 'Linear\\CodeOneTwoEight\\A', // CODE 128 A 42 | 'C128B' => 'Linear\\CodeOneTwoEight\\B', // CODE 128 B 43 | 'C128C' => 'Linear\\CodeOneTwoEight\\C', // CODE 128 C 44 | 'C128' => 'Linear\\CodeOneTwoEight', // CODE 128 45 | 'C39E+' => 'Linear\\CodeThreeNineExtCheck', // CODE 39 EXTENDED + CHECKSUM 46 | 'C39E' => 'Linear\\CodeThreeNineExt', // CODE 39 EXTENDED 47 | 'C39+' => 'Linear\\CodeThreeNineCheck', // CODE 39 + CHECKSUM 48 | 'C39' => 'Linear\\CodeThreeNine', // CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9. 49 | 'C93' => 'Linear\\CodeNineThree', // CODE 93 - USS-93 50 | 'CODABAR' => 'Linear\\Codabar', // CODABAR 51 | 'CODE11' => 'Linear\\CodeOneOne', // CODE 11 52 | 'EAN13' => 'Linear\\EanOneThree', // EAN 13 53 | 'EAN2' => 'Linear\\EanTwo', // EAN 2-Digits UPC-Based Extension 54 | 'EAN5' => 'Linear\\EanFive', // EAN 5-Digits UPC-Based Extension 55 | 'EAN8' => 'Linear\\EanEight', // EAN 8 56 | 'I25+' => 'Linear\\InterleavedTwoOfFiveCheck', // Interleaved 2 of 5 + CHECKSUM 57 | 'I25' => 'Linear\\InterleavedTwoOfFive', // Interleaved 2 of 5 58 | 'IMB' => 'Linear\\Imb', // IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200 59 | 'IMBPRE' => 'Linear\\ImbPre', // IMB - Intelligent Mail Barcode pre-processed 60 | 'KIX' => 'Linear\\KlantIndex', // KIX (Klant index - Customer index) 61 | 'MSI+' => 'Linear\\MsiCheck', // MSI + CHECKSUM (modulo 11) 62 | 'MSI' => 'Linear\\Msi', // MSI (Variation of Plessey code) 63 | 'PHARMA2T' => 'Linear\\PharmaTwoTracks', // PHARMACODE TWO-TRACKS 64 | 'PHARMA' => 'Linear\\Pharma', // PHARMACODE 65 | 'PLANET' => 'Linear\\Planet', // PLANET 66 | 'POSTNET' => 'Linear\\Postnet', // POSTNET 67 | 'RMS4CC' => 'Linear\\RoyalMailFourCc', // RMS4CC (Royal Mail 4-state Customer Bar Code) 68 | 'S25+' => 'Linear\\StandardTwoOfFiveCheck', // Standard 2 of 5 + CHECKSUM 69 | 'S25' => 'Linear\\StandardTwoOfFive', // Standard 2 of 5 70 | 'UPCA' => 'Linear\\UpcA', // UPC-A 71 | 'UPCE' => 'Linear\\UpcE', // UPC-E 72 | 'DATAMATRIX' => 'Square\\Datamatrix', // DATAMATRIX (ISO/IEC 16022) 73 | 'PDF417' => 'Square\\PdfFourOneSeven', // PDF417 (ISO/IEC 15438:2006) 74 | 'QRCODE' => 'Square\\QrCode', // QR-CODE 75 | 'LRAW' => 'Linear\\Raw', // 1D RAW MODE (comma-separated rows of 01 strings) 76 | 'SRAW' => 'Square\\Raw', // 2D RAW MODE (comma-separated rows of 01 strings) 77 | ); 78 | 79 | /** 80 | * Get the list of supported Barcode types 81 | * 82 | * @return array 83 | */ 84 | public function getTypes() 85 | { 86 | return array_keys(self::$typeclass); 87 | } 88 | 89 | /** 90 | * Get the barcode object 91 | * 92 | * @param string $type Barcode type 93 | * @param string $code Barcode content 94 | * @param int $width Barcode width in user units (excluding padding). 95 | * A negative value indicates the multiplication factor for each column. 96 | * @param int $height Barcode height in user units (excluding padding). 97 | * A negative value indicates the multiplication factor for each row. 98 | * @param string $color Foreground color in Web notation (color name, or hexadecimal code, or CSS syntax) 99 | * @param array $padding Additional padding to add around the barcode (top, right, bottom, left) in user units. 100 | * A negative value indicates the multiplication factor for each row or column. 101 | * 102 | * @return Type 103 | * 104 | * @throws BarcodeException in case of error 105 | */ 106 | public function getBarcodeObj( 107 | $type, 108 | $code, 109 | $width = -1, 110 | $height = -1, 111 | $color = 'black', 112 | $padding = array(0, 0, 0, 0) 113 | ) { 114 | // extract extra parameters (if any) 115 | $params = explode(',', $type); 116 | $type = array_shift($params); 117 | 118 | if (empty(self::$typeclass[$type])) { 119 | throw new BarcodeException('Unsupported barcode type: '.$type); 120 | } 121 | $bclass = '\\Com\\Tecnick\\Barcode\\Type\\'.self::$typeclass[$type]; 122 | return new $bclass($code, $width, $height, $color, $params, $padding); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /example/index.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2015-2020 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | // autoloader when using Composer 17 | require ('../vendor/autoload.php'); 18 | 19 | // autoloader when using RPM or DEB package installation 20 | //require ('/usr/share/php/Com/Tecnick/Barcode/autoload.php'); 21 | 22 | // data to generate for each barcode type 23 | $linear = array( 24 | 'C128A' => array('0123456789', 'CODE 128 A'), 25 | 'C128B' => array('0123456789', 'CODE 128 B'), 26 | 'C128C' => array('0123456789', 'CODE 128 C'), 27 | 'C128' => array('0123456789', 'CODE 128'), 28 | 'C39E+' => array('0123456789', 'CODE 39 EXTENDED + CHECKSUM'), 29 | 'C39E' => array('0123456789', 'CODE 39 EXTENDED'), 30 | 'C39+' => array('0123456789', 'CODE 39 + CHECKSUM'), 31 | 'C39' => array('0123456789', 'CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9'), 32 | 'C93' => array('0123456789', 'CODE 93 - USS-93'), 33 | 'CODABAR' => array('0123456789', 'CODABAR'), 34 | 'CODE11' => array('0123456789', 'CODE 11'), 35 | 'EAN13' => array('0123456789', 'EAN 13'), 36 | 'EAN2' => array('12', 'EAN 2-Digits UPC-Based Extension'), 37 | 'EAN5' => array('12345', 'EAN 5-Digits UPC-Based Extension'), 38 | 'EAN8' => array('1234567', 'EAN 8'), 39 | 'I25+' => array('0123456789', 'Interleaved 2 of 5 + CHECKSUM'), 40 | 'I25' => array('0123456789', 'Interleaved 2 of 5'), 41 | 'IMB' => array('01234567094987654321-01234567891', 'IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200'), 42 | 'IMBPRE' => array('AADTFFDFTDADTAADAATFDTDDAAADDTDTTDAFADADDDTFFFDDTTTADFAAADFTDAADA', 'IMB pre-processed'), 43 | 'KIX' => array('0123456789', 'KIX (Klant index - Customer index)'), 44 | 'MSI+' => array('0123456789', 'MSI + CHECKSUM (modulo 11)'), 45 | 'MSI' => array('0123456789', 'MSI (Variation of Plessey code)'), 46 | 'PHARMA2T' => array('0123456789', 'PHARMACODE TWO-TRACKS'), 47 | 'PHARMA' => array('0123456789', 'PHARMACODE'), 48 | 'PLANET' => array('0123456789', 'PLANET'), 49 | 'POSTNET' => array('0123456789', 'POSTNET'), 50 | 'RMS4CC' => array('0123456789', 'RMS4CC (Royal Mail 4-state Customer Bar Code)'), 51 | 'S25+' => array('0123456789', 'Standard 2 of 5 + CHECKSUM'), 52 | 'S25' => array('0123456789', 'Standard 2 of 5'), 53 | 'UPCA' => array('72527273070', 'UPC-A'), 54 | 'UPCE' => array('725277', 'UPC-E'), 55 | ); 56 | 57 | $square = array( 58 | 'LRAW' => array('0101010101', '1D RAW MODE (comma-separated rows of 01 strings)'), 59 | 'SRAW' => array('0101,1010', '2D RAW MODE (comma-separated rows of 01 strings)'), 60 | 'PDF417' => array('0123456789', 'PDF417 (ISO/IEC 15438:2006)'), 61 | 'QRCODE' => array('0123456789', 'QR-CODE'), 62 | 'QRCODE,H,ST,0,0' => array('abcdefghijklmnopqrstuvwxy0123456789', 'QR-CODE WITH PARAMETERS'), 63 | 'DATAMATRIX' => array('0123456789', 'DATAMATRIX (ISO/IEC 16022) SQUARE'), 64 | 'DATAMATRIX,R' => array('0123456789012345678901234567890123456789', 'DATAMATRIX Rectangular (ISO/IEC 16022) RECTANGULAR'), 65 | 'DATAMATRIX,S,GS1' => array(chr(232).'01095011010209171719050810ABCD1234'.chr(232).'2110', 'GS1 DATAMATRIX (ISO/IEC 16022) SQUARE GS1'), 66 | 'DATAMATRIX,R,GS1' => array(chr(232).'01095011010209171719050810ABCD1234'.chr(232).'2110', 'GS1 DATAMATRIX (ISO/IEC 16022) RECTANGULAR GS1'), 67 | ); 68 | 69 | $barcode = new \Com\Tecnick\Barcode\Barcode(); 70 | 71 | $examples = '

Linear

'."\n"; 72 | foreach ($linear as $type => $code) { 73 | $bobj = $barcode->getBarcodeObj($type, $code[0], -3, -30, 'black', array(0, 0, 0, 0)); 74 | $examples .= '

['.$type.'] '.$code[1].'

'.$bobj->getHtmlDiv().'

'."\n"; 75 | } 76 | 77 | $examples .= '

Square

'."\n"; 78 | foreach ($square as $type => $code) { 79 | $bobj = $barcode->getBarcodeObj($type, $code[0], -4, -4, 'black', array(0, 0, 0, 0)); 80 | $examples .= '

['.$type.'] '.$code[1].'

'.$bobj->getHtmlDiv().'

'."\n"; 81 | } 82 | 83 | $bobj = $barcode->getBarcodeObj('QRCODE,H', 'https://tecnick.com', -4, -4, 'black', array(-2, -2, -2, -2))->setBackgroundColor('#f0f0f0'); 84 | 85 | echo " 86 | 87 | 88 | 89 | Usage example of tc-lib-barcode library 90 | 91 | 100 | 101 | 102 |

Usage example of tc-lib-barcode library

103 |

This is an usage example of tc-lib-barcode library.

104 |

Output Formats

105 |

PNG Image

106 |

\"EmbeddedgetPngData())."\" />

107 |

SVG Image

108 |

".$bobj->getSvgCode()."

109 |

HTML DIV

110 |

".$bobj->getHtmlDiv()."

111 |

Unicode String

112 |
".$bobj->getGrid(json_decode('"\u00A0"'), json_decode('"\u2584"'))."
113 |

Binary String

114 |
".$bobj->getGrid()."
115 |

Barcode Types

116 | ".$examples." 117 | 118 | 119 | "; 120 | -------------------------------------------------------------------------------- /src/Type/Linear/RoyalMailFourCc.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 10 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 11 | * @link https://github.com/tecnickcom/tc-lib-barcode 12 | * 13 | * This file is part of tc-lib-barcode software library. 14 | */ 15 | 16 | namespace Com\Tecnick\Barcode\Type\Linear; 17 | 18 | use \Com\Tecnick\Barcode\Exception as BarcodeException; 19 | 20 | /** 21 | * Com\Tecnick\Barcode\Type\Linear\RoyalMailFourCc; 22 | * 23 | * RoyalMailFourCC Barcode type class 24 | * RMS4CC (Royal Mail 4-state Customer Bar Code) 25 | * 26 | * @since 2015-02-21 27 | * @category Library 28 | * @package Barcode 29 | * @author Nicola Asuni 30 | * @copyright 2010-2016 Nicola Asuni - Tecnick.com LTD 31 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 32 | * @link https://github.com/tecnickcom/tc-lib-barcode 33 | */ 34 | class RoyalMailFourCc extends \Com\Tecnick\Barcode\Type\Linear 35 | { 36 | /** 37 | * Barcode format 38 | * 39 | * @var string 40 | */ 41 | protected $format = 'RMS4CC'; 42 | 43 | /** 44 | * Map characters to barcodes 45 | * 46 | * @var array 47 | */ 48 | protected $chbar = array( 49 | '0' => '3322', 50 | '1' => '3412', 51 | '2' => '3421', 52 | '3' => '4312', 53 | '4' => '4321', 54 | '5' => '4411', 55 | '6' => '3142', 56 | '7' => '3232', 57 | '8' => '3241', 58 | '9' => '4132', 59 | 'A' => '4141', 60 | 'B' => '4231', 61 | 'C' => '3124', 62 | 'D' => '3214', 63 | 'E' => '3223', 64 | 'F' => '4114', 65 | 'G' => '4123', 66 | 'H' => '4213', 67 | 'I' => '1342', 68 | 'J' => '1432', 69 | 'K' => '1441', 70 | 'L' => '2332', 71 | 'M' => '2341', 72 | 'N' => '2431', 73 | 'O' => '1324', 74 | 'P' => '1414', 75 | 'Q' => '1423', 76 | 'R' => '2314', 77 | 'S' => '2323', 78 | 'T' => '2413', 79 | 'U' => '1144', 80 | 'V' => '1234', 81 | 'W' => '1243', 82 | 'X' => '2134', 83 | 'Y' => '2143', 84 | 'Z' => '2233' 85 | ); 86 | 87 | /** 88 | * Characters used for checksum 89 | * 90 | * @var array 91 | */ 92 | protected $chksum = array( 93 | '0' => '11', 94 | '1' => '12', 95 | '2' => '13', 96 | '3' => '14', 97 | '4' => '15', 98 | '5' => '10', 99 | '6' => '21', 100 | '7' => '22', 101 | '8' => '23', 102 | '9' => '24', 103 | 'A' => '25', 104 | 'B' => '20', 105 | 'C' => '31', 106 | 'D' => '32', 107 | 'E' => '33', 108 | 'F' => '34', 109 | 'G' => '35', 110 | 'H' => '30', 111 | 'I' => '41', 112 | 'J' => '42', 113 | 'K' => '43', 114 | 'L' => '44', 115 | 'M' => '45', 116 | 'N' => '40', 117 | 'O' => '51', 118 | 'P' => '52', 119 | 'Q' => '53', 120 | 'R' => '54', 121 | 'S' => '55', 122 | 'T' => '50', 123 | 'U' => '01', 124 | 'V' => '02', 125 | 'W' => '03', 126 | 'X' => '04', 127 | 'Y' => '05', 128 | 'Z' => '00' 129 | ); 130 | 131 | /** 132 | * Calculate the checksum. 133 | * 134 | * @param $code (string) code to represent. 135 | * 136 | * @return char checksum. 137 | * 138 | * @throws BarcodeException in case of error 139 | */ 140 | protected function getChecksum($code) 141 | { 142 | $row = 0; 143 | $col = 0; 144 | $len = strlen($code); 145 | for ($pos = 0; $pos < $len; ++$pos) { 146 | $char = $code[$pos]; 147 | if (!isset($this->chksum[$char])) { 148 | throw new BarcodeException('Invalid character: chr('.ord($char).')'); 149 | } 150 | $row += intval($this->chksum[$char][0]); 151 | $col += intval($this->chksum[$char][1]); 152 | } 153 | $row %= 6; 154 | $col %= 6; 155 | $check = array_keys($this->chksum, $row.$col); 156 | return $check[0]; 157 | } 158 | 159 | /** 160 | * Format code 161 | */ 162 | protected function formatCode() 163 | { 164 | $code = strtoupper($this->code); 165 | $this->extcode = $code.$this->getChecksum($code); 166 | } 167 | 168 | /** 169 | * Get the central bars 170 | * 171 | * @throws BarcodeException in case of error 172 | */ 173 | protected function getCoreBars() 174 | { 175 | $this->formatCode(); 176 | $clen = strlen($this->extcode); 177 | for ($chr = 0; $chr < $clen; ++$chr) { 178 | $char = $this->extcode[$chr]; 179 | for ($pos = 0; $pos < 4; ++$pos) { 180 | switch ($this->chbar[$char][$pos]) { 181 | case '1': 182 | $this->bars[] = array($this->ncols, 0, 1, 2); 183 | break; 184 | case '2': 185 | $this->bars[] = array($this->ncols, 0, 1, 3); 186 | break; 187 | case '3': 188 | $this->bars[] = array($this->ncols, 1, 1, 1); 189 | break; 190 | case '4': 191 | $this->bars[] = array($this->ncols, 1, 1, 2); 192 | break; 193 | } 194 | $this->ncols +=2; 195 | } 196 | } 197 | } 198 | 199 | /** 200 | * Get the bars array 201 | * 202 | * @throws BarcodeException in case of error 203 | */ 204 | protected function setBars() 205 | { 206 | $this->ncols = 0; 207 | $this->nrows = 3; 208 | $this->bars = array(); 209 | 210 | // start bar 211 | $this->bars[] = array($this->ncols, 0, 1, 2); 212 | $this->ncols += 2; 213 | 214 | $this->getCoreBars(); 215 | 216 | // stop bar 217 | $this->bars[] = array($this->ncols, 0, 1, 3); 218 | ++$this->ncols; 219 | } 220 | } 221 | -------------------------------------------------------------------------------- /test/TestStrings.php: -------------------------------------------------------------------------------- 1 | 10 | * @copyright 2015-2016 Nicola Asuni - Tecnick.com LTD 11 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 12 | * @link https://github.com/tecnickcom/tc-lib-barcode 13 | * 14 | * This file is part of tc-lib-barcode software library. 15 | */ 16 | 17 | namespace Test; 18 | 19 | /** 20 | * Barcode class test 21 | * 22 | * @since 2016-08-31 23 | * @category Library 24 | * @package Barcode 25 | * @author Nicola Asuni 26 | * @copyright 2015-2016 Nicola Asuni - Tecnick.com LTD 27 | * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) 28 | * @link https://github.com/tecnickcom/tc-lib-barcode 29 | */ 30 | class TestStrings 31 | { 32 | /** 33 | * Array containing testing strings. 34 | * 35 | * @var array 36 | */ 37 | public static $data = array( 38 | // Reserved keywords 39 | array('__halt_compiler abstract and array as break callable case catch class clone const continue declare default die do echo else elseif empty enddeclare endfor endforeach endif endswitch endwhile eval exit extends final for foreach function global goto if implements include include_once instanceof insteadof interface isset list namespace new or print private protected public require require_once return static switch throw trait try unset use var while xor'), 40 | array('__CLASS__ __DIR__ __FILE__ __FUNCTION__ __LINE__ __METHOD__ __NAMESPACE__ __TRAIT__ boolean bool integer float double string array object resource undefined undef null NULL (null) nil NIL true false True False TRUE FALSE None hasOwnProperty'), 41 | // Numeric Strings 42 | array('0 1 2 3 5 7 97 397 997 7919 99991 104729 01 012 0123 01234 012345 0123456 01234567 012345678 0123456789 1234567890 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890 012345678900112233445566778899 012345678900112233445566778899000111222333444555666777888999 123456789012345678901234567890123456789 999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999'), 43 | array('1.00 $1.00 1/2 1E2 1E02 1E+02 -1 -1.00 -$1.00 -1/2 -1E2 -1E02 -1E+02 1/0 0/0 -2147483648/-1 -9223372036854775808/-1 0.00 0..0 . 0.0.0 0,00 0,,0 , 0,0,0 0.0/0 1.0/0.0 0.0/0.0 1,0/0,0 0,0/0,0 --1 - -. -, NaN Infinity -Infinity INF 1#INF -1#IND 1#QNAN 1#SNAN 1#IND 0x0 0xffffffff 0xffffffffffffffff 0xabad1dea 1,000.00 1 000.00 1\'000.00 1,000,000.00 1 000 000.00 1\'000\'000.00 1.000,00 1 000,00 1\'000,00 1.000.000,00 1 000 000,00 1\'000\'000,00 01000 08 09 2.2250738585072011e-308 012-345-678-901-234-567-890-123-456-789'), 44 | // Special Characters 45 | array(' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~'), 46 | array('Roses are red, violets are blue. Hope you enjoy terminal hue But now...for my greatest trick... The quick brown fox...'), 47 | array('<<< ((( [[[ {{{ """ \'\'\' ``` ### ~~~ @@@ £££ $$$ %%% ^^^ &&& *** --- +++ === ___ ::: ;;; ,,, ... ??? ¬¬¬ ||| /// \\\\\\ !!! }}} ]]] ))) >>> ./;\'[]\-= <>?:"{}|_+ !@#$%^&*()`~ "\'"\'"\'\'\'\'"'), 48 | // Unicode Symbols 49 | array('Ω≈ç√∫˜µ≤≥÷ åß∂ƒ©˙∆˚¬…æ œ∑´®†¥¨ˆøπ“‘ ¡™£¢∞§¶•ªº–≠ ¸˛Ç◊ı˜Â¯˘¿ ÅÍÎÏ˝ÓÔÒÚÆ☃ Œ„´‰ˇÁ¨ˆØ∏”’ `⁄€‹›fifl‡°·‚—± ⅛⅜⅝⅞ ЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыьэюя ٠١٢٣٤٥٦٧٨٩   ᠎    ␣ ␢ ␡ ⁰⁴⁵ ₀₁₂ ⁰⁴⁵₀₁₂'), 50 | // Two-Byte Characters 51 | array('田中さんにあげて下さい パーティーへ行かないか 和製漢語 部落格 사회과학원 어학연구소 찦차를 타고 온 펲시맨과 쑛다리 똠방각하 社會科學院語學研究所 울란바토르 𠜎𠜱𠝹𠱓𠱸𠲖𠳏'), 52 | // Japanese Emoticons 53 | array('ヽ༼ຈل͜ຈ༽ノ ヽ༼ຈل͜ຈ༽ノ (。◕ ∀ ◕。) `ィ(´∀`∩ __ロ(,_,*) ・( ̄∀ ̄)・:*: ゚・✿ヾ╲(。◕‿◕。)╱✿・゚ ,。・:*:・゜’( ☻ ω ☻ )。・:*:・゜’ (╯°□°)╯︵ ┻━┻) (ノಥ益ಥ)ノ ┻━┻ ( ͡° ͜ʖ ͡°)'), 54 | // Emoji 55 | array('😍 👩🏽 👾 🙇 💁 🙅 🙆 🙋 🙎 🙍 🐵 🙈 🙉 🙊 ❤️ 💔 💌 💕 💞 💓 💗 💖 💘 💝 💟 💜 💛 💚 💙 ✋🏿 💪🏿 👐🏿 🙌🏿 👏🏿 🙏🏿 🚾 🆒 🆓 🆕 🆖 🆗 🆙 🏧 0️⃣ 1️⃣ 2️⃣ 3️⃣ 4️⃣ 5️⃣ 6️⃣ 7️⃣ 8️⃣ 9️⃣ 🔟'), 56 | // Regional Indicator Symbols 57 | array('🇺🇸🇷🇺🇸 🇦🇫🇦🇲🇸 🇺🇸🇷🇺🇸🇦🇫🇦🇲 🇺🇸🇷🇺🇸🇦'), 58 | // Unicode Numbers 59 | array('123 ١٢٣'), 60 | // Right-To-Left Strings 61 | array('ثم نفس سقطت وبالتحديد،, جزيرتي باستخدام أن دنو. إذ هنا؟ الستار وتنصيب كان. أهّل ايطاليا، بريطانيا-فرنسا قد أخذ. سليمان، إتفاقية بين ما, يذكر الحدود أي بعد, معاملة بولندا، الإطلاق عل إيو. בְּרֵאשִׁית, בָּרָא אֱלֹהִים, אֵת הַשָּׁמַיִם, וְאֵת הָאָרֶץ הָיְתָהtestالصفحات التّحول ﷽ ﷺ مُنَاقَشَةُ سُبُلِ اِسْتِخْدَامِ اللُّغَةِ فِي النُّظُمِ الْقَائِمَةِ وَفِيم يَخُصَّ التَّطْبِيقَاتُ الْحاسُوبِيَّةُ، '), 62 | // Trick Unicode 63 | array('‪‪test‪ ‫test‫ 
test
 test⁠test‫ ⁦test⁧'), 64 | // Strings which contain "corrupted" text 65 | array('Ṱ̺̺̕o͞ ̷i̲̬͇̪͙n̝̗͕v̟̜̘̦͟o̶̙̰̠kè͚̮̺̪̹̱̤ ̖t̝͕̳̣̻̪͞h̼͓̲̦̳̘̲e͇̣̰̦̬͎ ̢̼̻̱̘h͚͎͙̜̣̲ͅi̦̲̣̰̤v̻͍e̺̭̳̪̰-m̢iͅn̖̺̞̲̯̰d̵̼̟͙̩̼̘̳ ̞̥̱̳̭r̛̗̘e͙p͠r̼̞̻̭̗e̺̠̣͟s̘͇̳͍̝͉e͉̥̯̞̲͚̬͜ǹ̬͎͎̟̖͇̤t͍̬̤͓̼̭͘ͅi̪̱n͠g̴͉ ͏͉ͅc̬̟h͡a̫̻̯͘o̫̟̖͍̙̝͉s̗̦̲.̨̹͈̣ ̡͓̞ͅI̗̘̦͝n͇͇͙v̮̫ok̲̫̙͈i̖͙̭̹̠̞n̡̻̮̣̺g̲͈͙̭͙̬͎ ̰t͔̦h̞̲e̢̤ ͍̬̲͖f̴̘͕̣è͖ẹ̥̩l͖͔͚i͓͚̦͠n͖͍̗͓̳̮g͍ ̨o͚̪͡f̘̣̬ ̖̘͖̟͙̮c҉͔̫͖͓͇͖ͅh̵̤̣͚͔á̗̼͕ͅo̼̣̥s̱͈̺̖̦̻͢.̛̖̞̠̫̰ ̗̺͖̹̯͓'), 66 | array('Ṯ̤͍̥͇͈h̲́e͏͓̼̗̙̼̣͔ ͇̜̱̠͓͍ͅN͕͠e̗̱z̘̝̜̺͙p̤̺̹͍̯͚e̠̻̠͜r̨̤͍̺̖͔̖̖d̠̟̭̬̝͟i̦͖̩͓͔̤a̠̗̬͉̙n͚͜ ̻̞̰͚ͅh̵͉i̳̞v̢͇ḙ͎͟-҉̭̩̼͔m̤̭̫i͕͇̝̦n̗͙ḍ̟ ̯̲͕͞ǫ̟̯̰̲͙̻̝f ̪̰̰̗̖̭̘͘c̦͍̲̞͍̩̙ḥ͚a̮͎̟̙͜ơ̩̹͎s̤.̝̝ ҉Z̡̖̜͖̰̣͉̜a͖̰͙̬͡l̲̫̳͍̩g̡̟̼̱͚̞̬ͅo̗͜.̟ ̦H̬̤̗̤͝e͜ ̜̥̝̻͍̟́w̕h̖̯͓o̝͙̖͎̱̮ ҉̺̙̞̟͈W̷̼̭a̺̪͍į͈͕̭͙̯̜t̶̼̮s̘͙͖̕ ̠̫̠B̻͍͙͉̳ͅe̵h̵̬͇̫͙i̹͓̳̳̮͎̫̕n͟d̴̪̜̖ ̰͉̩͇͙̲͞ͅT͖̼͓̪͢h͏͓̮̻e̬̝̟ͅ ̤̹̝W͙̞̝͔͇͝ͅa͏͓͔̹̼̣l̴͔̰̤̟͔ḽ̫.͕'), 67 | // Unicode Upsidedown 68 | array('˙ɐnbᴉlɐ ɐuƃɐɯ ǝɹolop ʇǝ ǝɹoqɐl ʇn ʇunpᴉpᴉɔuᴉ ɹodɯǝʇ poɯsnᴉǝ op pǝs \'ʇᴉlǝ ƃuᴉɔsᴉdᴉpɐ ɹnʇǝʇɔǝsuoɔ \'ʇǝɯɐ ʇᴉs ɹolop ɯnsdᴉ ɯǝɹo˥ 00˙Ɩ$-'), 69 | // Unicode font 70 | array('The quick brown fox jumps over the lazy dog 𝐓𝐡𝐞 𝐪𝐮𝐢𝐜𝐤 𝐛𝐫𝐨𝐰𝐧 𝐟𝐨𝐱 𝐣𝐮𝐦𝐩𝐬 𝐨𝐯𝐞𝐫 𝐭𝐡𝐞 𝐥𝐚𝐳𝐲 𝐝𝐨𝐠 𝕿𝖍𝖊 𝖖𝖚𝖎𝖈𝖐 𝖇𝖗𝖔𝖜𝖓 𝖋𝖔𝖝 𝖏𝖚𝖒𝖕𝖘 𝖔𝖛𝖊𝖗 𝖙𝖍𝖊 𝖑𝖆𝖟𝖞 𝖉𝖔𝖌 𝑻𝒉𝒆 𝒒𝒖𝒊𝒄𝒌 𝒃𝒓𝒐𝒘𝒏 𝒇𝒐𝒙 𝒋𝒖𝒎𝒑𝒔 𝒐𝒗𝒆𝒓 𝒕𝒉𝒆 𝒍𝒂𝒛𝒚 𝒅𝒐𝒈 𝓣𝓱𝓮 𝓺𝓾𝓲𝓬𝓴 𝓫𝓻𝓸𝔀𝓷 𝓯𝓸𝔁 𝓳𝓾𝓶𝓹𝓼 𝓸𝓿𝓮𝓻 𝓽𝓱𝓮 𝓵𝓪𝔃𝔂 𝓭𝓸𝓰 '), 71 | array('𝕋𝕙𝕖 𝕢𝕦𝕚𝕔𝕜 𝕓𝕣𝕠𝕨𝕟 𝕗𝕠𝕩 𝕛𝕦𝕞𝕡𝕤 𝕠𝕧𝕖𝕣 𝕥𝕙𝕖 𝕝𝕒𝕫𝕪 𝕕𝕠𝕘 𝚃𝚑𝚎 𝚚𝚞𝚒𝚌𝚔 𝚋𝚛𝚘𝚠𝚗 𝚏𝚘𝚡 𝚓𝚞𝚖𝚙𝚜 𝚘𝚟𝚎𝚛 𝚝𝚑𝚎 𝚕𝚊𝚣𝚢 𝚍𝚘𝚐 ⒯⒣⒠ ⒬⒰⒤⒞⒦ ⒝⒭⒪⒲⒩ ⒡⒪⒳ ⒥⒰⒨⒫⒮ ⒪⒱⒠⒭ ⒯⒣⒠ ⒧⒜⒵⒴ ⒟⒪⒢'), 72 | // Unwanted Interpolation 73 | array('$HOME $ENV{\'HOME\'} %d %s {0} %*.*s'), 74 | // PHP code 75 | array('echo \'hello world\'; exit(); for($i=32;$i<120;++$i){echo chr($i);}'), 76 | ); 77 | } 78 | --------------------------------------------------------------------------------