Explorar o código

:octocat: +QROptionsTrait::$svgAddXmlHeader

smiley %!s(int64=2) %!d(string=hai) anos
pai
achega
cdaf8aac66
Modificáronse 2 ficheiros con 14 adicións e 2 borrados
  1. 7 2
      src/Output/QRMarkupSVG.php
  2. 7 0
      src/QROptionsTrait.php

+ 7 - 2
src/Output/QRMarkupSVG.php

@@ -77,8 +77,7 @@ class QRMarkupSVG extends QRMarkup{
 		$height = ($this->options->svgHeight !== null) ? sprintf(' height="%s"', $this->options->svgHeight) : '';
 		$height = ($this->options->svgHeight !== null) ? sprintf(' height="%s"', $this->options->svgHeight) : '';
 
 
 		/** @noinspection HtmlUnknownAttribute */
 		/** @noinspection HtmlUnknownAttribute */
-		return sprintf(
-			'<?xml version="1.0" encoding="UTF-8"?>%6$s'.
+		$header = sprintf(
 			'<svg xmlns="http://www.w3.org/2000/svg" class="qr-svg %1$s" viewBox="0 0 %2$s %2$s" preserveAspectRatio="%3$s"%4$s%5$s>%6$s',
 			'<svg xmlns="http://www.w3.org/2000/svg" class="qr-svg %1$s" viewBox="0 0 %2$s %2$s" preserveAspectRatio="%3$s"%4$s%5$s>%6$s',
 			$this->options->cssClass,
 			$this->options->cssClass,
 			($this->options->svgViewBoxSize ?? $this->moduleCount),
 			($this->options->svgViewBoxSize ?? $this->moduleCount),
@@ -87,6 +86,12 @@ class QRMarkupSVG extends QRMarkup{
 			$height,
 			$height,
 			$this->options->eol
 			$this->options->eol
 		);
 		);
+
+		if($this->options->svgAddXmlHeader){
+			$header = sprintf('<?xml version="1.0" encoding="UTF-8"?>%s%s', $this->options->eol, $header);
+		}
+
+		return $header;
 	}
 	}
 
 
 	/**
 	/**

+ 7 - 0
src/QROptionsTrait.php

@@ -315,6 +315,13 @@ trait QROptionsTrait{
 	 * QRMarkupSVG settings
 	 * QRMarkupSVG settings
 	 */
 	 */
 
 
+	/**
+	 * Whether to add an XML header line or not, e.g. to embed the SVG directly in HTML
+	 *
+	 * `<?xml version="1.0" encoding="UTF-8"?>`
+	 */
+	protected bool $svgAddXmlHeader = true;
+
 	/**
 	/**
 	 * SVG opacity
 	 * SVG opacity
 	 */
 	 */