smiley 2 лет назад
Родитель
Сommit
0578456800
5 измененных файлов с 40 добавлено и 28 удалено
  1. 15 12
      src/Output/QRMarkupSVG.php
  2. 10 10
      src/Output/QROutputAbstract.php
  3. 2 4
      src/QRCode.php
  4. 11 0
      src/QROptionsTrait.php
  5. 2 2
      tests/QRCodeTest.php

+ 15 - 12
src/Output/QRMarkupSVG.php

@@ -18,7 +18,10 @@ use function array_chunk, implode, is_string, preg_match, sprintf, trim;
  * @see https://github.com/codemasher/php-qrcode/pull/5
  * @see https://github.com/codemasher/php-qrcode/pull/5
  * @see https://developer.mozilla.org/en-US/docs/Web/SVG
  * @see https://developer.mozilla.org/en-US/docs/Web/SVG
  * @see https://www.sarasoueidan.com/demos/interactive-svg-coordinate-system/
  * @see https://www.sarasoueidan.com/demos/interactive-svg-coordinate-system/
- * @see http://apex.infogridpacific.com/SVG/svg-tutorial-contents.html
+ * @see https://lea.verou.me/blog/2019/05/utility-convert-svg-path-to-all-relative-or-all-absolute-commands/
+ * @see https://codepen.io/leaverou/full/RmwzKv
+ * @see https://jakearchibald.github.io/svgomg/
+ * @see https://web.archive.org/web/20200220211445/http://apex.infogridpacific.com/SVG/svg-tutorial-contents.html
  */
  */
 class QRMarkupSVG extends QRMarkup{
 class QRMarkupSVG extends QRMarkup{
 
 
@@ -54,6 +57,17 @@ class QRMarkupSVG extends QRMarkup{
 		return [$this->moduleCount, $this->moduleCount];
 		return [$this->moduleCount, $this->moduleCount];
 	}
 	}
 
 
+	/**
+	 * @inheritDoc
+	 */
+	protected function getCssClass(int $M_TYPE = 0):string{
+		return implode(' ', [
+			'qr-'.($this::LAYERNAMES[$M_TYPE] ?? $M_TYPE),
+			$this->matrix->isDark($M_TYPE) ? 'dark' : 'light',
+			$this->options->cssClass,
+		]);
+	}
+
 	/**
 	/**
 	 * @inheritDoc
 	 * @inheritDoc
 	 */
 	 */
@@ -159,17 +173,6 @@ class QRMarkupSVG extends QRMarkup{
 		return sprintf('<path class="%s" d="%s"/>', $this->getCssClass($M_TYPE), $path);
 		return sprintf('<path class="%s" d="%s"/>', $this->getCssClass($M_TYPE), $path);
 	}
 	}
 
 
-	/**
-	 * @inheritDoc
-	 */
-	protected function getCssClass(int $M_TYPE = 0):string{
-		return implode(' ', [
-			'qr-'.($this::LAYERNAMES[$M_TYPE] ?? $M_TYPE),
-			$this->matrix->isDark($M_TYPE) ? 'dark' : 'light',
-			$this->options->cssClass,
-		]);
-	}
-
 	/**
 	/**
 	 * returns a path segment for a single module
 	 * returns a path segment for a single module
 	 *
 	 *

+ 10 - 10
src/Output/QROutputAbstract.php

@@ -146,6 +146,16 @@ abstract class QROutputAbstract implements QROutputInterface{
 
 
 	}
 	}
 
 
+	/**
+	 * Prepares the value for the given input (return value depends on the output class)
+	 */
+	abstract protected function prepareModuleValue(mixed $value):mixed;
+
+	/**
+	 * Returns a default value for either dark or light modules (return value depends on the output class)
+	 */
+	abstract protected function getDefaultModuleValue(bool $isDark):mixed;
+
 	/**
 	/**
 	 * Returns the prepared value for the given $M_TYPE
 	 * Returns the prepared value for the given $M_TYPE
 	 *
 	 *
@@ -167,16 +177,6 @@ abstract class QROutputAbstract implements QROutputInterface{
 		return $this->getModuleValue($this->matrix->get($x, $y));
 		return $this->getModuleValue($this->matrix->get($x, $y));
 	}
 	}
 
 
-	/**
-	 * Prepares the value for the given input (return value depends on the output class)
-	 */
-	abstract protected function prepareModuleValue(mixed $value):mixed;
-
-	/**
-	 * Returns a default value for either dark or light modules (return value depends on the output class)
-	 */
-	abstract protected function getDefaultModuleValue(bool $isDark):mixed;
-
 	/**
 	/**
 	 * Returns a base64 data URI for the given string and mime type
 	 * Returns a base64 data URI for the given string and mime type
 	 */
 	 */

