本文整理汇总了Java中org.apache.batik.svggen.SVGGeneratorContext.setGraphicContextDefaults方法的典型用法代码示例。如果您正苦于以下问题:Java SVGGeneratorContext.setGraphicContextDefaults方法的具体用法?Java SVGGeneratorContext.setGraphicContextDefaults怎么用?Java SVGGeneratorContext.setGraphicContextDefaults使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.batik.svggen.SVGGeneratorContext
的用法示例。
在下文中一共展示了SVGGeneratorContext.setGraphicContextDefaults方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: processSvg
import org.apache.batik.svggen.SVGGeneratorContext; //导入方法依赖的package包/类
private void processSvg(Collection<Image> images, OutputStream stream, DrawLayout layout) throws OutputException {
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);
SVGGeneratorContext context = SVGGeneratorContext.createDefault(document);
context.setGraphicContextDefaults(new SVGGeneratorContext.GraphicContextDefaults());
// set default font
context.getGraphicContextDefaults().setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12));
// set antialiasing
Map<Key, Object> map = new HashMap<>();
map.put(RenderingHints.KEY_ANTIALIASING, Boolean.TRUE);
map.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
context.getGraphicContextDefaults().setRenderingHints(new RenderingHints(map));
SVGGraphics2D g2d = new SVGGraphics2D(context, false);
List<Dimension> sizes = this.getSizes(images, g2d);
Dimension size = this.getTotalSize(sizes, layout);
g2d.setSVGCanvasSize(size);
this.drawImages(sizes, images, g2d, layout);
// write to ouput - do not use css style
boolean useCSS = false;
try {
Writer out = new OutputStreamWriter(stream, "UTF-8");
g2d.stream(out, useCSS);
} catch (IOException e) {
throw new OutputException(e.getMessage(), e);
}
}