diff -urP --ignore-space-change orig/src/CH/ifa/draw/standard/CompositeFigure.java moin/src/CH/ifa/draw/standard/CompositeFigure.java
--- orig/src/CH/ifa/draw/standard/CompositeFigure.java	2003-02-02 10:16:46.000000000 +0000
+++ moin/src/CH/ifa/draw/standard/CompositeFigure.java	2005-11-27 18:33:04.000000000 +0000
@@ -395,7 +395,7 @@
 	String areas = "";
         Enumeration k = fFigures.elements();
         while (k.hasMoreElements())
-            areas += ((Storable) k.nextElement()).getMap();
+            areas = ((Storable) k.nextElement()).getMap() + areas;
 	return areas;
     }
 
diff -urP --ignore-space-change orig/src/CH/ifa/draw/twiki/TWikiFrame.java moin/src/CH/ifa/draw/twiki/TWikiFrame.java
--- orig/src/CH/ifa/draw/twiki/TWikiFrame.java	2005-03-08 17:59:34.000000000 +0000
+++ moin/src/CH/ifa/draw/twiki/TWikiFrame.java	2005-11-27 22:31:14.000000000 +0000
@@ -20,6 +20,7 @@
 import CH.ifa.draw.applet.*;
 import CH.ifa.draw.contrib.*;
 //import SVG.wiki.*;
+import com.keypoint.PngEncoderIndexed;
 
 import java.awt.*;
 import java.awt.event.*;
@@ -37,8 +38,10 @@
     static private String UNTITLED_PARAMETER   = "untitled";
     static private String DRAWPATH_PARAMETER   = "drawpath";
     static private String GIFPATH_PARAMETER    = "gifpath";
+    static private String PNGPATH_PARAMETER    = "pngpath";
     static private String SVGPATH_PARAMETER    = "svgpath";
     static private String SAVEPATH_PARAMETER   = "savepath";
+    static private String BASENAME_PARAMETER   = "basename";
     static private String HELPPATH_PARAMETER   = "helppath";
     static private String BORDERSIZE_PARAMETER = "bordersize";
     
@@ -361,8 +364,8 @@
     
     public boolean doSaveDrawing() {
         Application app = getApplication();
-        boolean savedDraw, savedSvg, savedGif, savedMap;
-        savedDraw = savedSvg = savedGif = savedMap = false;
+        boolean savedDraw, savedSvg, savedGif, savedPng, savedMap;
+        savedDraw = savedSvg = savedGif = savedPng = savedMap = false;
         
         // set wait cursor
         setCursor(new Cursor(Cursor.WAIT_CURSOR));
@@ -387,13 +390,18 @@
             if (savePath == null)
                 savePath = "";
             
+            // gets base filename
+            String baseName = app.getParameter(BASENAME_PARAMETER);
+            if (baseName == null)
+                baseName = "SET_BASENAME_PARAM";
+
             // submit POST command to the server three times:
-            // *.draw, *.map and *.gif
+            // *.draw, *.map, *.png and *.gif
             // first upload *.draw file
-            showStatus("Saving .draw file " + drawingPath);
+            showStatus("Saving " + baseName + ".draw");
             if (bPostEnabled)
                 savedDraw = app.post(
-                                     savePath, "", "text/plain", drawingPath,
+                                     savePath, baseName + ".draw", "text/plain", drawingPath,
                                      out.toString(), "TWiki Draw draw file");
             
             // calculate the minimum size of the gif image
@@ -423,7 +431,7 @@
             String map = drawing().getMap();
             if (map.length() > 0) {
                 String mapPath = drawingPath.substring(0, drawingPath.length() - 5) + ".map";
-                showStatus("Saving .map file " + mapPath);
+                showStatus("Saving " + baseName + ".map");
                 // enclose the map and add editable border. Note that the
                 // edit border is added LAST so the earlier AREAs take
                 // precedence.
@@ -452,12 +460,12 @@
                     
                     "</map>";
                 savedMap = app.post(
-                                    savePath, "", "text/plain", mapPath,
+                                    savePath, baseName + ".map", "text/plain", mapPath + ".map",
                                     map, "TWiki Draw map file");
             } else {
                 // erase any previous map file
                 String mapPath = drawingPath.substring(0, drawingPath.length() - 5);
-                savedMap = app.post( savePath, "", "text/plain", mapPath + ".map", "", "" );
+                savedMap = app.post( savePath, baseName + ".map", "text/plain", mapPath + ".map", "", "" );
             }
             
             // get pathname of the SVG file
@@ -477,24 +485,38 @@
             // gets pathname of the GIF image
             String gifPath = getApplication().getParameter(GIFPATH_PARAMETER);
             if (gifPath == null || gifPath.length() == 0)
-                gifPath = "untitled.gif";
-            
-            // then create *.gif image and upload file
-            showStatus("Saving .gif file " + gifPath);
+                gifPath = null;
             
-            // clear the selection so it doesn't appear
-            view().clearSelection();
+            // gets pathname of the PNG image
+            String pngPath = getApplication().getParameter(PNGPATH_PARAMETER);
+            if (pngPath == null || pngPath.length() == 0) 
+                pngPath = null;
+
+            if (gifPath != null || pngPath != null) {
+                final Image oImgBuffer = createImage(d, iBorder);
+            
+                if (bPostEnabled && pngPath != null)
+                {
+                    // then create *.png image and upload file
+                    showStatus("Saving " + baseName + ".png");
+                    final char[] aChar = convertToPng(oImgBuffer);
+                    // upload *.png file
+                    savedPng = app.post(savePath, baseName + ".png", "image/png",
+                                        pngPath, String.valueOf(aChar, 0, aChar.length),
+                                        "TWiki Draw PNG file");
+                }
             
-            final Image oImgBuffer =
-                this.view().createImage(d.width + iBorder, d.height + iBorder);
+                if (bPostEnabled && gifPath != null)
+                {
+                    // then create *.gif image and upload file
+                    showStatus("Saving " + baseName + ".gif");
             final char[] aChar = convertToGif(oImgBuffer);
-            
             // upload *.gif file
-            if (bPostEnabled)
-                savedGif = app.post(
-                                    savePath, "", "image/gif",
+                    savedGif = app.post(savePath, baseName + ".gif", "image/gif",
                                     gifPath, String.valueOf(aChar, 0, aChar.length),
                                     "TWiki Draw GIF file");
+                }
+            }
         } catch (MalformedURLException e) {
             this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
             showStatus("Bad Wiki servlet URL: "+e.getMessage());
@@ -506,7 +528,8 @@
         this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
         showStatus("Saved .draw " + (savedDraw ? "OK" : "Failed") +
                    " .map " + (savedMap ? "OK" : "Failed") +
-                   " .gif " + (savedGif ? "OK" : "Failed"));
+                   " .gif " + (savedGif ? "OK" : "Failed") +
+                   " .png " + (savedPng ? "OK" : "Failed"));
         return savedDraw;
     }
     
