Changeset 1085
- Timestamp:
- 02/26/10 11:55:07 (2 years ago)
- Location:
- trunk/docx4j/src/pptx4j/java/org/pptx4j
- Files:
-
- 2 added
- 2 edited
-
Box.java (added)
-
Point.java (added)
-
convert/out/svginhtml/SvgExporter.java (modified) (6 diffs)
-
convert/out/svginhtml/pptx2svginhtml.xslt (modified) (6 diffs)
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 } -
trunk/docx4j/src/pptx4j/java/org/pptx4j/convert/out/svginhtml/pptx2svginhtml.xslt
r1061 r1085 1 1 2 2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 3 xmlns="http://www.w3.org/1999/xhtml" 3 4 xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" 4 5 xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" … … 30 31 31 32 but, for now, make indent yes--> 32 <xsl:output method="xml" encoding="utf-8" omit-xml-declaration="yes" indent="yes" /> 33 <xsl:output method="xml" encoding="utf-8" omit-xml-declaration="no" indent="yes" 34 doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" 35 doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/> 36 <!-- either strict or transitional work for inline SVG --> 33 37 34 38 <!-- Input to this transform is a Shape Tree p:spTree. 35 39 36 Ou put is SVG in HTML.40 Output is SVG in HTML. 37 41 38 42 <text x="{$x}" y="{$y}"><xsl:value-of select="a:p/a:r/a:t"/></text> … … 55 59 <xsl:param name="wmlPackage"/> <!-- really, its pml --> 56 60 <xsl:param name="resolvedLayout"/> 57 <!--58 <xsl:param name="modelStates"/>59 <xsl:param name="imageDirPath"/>60 61 <xsl:param name="fontMapper"/>62 <xsl:param name="fontFamilyStack"/>63 64 <xsl:param name="conditionalComments"/>65 -->66 67 <!--68 69 <p:spTree xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture">70 <p:nvGrpSpPr>71 <p:cNvPr name="" id="1"/>72 <p:cNvGrpSpPr/>73 <p:nvPr/>74 </p:nvGrpSpPr>75 <p:grpSpPr>76 <a:xfrm>77 <a:off y="0" x="0"/>78 <a:ext cy="0" cx="0"/>79 <a:chOff y="0" x="0"/>80 <a:chExt cy="0" cx="0"/>81 </a:xfrm>82 </p:grpSpPr>83 <p:sp>84 <p:nvSpPr>85 <p:cNvPr name="Title 1" id="2"/>86 <p:cNvSpPr>87 <a:spLocks noGrp="true"/>88 </p:cNvSpPr>89 <p:nvPr/>90 </p:nvSpPr>91 <p:spPr>92 <a:xfrm>93 <a:off y="2130425" x="685800"/>94 <a:ext cy="1470025" cx="7772400"/>95 </a:xfrm>96 </p:spPr>97 <p:txBody>98 <a:bodyPr/>99 <a:lstStyle/>100 <a:p>101 <a:r>102 <a:rPr smtClean="false" lang="en-US"/>103 <a:t>My title</a:t>104 </a:r>105 <a:endParaRPr lang="en-US"/>106 </a:p>107 </p:txBody>108 </p:sp>109 <p:sp>110 <p:nvSpPr>111 <p:cNvPr name="Subtitle 2" id="3"/>112 <p:cNvSpPr>113 <a:spLocks noGrp="true"/>114 </p:cNvSpPr>115 <p:nvPr/>116 </p:nvSpPr>117 <p:spPr>118 <a:xfrm>119 <a:off y="3886200" x="1371600"/>120 <a:ext cy="1752600" cx="6400800"/>121 </a:xfrm>122 </p:spPr>123 <p:txBody>124 <a:bodyPr/>125 <a:lstStyle/>126 <a:p>127 <a:r>128 <a:rPr smtClean="false" lang="en-US"/>129 <a:t>My subtitle</a:t>130 </a:r>131 <a:endParaRPr lang="en-US"/>132 </a:p>133 </p:txBody>134 </p:sp>135 </p:spTree>136 61 137 62 138 139 -->140 141 63 <xsl:template match="/"> 142 <html> 64 <html xmlns="http://www.w3.org/1999/xhtml" 65 xmlns:svg="http://www.w3.org/2000/svg" 66 xmlns:xlink="http://www.w3.org/1999/xlink"> 143 67 <head> 144 68 <title>Slide output proof of concept</title> … … 155 79 </head> 156 80 <body> 157 158 81 <xsl:apply-templates/> 159 160 82 </body> 161 </html> 162 163 <!-- 164 <svg width="600px" height="600px" version="1.1" 165 baseProfile="full"> 166 <xsl:apply-templates/> 167 </svg> 168 --> 83 </html> 169 84 </xsl:template> 170 85 … … 176 91 <xsl:template match="p:grpSpPr"/> 177 92 178 <!--179 <p:sp>180 <p:nvSpPr>181 <p:cNvPr name="Title 1" id="2"/>182 <p:cNvSpPr>183 <a:spLocks noGrp="true"/>184 </p:cNvSpPr>185 <p:nvPr/>186 </p:nvSpPr>187 <p:spPr>188 <a:xfrm>189 <a:off y="2130425" x="685800"/>190 <a:ext cy="1470025" cx="7772400"/>191 </a:xfrm>192 </p:spPr>193 <p:txBody>194 <a:bodyPr/>195 <a:lstStyle/>196 <a:p>197 <a:r>198 <a:rPr smtClean="false" lang="en-US"/>199 <a:t>My title</a:t>200 </a:r>201 <a:endParaRPr lang="en-US"/>202 </a:p>203 </p:txBody>204 </p:sp>205 -->206 93 <xsl:template match="p:sp"> 207 94 <xsl:apply-templates select="p:txBody"/> … … 233 120 <!-- At present, docx4j doesn't do text boxes in its docx html, 234 121 so handle the box here. --> 235 <div style="position: absolute; width:{$cx} ; height:{$cy}; left:{$x}; top:{$y}; border: red dashed;">122 <div style="position: absolute; width:{$cx}px; height:{$cy}px; left:{$x}px; top:{$y}px; border: red dashed;"> 236 123 <xsl:apply-templates select="a:p"/> 237 124 </div> 238 125 </xsl:template> 126 127 <xsl:template match="p:cxnSp"> 128 129 <xsl:variable name="shape" select="."/> 130 131 <xsl:copy-of select="java:org.pptx4j.convert.out.svginhtml.SvgExporter.shapeToSVG( 132 $wmlPackage, $shape)" /> 133 134 </xsl:template> 135 239 136 240 137 <xsl:template match="a:p">
Note: See TracChangeset
for help on using the changeset viewer.
