@@ -83,47 +83,34 @@ protected function formatColor(array $values):string{
83
83
throw new QRCodeOutputException ('invalid color value ' );
84
84
}
85
85
86
+ // the EPS functions "C" and "R" are defined in the header below
86
87
$ 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
91
90
92
91
return sprintf ($ format , ...$ values );
93
92
}
94
93
95
94
public function dump (string |null $ file = null ):string {
96
- $ eps = $ this ->header ();
97
95
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
+ ]);
102
104
103
- if (empty ($ path )){
104
- continue ;
105
- }
105
+ $ this ->saveToFile ($ eps , $ file );
106
106
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 ;
119
108
}
120
109
121
110
/**
122
111
* Returns the main header for the EPS file, including function definitions and background
123
- *
124
- * @return array<int, string>
125
112
*/
126
- protected function header ():array {
113
+ protected function header ():string {
127
114
[$ width , $ height ] = $ this ->getOutputDimensions ();
128
115
129
116
$ header = [
@@ -149,7 +136,27 @@ protected function header():array{
149
136
$ header [] = sprintf ('0 0 %s %s F ' , $ width , $ height );
150
137
}
151
138
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 );
153
160
}
154
161
155
162
/**
0 commit comments