Skip to content

Commit 9b765ae

Browse files
committed
:octocat:
1 parent 61eb52f commit 9b765ae

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

src/Output/QRMarkupSVG.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ class QRMarkupSVG extends QRMarkup{
2828

2929
final public const string MIME_TYPE = 'image/svg+xml';
3030

31+
// micro optimization for circle radius and diameter values in long loops
32+
protected float $r;
33+
protected float $d;
34+
3135
/**
3236
* @todo: XSS proof
3337
*
@@ -116,6 +120,9 @@ protected function header():string{
116120
* returns one or more SVG <path> elements
117121
*/
118122
protected function paths():string{
123+
$this->r = $this->options->circleRadius;
124+
$this->d = $this->r * 2;
125+
119126
$paths = $this->collectModules();
120127
$svg = [];
121128

@@ -173,13 +180,11 @@ protected function moduleTransform(int $x, int $y, int $M_TYPE, int $M_TYPE_LAYE
173180

174181
if($this->options->drawCircularModules && !$this->matrix->checkTypeIn($x, $y, $this->options->keepAsSquare)){
175182
// string interpolation: ugly and fast
176-
$r = $this->options->circleRadius;
177-
$d = $r * 2;
178-
$ix = ($x + 0.5 - $r);
183+
$ix = ($x + 0.5 - $this->r);
179184
$iy = ($y + 0.5);
180185

181186
// phpcs:ignore
182-
return "M$ix $iy a$r $r 0 1 0 $d 0 a$r $r 0 1 0 -$d 0Z";
187+
return "M$ix $iy a$this->r $this->r 0 1 0 $this->d 0 a$this->r $this->r 0 1 0 -$this->d 0Z";
183188
}
184189

185190
// phpcs:ignore

src/Output/QROutputAbstract.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ abstract class QROutputAbstract implements QROutputInterface{
3737
*/
3838
protected int $length;
3939

40+
/**
41+
* The current module scale value (might have been modified)
42+
*
43+
* @see \chillerlan\QRCode\QROptions::$scale
44+
*/
45+
protected int $scale;
46+
4047
/**
4148
* an (optional) array of color values for the several QR matrix parts
4249
*
@@ -54,13 +61,6 @@ abstract class QROutputAbstract implements QROutputInterface{
5461
*/
5562
protected SettingsContainerInterface|QROptions $options;
5663

57-
/**
58-
* The current module scale value (might have been modified)
59-
*
60-
* @see \chillerlan\QRCode\QROptions::$scale
61-
*/
62-
protected int $scale;
63-
6464
/**
6565
* QROutputAbstract constructor.
6666
*/
@@ -84,7 +84,7 @@ public function __construct(SettingsContainerInterface|QROptions|iterable $optio
8484
/**
8585
* Sets/updates the matrix dimensions
8686
*
87-
* Call this method if you modify the matrix from within your custom module in case the dimensions have been changed
87+
* Call this method if you modify the matrix from within your custom output class in case the dimensions have been changed
8888
*/
8989
protected function setMatrixDimensions():void{
9090
$this->moduleCount = $this->matrix->moduleCount;

src/QROptionsTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ trait QROptionsTrait{
112112
}
113113

114114
/**
115-
* Mask Pattern to use (no value in using, mostly for unit testing purposes)
115+
* Mask Pattern to use (no value in using, mostly for unit testing purposes, will cause unreadable symbols)
116116
*
117117
* `0 ... 7` or `MaskPattern::PATTERN_AUTO` (default)
118118
*
@@ -150,7 +150,7 @@ trait QROptionsTrait{
150150
/**
151151
* Return the image resource instead of a render if applicable.
152152
*
153-
* - `QRGdImage`: `resource` (PHP < 8), `GdImage`
153+
* - `QRGdImage`: `GdImage`
154154
* - `QRImagick`: `Imagick`
155155
* - `QRFpdf`: `FPDF`
156156
*

0 commit comments

Comments
 (0)