Search in sources :

Example 41 with DOMImplementation

use of org.w3c.dom.DOMImplementation in project yamcs-studio by yamcs.

the class SimpleImageTranscoder method applyMatrix.

private Document applyMatrix(double[][] matrix) {
    // creation of the SVG document
    DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
    String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
    final Document newDocument = impl.createDocument(svgNS, "svg", null);
    // get the root element (the 'svg' element).
    Element svgRoot = newDocument.getDocumentElement();
    // get the original document size
    SVGSVGElement svgElmt = ((SVGOMDocument) originalDocument).getRootElement();
    double width = 30;
    double height = 30;
    try {
        width = svgElmt.getWidth().getBaseVal().getValue();
        height = svgElmt.getHeight().getBaseVal().getValue();
    } catch (NullPointerException e) {
        // FIXME
        // this is a dirty workaround for the RAP problem, which doesn't know how to
        // transform between units and pixels. Here we assume that all units are inches
        // and 96 dpi is used.
        SVGLength length = svgElmt.getWidth().getBaseVal();
        double value = length.getValueInSpecifiedUnits();
        width = value * 25.4 / 0.26458333333333333333333333333333;
        length = svgElmt.getHeight().getBaseVal();
        value = length.getValueInSpecifiedUnits();
        height = value * 25.4 / 0.26458333333333333333333333333333;
    }
    // current Transformation Matrix
    double[][] CTM = { { matrix[0][0], matrix[0][1], 0 }, { matrix[1][0], matrix[1][1], 0 }, { 0, 0, 1 } };
    // apply permutation to viewBox corner points
    double[] a = transformP(0.0, 0.0, 1.0, CTM);
    double[] b = transformP(width, 0.0, 1.0, CTM);
    double[] c = transformP(width, height, 1.0, CTM);
    double[] d = transformP(0.0, height, 1.0, CTM);
    // find new points
    double minX = findMin(a[0], b[0], c[0], d[0]);
    double minY = findMin(a[1], b[1], c[1], d[1]);
    double maxX = findMax(a[0], b[0], c[0], d[0]);
    double maxY = findMax(a[1], b[1], c[1], d[1]);
    double newWidth = maxX - minX;
    double newHeight = maxY - minY;
    // set the width and height attributes on the root 'svg' element.
    svgRoot.setAttributeNS(null, "width", String.valueOf(newWidth));
    svgRoot.setAttributeNS(null, "height", String.valueOf(newHeight));
    String vbs = minX + " " + minY + " " + newWidth + " " + newHeight;
    svgRoot.setAttributeNS(null, "viewBox", vbs);
    svgRoot.setAttributeNS(null, "preserveAspectRatio", "none");
    // Create the transform matrix
    StringBuilder sb = new StringBuilder();
    // a c e
    // b d f
    // 0 0 1
    sb.append("matrix(");
    sb.append(CTM[0][0] + ",");
    sb.append(CTM[1][0] + ",");
    sb.append(CTM[0][1] + ",");
    sb.append(CTM[1][1] + ",");
    sb.append(CTM[0][2] + ",");
    sb.append(CTM[1][2] + ")");
    Element graphic = newDocument.createElementNS(svgNS, "g");
    graphic.setAttributeNS(null, "transform", sb.toString());
    // Attach the transform to the root 'svg' element.
    Node copiedRoot = newDocument.importNode(originalDocument.getDocumentElement(), true);
    graphic.appendChild(copiedRoot);
    svgRoot.appendChild(graphic);
    // }
    return newDocument;
}
Also used : SVGSVGElement(org.w3c.dom.svg.SVGSVGElement) SVGStylableElement(org.apache.batik.anim.dom.SVGStylableElement) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) SVGLength(org.w3c.dom.svg.SVGLength) DOMImplementation(org.w3c.dom.DOMImplementation) SVGDOMImplementation(org.apache.batik.anim.dom.SVGDOMImplementation) Document(org.w3c.dom.Document) SVGOMDocument(org.apache.batik.anim.dom.SVGOMDocument) SVGSVGElement(org.w3c.dom.svg.SVGSVGElement) SVGOMDocument(org.apache.batik.anim.dom.SVGOMDocument)