+ 2 - 4
src/QRCode.php

@@ -100,8 +100,6 @@ class QRCode{
 
 
 	/**
 	/**
 	 * Returns a QRMatrix object for the given $data and current QROptions
 	 * Returns a QRMatrix object for the given $data and current QROptions
-	 *
-	 * @throws \chillerlan\QRCode\Data\QRCodeDataException
 	 */
 	 */
 	public function getQRMatrix():QRMatrix{
 	public function getQRMatrix():QRMatrix{
 		$matrix = (new QRData($this->options, $this->dataSegments))->writeMatrix();
 		$matrix = (new QRData($this->options, $this->dataSegments))->writeMatrix();
@@ -149,11 +147,11 @@ class QRCode{
 		$outputInterface = $this->options->outputInterface;
 		$outputInterface = $this->options->outputInterface;
 
 
 		if(empty($outputInterface) || !class_exists($outputInterface)){
 		if(empty($outputInterface) || !class_exists($outputInterface)){
-			throw new QRCodeOutputException('invalid output module');
+			throw new QRCodeOutputException('invalid output class');
 		}
 		}
 
 
 		if(!in_array(QROutputInterface::class, class_implements($outputInterface))){
 		if(!in_array(QROutputInterface::class, class_implements($outputInterface))){
-			throw new QRCodeOutputException('output module does not implement QROutputInterface');
+			throw new QRCodeOutputException('output class does not implement QROutputInterface');
 		}
 		}
 
 
 		return new $outputInterface($this->options, $matrix);
 		return new $outputInterface($this->options, $matrix);

+ 11 - 0
src/QROptionsTrait.php

@@ -204,12 +204,23 @@ trait QROptionsTrait{
 	/**
 	/**
 	 * Whether to connect the paths for the several module types to avoid weird glitches when using gradients etc.
 	 * Whether to connect the paths for the several module types to avoid weird glitches when using gradients etc.
 	 *
 	 *
+	 * This option is exclusive to output classes that use the module collector `QROutputAbstract::collectModules()`,
+	 * which converts the `$M_TYPE` of all modules to `QRMatrix::M_DATA` and `QRMatrix::M_DATA_DARK` respectively.
+	 *
+	 * Module types that should not be added to the connected path can be excluded via `QROptions::$excludeFromConnect`.
+	 *
+	 * Currentty used in `QREps` and `QRMarkupSVG`.
+	 *
+	 * @see \chillerlan\QRCode\Output\QROutputAbstract::collectModules()
+	 * @see \chillerlan\QRCode\QROptionsTrait::$excludeFromConnect
 	 * @see https://github.com/chillerlan/php-qrcode/issues/57
 	 * @see https://github.com/chillerlan/php-qrcode/issues/57
 	 */
 	 */
 	protected bool $connectPaths = false;
 	protected bool $connectPaths = false;
 
 
 	/**
 	/**
 	 * Specify which paths/patterns to exclude from connecting if `QROptions::$connectPaths` is set to `true`
 	 * Specify which paths/patterns to exclude from connecting if `QROptions::$connectPaths` is set to `true`
+	 *
+	 * @see \chillerlan\QRCode\QROptionsTrait::$connectPaths
 	 */
 	 */
 	protected array $excludeFromConnect = [];
 	protected array $excludeFromConnect = [];
 
 

+ 2 - 2
tests/QRCodeTest.php

@@ -39,7 +39,7 @@ final class QRCodeTest extends TestCase{
 	 */
 	 */
 	public function testInitCustomOutputInterfaceNotExistsException():void{
 	public function testInitCustomOutputInterfaceNotExistsException():void{
 		$this->expectException(QRCodeOutputException::class);
 		$this->expectException(QRCodeOutputException::class);
-		$this->expectExceptionMessage('invalid output module');
+		$this->expectExceptionMessage('invalid output class');
 
 
 		$this->options->outputInterface = 'foo';
 		$this->options->outputInterface = 'foo';
 
 
@@ -51,7 +51,7 @@ final class QRCodeTest extends TestCase{
 	 */
 	 */
 	public function testInitCustomOutputInterfaceNotImplementsException():void{
 	public function testInitCustomOutputInterfaceNotImplementsException():void{
 		$this->expectException(QRCodeOutputException::class);
 		$this->expectException(QRCodeOutputException::class);
-		$this->expectExceptionMessage('output module does not implement QROutputInterface');
+		$this->expectExceptionMessage('output class does not implement QROutputInterface');
 
 
 		$this->options->outputInterface = stdClass::class;
 		$this->options->outputInterface = stdClass::class;