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"));
}
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);
}
}
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);
}
}
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();
}
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;
}
Aggregations