diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2011-09-15 18:35:25 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2011-09-15 18:35:25 +0000 |
commit | a813f61a0e600e352310f6f1bc96606cf27a34ec (patch) | |
tree | c349b0c31cce388e7b39468599ee97e876c2b14c /collaboration | |
parent | c6c38f12af1fabd28b20399b9847f2f60dce5a7c (diff) |
Allow the generation of jpg
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1171217 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'collaboration')
3 files changed, 126 insertions, 12 deletions
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/pom.xml b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/pom.xml index e38c9badb6..3a3b4b4ec6 100644 --- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/pom.xml +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/pom.xml @@ -30,6 +30,8 @@ <artifactId>commons-cli</artifactId> <version>1.2</version> </dependency> + + <!-- <dependency> <groupId>org.apache.xmlgraphics</groupId> <artifactId>batik-anim</artifactId> @@ -47,19 +49,22 @@ <artifactId>batik-css</artifactId> <version>1.7</version> </dependency> - + <dependency> <groupId>org.apache.xmlgraphics</groupId> - <artifactId>batik-dom</artifactId> + <artifactId>batik-ext</artifactId> <version>1.7</version> </dependency> + --> <dependency> <groupId>org.apache.xmlgraphics</groupId> - <artifactId>batik-ext</artifactId> + <artifactId>batik-dom</artifactId> <version>1.7</version> </dependency> + + <dependency> <groupId>org.apache.xmlgraphics</groupId> <artifactId>batik-parser</artifactId> @@ -91,6 +96,12 @@ </dependency> <dependency> + <groupId>org.apache.xmlgraphics</groupId> + <artifactId>batik-codec</artifactId> + <version>1.7</version> + </dependency> + + <dependency> <groupId>xml-apis</groupId> <artifactId>xml-apis-ext</artifactId> <version>1.3.04</version> @@ -127,6 +138,7 @@ </configuration> </plugin> +<!-- <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> @@ -147,7 +159,7 @@ </execution> </executions> </plugin> - + --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/diagram/main/Main.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/diagram/main/Main.java index 8224e47955..2ce360a9c3 100755 --- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/diagram/main/Main.java +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/diagram/main/Main.java @@ -20,7 +20,11 @@ package org.apache.tuscany.sca.diagram.main; import java.io.File; +import java.io.FileOutputStream; import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.io.StringWriter; import javax.xml.parsers.DocumentBuilder; @@ -30,6 +34,12 @@ import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import org.apache.batik.transcoder.Transcoder; +import org.apache.batik.transcoder.TranscoderException; +import org.apache.batik.transcoder.TranscoderInput; +import org.apache.batik.transcoder.TranscoderOutput; +import org.apache.batik.transcoder.image.JPEGTranscoder; +import org.apache.batik.transcoder.image.PNGTranscoder; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.HelpFormatter; @@ -52,9 +62,12 @@ public class Main { Option opt2 = new Option("h", "html", false, "Generate HTML documents"); options.addOption(opt2); - Option opt3 = new Option("o", "output", true, "Output directory"); + Option opt3 = new Option("j", "jpeg", false, "Generate JPEG diagrams"); options.addOption(opt3); + Option opt4 = new Option("o", "output", true, "Output directory"); + options.addOption(opt4); + return options; } @@ -86,10 +99,12 @@ public class Main { boolean isHtml = false; boolean isSvg = false; + boolean isJpeg = false; isSvg = cli.hasOption('s'); isHtml = cli.hasOption('h'); + isJpeg = cli.hasOption('j'); - if (!isSvg && !isHtml) { + if (!isSvg && !isHtml && !isJpeg) { isSvg = true; isHtml = true; } @@ -103,10 +118,11 @@ public class Main { } File dir = new File(outFileDir); String[] compositeFiles = cli.getArgs(); - generate(dir, isSvg, isHtml, compositeFiles); + generate(dir, isSvg, isHtml, false, compositeFiles); } - public static void generate(File dir, boolean isSvg, boolean isHtml, String... compositeFiles) throws Exception { + public static void generate(File dir, boolean isSvg, boolean isHtml, boolean isJpeg, String... compositeFiles) + throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); for (String str : compositeFiles) { @@ -121,6 +137,11 @@ public class Main { DiagramGenerator dg = new DiagramGenerator(comp, isHtml); Document svg = dg.buildSVGDocument(); + if (isJpeg) { + String jpgFileName = comp.getName() + comp.getFileNameSuffix() + ".jpg"; + svgToJPEG(svg, new File(dir, jpgFileName)); + } + String svgContent = extractSvg(svg); if (isSvg) { @@ -141,9 +162,9 @@ public class Main { HTMLWrapper html = new HTMLWrapper(svg, comp.getName(), htmlFile); html.buildHTML(); -// System.err.println("--------------HTML Output for " + comp.getName() + "--------------\n"); -// System.out.println(content); -// System.err.println("--------------------------------------------------------------\n"); + // System.err.println("--------------HTML Output for " + comp.getName() + "--------------\n"); + // System.out.println(content); + // System.err.println("--------------------------------------------------------------\n"); } @@ -174,4 +195,85 @@ public class Main { return svgString; } + public static void svgToJPEG(File svg, File jpeg) throws IOException, TranscoderException { + // Create the transcoder input. + TranscoderInput input = new TranscoderInput(svg.toURI().toString()); + // Create the transcoder output. + OutputStream ostream = new FileOutputStream(jpeg); + TranscoderOutput output = new TranscoderOutput(ostream); + + // Create a JPEG transcoder + Transcoder t = new JPEGTranscoder(); + + // Set the transcoding hints. + t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(1.0)); + + // Save the image. + t.transcode(input, output); + + // Flush and close the stream. + ostream.flush(); + ostream.close(); + } + + public static void svgToJPEG(Document svg, File jpeg) throws IOException, TranscoderException { + // Create the transcoder input. + TranscoderInput input = new TranscoderInput(svg); + // Create the transcoder output. + OutputStream ostream = new FileOutputStream(jpeg); + TranscoderOutput output = new TranscoderOutput(ostream); + + // Create a JPEG transcoder + Transcoder t = new JPEGTranscoder(); + + // Set the transcoding hints. + t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(1.0)); + + // Save the image. + t.transcode(input, output); + + // Flush and close the stream. + ostream.flush(); + ostream.close(); + } + + public static void svgToJPEG(InputStream svg, OutputStream jpeg) throws IOException, TranscoderException { + // Create the transcoder input. + TranscoderInput input = new TranscoderInput(svg); + + TranscoderOutput output = new TranscoderOutput(jpeg); + + // Create a JPEG transcoder + Transcoder t = new JPEGTranscoder(); + + // Set the transcoding hints. + t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(1.0)); + + // Save the image. + t.transcode(input, output); + + // Flush and close the stream. + svg.close(); + jpeg.flush(); + jpeg.close(); + } + + public static void svgToPNG(InputStream svg, OutputStream png) throws IOException, TranscoderException { + // Create the transcoder input. + TranscoderInput input = new TranscoderInput(svg); + + TranscoderOutput output = new TranscoderOutput(png); + + // Create a JPEG transcoder + Transcoder t = new PNGTranscoder(); + + // Save the image. + t.transcode(input, output); + + // Flush and close the stream. + svg.close(); + png.flush(); + png.close(); + } + } diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/test/java/org/apache/tuscany/sca/diagram/layout/DiagramGeneratorTestCase.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/test/java/org/apache/tuscany/sca/diagram/layout/DiagramGeneratorTestCase.java index aee42dbfc0..ee0feb86bb 100644 --- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/test/java/org/apache/tuscany/sca/diagram/layout/DiagramGeneratorTestCase.java +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/test/java/org/apache/tuscany/sca/diagram/layout/DiagramGeneratorTestCase.java @@ -25,7 +25,7 @@ public class DiagramGeneratorTestCase { for (File xml : new File("input").listFiles()) { if (xml.getName().endsWith(".xml")) { System.out.println(xml); - Main.generate(new File("target"), true, false, xml.toString()); + Main.generate(new File("target"), true, false, false, xml.toString()); } } } |