mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-10-22 11:45:55 +00:00
Merge branch 'master' into php-7.4
# Conflicts: # composer.json # src/Output/QROutputAbstract.php # src/QROptionsTrait.php
This commit is contained in:
+16
-14
@@ -14,6 +14,8 @@ namespace chillerlan\QRCode\Data;
|
||||
|
||||
use chillerlan\QRCode\QRCode;
|
||||
|
||||
use function array_fill, array_key_exists, array_push, array_unshift, count, floor, in_array, max, min, range;
|
||||
|
||||
/**
|
||||
* @link http://www.thonky.com/qr-code-tutorial/format-version-information
|
||||
*/
|
||||
@@ -29,7 +31,7 @@ class QRMatrix{
|
||||
public const M_FORMAT = 0x0e;
|
||||
public const M_VERSION = 0x10;
|
||||
public const M_QUIETZONE = 0x12;
|
||||
public const M_LOGO = 0x14; // @todo
|
||||
# public const M_LOGO = 0x14; // @todo
|
||||
|
||||
public const M_TEST = 0xff;
|
||||
|
||||
@@ -184,18 +186,18 @@ class QRMatrix{
|
||||
*/
|
||||
public function __construct(int $version, int $eclevel){
|
||||
|
||||
if(!\in_array($version, \range(1, 40), true)){
|
||||
if(!in_array($version, range(1, 40), true)){
|
||||
throw new QRCodeDataException('invalid QR Code version');
|
||||
}
|
||||
|
||||
if(!\array_key_exists($eclevel, QRCode::ECC_MODES)){
|
||||
if(!array_key_exists($eclevel, QRCode::ECC_MODES)){
|
||||
throw new QRCodeDataException('invalid ecc level');
|
||||
}
|
||||
|
||||
$this->version = $version;
|
||||
$this->eclevel = $eclevel;
|
||||
$this->moduleCount = $this->version * 4 + 17;
|
||||
$this->matrix = \array_fill(0, $this->moduleCount, \array_fill(0, $this->moduleCount, $this::M_NULL));
|
||||
$this->matrix = array_fill(0, $this->moduleCount, array_fill(0, $this->moduleCount, $this::M_NULL));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -365,7 +367,7 @@ class QRMatrix{
|
||||
*/
|
||||
public function setTimingPattern():QRMatrix{
|
||||
|
||||
foreach(\range(8, $this->moduleCount - 8 - 1) as $i){
|
||||
foreach(range(8, $this->moduleCount - 8 - 1) as $i){
|
||||
|
||||
if($this->matrix[6][$i] !== $this::M_NULL || $this->matrix[$i][6] !== $this::M_NULL){
|
||||
continue;
|
||||
@@ -389,7 +391,7 @@ class QRMatrix{
|
||||
if($bits !== false){
|
||||
|
||||
for($i = 0; $i < 18; $i++){
|
||||
$a = (int)\floor($i / 3);
|
||||
$a = (int)floor($i / 3);
|
||||
$b = $i % 3 + $this->moduleCount - 8 - 3;
|
||||
$v = !$test && (($bits >> $i) & 1) === 1;
|
||||
|
||||
@@ -450,23 +452,23 @@ class QRMatrix{
|
||||
}
|
||||
|
||||
$size = $size !== null
|
||||
? \max(0, \min($size, \floor($this->moduleCount / 2)))
|
||||
? max(0, min($size, floor($this->moduleCount / 2)))
|
||||
: 4;
|
||||
|
||||
for($y = 0; $y < $this->moduleCount; $y++){
|
||||
for($i = 0; $i < $size; $i++){
|
||||
\array_unshift($this->matrix[$y], $this::M_QUIETZONE);
|
||||
\array_push($this->matrix[$y], $this::M_QUIETZONE);
|
||||
array_unshift($this->matrix[$y], $this::M_QUIETZONE);
|
||||
array_push($this->matrix[$y], $this::M_QUIETZONE);
|
||||
}
|
||||
}
|
||||
|
||||
$this->moduleCount += ($size * 2);
|
||||
|
||||
$r = \array_fill(0, $this->moduleCount, $this::M_QUIETZONE);
|
||||
$r = array_fill(0, $this->moduleCount, $this::M_QUIETZONE);
|
||||
|
||||
for($i = 0; $i < $size; $i++){
|
||||
\array_unshift($this->matrix, $r);
|
||||
\array_push($this->matrix, $r);
|
||||
array_unshift($this->matrix, $r);
|
||||
array_push($this->matrix, $r);
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -482,7 +484,7 @@ class QRMatrix{
|
||||
*/
|
||||
public function mapData(array $data, int $maskPattern):QRMatrix{
|
||||
$this->maskPattern = $maskPattern;
|
||||
$byteCount = \count($data);
|
||||
$byteCount = count($data);
|
||||
$size = $this->moduleCount - 1;
|
||||
|
||||
for($i = $size, $y = $size, $inc = -1, $byteIndex = 0, $bitIndex = 7; $i > 0; $i -= 2){
|
||||
@@ -550,7 +552,7 @@ class QRMatrix{
|
||||
$y % 2,
|
||||
$x % 3,
|
||||
$a % 3,
|
||||
(\floor($y / 2) + \floor($x / 3)) % 2,
|
||||
(floor($y / 2) + floor($x / 3)) % 2,
|
||||
$m % 2 + $m % 3,
|
||||
($m % 2 + $m % 3) % 2,
|
||||
($m % 3 + $a % 2) % 2
|
||||
|
||||
Reference in New Issue
Block a user