rrenkert@243: /* aheinecke@317: * Copyright (c) 2012 by Intevation GmbH, Germany rrenkert@243: * rrenkert@243: * This file is part of MXD2map. rrenkert@243: * rrenkert@243: * This program is free software under the LGPL (>=v2.1) rrenkert@243: * Read the file LICENCE.txt coming with the software for details rrenkert@243: * or visit http://www.gnu.org/licenses/ if it does not exist. rrenkert@243: * rrenkert@243: * MXD2map has been developed on behalf of the rrenkert@243: * Bundesamt fuer Seeschifffahrt und Hydrographie (BSH) in Hamburg rrenkert@243: * by Intevation GmbH. rrenkert@243: * rrenkert@243: * Authors: rrenkert@243: * Raimund Renkert rrenkert@243: * Bjoern Schilberg rrenkert@243: * Stephan Holl aheinecke@317: * Andre Heinecke rrenkert@243: */ rrenkert@243: raimund@179: package de.intevation.mxd.reader; raimund@179: raimund@179: import java.awt.Color; raimund@179: raimund@179: import org.apache.log4j.Logger; raimund@179: raimund@179: import com.esri.arcgis.display.ITextSymbol; raimund@179: import com.esri.arcgis.display.TextSymbol; raimund@179: import com.esri.arcgis.display.IRgbColor; raimund@179: import com.esri.arcgis.display.RgbColor; aheinecke@317: import com.esri.arcgis.display.LineCallout; aheinecke@317: import com.esri.arcgis.display.ITextBackground; aheinecke@317: import com.esri.arcgis.display.IColor; raimund@179: import com.esri.arcgis.support.ms.stdole.Font; raimund@179: raimund@179: import org.w3c.dom.Element; raimund@179: import java.io.IOException; raimund@179: raimund@179: /** raimund@179: * Reads text symbol information. raimund@179: * raimund@179: * @author Raimund Renkert raimund@179: */ raimund@179: public class TextSymbolReader raimund@179: extends AbstractSymbolReader { raimund@179: raimund@179: /** raimund@179: * The logger. raimund@179: */ raimund@179: private static final Logger logger = raimund@179: Logger.getLogger(TextSymbolReader.class); raimund@179: raimund@179: /** raimund@179: * Private member. raimund@179: */ raimund@179: private TextSymbol symbol; raimund@179: rrenkert@181: /** rrenkert@181: * Constructor with text symbol. rrenkert@181: * rrenkert@181: * @param symbol The symbol used to write text. rrenkert@181: */ raimund@179: public TextSymbolReader(ITextSymbol symbol) raimund@179: throws Exception { raimund@179: logger.debug("contructor()"); raimund@179: if(symbol instanceof TextSymbol) { raimund@179: this.symbol = (TextSymbol)symbol; raimund@179: } raimund@179: else { raimund@179: throw new Exception("Not a TextSymbol!"); raimund@179: } raimund@179: } raimund@179: raimund@179: /** raimund@179: * Reads the symbol attributes. raimund@179: * raimund@179: * @return The XML node. raimund@179: */ raimund@179: public Element read() { raimund@179: logger.debug("read()"); raimund@179: Element symbolElement = util.addSymbol(parent); raimund@179: raimund@179: try { raimund@179: symbolElement.setAttribute("name", symbol.getNameString()); raimund@179: } raimund@179: catch(IOException ioe) { raimund@179: logger.warn("Could not read name. Setting name to \"default\"."); raimund@179: symbolElement.setAttribute("name", "default"); raimund@179: } raimund@179: raimund@179: symbolElement.setAttribute("style", "text"); raimund@179: raimund@179: try { raimund@179: if(symbol.getColor() instanceof IRgbColor) { raimund@179: IRgbColor color = (IRgbColor)symbol.getColor(); raimund@179: Color c = new Color ( raimund@179: color.getRed(), raimund@179: color.getGreen(), raimund@179: color.getBlue()); raimund@179: symbolElement.setAttribute("color", String.valueOf(c.getRGB())); raimund@179: symbolElement.setAttribute("transparency", raimund@179: String.valueOf(color.getTransparency())); raimund@179: } raimund@179: else { raimund@179: RgbColor col = new RgbColor(); raimund@179: col.setRGB(symbol.getColor().getRGB()); raimund@179: Color c = new Color ( raimund@179: col.getRed(), raimund@179: col.getGreen(), raimund@179: col.getBlue()); raimund@179: symbolElement.setAttribute("color", String.valueOf(c.getRGB())); raimund@179: symbolElement.setAttribute("transparency", raimund@179: String.valueOf(col.getTransparency())); raimund@179: } raimund@179: } raimund@179: catch(IOException ioe) { raimund@179: logger.warn("Could not read color."); raimund@179: } raimund@179: raimund@179: try { raimund@179: symbolElement.setAttribute( raimund@179: "size", raimund@179: String.valueOf(symbol.getSize())); raimund@179: } raimund@179: catch(IOException ioe) { aheinecke@317: logger.warn("Could not read size. Setting size to 10."); aheinecke@317: symbolElement.setAttribute("size", "10"); raimund@179: } raimund@179: raimund@179: try { raimund@179: symbolElement.setAttribute( raimund@179: "angle", raimund@179: String.valueOf(symbol.getAngle())); raimund@179: } raimund@179: catch(IOException ioe) { raimund@179: logger.warn("Could not read angle."); raimund@179: } raimund@179: raimund@179: try { raimund@179: symbolElement.setAttribute( raimund@179: "offset", raimund@179: symbol.getXOffset() + "," + symbol.getYOffset()); raimund@179: } raimund@179: catch(IOException ioe) { raimund@179: logger.warn("Could not read offset."); raimund@179: } raimund@179: rrenkert@180: try { raimund@179: Font f = symbol.getFont(); raimund@179: symbolElement.setAttribute("font", f.getName()); raimund@179: symbolElement.setAttribute("char_set", String.valueOf(f.getCharset())); raimund@179: symbolElement.setAttribute("bold", String.valueOf(f.getBold())); raimund@179: symbolElement.setAttribute("italic", String.valueOf(f.getItalic())); raimund@179: symbolElement.setAttribute("font_size", String.valueOf(f.getSize())); raimund@179: symbolElement.setAttribute( raimund@179: "strike_through", raimund@179: String.valueOf(f.getStrikethrough())); raimund@179: symbolElement.setAttribute("weight", String.valueOf(f.getWeight())); raimund@179: } raimund@179: catch(IOException ioe) { raimund@179: logger.warn("Could not read font. Setting font to \"FreeSans\"."); raimund@179: symbolElement.setAttribute("font", "FreeSans"); raimund@179: } raimund@179: symbolElement.setAttribute("type", "text"); aheinecke@317: aheinecke@317: // Background aheinecke@317: try { aheinecke@317: ITextBackground background = symbol.getBackground(); aheinecke@317: if (background != null) { aheinecke@317: if (background instanceof LineCallout) { aheinecke@317: LineCallout lc = (LineCallout)background; aheinecke@317: IColor pcolor = lc.getBorder().getColor(); aheinecke@317: if(pcolor instanceof IRgbColor) { aheinecke@317: IRgbColor color = (IRgbColor)pcolor; aheinecke@317: Color c = new Color ( aheinecke@317: color.getRed(), aheinecke@317: color.getGreen(), aheinecke@317: color.getBlue()); aheinecke@317: symbolElement.setAttribute("bg_color", String.valueOf(c.getRGB())); aheinecke@317: symbolElement.setAttribute("bg_transparency", aheinecke@317: String.valueOf(color.getTransparency())); aheinecke@317: } aheinecke@317: else { aheinecke@317: RgbColor col = new RgbColor(); aheinecke@317: col.setRGB(pcolor.getRGB()); aheinecke@317: Color c = new Color ( aheinecke@317: col.getRed(), aheinecke@317: col.getGreen(), aheinecke@317: col.getBlue()); aheinecke@317: symbolElement.setAttribute("bg_color", String.valueOf(c.getRGB())); aheinecke@317: symbolElement.setAttribute("bg_transparency", aheinecke@317: String.valueOf(col.getTransparency())); aheinecke@317: } aheinecke@317: } else { aheinecke@317: logger.warn("Unhandled background of class: " + aheinecke@317: background.getClass().toString()); aheinecke@317: } aheinecke@317: } aheinecke@317: } aheinecke@317: catch(Exception e) { aheinecke@317: logger.warn("Could not read backgroundcolor."); aheinecke@317: } aheinecke@317: raimund@179: return symbolElement; raimund@179: } raimund@179: } raimund@179: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :