Skip to content

Instantly share code, notes, and snippets.

@offbynull
Last active January 14, 2020 22:58
Show Gist options
  • Select an option

  • Save offbynull/7f0e43a6973185bed008f7165654f509 to your computer and use it in GitHub Desktop.

Select an option

Save offbynull/7f0e43a6973185bed008f7165654f509 to your computer and use it in GitHub Desktop.
Apache Batik draw arc example
package com.mycompany.test;
import java.awt.Color;
import java.awt.Rectangle;
import java.awt.geom.Arc2D;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Path;
import org.apache.batik.dom.GenericDOMImplementation;
import org.apache.batik.svggen.SVGGeneratorContext;
import org.apache.batik.svggen.SVGGraphics2D;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
public final class Main {
public static void main(String[] args) throws IOException {
DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
Document document = domImpl.createDocument("http://www.w3.org/2000/svg", "svg", null);
SVGGraphics2D svgGenerator = new SVGGraphics2D(SVGGeneratorContext.createDefault(document), true);
svgGenerator.setPaint(Color.red);
svgGenerator.draw(new Arc2D.Double(0, 0, 400, 400, 0, 45, Arc2D.PIE));
svgGenerator.drawString("hello world", 100.0f, 100.0f);
try (Writer writer = Files.newBufferedWriter(Path.of("test.svg"))) {
svgGenerator.stream(writer, false);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment