:octocat: cleanup, align module() method between the several output classes where applicable

This commit is contained in:
smiley
2023-09-03 19:46:14 +02:00
parent f8d553b56d
commit bcd410a33b
5 changed files with 105 additions and 78 deletions
+16 -16
View File
@@ -10,7 +10,7 @@
namespace chillerlan\QRCode\Output;
use function sprintf;
use function implode, sprintf;
/**
* HTML output (a cheap markup substitute when SVG is not available or not an option)
@@ -21,29 +21,29 @@ class QRMarkupHTML extends QRMarkup{
* @inheritDoc
*/
protected function createMarkup(bool $saveToFile):string{
$html = empty($this->options->cssClass)
? '<div>'
: sprintf('<div class="%s">', $this->getCssClass());
$rows = [];
$html .= $this->options->eol;
foreach($this->matrix->getMatrix() as $row){
$element = '<span style="background: %s;"></span>';
$modules = array_map(fn(int $M_TYPE):string => sprintf($element, $this->getModuleValue($M_TYPE)), $row);
for($y = 0; $y < $this->moduleCount; $y++){
$html .= '<div>';
for($x = 0; $x < $this->moduleCount; $x++){
$html .= sprintf('<span style="background: %s;"></span>', $this->getModuleValueAt($x, $y));
}
$html .= '</div>'.$this->options->eol;
$rows[] = sprintf('<div>%s</div>%s', implode('', $modules), $this->options->eol);
}
$html .= '</div>'.$this->options->eol;
$html = sprintf(
'<div class="%1$s">%3$s%2$s</div>%3$s',
$this->getCssClass(),
implode('', $rows),
$this->options->eol
);
// wrap the snippet into a body when saving to file
if($saveToFile){
$html = sprintf(
'<!DOCTYPE html><html lang=""><head><meta charset="UTF-8"><title>QR Code</title></head><body>%s</body></html>',
$this->options->eol.$html
'<!DOCTYPE html><html lang="none">%2$s<head>%2$s<meta charset="UTF-8">%2$s'.
'<title>QR Code</title></head>%2$s<body>%1$s</body>%2$s</html>',
$html,
$this->options->eol
);
}