本文整理汇总了Java中org.apache.batik.svggen.SVGGeneratorContext.setComment方法的典型用法代码示例。如果您正苦于以下问题:Java SVGGeneratorContext.setComment方法的具体用法?Java SVGGeneratorContext.setComment怎么用?Java SVGGeneratorContext.setComment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.batik.svggen.SVGGeneratorContext
的用法示例。
在下文中一共展示了SVGGeneratorContext.setComment方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeSVG
import org.apache.batik.svggen.SVGGeneratorContext; //导入方法依赖的package包/类
/**
* Writes the specified diagram editor as SVG.
* @param editor a DiagramEditor
* @param file the file to write to
* @throws IOException if error occurred
*/
public void writeSVG(DiagramEditor editor, File file) throws IOException {
FileOutputStream out = null;
OutputStreamWriter writer = null;
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
DOMImplementation domImpl = builder.getDOMImplementation();
Document doc =
domImpl.createDocument("http://www.w3.org/2000/svg", "svg", null);
SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(doc);
ctx.setComment("Generated by TinyUML with Batik SVG Generator");
ctx.setEmbeddedFontsOn(true);
SVGGraphics2D g2d = new SVGGraphics2D(ctx, true);
g2d.setSVGCanvasSize(editor.getTotalCanvasSize());
editor.paintComponentNonScreen(g2d);
// write the file
File theFile = getFileWithExtension(file);
if (canWrite(editor, theFile)) {
out = new FileOutputStream(theFile);
writer = new OutputStreamWriter(out, "UTF-8");
g2d.stream(writer);
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (writer != null) { writer.close(); }
if (out != null) { out.close(); }
}
}
示例2: export
import org.apache.batik.svggen.SVGGeneratorContext; //导入方法依赖的package包/类
public void export(JComponent component, File file) {
if (component == null || file == null)
throw new IllegalArgumentException();
String fileName = file.getAbsolutePath();
if (!fileName.endsWith(".svg"))
fileName += ".svg";
// Get a DOMImplementation.
DOMImplementation domImpl = GenericDOMImplementation
.getDOMImplementation();
// Create an instance of org.w3c.dom.Document.
String svgNS = "http://www.w3.org/2000/svg";
Document doc = domImpl.createDocument(svgNS, "svg", null);
SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(doc);
ctx.setComment("Generated by MuLaViTo with Batik SVG");
SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, false);
// Prepare export: Exchange background color.
Color c = component.getBackground();
component.setBackground(Color.WHITE);
component.paint(svgGenerator);
component.setBackground(c);
// Modify export.
svgGenerator.setSVGCanvasSize(component.getSize());
// Export.
try {
svgGenerator.stream(fileName);
} catch (SVGGraphics2DIOException e) {
e.printStackTrace();
}
}
示例3: export
import org.apache.batik.svggen.SVGGeneratorContext; //导入方法依赖的package包/类
public void export(JComponent component, File file) {
if (component == null || file == null)
throw new IllegalArgumentException();
String fileName = file.getAbsolutePath();
if (!fileName.endsWith(".svg"))
fileName += ".svg";
// Get a DOMImplementation.
DOMImplementation domImpl = GenericDOMImplementation
.getDOMImplementation();
// Create an instance of org.w3c.dom.Document.
String svgNS = "http://www.w3.org/2000/svg";
Document doc = domImpl.createDocument(svgNS, "svg", null);
SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(doc);
ctx.setComment("Generated by MuLaViTo with Batik SVG");
SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, false);
// Prepare export: Exchange background color.
Color c = component.getBackground();
component.setBackground(Color.WHITE);
component.paint(svgGenerator);
component.setBackground(c);
// Modify export.
svgGenerator.setSVGCanvasSize(component.getSize());
// Export.
try {
svgGenerator.stream(fileName);
} catch (SVGGraphics2DIOException e) {
e.printStackTrace();
}
}
示例4: convert
import org.apache.batik.svggen.SVGGeneratorContext; //导入方法依赖的package包/类
public void convert(Node node, LayoutContext ctx, OutputStream out) throws IOException
{
Document document;
try {
document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
} catch (ParserConfigurationException e1) {
throw new IOException(e1);
}
document.appendChild(document.createElementNS("http://www.w3.org/2000/svg", "svg"));
SVGGeneratorContext svgCtx = SVGGeneratorContext.createDefault(document);
svgCtx.setComment("Converted from MathML using JEuclid");
SVGGraphics2D graphics = new SVGGraphics2D(svgCtx, true);
JEuclidView view = new JEuclidView(node, ctx, graphics);
int ascentHeight = (int) Math.ceil((double) view.getAscentHeight());
int descentHeight = (int) Math.ceil((double) view.getDescentHeight());
int height = ascentHeight + descentHeight;
int width = (int) Math.ceil((double) view.getWidth());
graphics.setSVGCanvasSize(new Dimension(width, height));
view.draw(graphics, 0.0F, (float) ascentHeight);
document.replaceChild(graphics.getRoot(), document.getFirstChild());
try {
Transformer transformer = TransformerFactory.newInstance().newTransformer();
DOMSource source = new DOMSource(document);
StreamResult result = new StreamResult(out);
transformer.transform(source, result);
} catch (TransformerException e) {
throw new IOException(e);
}
}
示例5: convert
import org.apache.batik.svggen.SVGGeneratorContext; //导入方法依赖的package包/类
/** {@inheritDoc} */
public Image convert(Image src, Map hints) throws ImageException {
checkSourceFlavor(src);
ImageGraphics2D g2dImage = (ImageGraphics2D)src;
DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
// Create an instance of org.w3c.dom.Document
Document document = domImpl.createDocument(
SVGDOMImplementation.SVG_NAMESPACE_URI, "svg", null);
Element root = document.getDocumentElement();
// Create an SVGGeneratorContext to customize SVG generation
SVGGeneratorContext genCtx = SVGGeneratorContext.createDefault(document);
genCtx.setComment("Generated by Apache Batik's SVGGraphics2D");
genCtx.setEmbeddedFontsOn(true);
// Create an instance of the SVG Generator
SVGGraphics2D g2d = new SVGGraphics2D(genCtx, true);
ImageSize size = src.getSize();
Dimension dim = size.getDimensionMpt();
g2d.setSVGCanvasSize(dim);
//SVGGraphics2D doesn't generate the viewBox by itself
root.setAttribute("viewBox", "0 0 " + dim.width + " " + dim.height);
g2dImage.getGraphics2DImagePainter().paint(g2d,
new Rectangle2D.Float(0, 0, dim.width, dim.height));
//Populate the document root with the generated SVG content.
g2d.getRoot(root);
//Return the generated SVG image
ImageXMLDOM svgImage = new ImageXMLDOM(src.getInfo(), document, BatikImageFlavors.SVG_DOM);
g2d.dispose();
return svgImage;
}
示例6: renderPage
import org.apache.batik.svggen.SVGGeneratorContext; //导入方法依赖的package包/类
/** {@inheritDoc} */
public void renderPage(PageViewport pageViewport) throws IOException {
log.debug("Rendering page: " + pageViewport.getPageNumberString());
// Get a DOMImplementation
DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
// Create an instance of org.w3c.dom.Document
this.document = domImpl.createDocument(null, "svg", null);
// Create an SVGGeneratorContext to customize SVG generation
SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(this.document);
ctx.setComment("Generated by " + userAgent.getProducer() + " with Batik SVG Generator");
ctx.setEmbeddedFontsOn(true);
// Create an instance of the SVG Generator
this.svgGenerator = new SVGGraphics2D(ctx, true);
Rectangle2D viewArea = pageViewport.getViewArea();
Dimension dim = new Dimension();
dim.setSize(viewArea.getWidth() / 1000, viewArea.getHeight() / 1000);
this.svgGenerator.setSVGCanvasSize(dim);
AffineTransform at = this.svgGenerator.getTransform();
this.state = new Java2DGraphicsState(this.svgGenerator, this.fontInfo, at);
try {
//super.renderPage(pageViewport);
renderPageAreas(pageViewport.getPage());
} finally {
this.state = null;
}
writeSVGFile(pageViewport.getPageIndex());
this.svgGenerator = null;
this.document = null;
}
示例7: exportSVG
import org.apache.batik.svggen.SVGGeneratorContext; //导入方法依赖的package包/类
/**
* Generate an SVG document from the supplied information. Note, use cavasSize first if you want
* to change the default output size.
*
* @param map
* Contains the layers (features + styles) to be rendered
* @param env
* The portion of the map to generate an SVG from
* @param out
* Stream to write the resulting SVG out to (probable should be a new file)
* @param canvasSize
* optional canvas size, will default to 300x300
* @throws IOException
* Should anything go wrong whilst writing to 'out'
* @throws ParserConfigurationException
* If critical XML tools are missing from the classpath
*/
public static void exportSVG(MapContent map, ReferencedEnvelope env, OutputStream out,
Dimension canvasSize) throws IOException, ParserConfigurationException {
if (canvasSize == null) {
canvasSize = new Dimension(300, 300); // default of 300x300
}
Document document = null;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
// Create an instance of org.w3c.dom.Document
document = db.getDOMImplementation().createDocument(null, "svg", null);
// Set up the map
SVGGeneratorContext ctx1 = SVGGeneratorContext.createDefault(document);
SVGGeneratorContext ctx = ctx1;
ctx.setComment("Generated by GeoTools2 with Batik SVG Generator");
SVGGraphics2D g2d = new SVGGraphics2D(ctx, true);
g2d.setSVGCanvasSize(canvasSize);
StreamingRenderer renderer = new StreamingRenderer();
renderer.setMapContent(map);
Rectangle outputArea = new Rectangle(g2d.getSVGCanvasSize());
ReferencedEnvelope dataArea = map.getMaxBounds();
LOGGER.finest("rendering map");
renderer.paint(g2d, outputArea, dataArea);
LOGGER.finest("writing to file");
OutputStreamWriter osw = null;
try {
osw = new OutputStreamWriter(out, "UTF-8");
g2d.stream(osw);
} finally {
if (osw != null)
osw.close();
}
}