Changeset 1086
- Timestamp:
- 02/26/10 13:02:07 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/docx4j/src/pptx4j/java/org/pptx4j/convert/out/svginhtml/SvgExporter.java
r1085 r1086 25 25 import org.docx4j.dml.CTTextParagraphProperties; 26 26 import org.docx4j.dml.CTTransform2D; 27 import org.docx4j.dml.wordprocessingDrawing.Inline; 27 28 import org.docx4j.jaxb.Context; 28 29 import org.docx4j.model.styles.StyleTree; 29 30 import org.docx4j.model.styles.Tree; 30 31 import org.docx4j.model.styles.StyleTree.AugmentedStyle; 32 import org.docx4j.openpackaging.exceptions.Docx4JException; 31 33 import org.docx4j.openpackaging.exceptions.InvalidFormatException; 32 34 import org.docx4j.openpackaging.packages.PresentationMLPackage; 33 35 import org.docx4j.openpackaging.packages.WordprocessingMLPackage; 34 36 import org.docx4j.wml.PPr; 37 import org.docx4j.wml.Pict; 35 38 import org.docx4j.wml.Style; 36 39 import org.plutext.jaxb.svg11.Line; … … 49 52 import org.w3c.dom.Node; 50 53 import org.w3c.dom.NodeList; 54 import org.w3c.dom.Text; 51 55 import org.w3c.dom.traversal.NodeIterator; 52 56 … … 355 359 NodeIterator shapeIt ) { 356 360 361 DocumentFragment docfrag=null; 362 Document d=null; 363 357 364 try { 358 Object shape = null; 359 365 Object shape = null; 360 366 if (shapeIt!=null) { 361 367 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 ); 368 if (n==null) { 369 d=makeErr( "[null node?!]" ); 370 } else { 371 log.debug("Handling " + n.getNodeName()); 372 373 if (n.getNodeName().equals("p:cxnSp") ) { 374 375 shape = nodeToObjectModel(n, CxnSp.class); 376 d = CxnSpToSVG( (CxnSp)shape); 377 378 } else { 379 log.info("** TODO " + n.getNodeName() ); 380 d=makeErr( "[" + n.getNodeName() + "]" ); 381 } 388 382 } 389 383 } 390 384 } catch (Exception e) { 391 // TODO Auto-generated catch block 392 e.printStackTrace(); 393 } 394 return null; 395 385 log.error(e); 386 d=makeErr(e.getMessage() ); 387 } 388 389 // Machinery 390 docfrag = d.createDocumentFragment(); 391 docfrag.appendChild(d.getDocumentElement()); 392 return docfrag; 396 393 } 397 394 398 395 396 /** 397 * Connection (line) 398 */ 399 399 public static Document CxnSpToSVG(CxnSp cxnSp) { 400 401 400 402 401 // Geometrical transforms … … 423 422 // Firefox needs the following; Chrome doesn't 424 423 xhtmlDiv.setAttribute("style", 425 "position: absolute; width:100%; height:100%; left:0px; top:0px;"); 426 424 "position: absolute; width:100%; height:100%; left:0px; top:0px;"); 427 425 Node n = document.appendChild(xhtmlDiv); 428 // TODO - set style429 426 430 427 // Convert the object itself to SVG … … 449 446 return document; 450 447 448 } 449 450 private static Document makeErr(String msg) { 451 Document d=null; 452 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 453 try { 454 d = factory.newDocumentBuilder().newDocument(); 455 } catch (ParserConfigurationException e1) { 456 // TODO Auto-generated catch block 457 e1.printStackTrace(); 458 } 459 Element span = d.createElement("span"); 460 span.setAttribute("style", "color:red;"); 461 d.appendChild(span); 462 463 Text err = d.createTextNode( msg ); 464 span.appendChild(err); 465 return d; 466 } 467 468 public static Object nodeToObjectModel(Node n, Class declaredType) throws Docx4JException { 469 Object jaxb=null; 470 try { 471 jaxb = XmlUtils.unmarshal(n, Context.jcPML, declaredType); 472 } catch (JAXBException e1) { 473 throw new Docx4JException("Couldn't unmarshall " + XmlUtils.w3CDomNodeToString(n), e1); 474 } 475 try { 476 if (jaxb instanceof JAXBElement ) { 477 478 JAXBElement jb = (JAXBElement)jaxb; 479 if (jb.getDeclaredType().getName().equals(declaredType.getName() )) { 480 return jb.getValue(); 481 } else { 482 log.error("UNEXPECTED " + 483 XmlUtils.JAXBElementDebug(jb) 484 ); 485 throw new Docx4JException("Expected " + declaredType.getName() + " but got " + 486 XmlUtils.JAXBElementDebug(jb) ); 487 } 488 } else if (jaxb.getClass().getName().equals(declaredType.getName() )) { 489 return jaxb; 490 } else { 491 log.error( jaxb.getClass().getName() ); 492 throw new Docx4JException("Expected " + declaredType.getName() + " but got " + 493 jaxb.getClass().getName() ); 494 } 495 } catch (ClassCastException e) { 496 throw new Docx4JException("Expected " + declaredType.getName() + " but got " + 497 jaxb.getClass().getName(), e ); 498 } 451 499 } 452 500
Note: See TracChangeset
for help on using the changeset viewer.
