|
@@ -1,5 +1,6 @@
|
|
|
<?php
|
|
<?php
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * Class QRCode
|
|
|
*
|
|
*
|
|
|
* @filesource QRCode.php
|
|
* @filesource QRCode.php
|
|
|
* @created 26.11.2015
|
|
* @created 26.11.2015
|
|
@@ -11,15 +12,16 @@
|
|
|
|
|
|
|
|
namespace codemasher\QRCode;
|
|
namespace codemasher\QRCode;
|
|
|
|
|
|
|
|
|
|
+use codemasher\QRCode\Polynomial;
|
|
|
|
|
+use codemasher\QRCode\QRConst;
|
|
|
use codemasher\QRCode\Data\AlphaNum;
|
|
use codemasher\QRCode\Data\AlphaNum;
|
|
|
-use codemasher\QRCode\Data\EightBitByte;
|
|
|
|
|
|
|
+use codemasher\QRCode\Data\Byte;
|
|
|
use codemasher\QRCode\Data\Kanji;
|
|
use codemasher\QRCode\Data\Kanji;
|
|
|
use codemasher\QRCode\Data\Number;
|
|
use codemasher\QRCode\Data\Number;
|
|
|
use codemasher\QRCode\Data\QRDataInterface;
|
|
use codemasher\QRCode\Data\QRDataInterface;
|
|
|
-use codemasher\QRCode\QRConst;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * Class QRCode
|
|
|
|
|
|
|
+ * @link https://github.com/kazuhikoarase/qrcode-generator/tree/master/php
|
|
|
*/
|
|
*/
|
|
|
class QRCode{
|
|
class QRCode{
|
|
|
|
|
|
|
@@ -29,22 +31,22 @@ class QRCode{
|
|
|
/**
|
|
/**
|
|
|
* @var int
|
|
* @var int
|
|
|
*/
|
|
*/
|
|
|
- protected $typeNumber;
|
|
|
|
|
|
|
+ public $typeNumber;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * @var
|
|
|
|
|
|
|
+ * @var array
|
|
|
*/
|
|
*/
|
|
|
protected $modules;
|
|
protected $modules;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * @var
|
|
|
|
|
|
|
+ * @var int
|
|
|
*/
|
|
*/
|
|
|
- protected $moduleCount;
|
|
|
|
|
|
|
+ public $moduleCount;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @var int
|
|
* @var int
|
|
|
*/
|
|
*/
|
|
|
- protected $errorCorrectLevel;
|
|
|
|
|
|
|
+ public $errorCorrectLevel;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @var array
|
|
* @var array
|
|
@@ -56,6 +58,11 @@ class QRCode{
|
|
|
*/
|
|
*/
|
|
|
protected $rsBlockList = [];
|
|
protected $rsBlockList = [];
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @var
|
|
|
|
|
+ */
|
|
|
|
|
+ protected $data;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @var \codemasher\QRCode\Util
|
|
* @var \codemasher\QRCode\Util
|
|
|
*/
|
|
*/
|
|
@@ -86,134 +93,45 @@ class QRCode{
|
|
|
$this->errorCorrectLevel = $errorCorrectLevel;
|
|
$this->errorCorrectLevel = $errorCorrectLevel;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * @return int
|
|
|
|
|
- */
|
|
|
|
|
- public function getTypeNumber(){
|
|
|
|
|
- return $this->typeNumber;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * @param int $typeNumber
|
|
|
|
|
- */
|
|
|
|
|
- public function setTypeNumber($typeNumber){
|
|
|
|
|
- $this->typeNumber = $typeNumber;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * @return int
|
|
|
|
|
- */
|
|
|
|
|
- public function getErrorCorrectLevel(){
|
|
|
|
|
- return $this->errorCorrectLevel;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * @param int $errorCorrectLevel
|
|
|
|
|
- */
|
|
|
|
|
- public function setErrorCorrectLevel($errorCorrectLevel){
|
|
|
|
|
- $this->errorCorrectLevel = $errorCorrectLevel;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* @param string $data
|
|
* @param string $data
|
|
|
* @param int $mode
|
|
* @param int $mode
|
|
|
*
|
|
*
|
|
|
|
|
+ * @return $this
|
|
|
* @throws \codemasher\QRCode\QRCodeException
|
|
* @throws \codemasher\QRCode\QRCodeException
|
|
|
*/
|
|
*/
|
|
|
- public function addData($data, $mode = 0){
|
|
|
|
|
- if($mode === 0){
|
|
|
|
|
|
|
+ public function addData($data, $mode = null){
|
|
|
|
|
+ if($mode === null){
|
|
|
$mode = $this->util->getMode($data);
|
|
$mode = $this->util->getMode($data);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
switch($mode){
|
|
switch($mode){
|
|
|
- case QRConst::MODE_NUMBER :
|
|
|
|
|
- $this->addDataImpl(new Number($data));
|
|
|
|
|
- break;
|
|
|
|
|
- case QRConst::MODE_ALPHA_NUM:
|
|
|
|
|
- $this->addDataImpl(new AlphaNum($data));
|
|
|
|
|
- break;
|
|
|
|
|
- case QRConst::MODE_8BIT_BYTE:
|
|
|
|
|
- $this->addDataImpl(new EightBitByte($data));
|
|
|
|
|
- break;
|
|
|
|
|
- case QRConst::MODE_KANJI :
|
|
|
|
|
- $this->addDataImpl(new Kanji($data));
|
|
|
|
|
- break;
|
|
|
|
|
- default :
|
|
|
|
|
|
|
+ case QRConst::MODE_NUMBER : $this->qrDataList[] = new Number($data); break;
|
|
|
|
|
+ case QRConst::MODE_ALPHANUM:$this->qrDataList[] = new AlphaNum($data); break;
|
|
|
|
|
+ case QRConst::MODE_BYTE:$this->qrDataList[] = new Byte($data); break;
|
|
|
|
|
+ case QRConst::MODE_KANJI : $this->qrDataList[] = new Kanji($data); break;
|
|
|
|
|
+ default:
|
|
|
throw new QRCodeException('mode: '.$mode);
|
|
throw new QRCodeException('mode: '.$mode);
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- *
|
|
|
|
|
- */
|
|
|
|
|
- public function clearData(){
|
|
|
|
|
- $this->qrDataList = [];
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * @param \codemasher\QRCode\Data\QRDataInterface $qrData
|
|
|
|
|
- *
|
|
|
|
|
- * @return $this
|
|
|
|
|
- */
|
|
|
|
|
- public function addDataImpl(QRDataInterface &$qrData){
|
|
|
|
|
- $this->qrDataList[] = $qrData;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
return $this;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * @return int
|
|
|
|
|
- */
|
|
|
|
|
- public function getDataCount(){
|
|
|
|
|
- return count($this->qrDataList);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * @param int $index
|
|
|
|
|
- *
|
|
|
|
|
- * @return \codemasher\QRCode\Data\QRDataInterface
|
|
|
|
|
- */
|
|
|
|
|
- public function getData($index){
|
|
|
|
|
- return $this->qrDataList[$index];
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* @param int $row
|
|
* @param int $row
|
|
|
* @param int $col
|
|
* @param int $col
|
|
|
*
|
|
*
|
|
|
- * @return mixed
|
|
|
|
|
|
|
+ * @return bool
|
|
|
*/
|
|
*/
|
|
|
public function isDark($row, $col){
|
|
public function isDark($row, $col){
|
|
|
if($this->modules[$row][$col] !== null){
|
|
if($this->modules[$row][$col] !== null){
|
|
|
- return $this->modules[$row][$col];
|
|
|
|
|
|
|
+ return (bool)$this->modules[$row][$col];
|
|
|
}
|
|
}
|
|
|
else{
|
|
else{
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * @return mixed
|
|
|
|
|
- */
|
|
|
|
|
- public function getModuleCount(){
|
|
|
|
|
- return $this->moduleCount;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * used for converting fg/bg colors (e.g. #0000ff = 0x0000FF) - added 2015.07.27 ~ DoktorJ
|
|
|
|
|
- *
|
|
|
|
|
- * @param int $hex
|
|
|
|
|
- *
|
|
|
|
|
- * @return array
|
|
|
|
|
- */
|
|
|
|
|
- public function hex2rgb($hex = 0x0){
|
|
|
|
|
- return [
|
|
|
|
|
- 'r' => floor($hex / 65536),
|
|
|
|
|
- 'g' => floor($hex / 256) % 256,
|
|
|
|
|
- 'b' => $hex % 256,
|
|
|
|
|
- ];
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
*
|
|
*
|
|
|
*/
|
|
*/
|
|
@@ -226,15 +144,123 @@ class QRCode{
|
|
|
/**
|
|
/**
|
|
|
* @return int
|
|
* @return int
|
|
|
*/
|
|
*/
|
|
|
- public function getBestMaskPattern(){
|
|
|
|
|
|
|
+ protected function getBestMaskPattern(){
|
|
|
$minLostPoint = 0;
|
|
$minLostPoint = 0;
|
|
|
$pattern = 0;
|
|
$pattern = 0;
|
|
|
|
|
|
|
|
for($i = 0; $i < 8; $i++){
|
|
for($i = 0; $i < 8; $i++){
|
|
|
$this->makeImpl(true, $i);
|
|
$this->makeImpl(true, $i);
|
|
|
- $lostPoint = $this->util->getLostPoint($this);
|
|
|
|
|
|
|
+ $lostPoint = 0;
|
|
|
|
|
+
|
|
|
|
|
+ // LEVEL1
|
|
|
|
|
+
|
|
|
|
|
+ for($row = 0; $row < $this->moduleCount; $row++){
|
|
|
|
|
+ for($col = 0; $col < $this->moduleCount; $col++){
|
|
|
|
|
+ $sameCount = 0;
|
|
|
|
|
+ $dark = $this->isDark($row, $col);
|
|
|
|
|
+
|
|
|
|
|
+ for($r = -1; $r <= 1; $r++){
|
|
|
|
|
+ if($row + $r < 0 || $this->moduleCount <= $row + $r){
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for($c = -1; $c <= 1; $c++){
|
|
|
|
|
+
|
|
|
|
|
+ if($col + $c < 0 || $this->moduleCount <= $col + $c){
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if($r == 0 && $c == 0){
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if($dark === $this->isDark($row + $r, $col + $c)){
|
|
|
|
|
+ $sameCount++;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if($sameCount > 5){
|
|
|
|
|
+ $lostPoint += (3 + $sameCount - 5);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // LEVEL2
|
|
|
|
|
+
|
|
|
|
|
+ for($row = 0; $row < $this->moduleCount - 1; $row++){
|
|
|
|
|
+ for($col = 0; $col < $this->moduleCount - 1; $col++){
|
|
|
|
|
+ $count = 0;
|
|
|
|
|
+
|
|
|
|
|
+ if($this->isDark($row, $col)){
|
|
|
|
|
+ $count++;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if($this->isDark($row + 1, $col)){
|
|
|
|
|
+ $count++;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if($this->isDark($row, $col + 1)){
|
|
|
|
|
+ $count++;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if($this->isDark($row + 1, $col + 1)){
|
|
|
|
|
+ $count++;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if($count === 0 || $count === 4){
|
|
|
|
|
+ $lostPoint += 3;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // LEVEL3
|
|
|
|
|
+
|
|
|
|
|
+ for($row = 0; $row < $this->moduleCount; $row++){
|
|
|
|
|
+ for($col = 0; $col < $this->moduleCount - 6; $col++){
|
|
|
|
|
+ if($this->isDark($row, $col)
|
|
|
|
|
+ && !$this->isDark($row, $col + 1)
|
|
|
|
|
+ && $this->isDark($row, $col + 2)
|
|
|
|
|
+ && $this->isDark($row, $col + 3)
|
|
|
|
|
+ && $this->isDark($row, $col + 4)
|
|
|
|
|
+ && !$this->isDark($row, $col + 5)
|
|
|
|
|
+ && $this->isDark($row, $col + 6)
|
|
|
|
|
+ ){
|
|
|
|
|
+ $lostPoint += 40;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if($i == 0 || $minLostPoint > $lostPoint){
|
|
|
|
|
|
|
+ for($col = 0; $col < $this->moduleCount; $col++){
|
|
|
|
|
+ for($row = 0; $row < $this->moduleCount - 6; $row++){
|
|
|
|
|
+ if($this->isDark($row, $col)
|
|
|
|
|
+ && !$this->isDark($row + 1, $col)
|
|
|
|
|
+ && $this->isDark($row + 2, $col)
|
|
|
|
|
+ && $this->isDark($row + 3, $col)
|
|
|
|
|
+ && $this->isDark($row + 4, $col)
|
|
|
|
|
+ && !$this->isDark($row + 5, $col)
|
|
|
|
|
+ && $this->isDark($row + 6, $col)
|
|
|
|
|
+ ){
|
|
|
|
|
+ $lostPoint += 40;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // LEVEL4
|
|
|
|
|
+
|
|
|
|
|
+ $darkCount = 0;
|
|
|
|
|
+ for($col = 0; $col < $this->moduleCount; $col++){
|
|
|
|
|
+ for($row = 0; $row < $this->moduleCount; $row++){
|
|
|
|
|
+ if($this->isDark($row, $col)){
|
|
|
|
|
+ $darkCount++;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $ratio = abs(100 * $darkCount / $this->moduleCount / $this->moduleCount - 50) / 5;
|
|
|
|
|
+ $lostPoint += $ratio * 10;
|
|
|
|
|
+
|
|
|
|
|
+ if($i === 0 || $minLostPoint > $lostPoint){
|
|
|
$minLostPoint = $lostPoint;
|
|
$minLostPoint = $lostPoint;
|
|
|
$pattern = $i;
|
|
$pattern = $i;
|
|
|
}
|
|
}
|
|
@@ -244,63 +270,117 @@ class QRCode{
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * @param int $length
|
|
|
|
|
- *
|
|
|
|
|
- * @return array
|
|
|
|
|
- */
|
|
|
|
|
- public function createNullArray($length){
|
|
|
|
|
- $nullArray = [];
|
|
|
|
|
- for($i = 0; $i < $length; $i++){
|
|
|
|
|
- $nullArray[] = null;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return $nullArray;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * @param $test
|
|
|
|
|
- * @param $maskPattern
|
|
|
|
|
|
|
+ * @param bool $test
|
|
|
|
|
+ * @param int $maskPattern
|
|
|
*
|
|
*
|
|
|
* @return $this
|
|
* @return $this
|
|
|
*/
|
|
*/
|
|
|
- public function makeImpl($test, $maskPattern){
|
|
|
|
|
|
|
+ protected function makeImpl($test, $maskPattern){
|
|
|
$this->moduleCount = $this->typeNumber * 4 + 17;
|
|
$this->moduleCount = $this->typeNumber * 4 + 17;
|
|
|
$this->modules = [];
|
|
$this->modules = [];
|
|
|
|
|
|
|
|
|
|
+ $nullArray = [];
|
|
|
|
|
+ for($i = 0; $i < $this->moduleCount; $i++){
|
|
|
|
|
+ $nullArray[] = null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
for($i = 0; $i < $this->moduleCount; $i++){
|
|
for($i = 0; $i < $this->moduleCount; $i++){
|
|
|
- $this->modules[] = $this->createNullArray($this->moduleCount);
|
|
|
|
|
|
|
+ $this->modules[] = $nullArray;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$this->setupPositionProbePattern(0, 0)
|
|
$this->setupPositionProbePattern(0, 0)
|
|
|
->setupPositionProbePattern($this->moduleCount - 7, 0)
|
|
->setupPositionProbePattern($this->moduleCount - 7, 0)
|
|
|
- ->setupPositionProbePattern(0, $this->moduleCount - 7)
|
|
|
|
|
- ->setupPositionAdjustPattern()
|
|
|
|
|
- ->setupTimingPattern()
|
|
|
|
|
- ->setupTypeInfo($test, $maskPattern);
|
|
|
|
|
|
|
+ ->setupPositionProbePattern(0, $this->moduleCount - 7);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ $pos = $this->util->PATTERN_POSITION[$this->typeNumber - 1];
|
|
|
|
|
+ $posCount = count($pos);
|
|
|
|
|
+
|
|
|
|
|
+ for($i = 0; $i < $posCount; $i++){
|
|
|
|
|
+ for($j = 0; $j < $posCount; $j++){
|
|
|
|
|
+ if($this->modules[$pos[$i]][$pos[$j]] !== null){
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for($r = -2; $r <= 2; $r++){
|
|
|
|
|
+ for($c = -2; $c <= 2; $c++){
|
|
|
|
|
+ $this->modules[$pos[$i] + $r][$pos[$j] + $c] =
|
|
|
|
|
+ $r === -2 || $r === 2 || $c === -2 || $c === 2 || ($r === 0 && $c === 0);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for($r = 8; $r < $this->moduleCount - 8; $r++){
|
|
|
|
|
+ if($this->modules[$r][6] !== null){
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $this->modules[$r][6] = $this->modules[6][$r] = $r % 2 === 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $data = ($this->errorCorrectLevel << 3) | $maskPattern;
|
|
|
|
|
+ $bits = $this->util->getBCHTypeInfo($data);
|
|
|
|
|
+
|
|
|
|
|
+ for($i = 0; $i < 15; $i++){
|
|
|
|
|
+ $mod = !$test && (($bits >> $i) & 1) === 1;
|
|
|
|
|
+
|
|
|
|
|
+ if($i < 6){
|
|
|
|
|
+ $this->modules[$i][8] = $mod;
|
|
|
|
|
+ }
|
|
|
|
|
+ else if($i < 8){
|
|
|
|
|
+ $this->modules[$i + 1][8] = $mod;
|
|
|
|
|
+ }
|
|
|
|
|
+ else{
|
|
|
|
|
+ $this->modules[$this->moduleCount - 15 + $i][8] = $mod;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if($i < 8){
|
|
|
|
|
+ $this->modules[8][$this->moduleCount - $i - 1] = $mod;
|
|
|
|
|
+ }
|
|
|
|
|
+ else if($i < 9){
|
|
|
|
|
+ $this->modules[8][15 - $i - 1 + 1] = $mod;
|
|
|
|
|
+ }
|
|
|
|
|
+ else{
|
|
|
|
|
+ $this->modules[8][15 - $i - 1] = $mod;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $this->modules[$this->moduleCount - 8][8] = !$test;
|
|
|
|
|
|
|
|
if($this->typeNumber >= 7){
|
|
if($this->typeNumber >= 7){
|
|
|
- $this->setupTypeNumber($test);
|
|
|
|
|
|
|
+ $bits = $this->util->getBCHTypeNumber($this->typeNumber);
|
|
|
|
|
+
|
|
|
|
|
+ for($i = 0; $i < 18; $i++){
|
|
|
|
|
+ $a = (int)floor($i / 3);
|
|
|
|
|
+ $b = $i % 3 + $this->moduleCount - 8 - 3;
|
|
|
|
|
+ $mod = !$test && (($bits >> $i) & 1) === 1;
|
|
|
|
|
+
|
|
|
|
|
+ $this->modules[$a][$b] = $this->modules[$b][$a] = $mod;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $data = $this->createData($this->typeNumber, $this->errorCorrectLevel);
|
|
|
|
|
|
|
+ $this->data = $this->createData($this->typeNumber, $this->errorCorrectLevel);
|
|
|
|
|
|
|
|
- $this->mapData($data, $maskPattern);
|
|
|
|
|
|
|
+ $this->mapData($maskPattern);
|
|
|
|
|
|
|
|
return $this;
|
|
return $this;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * @param $data
|
|
|
|
|
* @param $maskPattern
|
|
* @param $maskPattern
|
|
|
*
|
|
*
|
|
|
* @return $this
|
|
* @return $this
|
|
|
* @throws \codemasher\QRCode\QRCodeException
|
|
* @throws \codemasher\QRCode\QRCodeException
|
|
|
*/
|
|
*/
|
|
|
- public function mapData(&$data, $maskPattern){
|
|
|
|
|
|
|
+ protected function mapData($maskPattern){
|
|
|
$inc = -1;
|
|
$inc = -1;
|
|
|
$row = $this->moduleCount - 1;
|
|
$row = $this->moduleCount - 1;
|
|
|
$bitIndex = 7;
|
|
$bitIndex = 7;
|
|
|
$byteIndex = 0;
|
|
$byteIndex = 0;
|
|
|
|
|
+ $dataCount = count($this->data);
|
|
|
|
|
|
|
|
for($col = $this->moduleCount - 1; $col > 0; $col -= 2){
|
|
for($col = $this->moduleCount - 1; $col > 0; $col -= 2){
|
|
|
|
|
|
|
@@ -309,18 +389,28 @@ class QRCode{
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
while(true){
|
|
while(true){
|
|
|
-
|
|
|
|
|
for($c = 0; $c < 2; $c++){
|
|
for($c = 0; $c < 2; $c++){
|
|
|
|
|
|
|
|
if($this->modules[$row][$col - $c] === null){
|
|
if($this->modules[$row][$col - $c] === null){
|
|
|
-
|
|
|
|
|
$dark = false;
|
|
$dark = false;
|
|
|
|
|
|
|
|
- if($byteIndex < count($data)){
|
|
|
|
|
- $dark = ((($data[$byteIndex] >> $bitIndex) & 1) == 1);
|
|
|
|
|
|
|
+ if($byteIndex < $dataCount){
|
|
|
|
|
+ $dark = (($this->data[$byteIndex] >> $bitIndex) & 1) === 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $mask = $this->util->getMask($maskPattern, $row, $col - $c);
|
|
|
|
|
|
|
+ $_col = $col - $c;
|
|
|
|
|
+ switch($maskPattern){
|
|
|
|
|
+ case QRConst::MASK_PATTERN000: $mask = ($row + $_col) % 2 === 0; break;
|
|
|
|
|
+ case QRConst::MASK_PATTERN001: $mask = $row % 2 === 0; break;
|
|
|
|
|
+ case QRConst::MASK_PATTERN010: $mask = $_col % 3 === 0; break;
|
|
|
|
|
+ case QRConst::MASK_PATTERN011: $mask = ($row + $_col) % 3 === 0; break;
|
|
|
|
|
+ case QRConst::MASK_PATTERN100: $mask = (floor($row / 2) + floor($_col / 3)) % 2 === 0; break;
|
|
|
|
|
+ case QRConst::MASK_PATTERN101: $mask = ($row * $_col) % 2 + ($row * $_col) % 3 === 0; break;
|
|
|
|
|
+ case QRConst::MASK_PATTERN110: $mask = (($row * $_col) % 2 + ($row * $_col) % 3) % 2 === 0; break;
|
|
|
|
|
+ case QRConst::MASK_PATTERN111: $mask = (($row * $_col) % 3 + ($row + $_col) % 2) % 2 === 0; break;
|
|
|
|
|
+ default :
|
|
|
|
|
+ throw new QRCodeException('mask: '.$maskPattern);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if($mask){
|
|
if($mask){
|
|
|
$dark = !$dark;
|
|
$dark = !$dark;
|
|
@@ -329,10 +419,11 @@ class QRCode{
|
|
|
$this->modules[$row][$col - $c] = $dark;
|
|
$this->modules[$row][$col - $c] = $dark;
|
|
|
$bitIndex--;
|
|
$bitIndex--;
|
|
|
|
|
|
|
|
- if($bitIndex == -1){
|
|
|
|
|
|
|
+ if($bitIndex === -1){
|
|
|
$byteIndex++;
|
|
$byteIndex++;
|
|
|
$bitIndex = 7;
|
|
$bitIndex = 7;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -349,171 +440,41 @@ class QRCode{
|
|
|
return $this;
|
|
return $this;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * @return $this
|
|
|
|
|
- */
|
|
|
|
|
- public function setupPositionAdjustPattern(){
|
|
|
|
|
- $pos = $this->util->getPatternPosition($this->typeNumber);
|
|
|
|
|
-
|
|
|
|
|
- $posCount = count($pos);
|
|
|
|
|
- for($i = 0; $i < $posCount; $i++){
|
|
|
|
|
- for($j = 0; $j < $posCount; $j++){
|
|
|
|
|
-
|
|
|
|
|
- $row = $pos[$i];
|
|
|
|
|
- $col = $pos[$j];
|
|
|
|
|
-
|
|
|
|
|
- if($this->modules[$row][$col] !== null){
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- for($r = -2; $r <= 2; $r++){
|
|
|
|
|
- for($c = -2; $c <= 2; $c++){
|
|
|
|
|
-
|
|
|
|
|
- if($r == -2 || $r == 2 || $c == -2 || $c == 2
|
|
|
|
|
- || ($r == 0 && $c == 0)
|
|
|
|
|
- ){
|
|
|
|
|
- $this->modules[$row + $r][$col + $c] = true;
|
|
|
|
|
- }
|
|
|
|
|
- else{
|
|
|
|
|
- $this->modules[$row + $r][$col + $c] = false;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return $this;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* @param $row
|
|
* @param $row
|
|
|
* @param $col
|
|
* @param $col
|
|
|
*
|
|
*
|
|
|
* @return $this
|
|
* @return $this
|
|
|
*/
|
|
*/
|
|
|
- public function setupPositionProbePattern($row, $col){
|
|
|
|
|
|
|
+ protected function setupPositionProbePattern($row, $col){
|
|
|
|
|
|
|
|
for($r = -1; $r <= 7; $r++){
|
|
for($r = -1; $r <= 7; $r++){
|
|
|
for($c = -1; $c <= 7; $c++){
|
|
for($c = -1; $c <= 7; $c++){
|
|
|
|
|
|
|
|
- if($row + $r <= -1 || $this->moduleCount <= $row + $r
|
|
|
|
|
- || $col + $c <= -1 || $this->moduleCount <= $col + $c
|
|
|
|
|
- ){
|
|
|
|
|
|
|
+ if($row + $r <= -1 || $this->moduleCount <= $row + $r || $col + $c <= -1 || $this->moduleCount <= $col + $c){
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if((0 <= $r && $r <= 6 && ($c == 0 || $c == 6))
|
|
|
|
|
- || (0 <= $c && $c <= 6 && ($r == 0 || $r == 6))
|
|
|
|
|
- || (2 <= $r && $r <= 4 && 2 <= $c && $c <= 4)
|
|
|
|
|
- ){
|
|
|
|
|
- $this->modules[$row + $r][$col + $c] = true;
|
|
|
|
|
- }
|
|
|
|
|
- else{
|
|
|
|
|
- $this->modules[$row + $r][$col + $c] = false;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ $this->modules[$row + $r][$col + $c] =
|
|
|
|
|
+ (0 <= $r && $r <= 6 && ($c === 0 || $c === 6))
|
|
|
|
|
+ || (0 <= $c && $c <= 6 && ($r == 0 || $r === 6))
|
|
|
|
|
+ || (2 <= $r && $r <= 4 && 2 <= $c && $c <= 4);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
return $this;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * @return $this
|
|
|
|
|
- */
|
|
|
|
|
- public function setupTimingPattern(){
|
|
|
|
|
-
|
|
|
|
|
- for($r = 8; $r < $this->moduleCount - 8; $r++){
|
|
|
|
|
- if($this->modules[$r][6] !== null){
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- $this->modules[$r][6] = ($r % 2 == 0);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- for($c = 8; $c < $this->moduleCount - 8; $c++){
|
|
|
|
|
- if($this->modules[6][$c] !== null){
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- $this->modules[6][$c] = ($c % 2 == 0);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return $this;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * @param $test
|
|
|
|
|
- *
|
|
|
|
|
- * @return $this
|
|
|
|
|
- */
|
|
|
|
|
- public function setupTypeNumber($test){
|
|
|
|
|
- $bits = $this->util->getBCHTypeNumber($this->typeNumber);
|
|
|
|
|
-
|
|
|
|
|
- for($i = 0; $i < 18; $i++){
|
|
|
|
|
- $this->modules[(int)floor($i / 3)][$i % 3 + $this->moduleCount - 8 - 3] = !$test && (($bits >> $i) & 1) === 1;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- for($i = 0; $i < 18; $i++){
|
|
|
|
|
- $this->modules[$i % 3 + $this->moduleCount - 8 - 3][(int)floor($i / 3)] = !$test && (($bits >> $i) & 1) === 1;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return $this;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * @param $test
|
|
|
|
|
- * @param $maskPattern
|
|
|
|
|
- *
|
|
|
|
|
- * @return $this
|
|
|
|
|
- */
|
|
|
|
|
- public function setupTypeInfo($test, $maskPattern){
|
|
|
|
|
-
|
|
|
|
|
- $data = ($this->errorCorrectLevel << 3) | $maskPattern;
|
|
|
|
|
- $bits = $this->util->getBCHTypeInfo($data);
|
|
|
|
|
-
|
|
|
|
|
- for($i = 0; $i < 15; $i++){
|
|
|
|
|
-
|
|
|
|
|
- $mod = !$test && (($bits >> $i) & 1) === 1;
|
|
|
|
|
-
|
|
|
|
|
- if($i < 6){
|
|
|
|
|
- $this->modules[$i][8] = $mod;
|
|
|
|
|
- }
|
|
|
|
|
- else if($i < 8){
|
|
|
|
|
- $this->modules[$i + 1][8] = $mod;
|
|
|
|
|
- }
|
|
|
|
|
- else{
|
|
|
|
|
- $this->modules[$this->moduleCount - 15 + $i][8] = $mod;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- for($i = 0; $i < 15; $i++){
|
|
|
|
|
-
|
|
|
|
|
- $mod = !$test && (($bits >> $i) & 1) === 1;
|
|
|
|
|
-
|
|
|
|
|
- if($i < 8){
|
|
|
|
|
- $this->modules[8][$this->moduleCount - $i - 1] = $mod;
|
|
|
|
|
- }
|
|
|
|
|
- else if($i < 9){
|
|
|
|
|
- $this->modules[8][15 - $i - 1 + 1] = $mod;
|
|
|
|
|
- }
|
|
|
|
|
- else{
|
|
|
|
|
- $this->modules[8][15 - $i - 1] = $mod;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- $this->modules[$this->moduleCount - 8][8] = !$test;
|
|
|
|
|
-
|
|
|
|
|
- return $this;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* @param $typeNumber
|
|
* @param $typeNumber
|
|
|
* @param $errorCorrectLevel
|
|
* @param $errorCorrectLevel
|
|
|
*
|
|
*
|
|
|
* @return array
|
|
* @return array
|
|
|
* @throws \codemasher\QRCode\QRCodeException
|
|
* @throws \codemasher\QRCode\QRCodeException
|
|
|
- * @todo: slooooow
|
|
|
|
|
|
|
+ * @todo: slooooow in PHP5
|
|
|
*
|
|
*
|
|
|
*/
|
|
*/
|
|
|
- public function createData($typeNumber, $errorCorrectLevel){
|
|
|
|
|
|
|
+ protected function createData($typeNumber, $errorCorrectLevel){
|
|
|
$this->bitBuffer->reset();
|
|
$this->bitBuffer->reset();
|
|
|
|
|
|
|
|
$count = count($this->qrDataList);
|
|
$count = count($this->qrDataList);
|
|
@@ -521,7 +482,7 @@ class QRCode{
|
|
|
/** @var \codemasher\QRCode\Data\QRDataInterface $data */
|
|
/** @var \codemasher\QRCode\Data\QRDataInterface $data */
|
|
|
$data = $this->qrDataList[$i];
|
|
$data = $this->qrDataList[$i];
|
|
|
|
|
|
|
|
- $this->bitBuffer->put($data->getMode(), 4);
|
|
|
|
|
|
|
+ $this->bitBuffer->put($data->mode, 4);
|
|
|
$this->bitBuffer->put($data->getLength(), $data->getLengthInBits($typeNumber));
|
|
$this->bitBuffer->put($data->getLength(), $data->getLengthInBits($typeNumber));
|
|
|
$data->write($this->bitBuffer);
|
|
$data->write($this->bitBuffer);
|
|
|
}
|
|
}
|
|
@@ -531,88 +492,122 @@ class QRCode{
|
|
|
|
|
|
|
|
$count = count($this->rsBlockList);
|
|
$count = count($this->rsBlockList);
|
|
|
for($i = 0; $i < $count; $i++){
|
|
for($i = 0; $i < $count; $i++){
|
|
|
- $this->rsBlock->setCount($this->rsBlockList[$i][0], $this->rsBlockList[$i][1]);
|
|
|
|
|
|
|
+ $this->rsBlock->totalCount = $this->rsBlockList[$i][0];
|
|
|
|
|
+ $this->rsBlock->dataCount = $this->rsBlockList[$i][1];
|
|
|
|
|
|
|
|
- $totalDataCount += $this->rsBlock->getDataCount();
|
|
|
|
|
|
|
+ $totalDataCount += $this->rsBlock->dataCount;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if($this->bitBuffer->getLengthInBits() > $totalDataCount * 8){
|
|
|
|
|
- throw new QRCodeException('code length overflow. ('.$this->bitBuffer->getLengthInBits().'>'.($totalDataCount * 8).')');
|
|
|
|
|
|
|
+ if($this->bitBuffer->length > $totalDataCount * 8){
|
|
|
|
|
+ throw new QRCodeException('code length overflow. ('.$this->bitBuffer->length.'>'.($totalDataCount * 8).')');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// end code.
|
|
// end code.
|
|
|
- if($this->bitBuffer->getLengthInBits() + 4 <= $totalDataCount * 8){
|
|
|
|
|
|
|
+ if($this->bitBuffer->length + 4 <= $totalDataCount * 8){
|
|
|
$this->bitBuffer->put(0, 4);
|
|
$this->bitBuffer->put(0, 4);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// padding
|
|
// padding
|
|
|
- while($this->bitBuffer->getLengthInBits() % 8 != 0){
|
|
|
|
|
|
|
+ while($this->bitBuffer->length % 8 != 0){
|
|
|
$this->bitBuffer->putBit(false);
|
|
$this->bitBuffer->putBit(false);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// padding
|
|
// padding
|
|
|
while(true){
|
|
while(true){
|
|
|
|
|
|
|
|
- if($this->bitBuffer->getLengthInBits() >= $totalDataCount * 8){
|
|
|
|
|
|
|
+ if($this->bitBuffer->length >= $totalDataCount * 8){
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
$this->bitBuffer->put(self::QR_PAD0, 8);
|
|
$this->bitBuffer->put(self::QR_PAD0, 8);
|
|
|
|
|
|
|
|
- if($this->bitBuffer->getLengthInBits() >= $totalDataCount * 8){
|
|
|
|
|
|
|
+ if($this->bitBuffer->length >= $totalDataCount * 8){
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$this->bitBuffer->put(self::QR_PAD1, 8);
|
|
$this->bitBuffer->put(self::QR_PAD1, 8);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return $this->createBytes();
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * @return array
|
|
|
|
|
- */
|
|
|
|
|
- public function createBytes(){
|
|
|
|
|
$offset = $maxDcCount = $maxEcCount = 0;
|
|
$offset = $maxDcCount = $maxEcCount = 0;
|
|
|
- $dcdata = $ecdata = $this->createNullArray(count($this->rsBlockList));
|
|
|
|
|
$rsBlockCount = count($this->rsBlockList);
|
|
$rsBlockCount = count($this->rsBlockList);
|
|
|
|
|
|
|
|
|
|
+ $nullArray = [];
|
|
|
|
|
+ for($i = 0; $i < $rsBlockCount; $i++){
|
|
|
|
|
+ $nullArray[] = null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $dcdata = $ecdata = $nullArray;
|
|
|
|
|
+ $totalCodeCount = 0;
|
|
|
|
|
+
|
|
|
for($r = 0; $r < $rsBlockCount; $r++){
|
|
for($r = 0; $r < $rsBlockCount; $r++){
|
|
|
- $this->rsBlock->setCount($this->rsBlockList[$r][0], $this->rsBlockList[$r][1]);
|
|
|
|
|
|
|
+ $this->rsBlock->totalCount = $this->rsBlockList[$r][0];
|
|
|
|
|
+ $this->rsBlock->dataCount = $this->rsBlockList[$r][1];
|
|
|
|
|
+
|
|
|
|
|
|
|
|
- $dcCount = $this->rsBlock->getDataCount();
|
|
|
|
|
- $ecCount = $this->rsBlock->getTotalCount() - $dcCount;
|
|
|
|
|
|
|
+ $dcCount = $this->rsBlock->dataCount;
|
|
|
|
|
+ $ecCount = $this->rsBlock->totalCount - $dcCount;
|
|
|
|
|
|
|
|
$maxDcCount = max($maxDcCount, $dcCount);
|
|
$maxDcCount = max($maxDcCount, $dcCount);
|
|
|
$maxEcCount = max($maxEcCount, $ecCount);
|
|
$maxEcCount = max($maxEcCount, $ecCount);
|
|
|
|
|
|
|
|
- $dcdata[$r] = $this->createNullArray($dcCount);
|
|
|
|
|
|
|
+ $_nullArray = [];
|
|
|
|
|
+ for($i = 0; $i < $dcCount; $i++){
|
|
|
|
|
+ $_nullArray[] = null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $dcdata[$r] = $_nullArray;
|
|
|
$dcdataCount = count($dcdata[$r]);
|
|
$dcdataCount = count($dcdata[$r]);
|
|
|
for($i = 0; $i < $dcdataCount; $i++){
|
|
for($i = 0; $i < $dcdataCount; $i++){
|
|
|
- $bdata = $this->bitBuffer->getBuffer();
|
|
|
|
|
|
|
+ $bdata = $this->bitBuffer->buffer;
|
|
|
$dcdata[$r][$i] = 0xff & $bdata[$i + $offset];
|
|
$dcdata[$r][$i] = 0xff & $bdata[$i + $offset];
|
|
|
}
|
|
}
|
|
|
$offset += $dcCount;
|
|
$offset += $dcCount;
|
|
|
|
|
|
|
|
- $rsPoly = $this->util->getErrorCorrectPolynomial($ecCount);
|
|
|
|
|
- $rawPoly = new Polynomial($dcdata[$r], $rsPoly->getLength() - 1);
|
|
|
|
|
|
|
|
|
|
- $modPoly = $rawPoly->mod($rsPoly);
|
|
|
|
|
- $ecdata[$r] = $this->createNullArray($rsPoly->getLength() - 1);
|
|
|
|
|
|
|
+ $rsPoly = new Polynomial;
|
|
|
|
|
+ $modPoly = new Polynomial;
|
|
|
|
|
+
|
|
|
|
|
+$starttime = microtime(true);
|
|
|
|
|
+ // 0.09s
|
|
|
|
|
+ for($i = 0; $i < $ecCount; $i++){
|
|
|
|
|
+ $modPoly->setNum([1, $modPoly->gexp($i)]);
|
|
|
|
|
+ $rsPoly->multiply($modPoly->num);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $rsPolyCount = count($rsPoly->num);
|
|
|
|
|
+
|
|
|
|
|
+ // 0.11s
|
|
|
|
|
+ $modPoly->setNum($dcdata[$r], $rsPolyCount - 1)->mod($rsPoly->num);
|
|
|
|
|
+
|
|
|
|
|
+echo 'QRCode::createData '.round((microtime(true)-$starttime), 5).PHP_EOL;
|
|
|
|
|
+
|
|
|
|
|
+ $modPolyCount = count($modPoly->num);
|
|
|
|
|
+
|
|
|
|
|
+ $_nullArray = [];
|
|
|
|
|
+ for($i = 0; $i < $rsPolyCount - 1; $i++){
|
|
|
|
|
+ $_nullArray[] = null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $ecdata[$r] = $_nullArray;
|
|
|
$ecdataCount = count($ecdata[$r]);
|
|
$ecdataCount = count($ecdata[$r]);
|
|
|
|
|
+
|
|
|
for($i = 0; $i < $ecdataCount; $i++){
|
|
for($i = 0; $i < $ecdataCount; $i++){
|
|
|
- $modIndex = $i + $modPoly->getLength() - count($ecdata[$r]);
|
|
|
|
|
- $ecdata[$r][$i] = ($modIndex >= 0) ? $modPoly->getNum($modIndex) : 0;
|
|
|
|
|
|
|
+ $modIndex = $i + $modPolyCount - $ecdataCount;
|
|
|
|
|
+ $ecdata[$r][$i] = ($modIndex >= 0) ? $modPoly->num[$modIndex] : 0;
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- $totalCodeCount = 0;
|
|
|
|
|
- for($i = 0; $i < $rsBlockCount; $i++){
|
|
|
|
|
- $this->rsBlock->setCount($this->rsBlockList[$i][0], $this->rsBlockList[$i][1]);
|
|
|
|
|
|
|
+ $this->rsBlock->totalCount = $this->rsBlockList[$r][0];
|
|
|
|
|
+ $this->rsBlock->dataCount = $this->rsBlockList[$r][1];
|
|
|
|
|
|
|
|
- $totalCodeCount += $this->rsBlock->getTotalCount();
|
|
|
|
|
|
|
+ $totalCodeCount += $this->rsBlock->totalCount;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $data = $this->createNullArray($totalCodeCount);
|
|
|
|
|
|
|
+ $nullArray = [];
|
|
|
|
|
+ for($i = 0; $i < $totalCodeCount; $i++){
|
|
|
|
|
+ $nullArray[] = null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $data = $nullArray;
|
|
|
$index = 0;
|
|
$index = 0;
|
|
|
for($i = 0; $i < $maxDcCount; $i++){
|
|
for($i = 0; $i < $maxDcCount; $i++){
|
|
|
for($r = 0; $r < $rsBlockCount; $r++){
|
|
for($r = 0; $r < $rsBlockCount; $r++){
|
|
@@ -640,27 +635,26 @@ class QRCode{
|
|
|
* @return \codemasher\QRCode\QRCode
|
|
* @return \codemasher\QRCode\QRCode
|
|
|
* @throws \codemasher\QRCode\QRCodeException
|
|
* @throws \codemasher\QRCode\QRCodeException
|
|
|
*/
|
|
*/
|
|
|
- public function getMinimumQRCode($data, $errorCorrectLevel){
|
|
|
|
|
-
|
|
|
|
|
|
|
+ public function getMinimumQRCode($data, $errorCorrectLevel = QRConst::ERROR_CORRECT_LEVEL_H){
|
|
|
$mode = $this->util->getMode($data);
|
|
$mode = $this->util->getMode($data);
|
|
|
|
|
+ $this->addData($data, $mode);
|
|
|
|
|
|
|
|
- $qr = new QRCode();
|
|
|
|
|
- $qr->setErrorCorrectLevel($errorCorrectLevel);
|
|
|
|
|
- $qr->addData($data, $mode);
|
|
|
|
|
|
|
+ $this->errorCorrectLevel = $errorCorrectLevel;
|
|
|
|
|
|
|
|
- $qrData = $qr->getData(0);
|
|
|
|
|
|
|
+ /** @var \codemasher\QRCode\Data\QRDataBase $qrData */
|
|
|
|
|
+ $qrData = $this->qrDataList[0];
|
|
|
$length = $qrData->getLength();
|
|
$length = $qrData->getLength();
|
|
|
|
|
|
|
|
for($typeNumber = 1; $typeNumber <= 10; $typeNumber++){
|
|
for($typeNumber = 1; $typeNumber <= 10; $typeNumber++){
|
|
|
- if($length <= $this->util->getMaxLength($typeNumber, $mode, $errorCorrectLevel)){
|
|
|
|
|
- $qr->setTypeNumber($typeNumber);
|
|
|
|
|
|
|
+ if($length <= $this->util->getMaxLength($typeNumber, $mode, $this->errorCorrectLevel)){
|
|
|
|
|
+ $this->typeNumber = $typeNumber;
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $qr->make();
|
|
|
|
|
|
|
+ $this->makeImpl(false, $this->getBestMaskPattern());
|
|
|
|
|
|
|
|
- return $qr;
|
|
|
|
|
|
|
+ return $this;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -692,7 +686,7 @@ class QRCode{
|
|
|
$margin = 0;
|
|
$margin = 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $image_size = $this->getModuleCount() * $size + $margin * 2;
|
|
|
|
|
|
|
+ $image_size = $this->moduleCount * $size + $margin * 2;
|
|
|
|
|
|
|
|
$image = imagecreatetruecolor($image_size, $image_size);
|
|
$image = imagecreatetruecolor($image_size, $image_size);
|
|
|
|
|
|
|
@@ -705,8 +699,8 @@ class QRCode{
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// convert hexadecimal RGB to arrays for imagecolorallocate
|
|
// convert hexadecimal RGB to arrays for imagecolorallocate
|
|
|
- $fgrgb = $this->hex2rgb($fg);
|
|
|
|
|
- $bgrgb = $this->hex2rgb($bg);
|
|
|
|
|
|
|
+ $fgrgb = $this->util->hex2rgb($fg);
|
|
|
|
|
+ $bgrgb = $this->util->hex2rgb($bg);
|
|
|
|
|
|
|
|
// replace $black and $white with $fgc and $bgc
|
|
// replace $black and $white with $fgc and $bgc
|
|
|
$fgc = imagecolorallocate($image, $fgrgb['r'], $fgrgb['g'], $fgrgb['b']);
|
|
$fgc = imagecolorallocate($image, $fgrgb['r'], $fgrgb['g'], $fgrgb['b']);
|
|
@@ -718,9 +712,8 @@ class QRCode{
|
|
|
// update $white to $bgc
|
|
// update $white to $bgc
|
|
|
imagefilledrectangle($image, 0, 0, $image_size, $image_size, $bgc);
|
|
imagefilledrectangle($image, 0, 0, $image_size, $image_size, $bgc);
|
|
|
|
|
|
|
|
- $count = $this->getModuleCount();
|
|
|
|
|
- for($r = 0; $r < $count; $r++){
|
|
|
|
|
- for($c = 0; $c < $count; $c++){
|
|
|
|
|
|
|
+ for($r = 0; $r < $this->moduleCount; $r++){
|
|
|
|
|
+ for($c = 0; $c < $this->moduleCount; $c++){
|
|
|
if($this->isDark($r, $c)){
|
|
if($this->isDark($r, $c)){
|
|
|
|
|
|
|
|
// update $black to $fgc
|
|
// update $black to $fgc
|
|
@@ -742,7 +735,7 @@ class QRCode{
|
|
|
*/
|
|
*/
|
|
|
public function printHTML(){
|
|
public function printHTML(){
|
|
|
$html = '<table class="qrcode">';
|
|
$html = '<table class="qrcode">';
|
|
|
- $count = $this->getModuleCount();
|
|
|
|
|
|
|
+ $count = $this->moduleCount;
|
|
|
|
|
|
|
|
for($r = 0; $r < $count; $r++){
|
|
for($r = 0; $r < $count; $r++){
|
|
|
$html .= '<tr>';
|
|
$html .= '<tr>';
|