Search in sources :

Example 1 with GraphicContextDefaults

use of org.apache.batik.svggen.SVGGeneratorContext.GraphicContextDefaults in project freeplane by freeplane.

the class ExportVectorGraphic method fillSVGGraphics2D.

/**
 */
protected SVGGraphics2D fillSVGGraphics2D(final MapView view) {
    // work around svg/pdf-Export problems when exporting with Gtk or Nimbus L&Fs
    final String previousLnF = UIManager.getLookAndFeel().getClass().getName();
    setLnF(view, UIManager.getCrossPlatformLookAndFeelClassName());
    try {
        final DOMImplementation impl = GenericDOMImplementation.getDOMImplementation();
        final String namespaceURI = SVGConstants.SVG_NAMESPACE_URI;
        final Document domFactory = impl.createDocument(namespaceURI, "svg", null);
        final SVGGeneratorContext ctx = createGeneratorContext(domFactory);
        final GraphicContextDefaults defaults = new GraphicContextDefaults();
        defaults.setFont(new Font("Arial", Font.PLAIN, 12));
        ctx.setGraphicContextDefaults(defaults);
        ctx.setExtensionHandler(new GradientExtensionHandler());
        ctx.setPrecision(12);
        final SVGGraphics2D g2d = new SVGGraphics2D(ctx, false);
        g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT);
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT);
        view.preparePrinting();
        final Rectangle innerBounds = view.getInnerBounds();
        g2d.setSVGCanvasSize(new Dimension(innerBounds.width, innerBounds.height));
        g2d.translate(-innerBounds.x, -innerBounds.y);
        view.print(g2d);
        view.endPrinting();
        return g2d;
    } finally {
        setLnF(view, previousLnF);
    }
}
Also used : Rectangle(java.awt.Rectangle) GenericDOMImplementation(org.apache.batik.dom.GenericDOMImplementation) DOMImplementation(org.w3c.dom.DOMImplementation) SVGGraphics2D(org.apache.batik.svggen.SVGGraphics2D) Dimension(java.awt.Dimension) Document(org.w3c.dom.Document) SVGGeneratorContext(org.apache.batik.svggen.SVGGeneratorContext) GraphicContextDefaults(org.apache.batik.svggen.SVGGeneratorContext.GraphicContextDefaults) Font(java.awt.Font)

Aggregations

Dimension (java.awt.Dimension)1 Font (java.awt.Font)1 Rectangle (java.awt.Rectangle)1 GenericDOMImplementation (org.apache.batik.dom.GenericDOMImplementation)1 SVGGeneratorContext (org.apache.batik.svggen.SVGGeneratorContext)1 GraphicContextDefaults (org.apache.batik.svggen.SVGGeneratorContext.GraphicContextDefaults)1 SVGGraphics2D (org.apache.batik.svggen.SVGGraphics2D)1 DOMImplementation (org.w3c.dom.DOMImplementation)1 Document (org.w3c.dom.Document)1