本文整理汇总了Java中org.apache.batik.svggen.SVGGraphics2D.stream方法的典型用法代码示例。如果您正苦于以下问题:Java SVGGraphics2D.stream方法的具体用法?Java SVGGraphics2D.stream怎么用?Java SVGGraphics2D.stream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.batik.svggen.SVGGraphics2D
的用法示例。
在下文中一共展示了SVGGraphics2D.stream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exportImage
import org.apache.batik.svggen.SVGGraphics2D; //导入方法依赖的package包/类
public void exportImage() {
try {
File file = IOUtility.selectFileToSave(FileType.IMAGE);
if (file != null) {
Rectangle drawingArea = getDrawingArea();
String extension = FilenameUtils.getExtension(file.getName());
if (extension.equals("svg")) {
SVGGraphics2D svgGenerator = IOUtility.getSVGGraphics(drawingArea.getSize());
paintDrawing(svgGenerator, drawingArea.x, drawingArea.y);
svgGenerator.stream(new FileWriter(file));
svgGenerator.dispose();
} else {
BufferedImage bi = new BufferedImage(drawingArea.width, drawingArea.height, BufferedImage.TYPE_INT_RGB);
Graphics g = bi.createGraphics();
paintDrawing(g, drawingArea.x, drawingArea.y);
ImageIO.write(bi, extension, file);
g.dispose();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例2: writeSVG
import org.apache.batik.svggen.SVGGraphics2D; //导入方法依赖的package包/类
private void writeSVG(OutputStream stream) throws IOException {
DOMImplementation impl = GenericDOMImplementation
.getDOMImplementation();
String svgNS = "http://www.w3.org/2000/svg";
Document myFactory = impl.createDocument(svgNS, "svg", null);
SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(myFactory);
ctx.setEmbeddedFontsOn(Options.getBoolean("EMBEDDED_SVG_FONTS", true));
SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, Options.getBoolean(
"EMBEDDED_SVG_FONTS", true));
svgGenerator.setSVGCanvasSize(size);
paint(svgGenerator, 0, 0);
boolean useCSS = true;
Writer out = new OutputStreamWriter(stream, "UTF-8");
svgGenerator.stream(out, useCSS);
}
示例3: exportChartAsSVG
import org.apache.batik.svggen.SVGGraphics2D; //导入方法依赖的package包/类
/**
* Exports a JFreeChart to a SVG file.
*
* @param chart JFreeChart to export
* @param bounds the dimensions of the viewport
* @param svgFile the output file.
* @throws IOException if writing the svgFile fails.
*/
public static void exportChartAsSVG(
JFreeChart chart,
Rectangle bounds,
File svgFile) throws IOException {
// Get a DOMImplementation and create an XML document
DOMImplementation domImpl
= GenericDOMImplementation.getDOMImplementation();
Document document = domImpl.createDocument(null, "svg", null);
// Create an instance of the SVG Generator
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
// draw the chart in the SVG generator
chart.draw(svgGenerator, bounds);
// Write svg file
OutputStream outputStream = new FileOutputStream(svgFile);
Writer out = new OutputStreamWriter(outputStream, "UTF-8");
svgGenerator.stream(out, true /* use css */);
outputStream.flush();
outputStream.close();
}
示例4: export
import org.apache.batik.svggen.SVGGraphics2D; //导入方法依赖的package包/类
@Override
public void export(Model model, OutputStream out) throws IOException, SerialisationException {
if (!(model instanceof VisualModel)) {
throw new SerialisationException("Non-visual model cannot be exported as SVG file.");
}
VisualModel visualModel = (VisualModel) model;
try {
Document doc = XmlUtils.createDocument();
SVGGraphics2D g2d = new SVGGraphics2D(doc);
g2d.setUnsupportedAttributes(null);
g2d.scale(SCALE_FACTOR, SCALE_FACTOR);
VisualGroup visualGroup = (VisualGroup) model.getRoot();
Rectangle2D bounds = visualGroup.getBoundingBoxInLocalSpace();
g2d.translate(-bounds.getMinX(), -bounds.getMinY());
int canvasWidth = (int) (bounds.getWidth() * SCALE_FACTOR);
int canvasHeight = (int) (bounds.getHeight() * SCALE_FACTOR);
g2d.setSVGCanvasSize(new Dimension(canvasWidth, canvasHeight));
visualModel.draw(g2d, Decorator.Empty.INSTANCE);
g2d.stream(new OutputStreamWriter(out));
} catch (ParserConfigurationException e) {
throw new SerialisationException(e);
}
}
示例5: exportAsSVG
import org.apache.batik.svggen.SVGGraphics2D; //导入方法依赖的package包/类
public static <T, U> void exportAsSVG(VennFigureParameters<T> parameters, File file, Dimension size) throws IOException {
// Get a DOMImplementation.
DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
// Create an instance of org.w3c.dom.Document.
String svgNS = "http://www.w3.org/2000/svg";
Document document = domImpl.createDocument(svgNS, "svg", null);
// Create an instance of the SVG Generator.
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
VennDrawGraphics2D.draw(VennFigureCreator.createVennFigure(parameters), svgGenerator, size);
try (Writer writer = new FileWriter(file)) {
svgGenerator.stream(writer, true);
}
}
示例6: fullExportToStream
import org.apache.batik.svggen.SVGGraphics2D; //导入方法依赖的package包/类
@Override
public void fullExportToStream(ERDesignerGraph aGraph, OutputStream aStream) throws IOException {
Object[] cells = aGraph.getRoots();
Rectangle2D bounds = aGraph.toScreen(aGraph.getCellBounds(cells));
if (bounds != null) {
DOMImplementation theDomImpl = SVGDOMImplementation.getDOMImplementation();
String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
Document theDocument = theDomImpl.createDocument(svgNS, "svg", null);
SVGGraphics2D theSvgGenerator = new SVGGraphics2D(theDocument);
theSvgGenerator.translate(-bounds.getX() + 10, -bounds.getY() + 0);
RepaintManager theRepaintManager = RepaintManager.currentManager(aGraph);
theRepaintManager.setDoubleBufferingEnabled(false);
boolean theDoubleBuffered = aGraph.isDoubleBuffered();
// Disable double buffering to allow Batik to render svg elements
// instead of images
aGraph.setDoubleBuffered(false);
aGraph.paint(theSvgGenerator);
aGraph.setDoubleBuffered(theDoubleBuffered);
Writer theWriter = new OutputStreamWriter(aStream, PlatformConfig.getXMLEncoding());
theSvgGenerator.stream(theWriter, false);
theRepaintManager.setDoubleBufferingEnabled(true);
theWriter.flush();
theWriter.close();
}
}
示例7: exportToStream
import org.apache.batik.svggen.SVGGraphics2D; //导入方法依赖的package包/类
@Override
public void exportToStream(Component aComponent, OutputStream aStream) throws IOException {
DOMImplementation theDomImpl = GenericDOMImplementation.getDOMImplementation();
Document theDocument = theDomImpl.createDocument(null, "svg", null);
SVGGraphics2D theSvgGenerator = new SVGGraphics2D(theDocument);
RepaintManager theRepaintManager = RepaintManager.currentManager(aComponent);
theRepaintManager.setDoubleBufferingEnabled(false);
Dimension theSize = aComponent.getPreferredSize();
aComponent.setSize(theSize);
aComponent.paint(theSvgGenerator);
Writer theWriter = new OutputStreamWriter(aStream, PlatformConfig.getXMLEncoding());
theSvgGenerator.stream(theWriter, false);
theRepaintManager.setDoubleBufferingEnabled(true);
theWriter.flush();
theWriter.close();
}
示例8: generateSVG
import org.apache.batik.svggen.SVGGraphics2D; //导入方法依赖的package包/类
/**
* Create a SVG image. The image handler will write all images files to
* "res/images".
*
* @param p the drawable component.
* @param outStream the the output stream.
* @throws UnsupportedEncodingException error on unsupported encoding.
* @throws SVGGraphics2DIOException error on error to conversion.
*/
private void generateSVG(Drawable p, OutputStream outStream) throws UnsupportedEncodingException, SVGGraphics2DIOException {
DOMImplementation domImpl
= GenericDOMImplementation.getDOMImplementation();
String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
Document myFactory = domImpl.createDocument(svgNS, "svg", null);
SVGGeneratorContext ctx
= SVGGeneratorContext.createDefault(myFactory);
GenericImageHandler ihandler = new CachedImageHandlerPNGEncoder("res/images", null);
ctx.setGenericImageHandler(ihandler);
SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, false);
TurtleState ts = new TurtleState();
p.draw(svgGenerator, ts);
// Create the SVG DOM tree.
Writer out = new OutputStreamWriter(outStream, "UTF-8");
svgGenerator.stream(out, true);
}
示例9: exportChartAsSVG
import org.apache.batik.svggen.SVGGraphics2D; //导入方法依赖的package包/类
/**
* Export chart as svg.
*
* @param chart the chart
* @param bounds the bounds
* @param svgFile the svg file
* @throws IOException Signals that an I/O exception has occurred.
*/
private void exportChartAsSVG(JFreeChart chart, Rectangle bounds, File svgFile) throws IOException {
// Get a DOMImplementation and create an XML document
DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
Document document = domImpl.createDocument(null, "svg", null);
// Create an instance of the SVG Generator
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
// draw the chart in the SVG generator
chart.draw(svgGenerator, bounds);
// Write svg file
OutputStream outputStream = new FileOutputStream(svgFile);
Writer out = new OutputStreamWriter(outputStream, "UTF-8");
svgGenerator.stream(out, true /* use css */);
outputStream.flush();
outputStream.close();
}
示例10: exportSVGImage
import org.apache.batik.svggen.SVGGraphics2D; //导入方法依赖的package包/类
public static void exportSVGImage(PrintWriter pr, Component c) throws IOException {
// Get a DOMImplementation.
DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
// Create an instance of org.w3c.dom.Document.
String svgNS = "http://www.w3.org/2000/svg";
Document document = domImpl.createDocument(svgNS, "svg", null);
// Create an instance of the SVG Generator.
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
c.paint(svgGenerator);
// Finally, stream out SVG to the standard output using
// UTF-8 encoding.
svgGenerator.stream(pr, false);
}
示例11: export
import org.apache.batik.svggen.SVGGraphics2D; //导入方法依赖的package包/类
@Override
public boolean export(RepresentableNetwork net, NetworkStyle style, File output) throws IOException {
//Initializes SVG file
DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
String svgNS = "http://www.w3.org/2000/svg";
Document document = domImpl.createDocument(svgNS, "svg", null);
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
/*
* Convert canvas
*/
//Canvas style
renderCanvas(net, style, svgGenerator);
//Render edges and nodes
renderEdges(net, style, svgGenerator);
renderNodes(net, style, svgGenerator);
//Write the SVG file
Writer out = new OutputStreamWriter(new FileOutputStream(output), "UTF-8");
svgGenerator.stream(out, false);
return true;
}
示例12: saveToSVG
import org.apache.batik.svggen.SVGGraphics2D; //导入方法依赖的package包/类
/**
* Parses a mathematical formula like "(a+b)/c" to a pretty image and saves
* it as an SVG file.
*
* @param formula A raw formula input String.
* @param file The SVG file to save to.
* @throws ParseException When parsing the LaTeX formula failed.
* @throws IOException When writing the file failed.
* @throws DetailedParseCancellationException When parsing the raw formula to
* LaTeX failed.
*/
public static void saveToSVG(String formula, File file)
throws ParseException, IOException, DetailedParseCancellationException {
String latexFormula = FormulaParser.parseToLatex(formula);
TeXIcon icon = FormulaParser.getTeXIcon(latexFormula);
DOMImplementation domImpl = SVGDOMImplementation.getDOMImplementation();
Document document =domImpl.createDocument(
SVGDOMImplementation.SVG_NAMESPACE_URI, "svg", null);
SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(document);
SVGGraphics2D g2 = new SVGGraphics2D(ctx, true);
g2.setSVGCanvasSize(new Dimension(icon.getIconWidth(),icon.getIconHeight()));
icon.paintIcon(null, g2, 0, 0);
try (FileOutputStream svgs = new FileOutputStream(file)) {
Writer out = new OutputStreamWriter(svgs, "UTF-8");
g2.stream(out, false);
svgs.flush();
}
}
示例13: exportChartAsSVG
import org.apache.batik.svggen.SVGGraphics2D; //导入方法依赖的package包/类
/**
* Exports a JFreeChart to a SVG file using the
* <a href= "http://xmlgraphics.apache.org/batik/" target="_blank">Batik SVG
* Toolkit</a>, bundled with Fiji. This method is taken from
* {@literal http://dolf.trieschnigg.nl/jfreechart/}
*
* @param chart
* the <a href= "http://javadoc.imagej.net/JFreeChart/" target=
* "_blank">JFreeChart </a> to export.
* @param bounds
* the Rectangle delimiting the boundaries within which the chart
* should be drawn.
* @param file
* the output (destination) file.
* @throws IOException
* if writing to output file fails.
* @see #exportChartAsSVG(JFreeChart, Rectangle)
* @see #exportChartAsPDF(JFreeChart, Rectangle)
* @see #exportChartAsPDF(JFreeChart, Rectangle, File)
*/
public static void exportChartAsSVG(final JFreeChart chart, final Rectangle bounds, final File file)
throws IOException {
// Get a DOMImplementation and create an XML document
final DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
final org.w3c.dom.Document document = domImpl.createDocument(null, "svg", null);
// Create an instance of the SVG Generator
final SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
// draw the chart in the SVG generator
chart.draw(svgGenerator, bounds);
// Write svg file
final OutputStream outputStream = new FileOutputStream(file);
final Writer out = new OutputStreamWriter(outputStream, "UTF-8");
svgGenerator.stream(out, true /* use css */);
outputStream.flush();
outputStream.close();
}
示例14: exportSVG
import org.apache.batik.svggen.SVGGraphics2D; //导入方法依赖的package包/类
public void exportSVG() throws IOException {
// Get a DOMImplementation.
DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
// Create an instance of org.w3c.dom.Document.
String svgNS = "http://www.w3.org/2000/svg";
Document document = domImpl.createDocument(svgNS, "svg", null);
// Paint application to SVG structure.
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
rootPanel.paint(svgGenerator);
// Target file via dialog.
final JFileChooser fileChooser = new JFileChooser();
fileChooser.setName("Export SVG");
fileChooser.setSelectedFile(new File("eXamine_export.svg"));
int fileConfirm = fileChooser.showSaveDialog(rootPanel);
// Output to valid file.
if(fileConfirm == JFileChooser.APPROVE_OPTION) {
boolean useCSS = true; // we want to use CSS style attributes
Writer out = new FileWriter(fileChooser.getSelectedFile());
svgGenerator.stream(out, useCSS);
}
}
示例15: SVGGraphics2D
import org.apache.batik.svggen.SVGGraphics2D; //导入方法依赖的package包/类
public void 字組成svg(String 組字式, OutputStream 輸出檔案)
throws UnsupportedEncodingException, SVGGraphics2DIOException
{
DOMImplementation domImpl = GenericDOMImplementation
.getDOMImplementation();
// Create an instance of org.w3c.dom.Document.
String svgNS = "http://www.w3.org/2000/svg";
Document document = domImpl.createDocument(svgNS, "svg", null);
boolean useCSS = true; // we want to use CSS style
// attributes
// Create an instance of the SVG Generator.
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
svgGenerator.setSVGCanvasSize(new Dimension(字型大細, 字型大細));
組字(組字式, svgGenerator);
OutputStreamWriter svgOutput = new java.io.OutputStreamWriter(輸出檔案,
"UTF-8");
svgGenerator.stream(svgOutput, useCSS);
return;
}