diff src/java/de/intevation/mxd/writer/SymbolWriter.java @ 141:8f30f7e802d6

Manage symbol names and symbol comparison.
author vc11884admin@VC11884.win.bsh.de
date Mon, 27 Jun 2011 16:07:13 +0200
parents 11d63bf00326
children b2c5a66022f1
line wrap: on
line diff
--- a/src/java/de/intevation/mxd/writer/SymbolWriter.java	Thu Jun 23 16:59:29 2011 +0200
+++ b/src/java/de/intevation/mxd/writer/SymbolWriter.java	Mon Jun 27 16:07:13 2011 +0200
@@ -54,8 +54,19 @@
             writeArrow(sym, symbolElement);
         }
         else if (symType.equals("char")) {
-            //TODO Does not work at all...  waiting for fix.
-            writeCharacter(sym, symbolElement);
+            int exists = symbolExists(symbolElement);
+            if(exists == -1) {
+                String old = symbolElement.getAttribute("name");
+                symbolElement.setAttribute(
+                    "name",
+                    old + symbolSet.getNumsymbols() + 1);
+                writeCharacter(sym, symbolElement);
+            }
+            else {
+                symbolElement.setAttribute(
+                    "name",
+                    symbolSet.getSymbol(exists).getName());
+            }
         }
         else if (type.equals("line")) {
             writeHatch(sym);
@@ -106,6 +117,7 @@
         String font = symbolElement.getAttribute("font");
         //Remove all blank character to match the mapserver fonts.txt.
         font = font.replaceAll(" ", "");
+        symbol.setName(symbolElement.getAttribute("name"));
         symbol.setFont(font);
         symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_TRUETYPE.swigValue());
         symbol.setAntialias(1);
@@ -140,5 +152,40 @@
         }
         symbols.save(path);
     }
+
+    private int symbolExists (Element elem) {
+        symbolSetObj symbolSet = map.getSymbolset();
+        for (int i = 0; i < symbolSet.getNumsymbols(); i++) {
+            symbolObj sym = symbolSet.getSymbol(i);
+            int stype = sym.getType();
+            String etype = elem.getAttribute("style");
+            if(stype == MS_SYMBOL_TYPE.MS_SYMBOL_ELLIPSE.swigValue () &&
+                etype.equals("point")) {
+                return i;   
+            }
+            else if(stype == MS_SYMBOL_TYPE.MS_SYMBOL_VECTOR.swigValue () &&
+                    etype.equals("arrow")) {
+                return i;        
+            }
+            else if(stype == MS_SYMBOL_TYPE.MS_SYMBOL_TRUETYPE.swigValue () &&
+                    etype.equals("char")) {
+                String font = elem.getAttribute("font");
+                font = font.replaceAll(" ", "");
+                String c = elem.getAttribute("char");
+                c = "&#" + c + ";";
+                if (font.equals(sym.getFont()) &&
+                    c.equals(sym.getCharacter())) {
+                    return i;
+                }
+
+            }
+            else if(stype == MS_SYMBOL_TYPE.MS_SYMBOL_HATCH.swigValue () &&
+                    etype.equals("hatch")) {
+                return i;        
+            }
+
+        }
+        return -1;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)