splitbrain / dokuwiki-plugin-ditaa

Renders ASCII flowcharts contained in a DokuWiki page to images
http://www.dokuwiki.org/plugin:ditaa
5 stars 5 forks source link

Support for Umlauts/local character encodings #2

Closed einhirn closed 14 years ago

einhirn commented 14 years ago
diff -ruN ditaa-orig/syntax.php ditaa/syntax.php
--- ditaa-orig/syntax.php 2010-05-06 14:18:48.000000000 +0200
+++ ditaa/syntax.php        2010-05-18 17:00:53.000000000 +0200
@@ -136,10 +136,13 @@
     $temp = tempnam($conf['tmpdir'],'ditaa_');
     io_saveFile($temp,$data['data']);

+        $oldlang=getenv('LANG');
+        putenv('LANG=de_DE.UTF-8');
     $cmd  = $this->getConf('java');
     $cmd .= ' -Djava.awt.headless=true -jar';
     $cmd .= ' '.escapeshellarg(dirname(__FILE__).'/ditaa/ditaa0_9.jar'); //ditaa jar
     $cmd .= ' '.escapeshellarg($temp); //input
+        $cmd .= ' --encoding '.escapeshellarg("UTF-8"); //encoding
     $cmd .= ' '.escapeshellarg($cache); //output
     $cmd .= ' -s '.escapeshellarg($data['scale']);
     if(!$data['antialias']) $cmd .= ' -A';
@@ -150,6 +153,10 @@
     exec($cmd, $output, $error);
     @unlink($temp);

+       if ($oldlang) {
+               putenv("LANG=$oldlang");
+       }
+
     if ($error != 0) return false;
     return true;
     }

First I added the "--encoding"-Switch to the java command line, because the Wikitext (UTF-8) was interpreted as ISO-8859-1 and looked awful. Then I found out that Umlauts (äöü) weren't rendered but instead they were replaced by small rectangles.

This is because Java selects the Character set according to system locale. My server uses "C"-Locale (-> US-ASCII), and I wanted to keep it that way. But I still wanted ditaa to render Umlauts correctly, so I added the "putenv" part.

Note: Maybe the Patch will only apply with "patch --ignore-whitespace"...

splitbrain commented 14 years ago

Correctly use UTF-8 for locally generated diagrams. Closed by 36721e14251b95c6d53edf4fbd6c40a8a1b95a6e