Example 42 with DOMImplementation

use of org.w3c.dom.DOMImplementation in project j2objc by google.

the class XPathExpressionImpl method getDummyDocument.

private static Document getDummyDocument() {
    try {
        if (dbf == null) {
            dbf = DocumentBuilderFactory.newInstance();
            dbf.setNamespaceAware(true);
            dbf.setValidating(false);
        }
        db = dbf.newDocumentBuilder();
        DOMImplementation dim = db.getDOMImplementation();
        d = dim.createDocument("http://java.sun.com/jaxp/xpath", "dummyroot", null);
        return d;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : DOMImplementation(org.w3c.dom.DOMImplementation) XPathExpressionException(javax.xml.xpath.XPathExpressionException) TransformerException(javax.xml.transform.TransformerException)

Example 43 with DOMImplementation

use of org.w3c.dom.DOMImplementation in project buck by facebook.

the class SchemeGenerator method serializeScheme.

private static void serializeScheme(XCScheme scheme, OutputStream stream) {
    DocumentBuilder docBuilder;
    Transformer transformer;
    try {
        docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        transformer = TransformerFactory.newInstance().newTransformer();
    } catch (ParserConfigurationException | TransformerConfigurationException e) {
        throw new RuntimeException(e);
    }
    DOMImplementation domImplementation = docBuilder.getDOMImplementation();
    Document doc = domImplementation.createDocument(null, "Scheme", null);
    doc.setXmlVersion("1.0");
    Element rootElem = doc.getDocumentElement();
    rootElem.setAttribute("LastUpgradeVersion", "9999");
    rootElem.setAttribute("version", "1.7");
    Optional<XCScheme.BuildAction> buildAction = scheme.getBuildAction();
    if (buildAction.isPresent()) {
        Element buildActionElem = serializeBuildAction(doc, buildAction.get());
        rootElem.appendChild(buildActionElem);
    }
    Optional<XCScheme.TestAction> testAction = scheme.getTestAction();
    if (testAction.isPresent()) {
        Element testActionElem = serializeTestAction(doc, testAction.get());
        testActionElem.setAttribute("buildConfiguration", scheme.getTestAction().get().getBuildConfiguration());
        rootElem.appendChild(testActionElem);
    }
    Optional<XCScheme.LaunchAction> launchAction = scheme.getLaunchAction();
    if (launchAction.isPresent()) {
        Element launchActionElem = serializeLaunchAction(doc, launchAction.get());
        launchActionElem.setAttribute("buildConfiguration", launchAction.get().getBuildConfiguration());
        rootElem.appendChild(launchActionElem);
    } else {
        Element launchActionElem = doc.createElement("LaunchAction");
        launchActionElem.setAttribute("buildConfiguration", "Debug");
        rootElem.appendChild(launchActionElem);
    }
    Optional<XCScheme.ProfileAction> profileAction = scheme.getProfileAction();
    if (profileAction.isPresent()) {
        Element profileActionElem = serializeProfileAction(doc, profileAction.get());
        profileActionElem.setAttribute("buildConfiguration", profileAction.get().getBuildConfiguration());
        rootElem.appendChild(profileActionElem);
    } else {
        Element profileActionElem = doc.createElement("ProfileAction");
        profileActionElem.setAttribute("buildConfiguration", "Release");
        rootElem.appendChild(profileActionElem);
    }
    Optional<XCScheme.AnalyzeAction> analyzeAction = scheme.getAnalyzeAction();
    if (analyzeAction.isPresent()) {
        Element analyzeActionElem = doc.createElement("AnalyzeAction");
        analyzeActionElem.setAttribute("buildConfiguration", analyzeAction.get().getBuildConfiguration());
        rootElem.appendChild(analyzeActionElem);
    } else {
        Element analyzeActionElem = doc.createElement("AnalyzeAction");
        analyzeActionElem.setAttribute("buildConfiguration", "Debug");
        rootElem.appendChild(analyzeActionElem);
    }
    Optional<XCScheme.ArchiveAction> archiveAction = scheme.getArchiveAction();
    if (archiveAction.isPresent()) {
        Element archiveActionElem = doc.createElement("ArchiveAction");
        archiveActionElem.setAttribute("buildConfiguration", archiveAction.get().getBuildConfiguration());
        archiveActionElem.setAttribute("revealArchiveInOrganizer", "YES");
        rootElem.appendChild(archiveActionElem);
    } else {
        Element archiveActionElem = doc.createElement("ArchiveAction");
        archiveActionElem.setAttribute("buildConfiguration", "Release");
        rootElem.appendChild(archiveActionElem);
    }
    // write out
    DOMSource source = new DOMSource(doc);
    StreamResult result = new StreamResult(stream);
    try {
        transformer.transform(source, result);
    } catch (TransformerException e) {
        throw new RuntimeException(e);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) StreamResult(javax.xml.transform.stream.StreamResult) Element(org.w3c.dom.Element) DOMImplementation(org.w3c.dom.DOMImplementation) Document(org.w3c.dom.Document) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) TransformerException(javax.xml.transform.TransformerException)

Example 44 with DOMImplementation

use of org.w3c.dom.DOMImplementation in project robovm by robovm.

the class XPathImpl method getDummyDocument.

private static Document getDummyDocument() {
    // enter this code at the same time, we just waste a little time
    if (d == null) {
        DOMImplementation dim = getParser().getDOMImplementation();
        d = dim.createDocument("http://java.sun.com/jaxp/xpath", "dummyroot", null);
    }
    return d;
}
Also used : DOMImplementation(org.w3c.dom.DOMImplementation)

Example 45 with DOMImplementation

use of org.w3c.dom.DOMImplementation in project processing by processing.

the class PGraphicsSVG method beginDraw.

public void beginDraw() {
    DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
    // Create an instance of org.w3c.dom.Document.
    String ns = "http://www.w3.org/2000/svg";
    Document document = domImpl.createDocument(ns, "svg", null);
    // Create an instance of the SVG Generator.
    g2 = new SVGGraphics2D(document);
    ((SVGGraphics2D) g2).setSVGCanvasSize(new Dimension(width, height));
    // Done with our work, let's check on defaults and the rest
    //super.beginDraw();
    // Can't call super.beginDraw() because it'll nuke our g2
    checkSettings();
    // reset model matrix
    resetMatrix();
    vertexCount = 0;
    // Also need to push the matrix since the matrix doesn't reset on each run
    // http://dev.processing.org/bugs/show_bug.cgi?id=1227
    pushMatrix();
}
Also used : 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)

Aggregations

DOMImplementation (org.w3c.dom.DOMImplementation)82 Document (org.w3c.dom.Document)67 DOMException (org.w3c.dom.DOMException)35 Element (org.w3c.dom.Element)34 DocumentType (org.w3c.dom.DocumentType)28 DocumentBuilder (javax.xml.parsers.DocumentBuilder)25 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)22 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)22 ArrayList (java.util.ArrayList)8 TransformerException (javax.xml.transform.TransformerException)6 DOMImplementationRegistry (org.w3c.dom.bootstrap.DOMImplementationRegistry)6 DOMImplementationLS (org.w3c.dom.ls.DOMImplementationLS)6 IOException (java.io.IOException)5 Transformer (javax.xml.transform.Transformer)5 DOMSource (javax.xml.transform.dom.DOMSource)5 StreamResult (javax.xml.transform.stream.StreamResult)5 Node (org.w3c.dom.Node)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 NodeList (org.w3c.dom.NodeList)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3