Search in sources :

Example 1 with DOMTreeManager

use of org.apache.batik.svggen.DOMTreeManager in project jmathanim by davidgutierrezrubio.

the class LaTeXMathObject method generateDOMTreeFromLaTeX.

private Element generateDOMTreeFromLaTeX(String text) {
    Writer out = null;
    DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
    String latexText;
    if (mode == CompileMode.JLaTexMath) {
        latexText = "\\mbox{" + text + "}";
    } else {
        latexText = text;
    }
    TeXFormula formula = new TeXFormula(latexText);
    TeXIcon icon = formula.createTeXIcon(TeXConstants.ALIGN_LEFT, 40);
    String svgNS = "http://www.w3.org/2000/svg";
    Document document = domImpl.createDocument(svgNS, "svg", null);
    // Create an instance of the SVG Generator.
    SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(document);
    SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, true);
    ctx.setEmbeddedFontsOn(true);
    icon.paintIcon(null, svgGenerator, 0, 0);
    DOMTreeManager domTreeManager = svgGenerator.getDOMTreeManager();
    Element domFactory = svgGenerator.getRoot();
    return domFactory;
}
Also used : DOMTreeManager(org.apache.batik.svggen.DOMTreeManager) TeXFormula(org.scilab.forge.jlatexmath.TeXFormula) Element(org.w3c.dom.Element) DOMImplementation(org.w3c.dom.DOMImplementation) GenericDOMImplementation(org.apache.batik.dom.GenericDOMImplementation) SVGGraphics2D(org.apache.batik.svggen.SVGGraphics2D) Document(org.w3c.dom.Document) SVGGeneratorContext(org.apache.batik.svggen.SVGGeneratorContext) PrintWriter(java.io.PrintWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer) TeXIcon(org.scilab.forge.jlatexmath.TeXIcon)

Example 2 with DOMTreeManager

use of org.apache.batik.svggen.DOMTreeManager in project tmdmaker by tmdmaker.

the class GraphicsSVG method drawRenderedImage.

/* (non-Javadoc)
	 * @see org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.graphics.GraphicsToGraphics2DAdaptor#drawRenderedImage(org.eclipse.gmf.runtime.draw2d.ui.render.RenderedImage, org.eclipse.draw2d.geometry.Rectangle, org.eclipse.gmf.runtime.draw2d.ui.render.RenderingListener)
	 */
public RenderedImage drawRenderedImage(RenderedImage srcImage, Rectangle rect, RenderingListener listener) {
    // Check for a change in the state
    checkState();
    // Get the Tree Manager
    DOMTreeManager treeManager = getSVGGraphics2D().getDOMTreeManager();
    Point trans = getTranslationOffset();
    // Get the Root element of the SVG document to export
    if (srcImage instanceof SVGImage) {
        Document document = ((SVGImage) srcImage).getDocument();
        DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
        document = DOMUtilities.deepCloneDocument(document, impl);
        if (document instanceof SVGOMDocument) {
            RenderInfo info = srcImage.getRenderInfo();
            if (info != null && info.getBackgroundColor() != null && info.getForegroundColor() != null) {
                SVGColorConverter.getInstance().replaceDocumentColors((SVGOMDocument) document, new Color(info.getBackgroundColor().red, info.getBackgroundColor().green, info.getBackgroundColor().blue), new Color(info.getForegroundColor().red, info.getForegroundColor().green, info.getForegroundColor().blue));
            }
        }
        Element root = document.getDocumentElement();
        // Create a "deep" copy of the document
        Element toAppend = (Element) doc.importNode(root, true);
        // Modify the X Attribute
        toAppend.setAttributeNS(null, SVGConstants.SVG_X_ATTRIBUTE, String.valueOf(rect.x + trans.x));
        // Modify the Y Attribute
        toAppend.setAttributeNS(null, SVGConstants.SVG_Y_ATTRIBUTE, String.valueOf(rect.y + trans.y));
        // Modify the Width Attribute
        toAppend.setAttributeNS(null, SVGConstants.SVG_WIDTH_ATTRIBUTE, String.valueOf(rect.width));
        // Modify the Height Attribute
        toAppend.setAttributeNS(null, SVGConstants.SVG_HEIGHT_ATTRIBUTE, String.valueOf(rect.height));
        treeManager.appendGroup(toAppend, null);
        return srcImage;
    } else {
        return super.drawRenderedImage(srcImage, rect, listener);
    }
}
Also used : SVGOMDocument(org.apache.batik.dom.svg.SVGOMDocument) DOMTreeManager(org.apache.batik.svggen.DOMTreeManager) Color(java.awt.Color) Element(org.w3c.dom.Element) SVGDOMImplementation(org.apache.batik.dom.svg.SVGDOMImplementation) DOMImplementation(org.w3c.dom.DOMImplementation) Point(org.eclipse.draw2d.geometry.Point) SVGOMDocument(org.apache.batik.dom.svg.SVGOMDocument) Document(org.w3c.dom.Document) RenderInfo(org.eclipse.gmf.runtime.draw2d.ui.render.RenderInfo) SVGImage(org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.svg.SVGImage)

Aggregations

DOMTreeManager (org.apache.batik.svggen.DOMTreeManager)2 DOMImplementation (org.w3c.dom.DOMImplementation)2 Document (org.w3c.dom.Document)2 Element (org.w3c.dom.Element)2 Color (java.awt.Color)1 FileWriter (java.io.FileWriter)1 PrintWriter (java.io.PrintWriter)1 Writer (java.io.Writer)1 GenericDOMImplementation (org.apache.batik.dom.GenericDOMImplementation)1 SVGDOMImplementation (org.apache.batik.dom.svg.SVGDOMImplementation)1 SVGOMDocument (org.apache.batik.dom.svg.SVGOMDocument)1 SVGGeneratorContext (org.apache.batik.svggen.SVGGeneratorContext)1 SVGGraphics2D (org.apache.batik.svggen.SVGGraphics2D)1 Point (org.eclipse.draw2d.geometry.Point)1 RenderInfo (org.eclipse.gmf.runtime.draw2d.ui.render.RenderInfo)1 SVGImage (org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.svg.SVGImage)1 TeXFormula (org.scilab.forge.jlatexmath.TeXFormula)1 TeXIcon (org.scilab.forge.jlatexmath.TeXIcon)1