Revision 2074
branches/gvSIG_03_SLD/applications/appgvSIG/src/com/iver/cit/gvsig/gui/layout/fframes/FFramePicture.java | ||
---|---|---|
44 | 44 |
*/ |
45 | 45 |
package com.iver.cit.gvsig.gui.layout.fframes; |
46 | 46 |
|
47 |
import com.iver.andami.PluginServices; |
|
48 |
import com.iver.andami.messages.NotificationManager; |
|
49 |
|
|
50 |
import com.iver.cit.gvsig.fmap.DriverException; |
|
51 |
import com.iver.cit.gvsig.gui.layout.Layout; |
|
52 |
|
|
53 |
import com.iver.utiles.XMLEntity; |
|
54 |
import com.sun.jimi.core.Jimi; |
|
55 |
|
|
47 |
import java.awt.Graphics; |
|
56 | 48 |
import java.awt.Graphics2D; |
57 | 49 |
import java.awt.Image; |
58 |
import java.awt.MediaTracker; |
|
59 | 50 |
import java.awt.geom.AffineTransform; |
60 | 51 |
import java.awt.geom.Rectangle2D; |
61 | 52 |
import java.awt.image.BufferedImage; |
62 |
import java.io.IOException; |
|
53 |
import java.io.File; |
|
54 |
import java.net.MalformedURLException; |
|
63 | 55 |
|
64 | 56 |
import javax.swing.ImageIcon; |
65 | 57 |
|
58 |
import org.apache.batik.transcoder.TranscoderException; |
|
59 |
import org.apache.batik.transcoder.TranscoderOutput; |
|
66 | 60 |
|
61 |
import com.iver.andami.PluginServices; |
|
62 |
import com.iver.andami.messages.NotificationManager; |
|
63 |
import com.iver.cit.gvsig.fmap.DriverException; |
|
64 |
import com.iver.cit.gvsig.gui.layout.Layout; |
|
65 |
import com.iver.utiles.XMLEntity; |
|
66 |
import com.sun.jimi.core.Jimi; |
|
67 |
|
|
68 |
|
|
67 | 69 |
/** |
68 | 70 |
* FFrame para introducir una imagen en el Layout. |
69 | 71 |
* |
... | ... | |
78 | 80 |
private int m_quality = PRESENTACION; |
79 | 81 |
private int m_viewing = ACTIVO; |
80 | 82 |
private String m_path = null; |
81 |
|
|
83 |
private Graphics svgGraphics=null; |
|
84 |
private boolean isSVG=false; |
|
82 | 85 |
/** |
83 | 86 |
* Creates a new FFramePicture object. |
84 | 87 |
*/ |
... | ... | |
108 | 111 |
drawEmpty(g); |
109 | 112 |
} else { |
110 | 113 |
if ((rv == null) || (getQuality() == PRESENTACION)) { |
114 |
///if (!isSVG){ |
|
111 | 115 |
double scalex = (double) w / m_image.getWidth(null); |
112 | 116 |
double scaley = (double) h / m_image.getHeight(null); |
113 | 117 |
AffineTransform xform = AffineTransform.getScaleInstance(scalex, |
... | ... | |
116 | 120 |
y); |
117 | 121 |
xpos.concatenate(xform); |
118 | 122 |
g.drawRenderedImage(m_image, xpos); |
123 |
///}else if (isSVG){ |
|
124 |
/// drawSVG(g,at,r); |
|
125 |
///} |
|
119 | 126 |
} else { |
120 | 127 |
drawDraft(g); |
121 | 128 |
} |
... | ... | |
123 | 130 |
} |
124 | 131 |
} |
125 | 132 |
|
133 |
/*private void drawSVG(Graphics2D g,AffineTransform at,Rectangle2D rect) { |
|
134 |
JSVGCanvas svgCanvas = new JSVGCanvas(); |
|
135 |
try { |
|
136 |
svgCanvas.setURI(new File(m_path).toURL().toString()); |
|
137 |
} catch (MalformedURLException e) { |
|
138 |
e.printStackTrace(); |
|
139 |
} |
|
140 |
svgCanvas.paint(g); no funciona |
|
141 |
} |
|
142 |
*/ |
|
126 | 143 |
/** |
127 | 144 |
* Rellena la calidad seg?n el entero que se pasa como par?metro. |
128 | 145 |
* |
... | ... | |
214 | 231 |
tmpIcon = new ImageIcon(Jimi.getImage(file ,Jimi.VIRTUAL_MEMORY));//((File)main.allImages.elementAt(x)).getAbsolutePath()); |
215 | 232 |
} else if (iString.endsWith("png") || iString.endsWith("tif") || iString.endsWith("ico") || iString.endsWith("xpm") || iString.endsWith("bmp")) { |
216 | 233 |
tmpIcon = new ImageIcon(Jimi.getImage(file ,Jimi.VIRTUAL_MEMORY)); //new ImageIcon(f.getPath()); |
217 |
} |
|
234 |
} else if (iString.endsWith("svg")){ |
|
235 |
try { |
|
236 |
tmpIcon = new ImageIcon(getImageFromSVG(file)); |
|
237 |
} catch (MalformedURLException e) { |
|
238 |
e.printStackTrace(); |
|
239 |
} catch (TranscoderException e) { |
|
240 |
e.printStackTrace(); |
|
241 |
} |
|
242 |
} |
|
218 | 243 |
Image image = tmpIcon.getImage(); |
219 | 244 |
setPath(file); |
220 | 245 |
BufferedImage bi = new BufferedImage((int) image.getWidth(null), |
221 | 246 |
(int) image.getHeight(null), BufferedImage.TYPE_INT_ARGB); |
222 | 247 |
Graphics2D biContext = bi.createGraphics(); |
223 | 248 |
biContext.drawImage(image, 0, 0, null); |
249 |
|
|
224 | 250 |
setImage(bi); |
225 | 251 |
return image; |
226 | 252 |
} |
227 | 253 |
|
254 |
|
|
255 |
private Image getImageFromSVG(String file) throws TranscoderException, MalformedURLException { |
|
256 |
/* Rasterizer r = new Rasterizer(); |
|
257 |
TranscodingHints hints = new TranscodingHints(); |
|
258 |
|
|
259 |
r.setTranscodingHints((Map)hints); |
|
260 |
TranscoderInput input = new TranscoderInput(new File(file).toURL().toString()); |
|
261 |
r.transcode(input, null); |
|
262 |
return m_image; |
|
263 |
*/ |
|
264 |
/* isSVG=true; |
|
265 |
JSVGCanvas svgCanvas = new JSVGCanvas(); |
|
266 |
svgCanvas.setURI(new File(file).toURL().toString()); |
|
267 |
svgGraphics=m_image.getGraphics(); |
|
268 |
svgGraphics=svgCanvas.getGraphics(); |
|
269 |
return m_image; |
|
270 |
*/ |
|
271 |
|
|
272 |
isSVG=true; |
|
273 |
SVGRasterizer r = new SVGRasterizer(new File(file).toURL()); |
|
274 |
r.setBackgroundColor(java.awt.Color.white); |
|
275 |
return r.createBufferedImage(); |
|
276 |
|
|
277 |
} |
|
278 |
|
|
228 | 279 |
/** |
229 | 280 |
* Incorpora los atributos del XMLEntity en el objeto actual. |
230 | 281 |
* |
... | ... | |
265 | 316 |
throws DriverException { |
266 | 317 |
draw(g, at, null, null); |
267 | 318 |
} |
319 |
private class Rasterizer extends org.apache.batik.transcoder.image.ImageTranscoder { |
|
320 |
|
|
321 |
public BufferedImage createImage(int w, int h) { |
|
322 |
return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); |
|
323 |
} |
|
324 |
|
|
325 |
public void writeImage(BufferedImage img, TranscoderOutput output) |
|
326 |
throws TranscoderException { |
|
327 |
m_image = img; |
|
328 |
} |
|
329 |
} |
|
330 |
|
|
268 | 331 |
} |
branches/gvSIG_03_SLD/applications/appgvSIG/src/com/iver/cit/gvsig/gui/layout/fframes/dialogs/FFramePictureDialog.java | ||
---|---|---|
45 | 45 |
package com.iver.cit.gvsig.gui.layout.fframes.dialogs; |
46 | 46 |
|
47 | 47 |
import java.awt.Component; |
48 |
import java.awt.Graphics2D; |
|
49 | 48 |
import java.awt.Image; |
50 |
import java.awt.MediaTracker; |
|
51 | 49 |
import java.awt.geom.Rectangle2D; |
52 |
import java.awt.image.BufferedImage; |
|
53 | 50 |
import java.io.File; |
54 |
import java.io.FileInputStream; |
|
55 |
import java.io.IOException; |
|
56 |
import java.io.InputStream; |
|
57 | 51 |
|
58 |
import javax.swing.ImageIcon; |
|
59 | 52 |
import javax.swing.JFileChooser; |
60 | 53 |
import javax.swing.JPanel; |
61 | 54 |
|
... | ... | |
66 | 59 |
import com.iver.cit.gvsig.gui.layout.Layout; |
67 | 60 |
import com.iver.cit.gvsig.gui.layout.fframes.FFramePicture; |
68 | 61 |
import com.iver.utiles.GenericFileFilter; |
69 |
import com.sun.jimi.core.Jimi; |
|
70 | 62 |
|
71 | 63 |
|
72 | 64 |
/** |
... | ... | |
197 | 189 |
bExaminar.addActionListener(new java.awt.event.ActionListener() { |
198 | 190 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
199 | 191 |
String[] extensions = { |
200 |
"jpeg", "jpg", "gif", "png", "bmp" |
|
192 |
"jpeg", "jpg", "gif", "png", "bmp", "svg"
|
|
201 | 193 |
}; |
202 | 194 |
GenericFileFilter filter = new GenericFileFilter(extensions, |
203 |
"Image files (jpeg, jpg, gif, png, bmp)"); |
|
195 |
"Image files (jpeg, jpg, gif, png, bmp, svg)");
|
|
204 | 196 |
|
205 | 197 |
JFileChooser jfc = new JFileChooser(); |
206 | 198 |
jfc.addChoosableFileFilter(filter); |
branches/gvSIG_03_SLD/applications/appgvSIG/src/com/iver/cit/gvsig/gui/layout/fframes/SVGRasterizer.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package com.iver.cit.gvsig.gui.layout.fframes; |
|
42 |
|
|
43 |
/***************************************************************************** |
|
44 |
* Copyright (C) The Apache Software Foundation. All rights reserved. * |
|
45 |
* ------------------------------------------------------------------------- * |
|
46 |
* This software is published under the terms of the Apache Software License * |
|
47 |
* version 1.1, a copy of which has been included with this distribution in * |
|
48 |
* the LICENSE file. * |
|
49 |
|
|
50 |
*****************************************************************************/ |
|
51 |
|
|
52 |
import java.awt.Paint; |
|
53 |
import java.awt.image.BufferedImage; |
|
54 |
import java.io.File; |
|
55 |
import java.io.InputStream; |
|
56 |
import java.io.Reader; |
|
57 |
import java.net.URL; |
|
58 |
import java.util.Map; |
|
59 |
|
|
60 |
import org.apache.batik.transcoder.TranscoderException; |
|
61 |
import org.apache.batik.transcoder.TranscoderInput; |
|
62 |
import org.apache.batik.transcoder.TranscoderOutput; |
|
63 |
import org.apache.batik.transcoder.TranscodingHints; |
|
64 |
import org.apache.batik.transcoder.image.ImageTranscoder; |
|
65 |
import org.w3c.dom.svg.SVGDocument; |
|
66 |
|
|
67 |
/** |
|
68 |
* This class provides a simple and method based API for converting a SVG |
|
69 |
* document fragment to a <tt>BufferedImage</tt>. |
|
70 |
* |
|
71 |
* @author <a href="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a> |
|
72 |
* @version $Id$ |
|
73 |
*/ |
|
74 |
public class SVGRasterizer { |
|
75 |
|
|
76 |
/** |
|
77 |
* The transcoder input. |
|
78 |
*/ |
|
79 |
protected TranscoderInput input; |
|
80 |
|
|
81 |
/** |
|
82 |
* The transcoder hints. |
|
83 |
*/ |
|
84 |
protected TranscodingHints hints = new TranscodingHints(); |
|
85 |
|
|
86 |
/** |
|
87 |
* The image that represents the SVG document. |
|
88 |
*/ |
|
89 |
protected BufferedImage img; |
|
90 |
|
|
91 |
/** |
|
92 |
* Constructs a new SVGRasterizer. |
|
93 |
* |
|
94 |
* @param uri the uri of the document to rasterize |
|
95 |
*/ |
|
96 |
public SVGRasterizer(String uri) { |
|
97 |
this.input = new TranscoderInput(uri); |
|
98 |
} |
|
99 |
|
|
100 |
/** |
|
101 |
* Constructs a new SVGRasterizer. |
|
102 |
* |
|
103 |
* @param url the URL of the document to rasterize |
|
104 |
*/ |
|
105 |
public SVGRasterizer(URL url) { |
|
106 |
this.input = new TranscoderInput(url.toString()); |
|
107 |
} |
|
108 |
|
|
109 |
/** |
|
110 |
* Constructs a new SVGRasterizer converter. |
|
111 |
* |
|
112 |
* @param istream the input stream that represents the SVG document to |
|
113 |
* rasterize |
|
114 |
*/ |
|
115 |
public SVGRasterizer(InputStream istream) { |
|
116 |
this.input = new TranscoderInput(istream); |
|
117 |
} |
|
118 |
|
|
119 |
/** |
|
120 |
* Constructs a new SVGRasterizer converter. |
|
121 |
* |
|
122 |
* @param reader the reader that represents the SVG document to rasterize |
|
123 |
*/ |
|
124 |
public SVGRasterizer(Reader reader) { |
|
125 |
this.input = new TranscoderInput(reader); |
|
126 |
} |
|
127 |
|
|
128 |
/** |
|
129 |
* Constructs a new SVGRasterizer converter. |
|
130 |
* |
|
131 |
* @param document the SVG document to rasterize |
|
132 |
*/ |
|
133 |
public SVGRasterizer(SVGDocument document) { |
|
134 |
this.input = new TranscoderInput(document); |
|
135 |
} |
|
136 |
|
|
137 |
/** |
|
138 |
* Returns the image that represents the SVG document. |
|
139 |
*/ |
|
140 |
public BufferedImage createBufferedImage() throws TranscoderException { |
|
141 |
Rasterizer r = new Rasterizer(); |
|
142 |
r.setTranscodingHints((Map)hints); |
|
143 |
r.transcode(input, null); |
|
144 |
return img; |
|
145 |
} |
|
146 |
|
|
147 |
/** |
|
148 |
* Sets the width of the image to rasterize. |
|
149 |
* |
|
150 |
* @param width the image width |
|
151 |
*/ |
|
152 |
public void setImageWidth(float width) { |
|
153 |
hints.put(ImageTranscoder.KEY_WIDTH, new Float(width)); |
|
154 |
} |
|
155 |
|
|
156 |
/** |
|
157 |
* Sets the height of the image to rasterize. |
|
158 |
* |
|
159 |
* @param width the image height |
|
160 |
*/ |
|
161 |
public void setImageHeight(float height) { |
|
162 |
hints.put(ImageTranscoder.KEY_HEIGHT, new Float(height)); |
|
163 |
} |
|
164 |
|
|
165 |
/** |
|
166 |
* Sets the preferred language to use. SVG documents can provide text in |
|
167 |
* multiple languages, this method lets you control which language to use |
|
168 |
* if possible. e.g. "en" for english or "fr" for french. |
|
169 |
* |
|
170 |
* @param language the preferred language to use |
|
171 |
*/ |
|
172 |
public void setLanguages(String language) { |
|
173 |
hints.put(ImageTranscoder.KEY_LANGUAGE, language); |
|
174 |
} |
|
175 |
|
|
176 |
/** |
|
177 |
* Sets the unit conversion factor to the specified value. This method |
|
178 |
* lets you choose how units such as 'em' are converted. e.g. 0.26458 is |
|
179 |
* 96dpi (the default) or 0.3528 is 72dpi. |
|
180 |
* |
|
181 |
* @param px2mm the pixel to millimeter convertion factor. |
|
182 |
*/ |
|
183 |
public void setPixelToMMFactor(float px2mm) { |
|
184 |
hints.put(ImageTranscoder.KEY_PIXEL_TO_MM, new Float(px2mm)); |
|
185 |
} |
|
186 |
|
|
187 |
/** |
|
188 |
* Sets the uri of the user stylesheet. The user stylesheet can be used to |
|
189 |
* override styles. |
|
190 |
* |
|
191 |
* @param uri the uri of the user stylesheet |
|
192 |
*/ |
|
193 |
public void setUserStyleSheetURI(String uri) { |
|
194 |
hints.put(ImageTranscoder.KEY_USER_STYLESHEET_URI, uri); |
|
195 |
} |
|
196 |
|
|
197 |
/** |
|
198 |
* Sets whether or not the XML parser used to parse SVG document should be |
|
199 |
* validating or not, depending on the specified parameter. For futher |
|
200 |
* details about how media work, see the |
|
201 |
* <a href="http://www.w3.org/TR/CSS2/media.html">Media types in the CSS2 |
|
202 |
* specification</a>. |
|
203 |
* |
|
204 |
* @param b true means the XML parser will validate its input |
|
205 |
*/ |
|
206 |
public void setXMLParserValidating(boolean b) { |
|
207 |
hints.put(ImageTranscoder.KEY_XML_PARSER_VALIDATING, |
|
208 |
(b ? Boolean.TRUE : Boolean.FALSE)); |
|
209 |
} |
|
210 |
|
|
211 |
/** |
|
212 |
* Sets the media to rasterize. The medium should be separated by |
|
213 |
* comma. e.g. "screen", "print" or "screen, print" |
|
214 |
* |
|
215 |
* @param media the media to use |
|
216 |
*/ |
|
217 |
public void setMedia(String media) { |
|
218 |
hints.put(ImageTranscoder.KEY_MEDIA, media); |
|
219 |
} |
|
220 |
|
|
221 |
/** |
|
222 |
* Sets the alternate stylesheet to use. For futher details, you can have |
|
223 |
* a look at the <a href="http://www.w3.org/TR/xml-stylesheet/">Associating |
|
224 |
* Style Sheets with XML documents</a>. |
|
225 |
* |
|
226 |
* @param alternateStylesheet the alternate stylesheet to use if possible |
|
227 |
*/ |
|
228 |
public void setAlternateStylesheet(String alternateStylesheet) { |
|
229 |
hints.put(ImageTranscoder.KEY_ALTERNATE_STYLESHEET, |
|
230 |
alternateStylesheet); |
|
231 |
} |
|
232 |
|
|
233 |
/** |
|
234 |
* Sets the Paint to use for the background of the image. |
|
235 |
* |
|
236 |
* @param p the paint to use for the background |
|
237 |
*/ |
|
238 |
public void setBackgroundColor(Paint p) { |
|
239 |
hints.put(ImageTranscoder.KEY_BACKGROUND_COLOR, p); |
|
240 |
} |
|
241 |
|
|
242 |
/** |
|
243 |
* An image transcoder that stores the resulting image. |
|
244 |
*/ |
|
245 |
protected class Rasterizer extends ImageTranscoder { |
|
246 |
|
|
247 |
public BufferedImage createImage(int w, int h) { |
|
248 |
return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); |
|
249 |
} |
|
250 |
|
|
251 |
public void writeImage(BufferedImage img, TranscoderOutput output) |
|
252 |
throws TranscoderException { |
|
253 |
SVGRasterizer.this.img = img; |
|
254 |
} |
|
255 |
} |
|
256 |
|
|
257 |
// debug |
|
258 |
public static void main(String [] args) throws Exception { |
|
259 |
SVGRasterizer r = new SVGRasterizer(new File(args[0]).toURL()); |
|
260 |
r.setBackgroundColor(java.awt.Color.white); |
|
261 |
BufferedImage img = r.createBufferedImage(); |
|
262 |
javax.swing.JFrame f = new javax.swing.JFrame(); |
|
263 |
f.getContentPane().add(new javax.swing.JLabel(new javax.swing.ImageIcon(img)), java.awt.BorderLayout.CENTER); |
|
264 |
f.pack(); |
|
265 |
f.show(); |
|
266 |
} |
|
267 |
} |
|
0 | 268 |
Also available in: Unified diff