11
11
namespace chillerlan \QRCode \Data ;
12
12
13
13
use chillerlan \QRCode \Common \{BitBuffer , EccLevel , MaskPattern , ReedSolomonEncoder , Version };
14
- use function array_fill , array_map , array_reverse , count , floor , intdiv ;
14
+ use function array_fill , array_map , array_reverse , count , intdiv ;
15
15
16
16
/**
17
17
* Holds an array representation of the final QR Code that contains numerical values for later output modifications;
@@ -636,8 +636,8 @@ public function invert():self{
636
636
* Clears a space of $width * $height in order to add a logo or text.
637
637
* If no $height is given, the space will be assumed a square of $width.
638
638
*
639
- * Additionally, the logo space can be positioned within the QR Code - respecting the main functional patterns -
640
- * using $startX and $startY. If either of these are null, the logo space will be centered in that direction.
639
+ * Additionally, the logo space can be positioned within the QR Code using $startX and $startY.
640
+ * If either of these are null, the logo space will be centered in that direction.
641
641
* ECC level "H" (30%) is required.
642
642
*
643
643
* The coordinates of $startX and $startY do not include the quiet zone:
@@ -661,20 +661,18 @@ public function setLogoSpace(int $width, int $height = null, int $startX = null,
661
661
throw new QRCodeDataException ('ECC level "H" required to add logo space ' );
662
662
}
663
663
664
- if ($ height === null ){
665
- $ height = $ width ;
666
- }
664
+ $ height ??= $ width ;
667
665
668
666
// if width and height happen to be negative or 0 (default value), just return - nothing to do
669
667
if ($ width <= 0 || $ height <= 0 ){
670
668
return $ this ; // @codeCoverageIgnore
671
669
}
672
670
673
671
// $this->moduleCount includes the quiet zone (if created), we need the QR size here
674
- $ length = $ this ->version ->getDimension ();
672
+ $ dimension = $ this ->version ->getDimension ();
675
673
676
- // throw if the size is exceeds the qrcode size
677
- if ($ width > $ length || $ height > $ length ){
674
+ // throw if the size exceeds the qrcode size
675
+ if ($ width > $ dimension || $ height > $ dimension ){
678
676
throw new QRCodeDataException ('logo dimensions exceed matrix size ' );
679
677
}
680
678
@@ -688,28 +686,24 @@ public function setLogoSpace(int $width, int $height = null, int $startX = null,
688
686
}
689
687
690
688
// throw if the logo space exceeds the maximum error correction capacity
691
- if (($ width * $ height ) > floor ( $ length * $ length * 0.2 )){
689
+ if (($ width * $ height ) > ( int )( $ dimension * $ dimension * 0.25 )){
692
690
throw new QRCodeDataException ('logo space exceeds the maximum error correction capacity ' );
693
691
}
694
692
695
- // quiet zone size
696
- $ qz = (($ this ->moduleCount - $ length ) / 2 );
697
- // skip quiet zone and the first 9 rows/columns (finder-, mode-, version- and timing patterns)
698
- $ start = ($ qz + 9 );
699
- // skip quiet zone
700
- $ end = ($ this ->moduleCount - $ qz );
693
+ $ quietzone = (($ this ->moduleCount - $ dimension ) / 2 );
694
+ $ end = ($ this ->moduleCount - $ quietzone );
701
695
702
696
// determine start coordinates
703
- $ startX = ((( $ startX !== null ) ? $ startX : ( $ length - $ width ) / 2 ) + $ qz );
704
- $ startY = ((( $ startY !== null ) ? $ startY : ( $ length - $ height ) / 2 ) + $ qz );
705
- $ endX = ($ startX + $ width );
706
- $ endY = ($ startY + $ height );
697
+ $ startX ?? = (($ dimension - $ width ) / 2 );
698
+ $ startY ?? = (($ dimension - $ height ) / 2 );
699
+ $ endX = ($ quietzone + $ startX + $ width );
700
+ $ endY = ($ quietzone + $ startY + $ height );
707
701
708
702
// clear the space
709
- for ($ y = $ startY ; $ y < $ endY ; $ y ++){
710
- for ($ x = $ startX ; $ x < $ endX ; $ x ++){
703
+ for ($ y = ( $ quietzone + $ startY) ; $ y < $ endY ; $ y ++){
704
+ for ($ x = ( $ quietzone + $ startX) ; $ x < $ endX ; $ x ++){
711
705
// out of bounds, skip
712
- if ($ x < $ start || $ y < $ start ||$ x >= $ end || $ y >= $ end ){
706
+ if ($ x < $ quietzone || $ y < $ quietzone ||$ x >= $ end || $ y >= $ end ){
713
707
continue ;
714
708
}
715
709
0 commit comments