@@ -523,12 +546,11 @@
     	System.err.println("TWikiDraw:" + msg);
     }
     
-    /**
-     * convert Image to GIF-encoded data, reducing the number of colors
-     * if needed. Added by Bertrand Delacretaz
-     */
-    private char [] convertToGif(Image oImgBuffer) throws IOException {
-        debug("converting data to GIF...");
+    private Image createImage(Dimension d, int iBorder) {
+        // clear the selection so it doesn't appear
+        view().clearSelection();
+        final Image oImgBuffer =
+           this.view().createImage(d.width + iBorder, d.height + iBorder);
         Graphics oGrf = oImgBuffer.getGraphics();
         this.view().enableGuides(false);
         this.view().drawAll(oGrf);
@@ -539,8 +561,16 @@
         //tf.setImage(oImgBuffer);
         //tf.show();
 		
-        ByteArrayOutputStream oOut = null;
+        return oImgBuffer;
+    }
 		
+    /**
+     * convert Image to GIF-encoded data, reducing the number of colors
+     * if needed. Added by Bertrand Delacretaz
+     */
+    private char [] convertToGif(Image oImgBuffer) throws IOException {
+        debug("converting data to GIF...");
+        ByteArrayOutputStream oOut = null;
         try {
             oOut = new ByteArrayOutputStream();
             new GifEncoder(oImgBuffer,oOut).encode();
@@ -563,4 +593,21 @@
         debug("conversion to GIF successful.");
         return aChar;
     }
+
+    /**
+     * convert Image to PNG-encoded data
+     * Added by OliverGraf
+     */
+    private char [] convertToPng(Image oImgBuffer) throws IOException {
+        debug("converting data to PNG...");
+        PngEncoderIndexed oEncode = new PngEncoderIndexed(oImgBuffer);
+        byte[] aByte = oEncode.pngEncode();
+        int size = aByte.length;
+        char[] aChar = new char[size];
+        for(int i = 0; i < size; i++) {
+            aChar[i] = (char)aByte[i];
+        }
+        debug("conversion to PNG successful."); 
+        return aChar;
+    }
 }
diff -urP --ignore-space-change orig/src/CH/ifa/draw/util/StorableOutput.java moin/src/CH/ifa/draw/util/StorableOutput.java
--- orig/src/CH/ifa/draw/util/StorableOutput.java	2004-11-22 16:01:38.000000000 +0000
+++ moin/src/CH/ifa/draw/util/StorableOutput.java	2005-11-27 22:32:04.000000000 +0000
@@ -101,11 +101,11 @@
             char c = s.charAt(i);
             switch(c) {
                 // RobWalker 17 Jul 2003 - suppress \r
-            case '\r': break;
+            case '\r': fStream.print('\\'); fStream.print('r'); break;
             case '\n': fStream.print('\\'); fStream.print('n'); break;
             case '"' : fStream.print('\\'); fStream.print('"'); break;
             case '\\': fStream.print('\\'); fStream.print('\\'); break;
-            case '\t': fStream.print('\\'); fStream.print('\t'); break;
+            case '\t': fStream.print('\\'); fStream.print('t'); break;
             default:
                 if ((c >= 0x0001) && (c <= 0x007F)) {
                     fStream.print(c);
