Skip to content

Commit 54dac15

Browse files
committed
:octocat: QREps: extract header() method to ease customization
1 parent f9a98af commit 54dac15

File tree

1 file changed

+35
-24
lines changed

1 file changed

+35
-24
lines changed

src/Output/QREps.php

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -93,30 +93,7 @@ protected function formatColor(array $values):string{
9393
}
9494

9595
public function dump(string|null $file = null):string{
96-
[$width, $height] = $this->getOutputDimensions();
97-
98-
$eps = [
99-
// main header
100-
'%!PS-Adobe-3.0 EPSF-3.0',
101-
'%%Creator: php-qrcode (https://github.com/chillerlan/php-qrcode)',
102-
'%%Title: QR Code',
103-
sprintf('%%%%CreationDate: %1$s', date('c')),
104-
'%%DocumentData: Clean7Bit',
105-
'%%LanguageLevel: 3',
106-
sprintf('%%%%BoundingBox: 0 0 %s %s', $width, $height),
107-
'%%EndComments',
108-
// function definitions
109-
'%%BeginProlog',
110-
'/F { rectfill } def',
111-
'/R { setrgbcolor } def',
112-
'/C { setcmykcolor } def',
113-
'%%EndProlog',
114-
];
115-
116-
if($this::moduleValueIsValid($this->options->bgColor)){
117-
$eps[] = $this->prepareModuleValue($this->options->bgColor);
118-
$eps[] = sprintf('0 0 %s %s F', $width, $height);
119-
}
96+
$eps = $this->header();
12097

12198
// create the path elements
12299
$paths = $this->collectModules($this->module(...));
@@ -141,6 +118,40 @@ public function dump(string|null $file = null):string{
141118
return $data;
142119
}
143120

121+
/**
122+
* Returns the main header for the EPS file, including function definitions and background
123+
*
124+
* @return array<int, string>
125+
*/
126+
protected function header():array{
127+
[$width, $height] = $this->getOutputDimensions();
128+
129+
$header = [
130+
// main header
131+
'%!PS-Adobe-3.0 EPSF-3.0',
132+
'%%Creator: php-qrcode (https://github.com/chillerlan/php-qrcode)',
133+
'%%Title: QR Code',
134+
sprintf('%%%%CreationDate: %1$s', date('c')),
135+
'%%DocumentData: Clean7Bit',
136+
'%%LanguageLevel: 3',
137+
sprintf('%%%%BoundingBox: 0 0 %s %s', $width, $height),
138+
'%%EndComments',
139+
// function definitions
140+
'%%BeginProlog',
141+
'/F { rectfill } def',
142+
'/R { setrgbcolor } def',
143+
'/C { setcmykcolor } def',
144+
'%%EndProlog',
145+
];
146+
147+
if($this::moduleValueIsValid($this->options->bgColor)){
148+
$header[] = $this->prepareModuleValue($this->options->bgColor);
149+
$header[] = sprintf('0 0 %s %s F', $width, $height);
150+
}
151+
152+
return $header;
153+
}
154+
144155
/**
145156
* Returns a path segment for a single module
146157
*/

0 commit comments

Comments
 (0)