本文整理汇总了Java中org.apache.batik.svggen.SVGGeneratorContext.setEmbeddedFontsOn方法的典型用法代码示例。如果您正苦于以下问题:Java SVGGeneratorContext.setEmbeddedFontsOn方法的具体用法?Java SVGGeneratorContext.setEmbeddedFontsOn怎么用?Java SVGGeneratorContext.setEmbeddedFontsOn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.batik.svggen.SVGGeneratorContext
的用法示例。
在下文中一共展示了SVGGeneratorContext.setEmbeddedFontsOn方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeSVG
import org.apache.batik.svggen.SVGGeneratorContext; //导入方法依赖的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: createSvgGraphics2D
import org.apache.batik.svggen.SVGGeneratorContext; //导入方法依赖的package包/类
public SVGGraphics2D createSvgGraphics2D() {
DOMImplementation impl = GenericDOMImplementation
.getDOMImplementation();
String namespaceURI = SVGConstants.SVG_NAMESPACE_URI;
Document domFactory = impl.createDocument(namespaceURI, "svg", null);
SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(domFactory);
ctx.setEmbeddedFontsOn(true);
GraphicContextDefaults defaults = new GraphicContextDefaults();
defaults.setFont(new Font("Arial", Font.PLAIN, 12));
ctx.setGraphicContextDefaults(defaults);
ctx.setPrecision(12);
SVGGraphics2D g2d = new SVGGraphics2D(ctx, false);
// This prevents the
// "null incompatible with text-specific antialiasing enable key" error
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_DEFAULT);
return g2d;
}
示例3: 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(); }
}
}
示例4: 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;
}
示例5: 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;
}