Ejemplo n.º 1
0
  private static void svg(
      PresentationMLPackage presentationMLPackage,
      ResolvedLayout layout,
      javax.xml.transform.Result result,
      SvgSettings settings)
      throws Exception {
    SvgConversionContext context = null;
    org.w3c.dom.Document doc =
        XmlUtils.marshaltoW3CDomDocument(
            layout.getShapeTree(),
            Context.jcPML,
            "http://schemas.openxmlformats.org/presentationml/2006/main",
            "spTree",
            GroupShape.class);

    if (settings == null) {
      settings = new SvgSettings();
    }
    if ((settings.getImageDirPath() == null) && (imageDirPath != null)) {
      settings.setImageDirPath(imageDirPath);
    }

    context = new SvgConversionContext(settings, presentationMLPackage, layout);
    org.docx4j.XmlUtils.transform(doc, xslt, context.getXsltParameters(), result);
  }
Ejemplo n.º 2
0
  /** Connection (line) */
  public static Document CxnSpToSVG(CxnSp cxnSp) {

    // Geometrical transforms
    CTTransform2D xfrm = cxnSp.getSpPr().getXfrm();
    Box b =
        new Box(
            xfrm.getOff().getX(),
            xfrm.getOff().getY(),
            xfrm.getExt().getCx(),
            xfrm.getExt().getCy());

    if (xfrm.getRot() != 0) {
      b.rotate(xfrm.getRot());
    }
    if (xfrm.isFlipH()) {
      b.flipH();
    }
    if (xfrm.isFlipV()) {
      b.flipV();
    }

    // Convert from EMU to pixels
    b.toPixels();

    // Wrap in a div positioning it on the page
    Document document = XmlUtils.getNewDocumentBuilder().newDocument();
    Element xhtmlDiv = document.createElement("div");
    // Firefox needs the following; Chrome doesn't
    xhtmlDiv.setAttribute(
        "style", "position: absolute; width:100%; height:100%; left:0px; top:0px;");
    Node n = document.appendChild(xhtmlDiv);

    // Convert the object itself to SVG
    Svg svg = oFactory.createSvg();
    Line line = oFactory.createLine();
    svg.getSVGDescriptionClassOrSVGAnimationClassOrSVGStructureClass().add(line);

    line.setX1(b.getOffset().getXAsString());
    line.setY1(b.getOffset().getYAsString());

    Point otherEnd = b.getOtherCorner();

    line.setX2(otherEnd.getXAsString());
    line.setY2(otherEnd.getYAsString());

    line.setStyle("stroke:rgb(99,99,99)");
    // You can't see the line in Midori, unless you specify the color.
    // width eg stroke-width:2 is optional

    Document d2 = XmlUtils.marshaltoW3CDomDocument(svg, jcSVG);
    XmlUtils.treeCopy(d2, n);
    return document;
  }