Search in sources :

Example 1 with SVGGeneratorContext

use of org.apache.batik.svggen.SVGGeneratorContext in project archi by archimatetool.

the class AbstractExportProviderTests method testCreateContext.

@Test
public void testCreateContext() {
    provider.init(mock(IExportDialogAdapter.class), shell, rootFigure);
    SVGGeneratorContext ctx = provider.createContext(mock(Document.class), true);
    assertNotNull(ctx);
    assertTrue(ctx.isEmbeddedFontsOn());
    assertTrue(ctx.getComment().startsWith("Generated by Archi"));
}
Also used : IExportDialogAdapter(com.archimatetool.editor.diagram.IImageExportProvider.IExportDialogAdapter) SVGGeneratorContext(org.apache.batik.svggen.SVGGeneratorContext) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 2 with SVGGeneratorContext

use of org.apache.batik.svggen.SVGGeneratorContext 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)

Example 3 with SVGGeneratorContext

use of org.apache.batik.svggen.SVGGeneratorContext in project grafikon by jub77.

the class DrawOutput method processSvg.

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);
    }
}
Also used : HashMap(java.util.HashMap) DOMImplementation(org.w3c.dom.DOMImplementation) GenericDOMImplementation(org.apache.batik.dom.GenericDOMImplementation) SVGGraphics2D(org.apache.batik.svggen.SVGGraphics2D) Dimension(java.awt.Dimension) IOException(java.io.IOException) Document(org.w3c.dom.Document) SVGGeneratorContext(org.apache.batik.svggen.SVGGeneratorContext) Font(java.awt.Font) RenderingHints(java.awt.RenderingHints) OutputException(net.parostroj.timetable.output2.OutputException) OutputStreamWriter(java.io.OutputStreamWriter) Key(java.awt.RenderingHints.Key) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer)

Example 4 with SVGGeneratorContext

use of org.apache.batik.svggen.SVGGeneratorContext in project archi by archimatetool.

the class AbstractExportProvider method initialiseGraphics.

protected void initialiseGraphics() {
    // Ensure user fonts are loaded into AWT for Windows
    loadUserFontsIntoAWT();
    // Create a DOM Document
    Document document = createDocument();
    // Create a context for customisation
    // Don't embed fonts
    SVGGeneratorContext ctx = createContext(document, false);
    // Create a Batik SVGGraphics2D instance
    // Text is drawn as shapes
    svgGraphics2D = new SVGGraphics2D(ctx, true);
    // Create a Graphiti wrapper adapter
    GraphicsToGraphics2DAdaptor graphicsAdaptor = createGraphicsToGraphics2DAdaptor(svgGraphics2D, viewPortBounds);
    // Paint the figure onto the graphics instance
    figure.paint(graphicsAdaptor);
    // Dispose of this
    graphicsAdaptor.dispose();
}
Also used : GraphicsToGraphics2DAdaptor(com.archimatetool.export.svg.graphiti.GraphicsToGraphics2DAdaptor) SVGGraphics2D(org.apache.batik.svggen.SVGGraphics2D) Document(org.w3c.dom.Document) SVGGeneratorContext(org.apache.batik.svggen.SVGGeneratorContext)

Example 5 with SVGGeneratorContext

use of org.apache.batik.svggen.SVGGeneratorContext in project archi by archimatetool.

the class AbstractExportProvider method createContext.

/**
 * Create a SVGGeneratorContext and set its attributes
 * @param document The DOM Document
 * @param embeddedFonts If true will embed fonts
 * @return The SVGGeneratorContext
 */
protected SVGGeneratorContext createContext(Document document, boolean embedFonts) {
    SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(document);
    ctx.setEmbeddedFontsOn(embedFonts);
    // Add a comment
    ctx.setComment(Messages.SVGExportProvider_1);
    return ctx;
}
Also used : SVGGeneratorContext(org.apache.batik.svggen.SVGGeneratorContext)

Aggregations

SVGGeneratorContext (org.apache.batik.svggen.SVGGeneratorContext)6 SVGGraphics2D (org.apache.batik.svggen.SVGGraphics2D)4 Document (org.w3c.dom.Document)4 Dimension (java.awt.Dimension)2 Font (java.awt.Font)2 GenericDOMImplementation (org.apache.batik.dom.GenericDOMImplementation)2 DOMImplementation (org.w3c.dom.DOMImplementation)2 IExportDialogAdapter (com.archimatetool.editor.diagram.IImageExportProvider.IExportDialogAdapter)1 GraphicsToGraphics2DAdaptor (com.archimatetool.export.svg.graphiti.GraphicsToGraphics2DAdaptor)1 Rectangle (java.awt.Rectangle)1 RenderingHints (java.awt.RenderingHints)1 Key (java.awt.RenderingHints.Key)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 HashMap (java.util.HashMap)1 OutputException (net.parostroj.timetable.output2.OutputException)1 GraphicContextDefaults (org.apache.batik.svggen.SVGGeneratorContext.GraphicContextDefaults)1 Test (org.junit.Test)1 Element (org.w3c.dom.Element)1