- Timestamp:
- 02/23/10 06:32:26 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/docx4j/src/main/java/org/docx4j/model/images/WordXmlPicture.java
r979 r1078 28 28 import org.docx4j.openpackaging.parts.WordprocessingML.BinaryPart; 29 29 import org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage; 30 import org.docx4j.openpackaging.parts.WordprocessingML.MetafileEmfPart; 31 import org.docx4j.openpackaging.parts.WordprocessingML.MetafilePart; 32 import org.docx4j.openpackaging.parts.WordprocessingML.MetafileWmfPart; 30 33 import org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage.CxCy; 34 import org.docx4j.openpackaging.parts.WordprocessingML.MetafileWmfPart.SvgDocument; 31 35 import org.docx4j.relationships.Relationship; 32 36 import org.docx4j.wml.SectPr; 33 37 import org.w3c.dom.Document; 34 38 import org.w3c.dom.DocumentFragment; 39 import org.w3c.dom.Element; 35 40 import org.w3c.dom.Node; 41 import org.w3c.dom.Text; 36 42 import org.w3c.dom.css.CSSPrimitiveValue; 37 43 import org.w3c.dom.css.CSSStyleDeclaration; … … 58 64 Node imageElement = null; 59 65 Node linkElement = null; 66 67 private MetafilePart metaFile; 60 68 61 69 /** Extension function to create an HTML <img> element … … 80 88 picLink, linkData, true); 81 89 82 Document d = picture.createHtmlImageElement(); 83 84 DocumentFragment docfrag = d.createDocumentFragment(); 90 return getHtmlDocumentFragment(picture); 91 92 } 93 94 public static DocumentFragment getHtmlDocumentFragment(WordXmlPicture picture) { 95 96 DocumentFragment docfrag=null; 97 Document d=null; 98 try { 99 if (picture==null) { 100 log.warn("picture was null!"); 101 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 102 try { 103 d = factory.newDocumentBuilder().newDocument(); 104 } catch (ParserConfigurationException e1) { 105 // TODO Auto-generated catch block 106 e1.printStackTrace(); 107 } 108 Element span = d.createElement("span"); 109 span.setAttribute("style", "color:red;"); 110 d.appendChild(span); 111 112 Text err = d.createTextNode( "[null img]" ); 113 span.appendChild(err); 114 115 } else if (picture.metaFile==null) { 116 // Usual case 117 d = picture.createHtmlImageElement(); 118 } else if (picture.metaFile instanceof MetafileWmfPart) { 119 120 SvgDocument svgdoc = ((MetafileWmfPart)picture.metaFile).toSVG(); 121 d = svgdoc.getDomDocument(); 122 123 } else if (picture.metaFile instanceof MetafileEmfPart) { 124 125 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 126 d = factory.newDocumentBuilder().newDocument(); 127 128 //log.info("Document: " + document.getClass().getName() ); 129 130 Node span = d.createElement("span"); 131 d.appendChild(span); 132 133 Text err = d.createTextNode( "[TODO emf image]" ); 134 span.appendChild(err); 135 136 } 137 } catch (Exception e) { 138 log.error(e); 139 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 140 try { 141 d = factory.newDocumentBuilder().newDocument(); 142 } catch (ParserConfigurationException e1) { 143 // TODO Auto-generated catch block 144 e1.printStackTrace(); 145 } 146 Element span = d.createElement("span"); 147 span.setAttribute("style", "color:red;"); 148 d.appendChild(span); 149 150 Text err = d.createTextNode( e.getMessage() ); 151 span.appendChild(err); 152 } 153 docfrag = d.createDocumentFragment(); 85 154 docfrag.appendChild(d.getDocumentElement()); 86 87 155 return docfrag; 88 156 } … … 179 247 if (rel.getTargetMode() == null 180 248 || rel.getTargetMode().equals("Internal")) { 181 182 BinaryPartAbstractImage part = (BinaryPartAbstractImage)wmlPackage.getMainDocumentPart() 183 .getRelationshipsPart().getPart(rel); 249 250 251 BinaryPart part = (BinaryPart)wmlPackage.getMainDocumentPart() 252 .getRelationshipsPart().getPart(rel); 253 254 if (part instanceof MetafilePart) { 255 256 picture.metaFile = (MetafilePart)part; 257 258 } else { 259 260 BinaryPartAbstractImage imagepart = (BinaryPartAbstractImage)part; 261 262 String uri = handlePart(imageDirPath, picture, imagepart); 263 // Scale it? Shouldn't be necessary, since Word should 264 // be providing the height/width 265 // try { 266 // ImageInfo imageInfo = BinaryPartAbstractImage.getImageInfo(uri); 267 // 268 // List<SectionWrapper> sections = wmlPackage.getDocumentModel().getSections(); 269 // PageDimensions page = sections.get(sections.size()-1).getPageDimensions(); 270 // 271 // picture.ensureFitsPage(imageInfo, page ); 272 // } catch (Exception e) { 273 // e.printStackTrace(); 274 // } 275 276 } 184 277 185 String uri = handlePart(imageDirPath, picture, part);186 // Scale it? Shouldn't be necessary, since Word should187 // be providing the height/width188 // try {189 // ImageInfo imageInfo = BinaryPartAbstractImage.getImageInfo(uri);190 //191 // List<SectionWrapper> sections = wmlPackage.getDocumentModel().getSections();192 // PageDimensions page = sections.get(sections.size()-1).getPageDimensions();193 //194 // picture.ensureFitsPage(imageInfo, page );195 // } catch (Exception e) {196 // e.printStackTrace();197 // }198 199 278 } else { // External 200 279 picture.setSrc(rel.getTarget()); 280 281 // TODO: handle external metafiles 201 282 } 202 283 … … 420 501 shape, imageData, true); 421 502 422 if (picture==null) { 423 424 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 425 Document d; 426 try { 427 d = factory.newDocumentBuilder().newDocument(); 428 return d.createDocumentFragment(); 429 } catch (ParserConfigurationException e) { 430 log.error(e); 431 return null; 432 } 433 434 } else { 435 436 Document d = picture.createHtmlImageElement(); 437 438 DocumentFragment docfrag = d.createDocumentFragment(); 439 docfrag.appendChild(d.getDocumentElement()); 440 441 return docfrag; 442 } 503 return getHtmlDocumentFragment(picture); 443 504 } 444 505 … … 526 587 || rel.getTargetMode().equals("Internal") ) { 527 588 528 BinaryPart AbstractImagepart = (BinaryPartAbstractImage)wmlPackage.getMainDocumentPart()589 BinaryPart part = (BinaryPartAbstractImage)wmlPackage.getMainDocumentPart() 529 590 .getRelationshipsPart().getPart(rel); 530 String uri = handlePart(imageDirPath, picture, part); 591 592 if (part instanceof MetafilePart) { 593 594 picture.metaFile = (MetafilePart)part; 595 596 } else { 597 598 BinaryPartAbstractImage imagepart = (BinaryPartAbstractImage)part; 599 String uri = handlePart(imageDirPath, picture, imagepart); 531 600 532 601 // Scale it? Shouldn't be necessary, since Word should … … 542 611 // e.printStackTrace(); 543 612 // } 544 613 } 545 614 546 615 } else {
Note: See TracChangeset
for help on using the changeset viewer.
