Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AZTEC Code encoder #79

Merged
merged 67 commits into from
Oct 20, 2023
Merged
Changes from 62 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
2ec6729
Raise minimum PH version to 5.6 and use const arrays.
nicolaasuni Oct 13, 2023
f22cbbe
Use const array.
nicolaasuni Oct 13, 2023
6072177
Add Atzec code draft.
nicolaasuni Oct 13, 2023
50e43c6
Add aztec latch map
nicolaasuni Oct 13, 2023
7b7d347
Aztec code draft 2
nicolaasuni Oct 13, 2023
d86be3f
Aztec draft 3
nicolaasuni Oct 13, 2023
d1776ce
Aztec draft 4
nicolaasuni Oct 15, 2023
1c01afe
process punct pairs
nicolaasuni Oct 15, 2023
f903b5d
draft encoding
nicolaasuni Oct 15, 2023
2d730ad
high-level encoder
nicolaasuni Oct 16, 2023
50d5944
Split Encode class
nicolaasuni Oct 16, 2023
6e2762b
Add size tables
nicolaasuni Oct 16, 2023
1232ade
Format size tables
nicolaasuni Oct 16, 2023
ac190b7
Add layers size
nicolaasuni Oct 16, 2023
141a52f
Refactor layers
nicolaasuni Oct 16, 2023
bc6d9a8
Draft bit stuffing
nicolaasuni Oct 16, 2023
f1c1685
bit stuffing
nicolaasuni Oct 16, 2023
7683c86
Split classes
nicolaasuni Oct 16, 2023
5b78482
draft error correction
nicolaasuni Oct 17, 2023
a04cd9f
draft check codeword
nicolaasuni Oct 17, 2023
d640f4f
cleanup
nicolaasuni Oct 17, 2023
9927328
checkword
nicolaasuni Oct 17, 2023
36974fb
Fix mixed table
nicolaasuni Oct 18, 2023
098550d
add comments
nicolaasuni Oct 18, 2023
993e483
fixes
nicolaasuni Oct 18, 2023
2171aa3
Draw bulls eye
nicolaasuni Oct 18, 2023
fef6f83
Set reference grid
nicolaasuni Oct 18, 2023
9788e89
add mode messages
nicolaasuni Oct 18, 2023
839e194
draw compact data
nicolaasuni Oct 19, 2023
cc0b885
draft full data draw
nicolaasuni Oct 19, 2023
0072d2c
simplify
nicolaasuni Oct 19, 2023
36fb9cf
fixes
nicolaasuni Oct 19, 2023
2341a0e
fixes
nicolaasuni Oct 19, 2023
8be594a
simplify mode
nicolaasuni Oct 20, 2023
f381662
Add mode option
nicolaasuni Oct 20, 2023
2b30efb
Set params
nicolaasuni Oct 20, 2023
1b07928
call encoder
nicolaasuni Oct 20, 2023
55e319e
fixes
nicolaasuni Oct 20, 2023
d1cad65
fix highLevelEncoding
nicolaasuni Oct 20, 2023
3e3403d
convert bitstream to array of words
nicolaasuni Oct 20, 2023
f223f49
fix confition
nicolaasuni Oct 20, 2023
cc5ff2b
fix mode draw
nicolaasuni Oct 20, 2023
871b702
Fix data drawing
nicolaasuni Oct 20, 2023
4bab4b2
cleanup
nicolaasuni Oct 20, 2023
b376113
Fix condition
nicolaasuni Oct 20, 2023
834e069
fix del code
nicolaasuni Oct 20, 2023
e52a2c7
fix mode in full
nicolaasuni Oct 20, 2023
1c45982
remove debug lines
nicolaasuni Oct 20, 2023
968da48
fix layer side len
nicolaasuni Oct 20, 2023
950ba6b
skip reference grid
nicolaasuni Oct 20, 2023
5118dec
Add aztec tests
nicolaasuni Oct 20, 2023
4113f40
more tests
nicolaasuni Oct 20, 2023
882beb2
more tests
nicolaasuni Oct 20, 2023
103e27b
code cleanup
nicolaasuni Oct 20, 2023
9ff1440
code cleanup
nicolaasuni Oct 20, 2023
8528c8b
fix binary processor
nicolaasuni Oct 20, 2023
5b4ccda
fix condition
nicolaasuni Oct 20, 2023
2c4abc4
Add special cases
nicolaasuni Oct 20, 2023
677b6d7
more tests
nicolaasuni Oct 20, 2023
474a968
optimize code
nicolaasuni Oct 20, 2023
e9a527a
fixes
nicolaasuni Oct 20, 2023
14edf94
commemt
nicolaasuni Oct 20, 2023
c5ec9a0
Change for PHP 5.6 compatibility
nicolaasuni Oct 20, 2023
882b634
Changes for PHP 5.6 compatibility
nicolaasuni Oct 20, 2023
6bce590
Changes for PHP 5.6 compatibility
nicolaasuni Oct 20, 2023
0ca30ed
Changes for PHP 5.6 compatibility
nicolaasuni Oct 20, 2023
6d7cb18
Changes for PHP 5.6 compatibility
nicolaasuni Oct 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -28,9 +28,6 @@ jobs:
os: [ubuntu-latest]
coverage-extension: [pcov]
include:
#- { php-version: '5.3', experimental: false, os: ubuntu-latest, coverage-extension: 'xdebug' }
#- { php-version: '5.4', experimental: false, os: ubuntu-latest, coverage-extension: 'xdebug' }
- { php-version: '5.5', experimental: false, os: ubuntu-latest, coverage-extension: 'xdebug' }
- { php-version: '5.6', experimental: false, os: ubuntu-latest, coverage-extension: 'xdebug' }
- { php-version: '7.1', experimental: false, os: ubuntu-latest, coverage-extension: 'xdebug' }
steps:
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -53,6 +53,7 @@ This library includes utility PHP classes to generate linear and bidimensional b
* CODE11 : CODE 11
* PHARMA : PHARMACODE
* PHARMA2T : PHARMACODE TWO-TRACKS
* AZTEC : AZTEC Code (ISO/IEC 24778:2008)
* DATAMATRIX : DATAMATRIX (ISO/IEC 16022)
* PDF417 : PDF417 (ISO/IEC 15438:2006)
* QRCODE : QR-CODE
@@ -146,15 +147,15 @@ Create a composer.json in your projects root-directory:
```json
{
"require": {
"tecnickcom/tc-lib-barcode": "^1.17"
"tecnickcom/tc-lib-barcode": "^1.18"
}
}
```

