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