Index: trunk/extensions/Translate/Stats.php |
— | — | @@ -239,7 +239,7 @@ |
240 | 240 | |
241 | 241 | public function draw( FormOptions $opts ) { |
242 | 242 | wfLoadExtensionMessages( 'Translate' ); |
243 | | - global $wgTranslatePHPlotFont; |
| 243 | + global $wgTranslatePHPlotFont, $wgLang; |
244 | 244 | |
245 | 245 | $width = $opts->getValue( 'width' ); |
246 | 246 | $height = $opts->getValue( 'height' ); |
— | — | @@ -262,8 +262,12 @@ |
263 | 263 | $i--; |
264 | 264 | } |
265 | 265 | |
266 | | - $plot->SetDefaultTTFont( $wgTranslatePHPlotFont ); |
267 | | - |
| 266 | + $font = FCFontFinder::find( $wgLang->getCode() ); |
| 267 | + if ( $font ) { |
| 268 | + $plot->SetDefaultTTFont( $font ); |
| 269 | + } else { |
| 270 | + $plot->SetDefaultTTFont( $wgTranslatePHPlotFont ); |
| 271 | + } |
268 | 272 | $plot->SetDataValues( $data ); |
269 | 273 | |
270 | 274 | if ( $legend !== null ) |
Index: trunk/extensions/Translate/_autoload.php |
— | — | @@ -55,6 +55,7 @@ |
56 | 56 | # utils |
57 | 57 | $wgAutoloadClasses['ResourceLoader'] = $dir . 'utils/ResourceLoader.php'; |
58 | 58 | $wgAutoloadClasses['StringMatcher'] = $dir . 'utils/StringMatcher.php'; |
| 59 | +$wgAutoloadClasses['FCFontFinder'] = $dir . 'utils/Font.php'; |
59 | 60 | |
60 | 61 | $wgAutoloadClasses['StringMangler'] = $dir . 'utils/StringMangler.php'; |
61 | 62 | $wgAutoloadClasses['SmItem'] = $dir . 'utils/StringMangler.php'; |
Index: trunk/extensions/Translate/utils/Font.php |
— | — | @@ -0,0 +1,57 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Wrapper around font-config to get useful ttf font given a language code. |
| 6 | + * Uses wfShellExec, wfEscapeShellArg and wfDebugLog from MediaWiki. |
| 7 | + * @author Niklas Laxström, 2008 |
| 8 | + * @license PD |
| 9 | + */ |
| 10 | +class FCFontFinder { |
| 11 | + |
| 12 | + public static function find( $code ) { |
| 13 | + $code = wfEscapeShellArg( ":lang=$code" ); |
| 14 | + $ok = 0; |
| 15 | + $cmd = "fc-match $code"; |
| 16 | + $suggestion = wfShellExec( $cmd, $ok ); |
| 17 | + wfDebugLog( 'fcfont', "$cmd returned $ok" ); |
| 18 | + if ( $ok !== 0 ) { |
| 19 | + wfDebugLog( 'fcfont', "fc-match error output: $suggestion" ); |
| 20 | + return false; |
| 21 | + } |
| 22 | + |
| 23 | + $pattern = '/^(.*?): "(.*)" "(.*)"$/'; |
| 24 | + $matches = array(); |
| 25 | + if ( !preg_match( $pattern, $suggestion, $matches ) ) { |
| 26 | + wfDebugLog( 'fcfont', "fc-match: return format not understood: $suggestion" ); |
| 27 | + return false; |
| 28 | + } |
| 29 | + |
| 30 | + list( , $file, $family, $type ) = $matches; |
| 31 | + wfDebugLog( 'fcfont', "fc-match: got $file: $family $type" ); |
| 32 | + |
| 33 | + $file = wfEscapeShellArg( $file ); |
| 34 | + $family = wfEscapeShellArg( $family ); |
| 35 | + $type = wfEscapeShellArg( $type ); |
| 36 | + $cmd = "fc-list $family $type $code file | grep $file"; |
| 37 | + |
| 38 | + $candidates = trim( wfShellExec( $cmd, $ok ) ); |
| 39 | + |
| 40 | + wfDebugLog( 'fcfont', "$cmd returned $ok" ); |
| 41 | + if ( $ok !== 0 ) { |
| 42 | + wfDebugLog( 'fcfont', "fc-list error output: $candidates" ); |
| 43 | + return false; |
| 44 | + } |
| 45 | + |
| 46 | + # trim spaces |
| 47 | + $files = array_map( 'trim', explode( "\n", $candidates ) ); |
| 48 | + $count = count($files); |
| 49 | + if ( !$count ) wfDebugLog( 'fcfont', "fc-list got zero canditates: $candidates" ); |
| 50 | + |
| 51 | + # remove the trailing ":" |
| 52 | + $chosen = substr( $files[0], 0, -1 ); |
| 53 | + |
| 54 | + wfDebugLog( 'fcfont', "fc-list got $count candidates; using $chosen" ); |
| 55 | + return $chosen; |
| 56 | + } |
| 57 | + |
| 58 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/Translate/utils/Font.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 59 | + native |