- Timestamp:
- 02/26/10 00:55:07 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/docx4j/src/pptx4j/java/org/pptx4j/convert/out/svginhtml/SvgExporter.java
r1061 r1085 4 4 import java.io.IOException; 5 5 6 import javax.xml.bind.JAXBContext; 7 import javax.xml.bind.JAXBElement; 6 8 import javax.xml.bind.JAXBException; 7 9 import javax.xml.bind.Unmarshaller; 8 10 import javax.xml.parsers.DocumentBuilderFactory; 11 import javax.xml.parsers.ParserConfigurationException; 9 12 import javax.xml.transform.Result; 10 13 import javax.xml.transform.Source; … … 21 24 import org.docx4j.dml.CTTextListStyle; 22 25 import org.docx4j.dml.CTTextParagraphProperties; 26 import org.docx4j.dml.CTTransform2D; 23 27 import org.docx4j.jaxb.Context; 24 28 import org.docx4j.model.styles.StyleTree; … … 30 34 import org.docx4j.wml.PPr; 31 35 import org.docx4j.wml.Style; 36 import org.plutext.jaxb.svg11.Line; 37 import org.plutext.jaxb.svg11.ObjectFactory; 38 import org.plutext.jaxb.svg11.Svg; 39 import org.pptx4j.Box; 40 import org.pptx4j.Point; 32 41 import org.pptx4j.model.ResolvedLayout; 33 42 import org.pptx4j.model.TextStyles; 43 import org.pptx4j.pml.CxnSp; 34 44 import org.pptx4j.pml.GroupShape; 35 45 import org.w3c.dom.DOMException; … … 44 54 45 55 protected static Logger log = Logger.getLogger(SvgExporter.class); 46 56 57 static JAXBContext jcSVG; 58 static ObjectFactory oFactory; 47 59 static Templates xslt; 48 60 static { 61 49 62 try { 63 jcSVG = JAXBContext.newInstance("org.plutext.jaxb.svg11"); 64 oFactory = new ObjectFactory(); 65 50 66 Source xsltSource = new StreamSource( 51 67 org.docx4j.utils.ResourceUtils.getResource( 52 68 "org/pptx4j/convert/out/svginhtml/pptx2svginhtml.xslt")); 53 69 xslt = XmlUtils.getTransformerTemplate(xsltSource); 54 } catch ( IOException e) {70 } catch (Exception e) { 55 71 e.printStackTrace(); 56 } catch (TransformerConfigurationException e) { 57 e.printStackTrace(); 58 } 72 } 59 73 } 60 74 … … 68 82 69 83 String svg = intermediate.toString("UTF-8"); 70 log. debug(svg);84 log.info(svg); 71 85 } 72 86 … … 337 351 } 338 352 339 353 public static DocumentFragment shapeToSVG( 354 PresentationMLPackage pmlPackage, 355 NodeIterator shapeIt ) { 356 357 try { 358 Object shape = null; 359 360 if (shapeIt!=null) { 361 Node n = shapeIt.nextNode(); 362 363 log.debug(n.getClass().getName()); 364 // cxnSp 365 // System.out.println(n.getLocalName()); 366 // p:cxnSp 367 // System.out.println(n.getNodeName()); 368 369 String str = XmlUtils.w3CDomNodeToString(n); 370 System.out.println("STRING-->" + str); 371 if (str.equals("")) { 372 373 } else if (str.startsWith("<p:cxnSp") ){ 374 shape = XmlUtils.unmarshalString(str, Context.jcPML, CxnSp.class); 375 Document d = CxnSpToSVG( (CxnSp)shape); 376 377 // Machinery 378 DocumentFragment docfrag = d.createDocumentFragment(); 379 docfrag.appendChild(d.getDocumentElement()); 380 return docfrag; 381 } 382 383 log.info("** GOT " + shape.getClass().getName() ); 384 if (shape instanceof JAXBElement) { 385 log.info( 386 XmlUtils.JAXBElementDebug( (JAXBElement)shape) 387 ); 388 } 389 } 390 } catch (Exception e) { 391 // TODO Auto-generated catch block 392 e.printStackTrace(); 393 } 394 return null; 395 396 } 397 398 399 public static Document CxnSpToSVG(CxnSp cxnSp) { 400 401 402 // Geometrical transforms 403 CTTransform2D xfrm = cxnSp.getSpPr().getXfrm(); 404 Box b = new Box(xfrm.getOff().getX(), xfrm.getOff().getY(), 405 xfrm.getExt().getCx(), xfrm.getExt().getCx() ); 406 407 if (xfrm.getRot()!=0) { 408 b.rotate(xfrm.getRot()); 409 } 410 if (xfrm.isFlipH() ) { 411 b.flipH(); 412 } 413 if (xfrm.isFlipV() ) { 414 b.flipV(); 415 } 416 417 // Convert from EMU to pixels 418 b.toPixels(); 419 420 // Wrap in a div positioning it on the page 421 Document document = createDocument(); 422 Element xhtmlDiv = document.createElement("div"); 423 // Firefox needs the following; Chrome doesn't 424 xhtmlDiv.setAttribute("style", 425 "position: absolute; width:100%; height:100%; left:0px; top:0px;"); 426 427 Node n = document.appendChild(xhtmlDiv); 428 // TODO - set style 429 430 // Convert the object itself to SVG 431 Svg svg = oFactory.createSvg(); 432 Line line = oFactory.createLine(); 433 svg.getSVGDescriptionClassOrSVGAnimationClassOrSVGStructureClass().add(line); 434 435 line.setX1(b.getOffset().getXAsString() ); 436 line.setY1(b.getOffset().getYAsString() ); 437 438 Point otherEnd = b.getOtherCorner(); 439 440 line.setX2( otherEnd.getXAsString() ); 441 line.setY2( otherEnd.getYAsString() ); 442 443 line.setStyle("stroke:rgb(99,99,99)"); 444 // You can't see the line in Midori, unless you specify the color. 445 // width eg stroke-width:2 is optional 446 447 Document d2 = XmlUtils.marshaltoW3CDomDocument(svg, jcSVG); 448 XmlUtils.treeCopy(d2, n); 449 return document; 450 451 } 452 453 public static Document createDocument() { 454 455 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 456 Document document=null; 457 try { 458 document = factory.newDocumentBuilder().newDocument(); 459 } catch (ParserConfigurationException e) { 460 e.printStackTrace(); 461 } 462 return document; 463 } 340 464 }
Note: See TracChangeset
for help on using the changeset viewer.
