View | Details | Raw Unified | Return to bug 212024 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/gmf/runtime/diagram/ui/image/ImageFileFormat.java (-1 / +8 lines)
Lines 32-37 Link Here
32
32
33
	
33
	
34
	private static final int IMAGE_SVG = 100;
34
	private static final int IMAGE_SVG = 100;
35
	private static final int IMAGE_PDF = IMAGE_SVG + 1;
35
	static final long serialVersionUID = 1;
36
	static final long serialVersionUID = 1;
36
	
37
	
37
	/**
38
	/**
Lines 58-63 Link Here
58
	 * supported format Scalable Vector Graphics (SVG).
59
	 * supported format Scalable Vector Graphics (SVG).
59
	 */
60
	 */
60
	public static final ImageFileFormat SVG = new ImageFileFormat("SVG", IMAGE_SVG); //$NON-NLS-1$
61
	public static final ImageFileFormat SVG = new ImageFileFormat("SVG", IMAGE_SVG); //$NON-NLS-1$
62
	
63
	
64
	/**
65
	 * supported format Scalable Vector Graphics (PDF).
66
	 */
67
	public static final ImageFileFormat PDF = new ImageFileFormat("PDF", IMAGE_PDF); //$NON-NLS-1$
61
68
62
    /**
69
    /**
63
     * supported format PNG.
70
     * supported format PNG.
Lines 67-73 Link Here
67
	/**
74
	/**
68
	 * The list of values for this enumerated type.
75
	 * The list of values for this enumerated type.
69
	 */
76
	 */
70
	public static final ImageFileFormat[] VALUES = { GIF, BMP, JPEG, JPG, SVG, PNG };
77
	public static final ImageFileFormat[] VALUES = { GIF, BMP, JPEG, JPG, SVG, PNG, PDF };
71
78
72
	/**
79
	/**
73
	 * Constructs a new type with the specified
80
	 * Constructs a new type with the specified
(-)src/org/eclipse/gmf/runtime/diagram/ui/render/util/CopyToImageUtil.java (-29 / +62 lines)
Lines 45-50 Link Here
45
import org.eclipse.gmf.runtime.diagram.ui.render.internal.DiagramUIRenderPlugin;
45
import org.eclipse.gmf.runtime.diagram.ui.render.internal.DiagramUIRenderPlugin;
46
import org.eclipse.gmf.runtime.diagram.ui.util.DiagramEditorUtil;
46
import org.eclipse.gmf.runtime.diagram.ui.util.DiagramEditorUtil;
47
import org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.image.ImageExporter;
47
import org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.image.ImageExporter;
48
import org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.svg.SVGImage;
49
import org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.svg.SVGImageConverter;
48
import org.eclipse.gmf.runtime.notation.Diagram;
50
import org.eclipse.gmf.runtime.notation.Diagram;
49
import org.eclipse.swt.graphics.Image;
51
import org.eclipse.swt.graphics.Image;
50
import org.eclipse.swt.graphics.ImageData;
52
import org.eclipse.swt.graphics.ImageData;
Lines 196-202 Link Here
196
     * @return appropriate diagram generator
198
     * @return appropriate diagram generator
197
     */
199
     */
