diff --git a/examples/QRSvgWithLogo.php b/examples/QRSvgWithLogo.php
index fcfa8580c..a6e366d0c 100644
--- a/examples/QRSvgWithLogo.php
+++ b/examples/QRSvgWithLogo.php
@@ -10,44 +10,26 @@
namespace chillerlan\QRCodeExamples;
-use chillerlan\QRCode\Output\QRMarkup;
-use function file_get_contents, sprintf;
+use chillerlan\QRCode\Output\QRMarkupSVG;
+use function ceil, file_get_contents, sprintf;
/**
* Create SVG QR Codes with embedded logos (that are also SVG)
*/
-class QRSvgWithLogo extends QRMarkup{
+class QRSvgWithLogo extends QRMarkupSVG{
/**
- * SVG output
- *
- * @see https://github.com/codemasher/php-qrcode/pull/5
- * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/svg
- * @see https://www.sarasoueidan.com/demos/interactive-svg-coordinate-system/
+ * @inheritDoc
*/
- protected function svg(bool $saveToFile):string{
+ protected function paths():string{
$size = (int)ceil($this->moduleCount * $this->options->svgLogoScale);
// we're calling QRMatrix::setLogoSpace() manually, so QROptions::$addLogoSpace has no effect here
$this->matrix->setLogoSpace($size, $size);
- $svg = $this->svgHeader();
-
- if(!empty($this->options->svgDefs)){
- $svg .= sprintf('%1$s%2$s%2$s', $this->options->svgDefs, $this->options->eol);
- }
-
- $svg .= $this->svgPaths();
+ $svg = parent::paths();
$svg .= $this->getLogo();
- // close svg
- $svg .= sprintf('%1$s%1$s', $this->options->eol);
-
- // transform to data URI only when not saving to file
- if(!$saveToFile && $this->options->imageBase64){
- $svg = $this->base64encode($svg, 'image/svg+xml');
- }
-
return $svg;
}
diff --git a/src/Output/QRMarkup.php b/src/Output/QRMarkup.php
index 027281617..062423510 100644
--- a/src/Output/QRMarkup.php
+++ b/src/Output/QRMarkup.php
@@ -10,15 +10,12 @@
namespace chillerlan\QRCode\Output;
-use chillerlan\QRCode\Data\QRMatrix;
-use chillerlan\QRCode\QRCode;
-
-use function implode, is_string, sprintf, strip_tags, trim;
+use function is_string, strip_tags, trim;
/**
- * Converts the matrix into markup types: HTML, SVG, ...
+ * Abstract for markup types: HTML, SVG, ... XML anyone?
*/
-class QRMarkup extends QROutputAbstract{
+abstract class QRMarkup extends QROutputAbstract{
/**
* @inheritDoc
@@ -44,18 +41,11 @@ class QRMarkup extends QROutputAbstract{
/**
* @inheritDoc
*/
- public function dump(string $file = null){
+ public function dump(string $file = null):string{
$file ??= $this->options->cachefile;
$saveToFile = $file !== null;
- switch($this->options->outputType){
- case QRCode::OUTPUT_MARKUP_HTML:
- $data = $this->html($saveToFile);
- break;
- case QRCode::OUTPUT_MARKUP_SVG:
- default:
- $data = $this->svg($saveToFile);
- }
+ $data = $this->createMarkup($saveToFile);
if($saveToFile){
$this->saveToFile($data, $file);
@@ -65,143 +55,7 @@ class QRMarkup extends QROutputAbstract{
}
/**
- * HTML output
- */
- protected function html(bool $saveToFile):string{
-
- $html = empty($this->options->cssClass)
- ? '
'
- : sprintf('
', $this->options->cssClass);
-
- $html .= $this->options->eol;
-
- foreach($this->matrix->matrix() as $row){
- $html .= '
';
-
- foreach($row as $M_TYPE){
- $html .= sprintf('', $this->moduleValues[$M_TYPE]);
- }
-
- $html .= '
'.$this->options->eol;
- }
-
- $html .= '
'.$this->options->eol;
-
- if($saveToFile){
- return sprintf(
- '
QR Code%s',
- $this->options->eol.$html
- );
- }
-
- return $html;
- }
-
- /**
- * SVG output
*
- * @see https://github.com/codemasher/php-qrcode/pull/5
- * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/svg
- * @see https://www.sarasoueidan.com/demos/interactive-svg-coordinate-system/
*/
- protected function svg(bool $saveToFile):string{
- $svg = $this->svgHeader();
-
- if(!empty($this->options->svgDefs)){
- $svg .= sprintf('
%1$s%2$s%2$s', $this->options->svgDefs, $this->options->eol);
- }
-
- $svg .= $this->svgPaths();
-
- // close svg
- $svg .= sprintf('%1$s%1$s', $this->options->eol);
-
- // transform to data URI only when not saving to file
- if(!$saveToFile && $this->options->imageBase64){
- $svg = $this->base64encode($svg, 'image/svg+xml');
- }
-
- return $svg;
- }
-
- /**
- * returns the