diff --git a/src/Output/QRMarkupSVG.php b/src/Output/QRMarkupSVG.php index 92815ebde..0dc586f16 100644 --- a/src/Output/QRMarkupSVG.php +++ b/src/Output/QRMarkupSVG.php @@ -28,6 +28,10 @@ class QRMarkupSVG extends QRMarkup{ final public const string MIME_TYPE = 'image/svg+xml'; + // micro optimization for circle radius and diameter values in long loops + protected float $r; + protected float $d; + /** * @todo: XSS proof * @@ -116,6 +120,9 @@ class QRMarkupSVG extends QRMarkup{ * returns one or more SVG elements */ protected function paths():string{ + $this->r = $this->options->circleRadius; + $this->d = $this->r * 2; + $paths = $this->collectModules(); $svg = []; @@ -173,13 +180,11 @@ class QRMarkupSVG extends QRMarkup{ if($this->options->drawCircularModules && !$this->matrix->checkTypeIn($x, $y, $this->options->keepAsSquare)){ // string interpolation: ugly and fast - $r = $this->options->circleRadius; - $d = $r * 2; - $ix = ($x + 0.5 - $r); + $ix = ($x + 0.5 - $this->r); $iy = ($y + 0.5); // phpcs:ignore - return "M$ix $iy a$r $r 0 1 0 $d 0 a$r $r 0 1 0 -$d 0Z"; + 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"; } // phpcs:ignore diff --git a/src/Output/QROutputAbstract.php b/src/Output/QROutputAbstract.php index c6ff3533a..86034bfc5 100644 --- a/src/Output/QROutputAbstract.php +++ b/src/Output/QROutputAbstract.php @@ -37,6 +37,13 @@ abstract class QROutputAbstract implements QROutputInterface{ */ protected int $length; + /** + * The current module scale value (might have been modified) + * + * @see \chillerlan\QRCode\QROptions::$scale + */ + protected int $scale; + /** * an (optional) array of color values for the several QR matrix parts * @@ -54,13 +61,6 @@ abstract class QROutputAbstract implements QROutputInterface{ */ protected SettingsContainerInterface|QROptions $options; - /** - * The current module scale value (might have been modified) - * - * @see \chillerlan\QRCode\QROptions::$scale - */ - protected int $scale; - /** * QROutputAbstract constructor. */ @@ -84,7 +84,7 @@ abstract class QROutputAbstract implements QROutputInterface{ /** * Sets/updates the matrix dimensions * - * Call this method if you modify the matrix from within your custom module in case the dimensions have been changed + * Call this method if you modify the matrix from within your custom output class in case the dimensions have been changed */ protected function setMatrixDimensions():void{ $this->moduleCount = $this->matrix->moduleCount; diff --git a/src/QROptionsTrait.php b/src/QROptionsTrait.php index 396f9b06e..60743de71 100644 --- a/src/QROptionsTrait.php +++ b/src/QROptionsTrait.php @@ -112,7 +112,7 @@ trait QROptionsTrait{ } /** - * Mask Pattern to use (no value in using, mostly for unit testing purposes) + * Mask Pattern to use (no value in using, mostly for unit testing purposes, will cause unreadable symbols) * * `0 ... 7` or `MaskPattern::PATTERN_AUTO` (default) * @@ -150,7 +150,7 @@ trait QROptionsTrait{ /** * Return the image resource instead of a render if applicable. * - * - `QRGdImage`: `resource` (PHP < 8), `GdImage` + * - `QRGdImage`: `GdImage` * - `QRImagick`: `Imagick` * - `QRFpdf`: `FPDF` *