Or add to an existing project with:

```bash
composer require tecnickcom/tc-lib-barcode ^1.17
composer require tecnickcom/tc-lib-barcode ^1.18
```

## Packaging
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.17.38
1.18.0
58 changes: 31 additions & 27 deletions composer.json
Original file line number Diff line number Diff line change
@@ -5,41 +5,45 @@
"homepage": "http://www.tecnick.com",
"license": "LGPL-3.0-or-later",
"keywords": [
"tc-lib-barcode",
"3 of 9",
"ANSI MH10.8M-1983",
"AZTEC",
"barcode",
"CBC",
"CODABAR",
"CODE 11",
"CODE 128 A B C",
"CODE 39",
"ANSI MH10.8M-1983",
"USD-3",
"3 of 9",
"CODE 93",
"USS-93",
"Standard 2 of 5",
"Interleaved 2 of 5",
"CODE 128 A B C",
"UPC",
"EAN 8",
"Datamatrix",
"EAN 13",
"UPC-A",
"UPC-E",
"MSI",
"POSTNET",
"PLANET",
"RMS4CC",
"Royal Mail",
"CBC",
"EAN 8",
"ECC200",
"Intelligent Mail Barcode",
"Interleaved 2 of 5",
"ISO/IEC 15438:2006",
"ISO/IEC 16022",
"ISO/IEC 24778:2008",
"KIX",
"Klant",
"Intelligent Mail Barcode",
"MSI",
"Onecode",
"USPS-B-3200",
"CODABAR",
"CODE 11",
"PHARMACODE",
"PDF417",
"PHARMACODE TWO-TRACKS",
"Datamatrix",
"ECC200",
"PHARMACODE",
"PLANET",
"POSTNET",
"QR-Code",
"PDF417"
"RMS4CC",
"Royal Mail",
"Standard 2 of 5",
"tc-lib-barcode",
"UPC-A",
"UPC-E",
"UPC",
"USD-3",
"USPS-B-3200",
"USS-93"
],
"authors": [
{
@@ -49,7 +53,7 @@
}
],
"require": {
"php": ">=5.4",
"php": ">=5.6",
"ext-bcmath": "*",
"ext-date": "*",
"ext-gd": "*",
2 changes: 2 additions & 0 deletions example/index.php
Original file line number Diff line number Diff line change
@@ -57,6 +57,8 @@
$square = array(
'LRAW' => array('0101010101', '1D RAW MODE (comma-separated rows of 01 strings)'),
'SRAW' => array('0101,1010', '2D RAW MODE (comma-separated rows of 01 strings)'),
'AZTEC' => array('ABCDabcd01234', 'AZTEC (ISO/IEC 24778:2008)'),
'AZTEC,50,A,A' => array('ABCDabcd01234', 'AZTEC (ISO/IEC 24778:2008)'),
'PDF417' => array('0123456789', 'PDF417 (ISO/IEC 15438:2006)'),
'QRCODE' => array('0123456789', 'QR-CODE'),
'QRCODE,H,ST,0,0' => array('abcdefghijklmnopqrstuvwxy0123456789', 'QR-CODE WITH PARAMETERS'),
29 changes: 14 additions & 15 deletions src/Barcode.php
Original file line number Diff line number Diff line change
@@ -35,45 +35,44 @@ class Barcode
{
/**
* Array containing the map between the barcode type and correspondent class
*
* @var array
*/
protected static $typeclass = array(
const TYPECLASS = array(
'C128' => 'Linear\\CodeOneTwoEight', // CODE 128
'C128A' => 'Linear\\CodeOneTwoEight\\CodeOneTwoEightA', // CODE 128 A
'C128B' => 'Linear\\CodeOneTwoEight\\CodeOneTwoEightB', // CODE 128 B
'C128C' => 'Linear\\CodeOneTwoEight\\CodeOneTwoEightC', // CODE 128 C
'C128' => 'Linear\\CodeOneTwoEight', // CODE 128
'C39E+' => 'Linear\\CodeThreeNineExtCheck', // CODE 39 EXTENDED + CHECKSUM
'C39E' => 'Linear\\CodeThreeNineExt', // CODE 39 EXTENDED
'C39+' => 'Linear\\CodeThreeNineCheck', // CODE 39 + CHECKSUM
'C39' => 'Linear\\CodeThreeNine', // CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.
'C39+' => 'Linear\\CodeThreeNineCheck', // CODE 39 + CHECKSUM
'C39E' => 'Linear\\CodeThreeNineExt', // CODE 39 EXTENDED
'C39E+' => 'Linear\\CodeThreeNineExtCheck', // CODE 39 EXTENDED + CHECKSUM
'C93' => 'Linear\\CodeNineThree', // CODE 93 - USS-93
'CODABAR' => 'Linear\\Codabar', // CODABAR
'CODE11' => 'Linear\\CodeOneOne', // CODE 11
'EAN13' => 'Linear\\EanOneThree', // EAN 13
'EAN2' => 'Linear\\EanTwo', // EAN 2-Digits UPC-Based Extension
'EAN5' => 'Linear\\EanFive', // EAN 5-Digits UPC-Based Extension
'EAN8' => 'Linear\\EanEight', // EAN 8
'I25+' => 'Linear\\InterleavedTwoOfFiveCheck', // Interleaved 2 of 5 + CHECKSUM
'I25' => 'Linear\\InterleavedTwoOfFive', // Interleaved 2 of 5
'I25+' => 'Linear\\InterleavedTwoOfFiveCheck', // Interleaved 2 of 5 + CHECKSUM
'IMB' => 'Linear\\Imb', // IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200
'IMBPRE' => 'Linear\\ImbPre', // IMB - Intelligent Mail Barcode pre-processed
'KIX' => 'Linear\\KlantIndex', // KIX (Klant index - Customer index)
'MSI+' => 'Linear\\MsiCheck', // MSI + CHECKSUM (modulo 11)
'LRAW' => 'Linear\\Raw', // 1D RAW MODE (comma-separated rows of 01 strings)
'MSI' => 'Linear\\Msi', // MSI (Variation of Plessey code)
'PHARMA2T' => 'Linear\\PharmaTwoTracks', // PHARMACODE TWO-TRACKS
'MSI+' => 'Linear\\MsiCheck', // MSI + CHECKSUM (modulo 11)
'PHARMA' => 'Linear\\Pharma', // PHARMACODE
'PHARMA2T' => 'Linear\\PharmaTwoTracks', // PHARMACODE TWO-TRACKS
'PLANET' => 'Linear\\Planet', // PLANET
'POSTNET' => 'Linear\\Postnet', // POSTNET
'RMS4CC' => 'Linear\\RoyalMailFourCc', // RMS4CC (Royal Mail 4-state Customer Bar Code)
'S25+' => 'Linear\\StandardTwoOfFiveCheck', // Standard 2 of 5 + CHECKSUM
'S25' => 'Linear\\StandardTwoOfFive', // Standard 2 of 5
'S25+' => 'Linear\\StandardTwoOfFiveCheck', // Standard 2 of 5 + CHECKSUM
'UPCA' => 'Linear\\UpcA', // UPC-A
'UPCE' => 'Linear\\UpcE', // UPC-E
'AZTEC' => 'Square\\Aztec', // AZTEC Code (ISO/IEC 24778:2008)
'DATAMATRIX' => 'Square\\Datamatrix', // DATAMATRIX (ISO/IEC 16022)
'PDF417' => 'Square\\PdfFourOneSeven', // PDF417 (ISO/IEC 15438:2006)
'QRCODE' => 'Square\\QrCode', // QR-CODE
'LRAW' => 'Linear\\Raw', // 1D RAW MODE (comma-separated rows of 01 strings)
'SRAW' => 'Square\\Raw', // 2D RAW MODE (comma-separated rows of 01 strings)
);

@@ -84,7 +83,7 @@ class Barcode
*/
public function getTypes()
{
return array_keys(self::$typeclass);
return array_keys(self::TYPECLASS);
}

/**
@@ -116,10 +115,10 @@ public function getBarcodeObj(
$params = explode(',', $type);
$type = array_shift($params);

if (empty(self::$typeclass[$type])) {
if (empty(self::TYPECLASS[$type])) {
throw new BarcodeException('Unsupported barcode type: ' . $type);
}
$bclass = '\\Com\\Tecnick\\Barcode\\Type\\' . self::$typeclass[$type];
$bclass = '\\Com\\Tecnick\\Barcode\\Type\\' . self::TYPECLASS[$type];
return new $bclass($code, $width, $height, $color, $params, $padding);
}
}
12 changes: 6 additions & 6 deletions src/Type/Linear/Imb.php
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@ class Imb extends \Com\Tecnick\Barcode\Type\Linear
*
* @var array
*/
protected static $asc_chr = array(
const ASC_CHR = array(
4,0,2,6,3,5,1,9,8,7,
1,2,0,6,4,8,2,9,5,3,
0,1,3,7,4,6,8,9,2,0,
@@ -82,7 +82,7 @@ class Imb extends \Com\Tecnick\Barcode\Type\Linear
*
* @var array
*/
protected static $dsc_chr = array(
const DSC_CHR = array(
7,1,9,5,8,0,2,4,6,3,
5,8,9,7,3,0,6,1,7,4,
6,8,9,2,5,1,7,5,4,3,
@@ -96,7 +96,7 @@ class Imb extends \Com\Tecnick\Barcode\Type\Linear
*
* @var array
*/
protected static $asc_pos = array(
const ASC_POS = array(
3,0,8,11,1,12,8,11,10,6,4,12,2,7,9,6,7,9,2,8,4,0,12,7,10,9,0,7,10,5,7,9,
6,8,2,12,1,4,2,0,1,5,4,6,12,1,0,9,4,7,5,10,2,6,9,11,2,12,6,7,5,11,0,3,2);

@@ -105,7 +105,7 @@ class Imb extends \Com\Tecnick\Barcode\Type\Linear
*
* @var array
*/
protected static $dsc_pos = array(
const DSC_POS = array(
2,10,12,5,9,1,5,4,3,9,11,5,10,1,6,3,4,1,10,0,2,11,8,6,1,12,3,8,6,4,4,11,
0,6,1,9,11,5,3,7,3,10,7,11,8,2,10,3,5,8,0,3,12,11,8,4,5,1,3,0,7,12,9,8,10);

@@ -312,8 +312,8 @@ protected function setBars()
{
$chars = $this->getCharsArray();
for ($pos = 0; $pos < 65; ++$pos) {
$asc = (($chars[self::$asc_chr[$pos]] & pow(2, self::$asc_pos[$pos])) > 0);
$dsc = (($chars[self::$dsc_chr[$pos]] & pow(2, self::$dsc_pos[$pos])) > 0);
$asc = (($chars[self::ASC_CHR[$pos]] & pow(2, self::ASC_POS[$pos])) > 0);
$dsc = (($chars[self::DSC_CHR[$pos]] & pow(2, self::DSC_POS[$pos])) > 0);
if ($asc and $dsc) {
// full bar (F)
$this->bars[] = array($this->ncols, 0, 1, 3);
134 changes: 134 additions & 0 deletions src/Type/Square/Aztec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php

/**
* Aztec.php
*
* @since 2023-10-12
* @category Library
* @package Barcode
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2023-2023 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-barcode
*
* This file is part of tc-lib-barcode software library.
*/

namespace Com\Tecnick\Barcode\Type\Square;

use Com\Tecnick\Barcode\Type\Square\Aztec\Data;
use Com\Tecnick\Barcode\Type\Square\Aztec\Encode;
use Com\Tecnick\Barcode\Exception as BarcodeException;

/**
* Com\Tecnick\Barcode\Type\Square\Aztec
*
* Aztec Barcode type class
*
* @since 2023-10-12
* @category Library
* @package Barcode
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2015-2023 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-barcode
*/
class Aztec extends \Com\Tecnick\Barcode\Type\Square
{
/**
* Barcode format
*
* @var string
*/
protected $format = 'AZTEC';

/**
* Error correction code percentage of error check words.
* A minimum of 23% + 3 words is recommended by ISO/IEC 24778:2008a.
*
* @var int
*/
protected $ecc = 33;

/**
* Encoding mode
*
* @var string
*/
protected $hint = 'A';

/**
* Mode:
* - A = Automatic selection between Compact (priority) and Full Range.
* - F = Force Full Range mode.
*
* @var string
*/
protected $mode = 'A';

/**
* Extended Channel Interpretation (ECI) code to be added at the beginning of the stream.
* See Data:ECI for the list of supported codes.
* NOTE: Even if special FNC1 or ECI flag characters could be inserted
* at any points in the stream, this will only be added at the beginning of the stream.
*
* @var int
*/
protected $eci = -1;

/**
* Set extra (optional) parameters:
* 1: ECC : Error correction code percentage of error check words.
* A minimum of 23% + 3 words is recommended by ISO/IEC 24778:2008a.
* 2: HINT : Encoding mode: A=Automatic, B=Binary.
* 3: LAYERS : Custom number of layers (0 = auto).
* 4: ECI : Extended Channel Interpretation (ECI) code. Use -1 for FNC1. See $this->eci.
*/
protected function setParameters()
{
parent::setParameters();

// ecc percentage
if (!isset($this->params[0]) || !in_array($this->params[0], range(1, 100))) {
$this->params[0] = 33;
}
$this->ecc = intval($this->params[0]);

// hint
if (!isset($this->params[1]) || !in_array($this->params[1], ['A', 'B'])) {
$this->params[1] = 'A';
}
$this->hint = $this->params[1];

// mode
if (!isset($this->params[2]) || !in_array($this->params[2], ['A', 'F'])) {
$this->params[2] = 'A';
}
$this->mode = $this->params[2];

// eci code. Used to set the charset encoding. See $this->eci.
if (!isset($this->params[3]) || !isset(Data::ECI[$this->params[3]])) {
$this->params[3] = -1;
}
$this->eci = intval($this->params[3]);
}

/**
* Get the bars array
*
* @throws BarcodeException in case of error
*/
protected function setBars()
{
if (strlen((string)$this->code) == 0) {
throw new BarcodeException('Empty input');
}
try {
$enc = new Encode($this->code, $this->ecc, $this->eci, $this->hint, $this->mode);
$grid = $enc->getGrid();
$this->processBinarySequence($grid);
} catch (BarcodeException $e) {
throw new BarcodeException('AZTEC: ' . $e->getMessage());
}
}
}
Loading