Skip to content

Commit 943ed37

Browse files
committed
:octocat: QREps: cleanup, align with other output classes
1 parent 0ef7bc7 commit 943ed37

File tree

1 file changed

+35
-28
lines changed

1 file changed

+35
-28
lines changed

src/Output/QREps.php

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -83,47 +83,34 @@ protected function formatColor(array $values):string{
8383
throw new QRCodeOutputException('invalid color value');
8484
}
8585

86+
// the EPS functions "C" and "R" are defined in the header below
8687
$format = ($count === 4)
87-
// CMYK
88-
? '%f %f %f %f C'
89-
// RGB
90-
: '%f %f %f R';
88+
? '%f %f %f %f C' // CMYK
89+
: '%f %f %f R'; // RGB
9190

9291
return sprintf($format, ...$values);
9392
}
9493

9594
public function dump(string|null $file = null):string{
96-
$eps = $this->header();
9795

98-
// create the path elements
99-
$paths = $this->collectModules($this->module(...));
100-
101-
foreach($paths as $M_TYPE => $path){
96+
$eps = implode("\n", [
97+
// initialize header
98+
$this->header(),
99+
// create the path elements
100+
$this->paths(),
101+
// end file
102+
'%%EOF'
103+
]);
102104

103-
if(empty($path)){
104-
continue;
105-
}
105+
$this->saveToFile($eps, $file);
106106

107-
$eps[] = $this->getModuleValue($M_TYPE);
108-
$eps[] = implode("\n", $path);
109-
}
110-
111-
// end file
112-
$eps[] = '%%EOF';
113-
114-
$data = implode("\n", $eps);
115-
116-
$this->saveToFile($data, $file);
117-
118-
return $data;
107+
return $eps;
119108
}
120109

121110
/**
122111
* Returns the main header for the EPS file, including function definitions and background
123-
*
124-
* @return array<int, string>
125112
*/
126-
protected function header():array{
113+
protected function header():string{
127114
[$width, $height] = $this->getOutputDimensions();
128115

129116
$header = [
@@ -149,7 +136,27 @@ protected function header():array{
149136
$header[] = sprintf('0 0 %s %s F', $width, $height);
150137
}
151138

152-
return $header;
139+
return implode("\n", $header);
140+
}
141+
142+
/**
143+
* returns one or more EPS path blocks
144+
*/
145+
protected function paths():string{
146+
$paths = $this->collectModules($this->module(...));
147+
$eps = [];
148+
149+
foreach($paths as $M_TYPE => $path){
150+
151+
if(empty($path)){
152+
continue;
153+
}
154+
155+
$eps[] = $this->getModuleValue($M_TYPE);
156+
$eps[] = implode("\n", $path);
157+
}
158+
159+
return implode("\n", $eps);
153160
}
154161

155162
/**

0 commit comments

Comments
 (0)