当前位置: 首页>>代码示例>>Java>>正文


Java SVGGraphics2D.setSVGCanvasSize方法代码示例

本文整理汇总了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);

}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:21,代码来源:PIDEF0painter.java

示例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);
    }
}
 
开发者ID:workcraft,项目名称:workcraft,代码行数:24,代码来源:SvgExporter.java

示例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;
}
 
开发者ID:compomics,项目名称:compomics-utilities,代码行数:28,代码来源:Export.java

示例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;
}
 
开发者ID:donkirkby,项目名称:donkirkby,代码行数:17,代码来源:PaintWriter.java

示例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;
}
 
开发者ID:donkirkby,项目名称:donkirkby,代码行数:17,代码来源:PaintWriter.java

示例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;
}
 
开发者ID:compomics,项目名称:mitraq,代码行数:28,代码来源:Export.java

示例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;
}
 
开发者ID:iwabuchiken,项目名称:freemind_1.0.0_20140624_214725,代码行数:25,代码来源:ExportVectorGraphic.java

示例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();
      }
 }
 
开发者ID:mzur,项目名称:pretty-formula,代码行数:33,代码来源:FormulaParser.java

示例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;
}
 
开发者ID:SiLeBAT,项目名称:BfROpenLab,代码行数:21,代码来源:CanvasUtils.java

示例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;
}
 
开发者ID:sih4sing5hong5,项目名称:han3_ji7_tsoo1_kian3,代码行数:22,代码来源:IDSrendService.java

示例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;
}
 
开发者ID:onprom,项目名称:onprom,代码行数:8,代码来源:IOUtility.java

示例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);
 }
}
 
开发者ID:seqcode,项目名称:seqcode-core,代码行数:31,代码来源:RegionPanel.java

示例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();
	}
}
 
开发者ID:seqcode,项目名称:seqcode-core,代码行数:40,代码来源:ProfilePanel.java

示例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();
	}
}
 
开发者ID:seqcode,项目名称:seqcode-core,代码行数:38,代码来源:ProfileLinePanel.java

示例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();
    }
}
 
开发者ID:seqcode,项目名称:seqcode-core,代码行数:39,代码来源:ScatterPlot.java


注:本文中的org.apache.batik.svggen.SVGGraphics2D.setSVGCanvasSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。