Index: trunk/extensions/LilyPond/LilyPond.php |
— | — | @@ -30,7 +30,6 @@ |
31 | 31 | |
32 | 32 | # You can set the variable $wgLilypond if you want/need to override the |
33 | 33 | # path to the Lilypond executable. For example: |
34 | | -# $wgLilypond = "/home/username/bin/lilypond"; |
35 | 34 | |
36 | 35 | # Add a text link to prompt user to listen to midi, before and/or after |
37 | 36 | # the image. Remember line breaks |
— | — | @@ -48,288 +47,297 @@ |
49 | 48 | # End User Settings |
50 | 49 | |
51 | 50 | # Defaulting of user settings |
52 | | -if( !isset( $wgLilypond ) ) |
53 | | - $wgLilypond = "PATH=\$PATH:/usr/local/bin /usr/local/bin/lilypond"; |
| 51 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 52 | + die( "This is not a valid entry point.\n" ); |
| 53 | +} |
54 | 54 | |
55 | | -if( !isset( $wgLilypondPreMidi ) ) |
56 | | - $wgLilypondPreMidi = ""; |
| 55 | +$wgExtensionCredits['parserhooks'][] = array( |
| 56 | + 'path' => __FILE__, |
| 57 | + 'name' => 'LilyPond', |
| 58 | + 'version' => 0.01, |
| 59 | + 'author' => 'Johannes E. Schindelin', |
| 60 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:LilyPond', |
| 61 | + 'descriptionmsg' => 'lilypond-desc', |
| 62 | +); |
57 | 63 | |
58 | | -if( !isset( $wgLilypondPostMidi ) ) |
59 | | - $wgLilypondPostMidi = ""; |
| 64 | +if ( !isset( $wgLilypond ) ) |
| 65 | + $wgLilypond = "/usr/local/bin/lilypond"; |
60 | 66 | |
61 | | -if( !isset( $wgLilypondTrim ) ) { |
62 | | - $wgLilypondTrim = true; |
| 67 | +if ( !isset( $wgLilypondPreMidi ) ) |
| 68 | + $wgLilypondPreMidi = ""; |
| 69 | + |
| 70 | +if ( !isset( $wgLilypondPostMidi ) ) |
| 71 | + $wgLilypondPostMidi = ""; |
| 72 | + |
| 73 | +if ( !isset( $wgLilypondTrim ) ) { |
| 74 | + $wgLilypondTrim = true; |
63 | 75 | } |
64 | 76 | |
65 | | -if( !isset( $wgLilypondBorderX ) ) { |
66 | | - $wgLilypondBorderX = 0; |
| 77 | +if ( !isset( $wgLilypondBorderX ) ) { |
| 78 | + $wgLilypondBorderX = 0; |
67 | 79 | } |
68 | 80 | |
69 | | -if( !isset( $wgLilypondBorderY ) ) { |
70 | | - $wgLilypondBorderY = 0; |
| 81 | +if ( !isset( $wgLilypondBorderY ) ) { |
| 82 | + $wgLilypondBorderY = 0; |
71 | 83 | } |
72 | 84 | |
73 | 85 | $wgExtensionFunctions[] = "wfLilyPondExtension"; |
74 | 86 | |
75 | 87 | function wfLilyPondExtension() { |
76 | | - global $wgParser; |
77 | | - $wgParser->setHook( "lilypond", "renderLilyPondFragment" ); |
78 | | - $wgParser->setHook( "lilymidi", "renderLilyPondMidiFragment" ); |
79 | | - $wgParser->setHook( "lilybook", "renderLilyPond" ); |
| 88 | + global $wgParser; |
| 89 | + $wgParser->setHook( "lilypond", "renderLilyPondFragment" ); |
| 90 | + $wgParser->setHook( "lilymidi", "renderLilyPondMidiFragment" ); |
| 91 | + $wgParser->setHook( "lilybook", "renderLilyPond" ); |
80 | 92 | } |
81 | 93 | |
82 | | -function renderLilyPondMidiFragment( $lilypond_code ) |
83 | | -{ |
84 | | - return renderLilyPondFragment( $lilypond_code, true ); |
| 94 | +function renderLilyPondMidiFragment( $lilypond_code ) { |
| 95 | + return renderLilyPondFragment( $lilypond_code, true ); |
85 | 96 | } |
86 | 97 | |
87 | | -function renderLilyPondFragment( $lilypond_code, $midi=false ) |
88 | | -{ |
89 | | - return renderLilyPond( "\\header {\n" |
90 | | - . "\ttagline = ##f\n" |
91 | | - . "}\n" |
92 | | - . "\\paper {\n" |
93 | | - . "\traggedright = ##t\n" |
94 | | - . "\traggedbottom = ##t\n" |
95 | | - . "\tindent = 0\mm\n" |
96 | | - . "}\n" |
97 | | - . "\\score {\n" |
98 | | - . $lilypond_code |
99 | | - . "\t\\layout { }\n" |
100 | | - . ($midi?"\t\\midi { }\n":"") |
101 | | - . "}\n", $lilypond_code ); |
| 98 | +function renderLilyPondFragment( $lilypond_code, $midi = false ) { |
| 99 | + return renderLilyPond( "\\header {\n" |
| 100 | + . "\ttagline = ##f\n" |
| 101 | + . "}\n" |
| 102 | + . "\\paper {\n" |
| 103 | + . "\traggedright = ##t\n" |
| 104 | + . "\traggedbottom = ##t\n" |
| 105 | + . "\tindent = 0\mm\n" |
| 106 | + . "}\n" |
| 107 | + . "\\score {\n" |
| 108 | + . $lilypond_code |
| 109 | + . "\t\\layout { }\n" |
| 110 | + . ( $midi ? "\t\\midi { }\n":"" ) |
| 111 | + . "}\n", $lilypond_code ); |
102 | 112 | } |
103 | 113 | |
104 | | -function renderLilyPond( $lilypond_code, $short_code=false ) |
105 | | -{ |
106 | | - global $wgMathPath, $wgMathDirectory, $wgTmpDirectory, $wgLilypond, $wgLilypondPreMidi, $wgLilypondPostMidii, $wgLilypondTrim, $wgLilypondBorderX, $wgLilypondBorderY; |
| 114 | +function renderLilyPond( $lilypond_code, $short_code = false ) { |
| 115 | + global $wgMathPath, $wgMathDirectory, $wgTmpDirectory, $wgLilypond, $wgLilypondPreMidi, |
| 116 | + $wgLilypondPostMidii, $wgLilypondTrim, $wgLilypondBorderX, $wgLilypondBorderY; |
107 | 117 | |
108 | | - $mf = wfMsg( "math_failure" ); |
109 | | - $munk = wfMsg( "math_unknown_error" ); |
| 118 | + $mf = wfMsg( "math_failure" ); |
| 119 | + $munk = wfMsg( "math_unknown_error" ); |
110 | 120 | |
111 | | - $fname = "renderMusic"; |
| 121 | + $fname = "renderMusic"; |
112 | 122 | |
113 | | - $md5 = md5($lilypond_code); |
| 123 | + $md5 = md5( $lilypond_code ); |
114 | 124 | |
115 | | - if( file_exists( $wgMathDirectory."/".$md5.".midi" ) ) { |
116 | | - $pre = "<a href=\"".$wgMathPath."/".$md5.".midi\"> " . $wgLilypondPreMidi; |
117 | | - $post = $wgLilypondPostMidi . " </a>"; |
118 | | - } else { |
119 | | - $pre = ""; |
120 | | - $post = ""; |
121 | | - } |
| 125 | + if ( file_exists( $wgMathDirectory . "/" . $md5 . ".midi" ) ) { |
| 126 | + $pre = "<a href=\"" . $wgMathPath . "/" . $md5 . ".midi\"> " . $wgLilypondPreMidi; |
| 127 | + $post = $wgLilypondPostMidi . " </a>"; |
| 128 | + } else { |
| 129 | + $pre = ""; |
| 130 | + $post = ""; |
| 131 | + } |
122 | 132 | |
123 | | - # if short_code is supplied, this is a fragment |
124 | | - if( $short_code ) { |
125 | | - $link = "<img src=\"".$wgMathPath."/".$md5.".png\" alt=\"" |
126 | | - .htmlspecialchars( $short_code )."\">"; |
| 133 | + # if short_code is supplied, this is a fragment |
| 134 | + if ( $short_code ) { |
| 135 | + $link = "<img src=\"" . $wgMathPath . "/" . $md5 . ".png\" alt=\"" |
| 136 | + . htmlspecialchars( $short_code ) . "\">"; |
127 | 137 | |
128 | | - if( file_exists( "$wgMathDirectory/$md5.png" ) ) { |
129 | | - return $pre.$link.$post; |
130 | | - } |
131 | | - } else { |
132 | | - if( file_exists( "$wgMathDirectory/$md5-1.png" ) ) { |
133 | | - $link=""; |
134 | | - for($i=1; file_exists( $wgMathDirectory . "/" . |
135 | | - $md5 . "-" . $i . ".png" ); |
136 | | - $i++) { |
| 138 | + if ( file_exists( "$wgMathDirectory/$md5.png" ) ) { |
| 139 | + return $pre . $link . $post; |
| 140 | + } |
| 141 | + } else { |
| 142 | + if ( file_exists( "$wgMathDirectory/$md5-1.png" ) ) { |
| 143 | + $link = ""; |
| 144 | + for ( $i = 1; file_exists( $wgMathDirectory . "/" . |
| 145 | + $md5 . "-" . $i . ".png" ); |
| 146 | + $i++ ) { |
137 | 147 | |
138 | | - $link .= "<img src=\"" . $wgMathPath . "/" . |
139 | | - $md5 . "-" . $i . ".png\" alt=\"" . |
140 | | - htmlspecialchars( "page ".$i )."\">"; |
141 | | - } |
142 | | - return $pre.$link.$post; |
143 | | - } |
| 148 | + $link .= "<img src=\"" . $wgMathPath . "/" . |
| 149 | + $md5 . "-" . $i . ".png\" alt=\"" . |
| 150 | + htmlspecialchars( "page " . $i ) . "\">"; |
| 151 | + } |
| 152 | + return $pre . $link . $post; |
144 | 153 | } |
| 154 | + } |
145 | 155 | |
146 | | - # Ensure that the temp and output dirs are available before continuing. |
147 | | - if( !file_exists( $wgMathDirectory ) ) { |
148 | | - if( !@mkdir( $wgMathDirectory ) ) { |
149 | | - return "<b>$mf (" . wfMsg( "math_bad_output" ) . |
150 | | - $wgMathDirectory . ")</b>"; |
151 | | - } |
152 | | - } elseif( !is_dir( $wgMathDirectory ) || |
153 | | - !is_writable( $wgMathDirectory ) ) { |
154 | | - return "<b>$mf (" . wfMsg( "math_bad_output" ) . ")</b>"; |
| 156 | + # Ensure that the temp and output dirs are available before continuing. |
| 157 | + if ( !file_exists( $wgMathDirectory ) ) { |
| 158 | + if ( !@mkdir( $wgMathDirectory ) ) { |
| 159 | + return "<b>$mf (" . wfMsg( "math_bad_output" ) . |
| 160 | + $wgMathDirectory . ")</b>"; |
155 | 161 | } |
156 | | - if( !file_exists( $wgTmpDirectory ) ) { |
157 | | - if( !@mkdir( $wgTmpDirectory ) ) { |
158 | | - return "<b>$mf (" . wfMsg( "math_bad_tmpdir" ) |
159 | | - . ")</b>"; |
160 | | - } |
161 | | - } elseif( !is_dir( $wgTmpDirectory ) || |
162 | | - !is_writable( $wgTmpDirectory ) ) { |
163 | | - return "<b>$mf (" . wfMsg( "math_bad_tmpdir" ) . ")</b>"; |
| 162 | + } elseif ( !is_dir( $wgMathDirectory ) || |
| 163 | + !is_writable( $wgMathDirectory ) ) { |
| 164 | + return "<b>$mf (" . wfMsg( "math_bad_output" ) . ")</b>"; |
| 165 | + } |
| 166 | + if ( !file_exists( $wgTmpDirectory ) ) { |
| 167 | + if ( !@mkdir( $wgTmpDirectory ) ) { |
| 168 | + return "<b>$mf (" . wfMsg( "math_bad_tmpdir" ) |
| 169 | + . ")</b>"; |
164 | 170 | } |
| 171 | + } elseif ( !is_dir( $wgTmpDirectory ) || |
| 172 | + !is_writable( $wgTmpDirectory ) ) { |
| 173 | + return "<b>$mf (" . wfMsg( "math_bad_tmpdir" ) . ")</b>"; |
| 174 | + } |
165 | 175 | |
166 | | - $lyFile = $md5.".ly"; |
167 | | - $out = fopen( $wgTmpDirectory."/".$lyFile, "w" ); |
168 | | - if( $out === false ) { |
169 | | - return "<b>$mf (" . wfMsg( "math_bad_tmpdir" ) . ")</b>"; |
170 | | - } |
171 | | - fwrite( $out, $lilypond_code ); |
172 | | - fclose( $out ); |
| 176 | + $lyFile = $md5 . ".ly"; |
| 177 | + $out = fopen( $wgTmpDirectory . "/" . $lyFile, "w" ); |
| 178 | + if ( $out === false ) { |
| 179 | + return "<b>$mf (" . wfMsg( "math_bad_tmpdir" ) . ")</b>"; |
| 180 | + } |
| 181 | + fwrite( $out, $lilypond_code ); |
| 182 | + fclose( $out ); |
173 | 183 | |
174 | | - $cmd = $wgLilypond . |
175 | | - " -dsafe='#t' -dbackend=eps --png --header=texidoc " . |
176 | | - escapeshellarg($lyFile) . " 2>&1"; |
| 184 | + $cmd = $wgLilypond . |
| 185 | + " -dsafe='#t' -dbackend=eps --png --header=texidoc " . |
| 186 | + escapeshellarg( $lyFile ) . " 2>&1"; |
177 | 187 | |
178 | | - wfDebug( "Lilypond: $cmd\n" ); |
179 | | - $oldcwd = getcwd(); |
180 | | - chdir( $wgTmpDirectory ); |
181 | | - $contents = exec( $cmd, $output, $ret ); |
182 | | - chdir( $oldcwd ); |
| 188 | + wfDebug( "Lilypond: $cmd\n" ); |
| 189 | + $oldcwd = getcwd(); |
| 190 | + chdir( $wgTmpDirectory ); |
| 191 | + $contents = exec( $cmd, $output, $ret ); |
| 192 | + chdir( $oldcwd ); |
183 | 193 | |
184 | | - if( $ret != 0 ) { |
185 | | - return "<br><b>LilyPond error:</b><br><i>" |
186 | | - . str_replace( array( $md5, " " ), |
187 | | - array( "<b>your code</b>", " " ), |
188 | | - nl2br( htmlentities( join( "\n", $output ) ) ) ) |
189 | | - . "</i><br>"; |
190 | | - } |
| 194 | + if ( $ret != 0 ) { |
| 195 | + return "<br><b>LilyPond error:</b><br><i>" |
| 196 | + . str_replace( array( $md5, " " ), |
| 197 | + array( "<b>your code</b>", " " ), |
| 198 | + nl2br( htmlentities( join( "\n", $output ) ) ) ) |
| 199 | + . "</i><br>"; |
| 200 | + } |
191 | 201 | |
192 | | - if($short_code) { |
193 | | - $outputFile = $wgTmpDirectory."/".$md5.".png"; |
| 202 | + if ( $short_code ) { |
| 203 | + $outputFile = $wgTmpDirectory . "/" . $md5 . ".png"; |
194 | 204 | |
195 | | - if( !file_exists( $outputFile ) ) { |
196 | | - return "<b>$mf (" . wfMsg( "math_image_error" ) |
197 | | - . ")</b>"; |
198 | | - } |
199 | | - |
200 | | - rename( $outputFile, $wgMathDirectory."/".$md5.".png"); |
| 205 | + if ( !file_exists( $outputFile ) ) { |
| 206 | + return "<b>$mf (" . wfMsg( "math_image_error" ) |
| 207 | + . ")</b>"; |
201 | 208 | } |
202 | 209 | |
203 | | - # remove all temporary files |
204 | | - $files = opendir( $wgTmpDirectory ); |
205 | | - $last_page = 0; |
| 210 | + rename( $outputFile, $wgMathDirectory . "/" . $md5 . ".png" ); |
| 211 | + } |
206 | 212 | |
207 | | - while( false !== ($file = readdir( $files ))) { |
208 | | - if( substr( $file, 0, 32 ) != $md5 ) |
209 | | - continue; |
| 213 | + # remove all temporary files |
| 214 | + $files = opendir( $wgTmpDirectory ); |
| 215 | + $last_page = 0; |
210 | 216 | |
211 | | - $file_absolute = $wgTmpDirectory . "/" . $file; |
212 | | - if( !$short_code && preg_match( '/-page(\d+)\.png$/', |
213 | | - $file, $matches ) ) { |
214 | | - if($matches[1]>$last_page) |
215 | | - $last_page = $matches[1]; |
216 | | - rename( $file_absolute, $wgMathDirectory . "/" . |
217 | | - $md5 . "-" . $matches[1] . ".png" ); |
218 | | - continue; |
219 | | - } |
| 217 | + while ( false !== ( $file = readdir( $files ) ) ) { |
| 218 | + if ( substr( $file, 0, 32 ) != $md5 ) |
| 219 | + continue; |
220 | 220 | |
221 | | - if( preg_match( '/.png$/', $file ) ) { |
222 | | - rename( $file_absolute, $wgMathDirectory."/".$md5.".png" ); |
223 | | - continue; |
224 | | - } |
| 221 | + $file_absolute = $wgTmpDirectory . "/" . $file; |
| 222 | + if ( !$short_code && preg_match( '/-page(\d+)\.png$/', |
| 223 | + $file, $matches ) ) { |
| 224 | + if ( $matches[1] > $last_page ) |
| 225 | + $last_page = $matches[1]; |
| 226 | + rename( $file_absolute, $wgMathDirectory . "/" . |
| 227 | + $md5 . "-" . $matches[1] . ".png" ); |
| 228 | + continue; |
| 229 | + } |
225 | 230 | |
226 | | - if( preg_match( '/.midi$/', $file ) ) { |
227 | | - rename( $file_absolute, $wgMathDirectory . "/" . |
228 | | - $md5 . ".midi" ); |
229 | | - $pre = "<a href=\"".$wgMathPath."/".$md5.".midi\"> " . $wgLilypondPreMidi; |
230 | | - $post = $wgLilypondPostMidi . " </a>"; |
231 | | - continue; |
232 | | - } |
| 231 | + if ( preg_match( '/.png$/', $file ) ) { |
| 232 | + rename( $file_absolute, $wgMathDirectory . "/" . $md5 . ".png" ); |
| 233 | + continue; |
| 234 | + } |
233 | 235 | |
234 | | - if( !is_file( $file_absolute ) ) |
235 | | - continue; |
236 | | - unlink( $file_absolute ); |
| 236 | + if ( preg_match( '/.midi$/', $file ) ) { |
| 237 | + rename( $file_absolute, $wgMathDirectory . "/" . |
| 238 | + $md5 . ".midi" ); |
| 239 | + $pre = "<a href=\"" . $wgMathPath . "/" . $md5 . ".midi\"> " . $wgLilypondPreMidi; |
| 240 | + $post = $wgLilypondPostMidi . " </a>"; |
| 241 | + continue; |
237 | 242 | } |
238 | | - closedir( $files ); |
239 | 243 | |
240 | | - if( $short_code ) { |
241 | | - if( !file_exists( $wgMathDirectory."/".$md5.".png" ) ) { |
242 | | - $errmsg = wfMsg( "math_image_error" ); |
243 | | - return "<h3>$mf ($errmsg): " . |
244 | | - htmlspecialchars($lilypond_code) . "</h3>"; |
245 | | - } |
246 | | - } else { |
247 | | - $link .= "<img src=\"".$wgMathPath."/".$md5.".png\" alt=\"" |
248 | | - . htmlspecialchars( "page " )."\">"; |
| 244 | + if ( !is_file( $file_absolute ) ) |
| 245 | + continue; |
| 246 | + unlink( $file_absolute ); |
| 247 | + } |
| 248 | + closedir( $files ); |
| 249 | + |
| 250 | + if ( $short_code ) { |
| 251 | + if ( !file_exists( $wgMathDirectory . "/" . $md5 . ".png" ) ) { |
| 252 | + $errmsg = wfMsg( "math_image_error" ); |
| 253 | + return "<h3>$mf ($errmsg): " . |
| 254 | + htmlspecialchars( $lilypond_code ) . "</h3>"; |
249 | 255 | } |
| 256 | + } else { |
| 257 | + $link .= "<img src=\"" . $wgMathPath . "/" . $md5 . ".png\" alt=\"" |
| 258 | + . htmlspecialchars( "page " ) . "\">"; |
| 259 | + } |
250 | 260 | |
251 | | - if( $wgLilypondTrim ) { |
252 | | - $imgFile = $wgMathDirectory ."/" .$md5 . ".png"; |
253 | | - trimImage( $imgFile, $imgFile, 0xFFFFFF ); |
254 | | - }; |
| 261 | + if ( $wgLilypondTrim ) { |
| 262 | + $imgFile = $wgMathDirectory . "/" . $md5 . ".png"; |
| 263 | + trimImage( $imgFile, $imgFile, 0xFFFFFF ); |
| 264 | + } ; |
255 | 265 | |
256 | | - if( $wgLilypondBorderX > 0 || $wgLilypondBorderY > 0 ) { |
257 | | - $imgFile = $wgMathDirectory ."/" .$md5 . ".png"; |
258 | | - frameImage( $imgFile, $imgFile, 0xFFFFFF, $wgLilypondBorderX, $wgLilypondBorderY ); |
259 | | - }; |
| 266 | + if ( $wgLilypondBorderX > 0 || $wgLilypondBorderY > 0 ) { |
| 267 | + $imgFile = $wgMathDirectory . "/" . $md5 . ".png"; |
| 268 | + frameImage( $imgFile, $imgFile, 0xFFFFFF, $wgLilypondBorderX, $wgLilypondBorderY ); |
| 269 | + } ; |
260 | 270 | |
261 | | - return $pre . $link . $post; |
| 271 | + return $pre . $link . $post; |
262 | 272 | } |
263 | 273 | |
264 | | -function trimImage( $source, $dest, $bgColour ) |
265 | | -{ |
266 | | - $srcImage = imagecreatefrompng( $source ); |
267 | | - $width = imagesx( $srcImage ); |
268 | | - $height = imagesy( $srcImage ); |
| 274 | +function trimImage( $source, $dest, $bgColour ) { |
| 275 | + $srcImage = imagecreatefrompng( $source ); |
| 276 | + $width = imagesx( $srcImage ); |
| 277 | + $height = imagesy( $srcImage ); |
269 | 278 | |
270 | | - $xmin = 0; |
271 | | - $found = false; |
272 | | - for( $x = 0; $x < $width && !$found; $x++ ) { |
273 | | - for( $y = 0; $y < $height && !$found; $y++ ) { |
274 | | - $rgb = imagecolorat( $srcImage, $x, $y ); |
275 | | - if( $rgb != $bgColour ) { |
276 | | - $xmin = $x; |
277 | | - $found = true; |
278 | | - } |
| 279 | + $xmin = 0; |
| 280 | + $found = false; |
| 281 | + for ( $x = 0; $x < $width && !$found; $x++ ) { |
| 282 | + for ( $y = 0; $y < $height && !$found; $y++ ) { |
| 283 | + $rgb = imagecolorat( $srcImage, $x, $y ); |
| 284 | + if ( $rgb != $bgColour ) { |
| 285 | + $xmin = $x; |
| 286 | + $found = true; |
| 287 | + } |
| 288 | + } |
279 | 289 | } |
280 | | - } |
281 | 290 | |
282 | | - $xmax = $xmin; |
283 | | - $found = false; |
284 | | - for( $x = $width-1; $x > $xmin && !$found; $x-- ) { |
285 | | - for( $y = 0; $y < $height && !$found; $y++ ) { |
286 | | - $rgb = imagecolorat( $srcImage, $x, $y ); |
287 | | - if( $rgb != $bgColour ) { |
288 | | - $xmax = $x; |
289 | | - $found = true; |
290 | | - } |
| 291 | + $xmax = $xmin; |
| 292 | + $found = false; |
| 293 | + for ( $x = $width -1; $x > $xmin && !$found; $x-- ) { |
| 294 | + for ( $y = 0; $y < $height && !$found; $y++ ) { |
| 295 | + $rgb = imagecolorat( $srcImage, $x, $y ); |
| 296 | + if ( $rgb != $bgColour ) { |
| 297 | + $xmax = $x; |
| 298 | + $found = true; |
| 299 | + } |
| 300 | + } |
291 | 301 | } |
292 | | - } |
293 | 302 | |
294 | | - $ymin = 0; |
295 | | - $found = false; |
296 | | - for( $y = 0; $y < $height && !$found; $y++ ) { |
297 | | - for( $x = 0; $x < $width && !$found; $x++ ) { |
298 | | - $rgb = imagecolorat( $srcImage, $x, $y ); |
299 | | - if( $rgb != $bgColour ) { |
300 | | - $ymin = $y; |
301 | | - $found = true; |
302 | | - } |
| 303 | + $ymin = 0; |
| 304 | + $found = false; |
| 305 | + for ( $y = 0; $y < $height && !$found; $y++ ) { |
| 306 | + for ( $x = 0; $x < $width && !$found; $x++ ) { |
| 307 | + $rgb = imagecolorat( $srcImage, $x, $y ); |
| 308 | + if ( $rgb != $bgColour ) { |
| 309 | + $ymin = $y; |
| 310 | + $found = true; |
| 311 | + } |
| 312 | + } |
303 | 313 | } |
304 | | - } |
305 | 314 | |
306 | | - $ymax = $ymin; |
307 | | - $found = false; |
308 | | - for( $y = $height-1; $y > $ymin && !$found; $y-- ) { |
309 | | - for( $x = 0; $x < $width && !$found; $x++ ) { |
310 | | - $rgb = imagecolorat( $srcImage, $x, $y ); |
311 | | - if( $rgb != $bgColour ) { |
312 | | - $ymax = $y; |
313 | | - $found = true; |
314 | | - } |
| 315 | + $ymax = $ymin; |
| 316 | + $found = false; |
| 317 | + for ( $y = $height -1; $y > $ymin && !$found; $y-- ) { |
| 318 | + for ( $x = 0; $x < $width && !$found; $x++ ) { |
| 319 | + $rgb = imagecolorat( $srcImage, $x, $y ); |
| 320 | + if ( $rgb != $bgColour ) { |
| 321 | + $ymax = $y; |
| 322 | + $found = true; |
| 323 | + } |
| 324 | + } |
315 | 325 | } |
316 | | - } |
317 | 326 | |
318 | | - $newWidth = $xmax - $xmin + 1; |
319 | | - $newHeight = $ymax - $ymin + 1; |
| 327 | + $newWidth = $xmax - $xmin + 1; |
| 328 | + $newHeight = $ymax - $ymin + 1; |
320 | 329 | |
321 | | - $dstImage = imagecreatetruecolor( $newWidth, $newHeight ); |
322 | | - imagecopy( $dstImage, $srcImage, 0, 0, $xmin, $ymin, $newWidth, $newHeight ); |
323 | | - imagepng( $dstImage, $dest ); |
| 330 | + $dstImage = imagecreatetruecolor( $newWidth, $newHeight ); |
| 331 | + imagecopy( $dstImage, $srcImage, 0, 0, $xmin, $ymin, $newWidth, $newHeight ); |
| 332 | + imagepng( $dstImage, $dest ); |
324 | 333 | } |
325 | 334 | |
326 | | -function frameImage( $source, $dest, $bgColour, $borderWidth, $borderHeight ) |
327 | | -{ |
328 | | - $srcImage = imagecreatefrompng( $source ); |
329 | | - $width = imagesx( $srcImage ); |
330 | | - $height = imagesy( $srcImage ); |
331 | | - $dstImage = imagecreatetruecolor( $width + 2*$borderWidth, $height + 2*$borderHeight ); |
332 | | - $allocatedBgColour = imagecolorallocate( $dstImage, ($bgColour >> 16) & 0xFF, ($bgColour >> 8) & 0xFF, $bgColour & 0xFF); |
333 | | - imagefill( $dstImage, 0, 0, $allocatedBgColour ); |
334 | | - imagecopy( $dstImage, $srcImage, $borderWidth, $borderHeight, 0, 0, $width, $height ); |
335 | | - imagepng( $dstImage, $dest ); |
| 335 | +function frameImage( $source, $dest, $bgColour, $borderWidth, $borderHeight ) { |
| 336 | + $srcImage = imagecreatefrompng( $source ); |
| 337 | + $width = imagesx( $srcImage ); |
| 338 | + $height = imagesy( $srcImage ); |
| 339 | + $dstImage = imagecreatetruecolor( $width + 2 * $borderWidth, $height + 2 * $borderHeight ); |
| 340 | + $allocatedBgColour = imagecolorallocate( $dstImage, ( $bgColour >> 16 ) & 0xFF, ( $bgColour >> 8 ) & 0xFF, $bgColour & 0xFF ); |
| 341 | + imagefill( $dstImage, 0, 0, $allocatedBgColour ); |
| 342 | + imagecopy( $dstImage, $srcImage, $borderWidth, $borderHeight, 0, 0, $width, $height ); |
| 343 | + imagepng( $dstImage, $dest ); |
336 | 344 | } |
Index: trunk/extensions/LilyPond/LilyPond.i18n.php |
— | — | @@ -0,0 +1,16 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Copyright (c) 2011 Mark A. Hershberger <mah@everybody.org> |
| 5 | + */ |
| 6 | + |
| 7 | +$messages = array(); |
| 8 | + |
| 9 | +$messages['en'] = array( |
| 10 | + 'lilypond-desc' => 'Adds <code><lilypond></code>, <code><lilymidi></code>, and <code><lilybook></code> tags to format musicusing LilyPond', |
| 11 | +); |
| 12 | + |
| 13 | +/** Message documentation (Message documentation) |
| 14 | + */ |
| 15 | +$messages['qqq'] = array( |
| 16 | + 'lilypond-desc' => '{{desc}}', |
| 17 | +); |
Property changes on: trunk/extensions/LilyPond/LilyPond.i18n.php |
___________________________________________________________________ |
Added: svn:eol-syle |
1 | 18 | + native |