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