Index: trunk/phase3/tests/phpunit/includes/api/RandomImageGenerator.php |
— | — | @@ -161,6 +161,20 @@ |
162 | 162 | return $spec; |
163 | 163 | } |
164 | 164 | |
| 165 | + /** |
| 166 | + * Given array( array('x' => 10, 'y' => 20), array( 'x' => 30, y=> 5 ) ) |
| 167 | + * returns "10,20 30,5" |
| 168 | + * Useful for SVG and imagemagick command line arguments |
| 169 | + * @param $shape: Array of arrays, each array containing x & y keys mapped to numeric values |
| 170 | + * @return string |
| 171 | + */ |
| 172 | + static function shapePointsToString( $shape ) { |
| 173 | + $points = array(); |
| 174 | + foreach ( $shape as $point ) { |
| 175 | + $points[] = $point['x'] . ',' . $point['y']; |
| 176 | + } |
| 177 | + return join( " ", $points ); |
| 178 | + } |
165 | 179 | |
166 | 180 | /** |
167 | 181 | * Based on image specification, write a very simple SVG file to disk. |
— | — | @@ -179,7 +193,7 @@ |
180 | 194 | foreach ( $spec['draws'] as $drawSpec ) { |
181 | 195 | $shape = $g->addChild( 'polygon' ); |
182 | 196 | $shape->addAttribute( 'fill', $drawSpec['fill'] ); |
183 | | - $shape->addAttribute( 'points', shapePointsToString( $drawSpec['shape'] ) ); |
| 197 | + $shape->addAttribute( 'points', self::shapePointsToString( $drawSpec['shape'] ) ); |
184 | 198 | }; |
185 | 199 | if ( ! $fh = fopen( $filename, 'w' ) ) { |
186 | 200 | throw new Exception( "couldn't open $filename for writing" ); |
— | — | @@ -190,14 +204,6 @@ |
191 | 205 | } |
192 | 206 | } |
193 | 207 | |
194 | | - public function shapePointsToString( $shape ) { |
195 | | - $points = array(); |
196 | | - foreach ( $shape as $point ) { |
197 | | - $points[] = $point['x'] . ',' . $point['y']; |
198 | | - } |
199 | | - return join( " ", $points ); |
200 | | - } |
201 | | - |
202 | 208 | /** |
203 | 209 | * Based on an image specification, write such an image to disk, using Imagick PHP extension |
204 | 210 | * @param $spec: spec describing background and circles to draw |
— | — | @@ -240,7 +246,7 @@ |
241 | 247 | $args[] = wfEscapeShellArg( "xc:" . $spec['fill'] ); |
242 | 248 | foreach( $spec['draws'] as $draw ) { |
243 | 249 | $fill = $draw['fill']; |
244 | | - $polygon = shapePointsToString( $draw['shape'] ); |
| 250 | + $polygon = self::shapePointsToString( $draw['shape'] ); |
245 | 251 | $drawCommand = "fill $fill polygon $polygon"; |
246 | 252 | $args[] = '-draw ' . wfEscapeShellArg( $drawCommand ); |
247 | 253 | } |