198
    protected DiagramGenerator getDiagramGenerator(DiagramEditPart diagramEP, ImageFileFormat format) {
200
    protected DiagramGenerator getDiagramGenerator(DiagramEditPart diagramEP, ImageFileFormat format) {
199
        if (format.equals(ImageFileFormat.SVG)) {
201
        if (format.equals(ImageFileFormat.SVG) || format.equals(ImageFileFormat.PDF)) {
200
            return new DiagramSVGGenerator(diagramEP);
202
            return new DiagramSVGGenerator(diagramEP);
201
        } else {
203
        } else {
202
        	return new DiagramImageGenerator(diagramEP);
204
        	return new DiagramImageGenerator(diagramEP);
Lines 227-236 Link Here
227
			ImageFileFormat format, IProgressMonitor monitor)
229
			ImageFileFormat format, IProgressMonitor monitor)
228
			throws CoreException {
230
			throws CoreException {
229
		boolean found = false;
231
		boolean found = false;
230
		if (format.equals(ImageFileFormat.SVG)) {
232
		if (format.equals(ImageFileFormat.SVG)
233
				|| format.equals(ImageFileFormat.PDF)) {
231
			gen.createSWTImageDescriptorForParts(editParts, imageRect);
234
			gen.createSWTImageDescriptorForParts(editParts, imageRect);
232
			monitor.worked(1);
235
			monitor.worked(1);
233
			saveSVGToFile(destination, (DiagramSVGGenerator) gen, monitor);
236
			saveToFile(destination, (DiagramSVGGenerator) gen, format, monitor);
234
			found = true;
237
			found = true;
235
		} else if (format.equals(ImageFileFormat.JPEG)
238
		} else if (format.equals(ImageFileFormat.JPEG)
236
				|| format.equals(ImageFileFormat.PNG)) {
239
				|| format.equals(ImageFileFormat.PNG)) {
Lines 304-309 Link Here
304
        refreshLocal(destination);
307
        refreshLocal(destination);
305
    }
308
    }
306
309
310
    
307
    /**
311
    /**
308
     * Saves an SVG DOM to a file.
312
     * Saves an SVG DOM to a file.
309
     * 
313
     * 
Lines 317-353 Link Here
317
     *                if this method fails
321
     *                if this method fails
318
     */
322
     */
319
    protected void saveSVGToFile(IPath destination,
323
    protected void saveSVGToFile(IPath destination,
320
            DiagramSVGGenerator generator, IProgressMonitor monitor)
324
			DiagramSVGGenerator generator, IProgressMonitor monitor)
321
        throws CoreException {
325
			throws CoreException {
322
326
		saveToFile(destination, generator, ImageFileFormat.SVG, monitor);
323
        IStatus fileModificationStatus = createFile(destination);
327
	}
324
        if (!fileModificationStatus.isOK()) {
325
        	// can't write to the file
326
        	return;
327
        }
328
        
328
        
329
        monitor.worked(1);
329
    
330
    /**
331
	 * Saves an SVG or PDF files.
332
	 * 
333
	 * @param destination
334
	 *            the destination file, including path and file name
335
	 * @param generator
336
	 *            the svg generator for a diagram, used to write
337
	 * @param format
338
	 *            currently supports SVG or PDF
339
	 * @param monitor
340
	 *            the progress monitor
341
	 * @exception CoreException
342
	 *                if this method fails
343
	 */
344
    protected void saveToFile(IPath destination,
345
            DiagramSVGGenerator generator, ImageFileFormat format, IProgressMonitor monitor)
346
        throws CoreException {
330
347
331
        try {
348
		IStatus fileModificationStatus = createFile(destination);
349
		if (!fileModificationStatus.isOK()) {
350
			// can't write to the file
351
			return;
352
		}
353
		monitor.worked(1);
332
354
333
            FileOutputStream os = new FileOutputStream(destination.toOSString());
355
		try {
334
            monitor.worked(1);
356
			FileOutputStream os = new FileOutputStream(destination.toOSString());
357
			monitor.worked(1);
335
358
336
            generator.stream(os);
359
			if (format == ImageFileFormat.PDF) {
337
            monitor.worked(1);
360
				SVGImageConverter.exportToPDF((SVGImage) generator.getRenderedImage(), os);
361
			} else if (format == ImageFileFormat.SVG) {
362
				generator.stream(os);
363
			} else {
364
				throw new IllegalArgumentException(
365
						"Unexpected format: " + format.getName()); //$NON-NLS-1$
366
			}
367
			monitor.worked(1);
338
368
339
            os.close();
369
			os.close();
340
            monitor.worked(1);
370
			monitor.worked(1);
341
            refreshLocal(destination);
371
			refreshLocal(destination);
342
        } catch (IOException ex) {
372
		} catch (IOException ex) {
343
            Log.error(DiagramUIRenderPlugin.getInstance(), IStatus.ERROR, ex
373
			Log.error(DiagramUIRenderPlugin.getInstance(), IStatus.ERROR, ex
344
                .getMessage(), ex);
374
					.getMessage(), ex);
345
            IStatus status =
375
			IStatus status = new Status(IStatus.ERROR,
346
                new Status(IStatus.ERROR, "exportToFile", IStatus.OK, //$NON-NLS-1$
376
					"exportToFile", IStatus.OK, //$NON-NLS-1$
347
                    ex.getMessage(), null);
377
					ex.getMessage(), null);
348
            throw new CoreException(status);
378
			throw new CoreException(status);
349
        }
379
		}
350
    }
380
	}
381
        
382
  
383
    
351
384
352
    /**
385
    /**
353
     * create a file in the workspace if the destination is in a project in the
386
     * create a file in the workspace if the destination is in a project in the
(-)src/org/eclipse/gmf/runtime/diagram/ui/render/util/CopyToHTMLImageUtil.java (+1 lines)
Lines 99-104 Link Here
99
		imageFormatToTileSizeMap.put(ImageFileFormat.PNG, new Dimension(3000,
99
		imageFormatToTileSizeMap.put(ImageFileFormat.PNG, new Dimension(3000,
100
				3000));
100
				3000));
101
		imageFormatToTileSizeMap.put(ImageFileFormat.SVG, new Dimension(0, 0));
101
		imageFormatToTileSizeMap.put(ImageFileFormat.SVG, new Dimension(0, 0));
102
		imageFormatToTileSizeMap.put(ImageFileFormat.PDF, new Dimension(0, 0));
102
	}
103
	}
103
104
104
	/*
105
	/*
(-)src/org/eclipse/gmf/runtime/diagram/ui/render/clipboard/DiagramSVGGenerator.java (-12 / +13 lines)
Lines 1-5 Link Here
1
/******************************************************************************
1
/******************************************************************************
2
 * Copyright (c) 2004, 2006 IBM Corporation and others.
2
 * Copyright (c) 2004, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 50-56 Link Here
50
public class DiagramSVGGenerator
50
public class DiagramSVGGenerator
51
	extends DiagramGenerator {
51
	extends DiagramGenerator {
52
52
53
	private RenderedImage svgImage = null;
53
	private RenderedImage renderedImage = null;
54
54
55
	private Element svgRoot = null;
55
	private Element svgRoot = null;
56
56
Lines 88-97 Link Here
88
			stream(os);
88
			stream(os);
89
			os.close();
89
			os.close();
90
90
91
			setSVGImage(RenderedImageFactory.getInstance(os.toByteArray()));
91
			setRenderedImage(RenderedImageFactory.getInstance(os.toByteArray()));
92
92
93
			return RenderedImageDescriptor
93
			return RenderedImageDescriptor
94
				.createFromRenderedImage(getSVGImage());
94
				.createFromRenderedImage(getRenderedImage());
95
		} catch (IOException ex) {
95
		} catch (IOException ex) {
96
			Log.error(DiagramUIRenderPlugin.getInstance(), IStatus.ERROR, ex
96
			Log.error(DiagramUIRenderPlugin.getInstance(), IStatus.ERROR, ex
97
				.getMessage(), ex);
97
				.getMessage(), ex);
Lines 139-149 Link Here
139
	 */
139
	 */
140
	public Image createAWTImageForParts(List editparts, org.eclipse.swt.graphics.Rectangle sourceRect) {
140
	public Image createAWTImageForParts(List editparts, org.eclipse.swt.graphics.Rectangle sourceRect) {
141
		createSWTImageDescriptorForParts(editparts, sourceRect);
141
		createSWTImageDescriptorForParts(editparts, sourceRect);
142
		if (getSVGImage() != null) {
142
		if (getRenderedImage() != null) {
143
			try {
143
			try {
144
				BufferedImage bufImg = (BufferedImage)getSVGImage().getAdapter(BufferedImage.class);
144
				BufferedImage bufImg = (BufferedImage)getRenderedImage().getAdapter(BufferedImage.class);
145
				if (bufImg == null)
145
				if (bufImg == null)
146
					bufImg = ImageConverter.convert(getSVGImage().getSWTImage());
146
					bufImg = ImageConverter.convert(getRenderedImage().getSWTImage());
147
				return bufImg;
147
				return bufImg;
148
			} catch (Error e) {
148
			} catch (Error e) {
149
				// log the Error but allow execution to continue
149
				// log the Error but allow execution to continue
Lines 169-185 Link Here
169
	}
169
	}
170
170
171
	/**
171
	/**
172
	 * @return Returns the svgImage.
172
	 * @return Returns the rendered image created by previous 
173
	 * call to createSWTImageDescriptorForParts
173
	 */
174
	 */
174
	private RenderedImage getSVGImage() {
175
	public RenderedImage getRenderedImage() {
175
		return svgImage;
176
		return renderedImage;
176
	}
177
	}
177
178
178
	/**
179
	/**
179
	 * @param svgImage
180
	 * @param svgImage
180
	 *            The svgImage to set.
181
	 *            The svgImage to set.
181
	 */
182
	 */
182
	private void setSVGImage(RenderedImage svgImage) {
183
	private void setRenderedImage(RenderedImage renderedImage) {
183
		this.svgImage = svgImage;
184
		this.renderedImage = renderedImage;
184
	}
185
	}
185
}
186
}
(-)META-INF/MANIFEST.MF (-1 / +2 lines)
Lines 26-30 Link Here
26
 org.apache.batik.dom.svg,
26
 org.apache.batik.dom.svg,
27
 org.apache.batik.svggen,
27
 org.apache.batik.svggen,
28
 org.apache.batik.util,
28
 org.apache.batik.util,
29
 org.w3c.dom.svg;bundle-version="1.1.0"
29
 org.w3c.dom.svg;bundle-version="1.1.0",
30
 org.apache.batik.pdf
30
Eclipse-LazyStart: true
31
Eclipse-LazyStart: true
(-)src/org/eclipse/gmf/runtime/draw2d/ui/render/awt/internal/svg/SVGImageConverter.java (-2 / +39 lines)
Lines 1-5 Link Here
1
/******************************************************************************
1
/******************************************************************************
2
 * Copyright (c) 2002, 2006 IBM Corporation and others.
2
 * Copyright (c) 2002, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 15-27 Link Here
15
import java.awt.image.BufferedImage;
15
import java.awt.image.BufferedImage;
16
import java.io.ByteArrayInputStream;
16
import java.io.ByteArrayInputStream;
17
import java.io.FileInputStream;
17
import java.io.FileInputStream;
18
import java.io.FileOutputStream;
18
import java.io.InputStream;
19
import java.io.InputStream;
19
20
20
import org.apache.batik.transcoder.Transcoder;
21
import org.apache.batik.transcoder.Transcoder;
22
import org.apache.batik.transcoder.TranscoderException;
21
import org.apache.batik.transcoder.TranscoderInput;
23
import org.apache.batik.transcoder.TranscoderInput;
22
import org.apache.batik.transcoder.TranscoderOutput;
24
import org.apache.batik.transcoder.TranscoderOutput;
23
import org.apache.batik.transcoder.image.ImageTranscoder;
25
import org.apache.batik.transcoder.image.ImageTranscoder;
26
import org.apache.fop.svg.PDFTranscoder;
27
import org.eclipse.core.runtime.CoreException;
28
import org.eclipse.core.runtime.IStatus;
29
import org.eclipse.core.runtime.Status;
30
import org.eclipse.gmf.runtime.common.core.util.Log;
24
import org.eclipse.gmf.runtime.draw2d.ui.render.RenderInfo;
31
import org.eclipse.gmf.runtime.draw2d.ui.render.RenderInfo;
32
import org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.Draw2dRenderPlugin;
25
import org.eclipse.swt.graphics.Image;
33
import org.eclipse.swt.graphics.Image;
26
import org.w3c.dom.Document;
34
import org.w3c.dom.Document;
27
35
Lines 31-37 Link Here
31
 *
39
 *
32
 * Class for conversion of SVG to different Image formats
40
 * Class for conversion of SVG to different Image formats
33
 */
41
 */
34
class SVGImageConverter {
42
public class SVGImageConverter {
35
	/**
43
	/**
36
	 * Consructor to create a new instance of SVGtoBufferedImageConverter
44
	 * Consructor to create a new instance of SVGtoBufferedImageConverter
37
	 */
45
	 */
Lines 252-255 Link Here
252
		
260
		
253
		return transcoder.getSWTImage();
261
		return transcoder.getSWTImage();
254
	}
262
	}
263
	
264
	 /**
265
	 * Export SVG image to PDF file format.
266
	 * 
267
	 * @param SVGImage The input SVG image.
268
	 * @param fileOutputStream The output stream to write the PDF to.
269
	 * @throws CoreException
270
	 */
271
    public static void exportToPDF(SVGImage svgImage,
272
			FileOutputStream fileOutputStream)
273
			throws CoreException {
274
    	
275
		try {
276
			TranscoderOutput transcoderOutput = new TranscoderOutput(fileOutputStream);
277
			TranscoderInput transcoderInput = new TranscoderInput(svgImage
278
					.getDocument());
279
280
			PDFTranscoder pdfTranscoder = new PDFTranscoder();
281
			pdfTranscoder.transcode(transcoderInput, transcoderOutput);
282
283
		} catch (TranscoderException e) {
284
			Log.error(Draw2dRenderPlugin.getInstance(), IStatus.ERROR, e
285
					.getMessage(), e);
286
			IStatus status = new Status(IStatus.ERROR,
287
					"exportToPDF", IStatus.OK, //$NON-NLS-1$
288
					e.getMessage(), null);
289
			throw new CoreException(status);
290
		} 
291
	}
255
}
292
}

Return to bug 212024