本文整理汇总了Java中org.apache.batik.svggen.SVGGraphics2D.setSVGCanvasSize方法的典型用法代码示例。如果您正苦于以下问题:Java SVGGraphics2D.setSVGCanvasSize方法的具体用法?Java SVGGraphics2D.setSVGCanvasSize怎么用?Java SVGGraphics2D.setSVGCanvasSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.batik.svggen.SVGGraphics2D
的用法示例。
在下文中一共展示了SVGGraphics2D.setSVGCanvasSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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);
}
}
示例3: drawSvgGraphics
import org.apache.batik.svggen.SVGGraphics2D; //导入方法依赖的package包/类
/**
* Draws the selected component (assumed to be a Component) into the
* provided SVGGraphics2D object.
*
* @param component
* @param bounds
*/
private static SVGGraphics2D drawSvgGraphics(Object component, Rectangle bounds) {
// Get a SVGDOMImplementation and create an XML document
DOMImplementation domImpl = SVGDOMImplementation.getDOMImplementation();
String svgNS = "http://www.w3.org/2000/svg";
SVGDocument svgDocument = (SVGDocument) domImpl.createDocument(svgNS, "svg", null);
// Create an instance of the SVG Generator
SVGGraphics2D svgGenerator = new SVGGraphics2D(svgDocument);
svgGenerator.setSVGCanvasSize(bounds.getSize());
// draw the panel in the SVG generator
if (component instanceof JFreeChart) {
((JFreeChart) component).draw(svgGenerator, bounds);
} else if (component instanceof JComponent) {
((JComponent) component).paintAll(svgGenerator);
}
return svgGenerator;
}
示例4: createGraphicsContext
import org.apache.batik.svggen.SVGGraphics2D; //导入方法依赖的package包/类
public Graphics2D createGraphicsContext(int width, int height)
{
// 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.
svgGenerator = new SVGGraphics2D(document);
svgGenerator.setSVGCanvasSize(new Dimension(width, height));
return svgGenerator;
}
示例5: createGraphicsContext
import org.apache.batik.svggen.SVGGraphics2D; //导入方法依赖的package包/类
public Graphics2D createGraphicsContext()
{
// 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.
svgGenerator = new SVGGraphics2D(document);
svgGenerator.setSVGCanvasSize(new Dimension(300, 300));
return svgGenerator;
}
示例6: drawSvgGraphics
import org.apache.batik.svggen.SVGGraphics2D; //导入方法依赖的package包/类
/**
* Draws the selected component (assumed to be a Component) into the provided
* SVGGraphics2D object.
*
* @param component
* @param bounds
*/
private static SVGGraphics2D drawSvgGraphics(Object component, Rectangle bounds) {
// Get a SVGDOMImplementation and create an XML document
DOMImplementation domImpl = SVGDOMImplementation.getDOMImplementation();
String svgNS = "http://www.w3.org/2000/svg";
SVGDocument svgDocument = (SVGDocument) domImpl.createDocument(svgNS, "svg", null);
// Create an instance of the SVG Generator
SVGGraphics2D svgGenerator = new SVGGraphics2D(svgDocument);
svgGenerator.setSVGCanvasSize(bounds.getSize());
// draw the panel in the SVG generator
if (component instanceof JFreeChart) {
((JFreeChart) component).draw(svgGenerator, bounds);
} else if (component instanceof JComponent) {
((JComponent) component).paintAll(svgGenerator);
}
return svgGenerator;
}
示例7: fillSVGGraphics2D
import org.apache.batik.svggen.SVGGraphics2D; //导入方法依赖的package包/类
/**
*/
protected SVGGraphics2D fillSVGGraphics2D(MapView view) {
// NodeAdapter root = (NodeAdapter) getController().getMap().getRoot();
SVGGraphics2D g2d = createSvgGraphics2D();
try {
view.preparePrinting();
Rectangle innerBounds = view.getInnerBounds();
g2d.setSVGCanvasSize(new Dimension(innerBounds.width,
innerBounds.height));
g2d.translate(-innerBounds.x, -innerBounds.y);
//
// Generate SVG content
//
view.print(g2d);
} finally {
view.endPrinting();
}
// g2d.setColor(Color.BLACK);
// g2d.setStroke(new BasicStroke(3));
// g2d.drawRect(innerBounds.x, innerBounds.y, innerBounds.width - 2,
// innerBounds.height - 2);
return g2d;
}
示例8: 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();
}
}
示例9: getPseudoEmptySvgDocument
import org.apache.batik.svggen.SVGGraphics2D; //导入方法依赖的package包/类
/**
* Return a Non-Empty SVGDocument, with a string out of image bounds (not visible)
*
*/
private static SVGDocument getPseudoEmptySvgDocument() {
int width = 1;
int height = 1;
SVGDocument document = (SVGDocument) new SVGDOMImplementation().createDocument(null, "svg", null);
SVGGraphics2D g = new SVGGraphics2D(document);
g.setSVGCanvasSize(new Dimension(width, height));
g.drawString("Image not available.", width*2, height*2);
g.dispose();
document.replaceChild(g.getRoot(), document.getDocumentElement());
return document;
}
示例10: 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;
}
示例11: getSVGGraphics
import org.apache.batik.svggen.SVGGraphics2D; //导入方法依赖的package包/类
public static SVGGraphics2D getSVGGraphics(Dimension dimension) {
SVGGraphics2D svgGenerator = new SVGGraphics2D(GenericDOMImplementation.getDOMImplementation().createDocument("http://www.w3.org/2000/svg", "svg", null));
//set drawing canvas as the drawing area
svgGenerator.setSVGCanvasSize(dimension);
svgGenerator.setClip(0, 0, dimension.width, dimension.height);
return svgGenerator;
}
示例12: saveImage
import org.apache.batik.svggen.SVGGraphics2D; //导入方法依赖的package包/类
public void saveImage(File f, int w, int h, boolean raster) throws IOException {
if (raster) {
BufferedImage im =
new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics g = im.getGraphics();
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
mainPanel.paintComponent(g,0,0,w,h);
ImageIO.write(im, "png", f);
g.dispose();
} else {
DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
// Create an instance of org.w3c.dom.Document
Document document = domImpl.createDocument(null, "svg", null);
// Create an instance of the SVG Generator
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
svgGenerator.setSVGCanvasSize(new Dimension(w,h));
// Ask the test to render into the SVG Graphics2D implementation
svgGenerator.setColor(Color.white);
svgGenerator.fillRect(0,0,w,h);
mainPanel.paintComponent(svgGenerator,50,50,w-100,h-100);
// Finally, stream out SVG to the standard output using UTF-8
// character to byte encoding
boolean useCSS = true; // we want to use CSS style attribute
Writer out = new OutputStreamWriter(new FileOutputStream(f), "UTF-8");
svgGenerator.stream(out, useCSS);
}
}
示例13: saveImage
import org.apache.batik.svggen.SVGGraphics2D; //导入方法依赖的package包/类
public void saveImage(File f, int w, int h, boolean raster)
throws IOException {
if(raster){
if(transparent)
this.setOpaque(false);
this.setSize(new Dimension(w, h));
repaint();
BufferedImage im =
new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = im.createGraphics();
graphics.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
this.print(graphics);
graphics.dispose();
ImageIO.write(im, "png", f);
}else{
DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
// Create an instance of org.w3c.dom.Document
Document document = domImpl.createDocument(null, "svg", null);
// Create an instance of the SVG Generator
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
svgGenerator.setSVGCanvasSize(new Dimension(w,h));
// Ask the test to render into the SVG Graphics2D implementation
if(!transparent){
svgGenerator.setColor(Color.white);
svgGenerator.fillRect(0,0,w,h);
}
this.paintComponent(svgGenerator);
// Finally, stream out SVG to the standard output using UTF-8
// character to byte encoding
boolean useCSS = true; // we want to use CSS style attribute
FileOutputStream outStream = new FileOutputStream(f);
Writer out = new OutputStreamWriter(outStream, "UTF-8");
svgGenerator.stream(out, useCSS);
outStream.flush();
outStream.close();
}
}
示例14: saveImage
import org.apache.batik.svggen.SVGGraphics2D; //导入方法依赖的package包/类
public void saveImage(File f, int w, int h, boolean raster)
throws IOException {
if(raster){
if(transparent)
this.setOpaque(false);
BufferedImage im =
new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = im.createGraphics();
graphics.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
this.print(graphics);
graphics.dispose();
ImageIO.write(im, "png", f);
}else{
DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
// Create an instance of org.w3c.dom.Document
Document document = domImpl.createDocument(null, "svg", null);
// Create an instance of the SVG Generator
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
svgGenerator.setSVGCanvasSize(new Dimension(w,h));
// Ask the test to render into the SVG Graphics2D implementation
if(!transparent){
svgGenerator.setColor(Color.white);
svgGenerator.fillRect(0,0,w,h);
}
this.paintComponent(svgGenerator);
// Finally, stream out SVG to the standard output using UTF-8
// character to byte encoding
boolean useCSS = true; // we want to use CSS style attribute
FileOutputStream outStream = new FileOutputStream(f);
Writer out = new OutputStreamWriter(outStream, "UTF-8");
svgGenerator.stream(out, useCSS);
outStream.flush();
outStream.close();
}
}
示例15: saveImage
import org.apache.batik.svggen.SVGGraphics2D; //导入方法依赖的package包/类
/**
* Save image
* If raster is false, save a SVG, otherwise save a PNG
*
*/
public void saveImage(File f, int w, int h, boolean raster)
throws IOException {
if (raster) {
BufferedImage im =
new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics g = im.getGraphics();
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
chart.draw(g2, new Rectangle(0,0,w,h));
ImageIO.write(im, "png", f);
}else{
DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
// Create an instance of org.w3c.dom.Document
Document document = domImpl.createDocument(null, "svg", null);
// Create an instance of the SVG Generator
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
svgGenerator.setSVGCanvasSize(new Dimension(w,h));
// Ask the test to render into the SVG Graphics2D implementation
svgGenerator.setColor(Color.white);
svgGenerator.fillRect(0,0,w,h);
chart.draw(svgGenerator, new Rectangle(0,0,w,h));
// Finally, stream out SVG to the standard output using UTF-8
// character to byte encoding
boolean useCSS = true; // we want to use CSS style attribute
FileOutputStream outStream = new FileOutputStream(f);
Writer out = new OutputStreamWriter(outStream, "UTF-8");
svgGenerator.stream(out, useCSS);
outStream.flush();
outStream.close();
}
}