Mercurial > mxd2map
comparison src/java/de/intevation/mxd/reader/PictureFillSymbolReader.java @ 251:6b80e46b8f38
Added picture symbol support to the converter.
author | raimund renkert <raimund.renkert@intevation.de> |
---|---|
date | Fri, 12 Aug 2011 16:08:57 +0200 |
parents | |
children | 2cb2f26d0d54 |
comparison
equal
deleted
inserted
replaced
250:d10fd4de02aa | 251:6b80e46b8f38 |
---|---|
1 /* | |
2 * Copyright (c) 2011 by Intevation GmbH, Germany <info@intevation.de> | |
3 * | |
4 * This file is part of MXD2map. | |
5 * | |
6 * This program is free software under the LGPL (>=v2.1) | |
7 * Read the file LICENCE.txt coming with the software for details | |
8 * or visit http://www.gnu.org/licenses/ if it does not exist. | |
9 * | |
10 * MXD2map has been developed on behalf of the | |
11 * Bundesamt fuer Seeschifffahrt und Hydrographie (BSH) in Hamburg | |
12 * by Intevation GmbH. | |
13 * | |
14 * Authors: | |
15 * Raimund Renkert <raimund.renkert@intevation.de> | |
16 * Bjoern Schilberg <bjoern.schilberg@intevation.de> | |
17 * Stephan Holl <stephan.holl@intevation.de> | |
18 */ | |
19 | |
20 package de.intevation.mxd.reader; | |
21 | |
22 import java.awt.Color; | |
23 import java.awt.Image; | |
24 | |
25 import org.apache.log4j.Logger; | |
26 | |
27 import com.esri.arcgis.display.ISymbol; | |
28 import com.esri.arcgis.display.ILineSymbol; | |
29 import com.esri.arcgis.display.IFillSymbol; | |
30 import com.esri.arcgis.display.PictureFillSymbol; | |
31 import com.esri.arcgis.support.ms.stdole.Picture; | |
32 import com.esri.arcgis.display.IRgbColor; | |
33 import com.esri.arcgis.display.RgbColor; | |
34 | |
35 import org.w3c.dom.Element; | |
36 import java.io.IOException; | |
37 import java.awt.image.BufferedImage; | |
38 import java.awt.image.DataBufferByte; | |
39 import javax.imageio.ImageIO; | |
40 import java.io.ByteArrayOutputStream; | |
41 | |
42 import org.apache.commons.codec.binary.Base64; | |
43 /** | |
44 * Reads picture fill symbol information. | |
45 * | |
46 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | |
47 */ | |
48 public class PictureFillSymbolReader | |
49 extends AbstractSymbolReader { | |
50 | |
51 /** | |
52 * The logger. | |
53 */ | |
54 private static final Logger logger = | |
55 Logger.getLogger(PictureFillSymbolReader.class); | |
56 | |
57 /** | |
58 * Private member. | |
59 */ | |
60 private PictureFillSymbol symbol; | |
61 | |
62 public PictureFillSymbolReader(ISymbol symbol) | |
63 throws Exception { | |
64 logger.debug("contructor()"); | |
65 if(symbol instanceof PictureFillSymbol) { | |
66 this.symbol = (PictureFillSymbol)symbol; | |
67 } | |
68 else { | |
69 throw new Exception("Not a PictureFillSymbol!"); | |
70 } | |
71 } | |
72 | |
73 public PictureFillSymbolReader(IFillSymbol symbol) | |
74 throws Exception { | |
75 logger.debug("contructor()"); | |
76 if(symbol instanceof PictureFillSymbol) { | |
77 this.symbol = (PictureFillSymbol)symbol; | |
78 } | |
79 else { | |
80 throw new Exception("Not a PictureFillSymbol!"); | |
81 } | |
82 } | |
83 | |
84 /** | |
85 * Reads the symbol attributes. | |
86 * | |
87 * @return The XML node. | |
88 */ | |
89 public Element read() { | |
90 logger.debug("read()"); | |
91 Element symbolElement = util.addSymbol(parent); | |
92 | |
93 try { | |
94 symbolElement.setAttribute("name", symbol.getNameString()); | |
95 } | |
96 catch(IOException ioe) { | |
97 logger.warn("Could not read name. Setting name to \"default\""); | |
98 symbolElement.setAttribute("name", "default"); | |
99 } | |
100 | |
101 try { | |
102 symbolElement.setAttribute( | |
103 "x_scale", | |
104 String.valueOf(symbol.getXScale())); | |
105 } | |
106 catch(IOException ioe) { | |
107 logger.warn("Could not read x-scale."); | |
108 } | |
109 | |
110 try { | |
111 symbolElement.setAttribute( | |
112 "y_scale", | |
113 String.valueOf(symbol.getYScale())); | |
114 } | |
115 catch(IOException ioe) { | |
116 logger.warn("Could not read y-scale."); | |
117 } | |
118 | |
119 try { | |
120 symbolElement.setAttribute( | |
121 "xseparation", | |
122 String.valueOf(symbol.getXSeparation())); | |
123 } | |
124 catch(IOException ioe) { | |
125 logger.warn("Could not read x-separation."); | |
126 } | |
127 | |
128 try { | |
129 symbolElement.setAttribute( | |
130 "yseparation", | |
131 String.valueOf(symbol.getYSeparation())); | |
132 } | |
133 catch(IOException ioe) { | |
134 logger.warn( | |
135 "Could not read y-separation."); | |
136 } | |
137 | |
138 try { | |
139 ILineSymbol ls = symbol.getOutline(); | |
140 LineSymbolReader lsr = new LineSymbolReader(); | |
141 if(lsr.canRead(ls)) { | |
142 lsr.setSymbol(ls); | |
143 lsr.setUtil(util); | |
144 lsr.setParent(symbolElement); | |
145 lsr.read(); | |
146 } | |
147 else { | |
148 logger.debug("The type of " + ls.getClass().toString() + | |
149 " is not implemented!"); | |
150 } | |
151 } | |
152 catch(Exception e) { | |
153 logger.warn("Could not read outline."); | |
154 } | |
155 | |
156 //Read the picture and convert to base64. | |
157 try { | |
158 Picture p = symbol.getPicture(); | |
159 Image i = p.toImage(); | |
160 if(i instanceof BufferedImage) { | |
161 BufferedImage bi = (BufferedImage)i; | |
162 ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |
163 //Get byte array from image. | |
164 ImageIO.write(bi, "BMP", baos); | |
165 Base64 encoder = new Base64(); | |
166 //encode in a base64 string | |
167 String pict = encoder.encodeBase64String(baos.toByteArray()); | |
168 symbolElement.setAttribute("picture", pict); | |
169 | |
170 //Get transparent color. | |
171 RgbColor c = new RgbColor(); | |
172 c.setRGB(symbol.getBitmapTransparencyColor().getRGB()); | |
173 Color transp = new Color ( | |
174 c.getRed(), | |
175 c.getGreen(), | |
176 c.getBlue()); | |
177 symbolElement.setAttribute( | |
178 "transparent_color", | |
179 String.valueOf(transp.getRGB())); | |
180 } | |
181 else { | |
182 logger.warn("Could not read image symbol."); | |
183 return null; | |
184 } | |
185 } | |
186 catch(IOException ioe) { | |
187 logger.warn("Could not read picture."); | |
188 } | |
189 symbolElement.setAttribute("type", "fill"); | |
190 symbolElement.setAttribute("style", "picture"); | |
191 | |
192 return symbolElement; | |
193 } | |
194 } | |
195 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |