Changeset 1098
- Timestamp:
- 03/02/10 10:14:12 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/docx4j/src/main/java/org/docx4j/model/images/WordXmlPictureE20.java
r1097 r1098 23 23 import org.docx4j.XmlUtils; 24 24 import org.docx4j.dml.CTBlip; 25 import org.docx4j.dml.CTNonVisualDrawingProps; 25 26 import org.docx4j.dml.CTPositiveSize2D; 26 27 import org.docx4j.dml.picture.Pic; 28 import org.docx4j.dml.wordprocessingDrawing.Anchor; 27 29 import org.docx4j.dml.wordprocessingDrawing.Inline; 28 30 import org.docx4j.jaxb.Context; 31 import org.docx4j.model.images.AbstractWordXmlPicture.Dimensions; 29 32 import org.docx4j.openpackaging.packages.WordprocessingMLPackage; 30 33 import org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage; … … 74 77 </wp:inline> 75 78 </w:drawing> 79 80 <w:drawing> 81 <wp:anchor distT="0" distB="0" distL="114300" distR="114300" simplePos="0" 82 relativeHeight="251662336" behindDoc="0" locked="0" layoutInCell="1" allowOverlap="1"> 83 <wp:simplePos x="0" y="0" /> 84 <wp:positionH relativeFrom="column"> 85 <wp:posOffset>3400425</wp:posOffset> 86 </wp:positionH> 87 <wp:positionV relativeFrom="paragraph"> 88 <wp:posOffset>1991360</wp:posOffset> 89 </wp:positionV> 90 <wp:extent cx="552450" cy="209550" /> 91 <wp:effectExtent l="38100" t="0" r="19050" b="38100" /> 92 <wp:wrapTopAndBottom /> 93 <wp:docPr id="4" name="Picture 1" descr="D:\\stuff\\untitled.bmp" /> 94 <wp:cNvGraphicFramePr> 95 <a:graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" noChangeAspect="1" /> 96 </wp:cNvGraphicFramePr> 97 <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"> 98 <a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture"> 99 <pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"> 100 <pic:nvPicPr> 101 <pic:cNvPr id="0" name="Picture 1" descr="D:\\stuff\\untitled.bmp" /> 102 <pic:cNvPicPr> 103 <a:picLocks noChangeAspect="1" noChangeArrowheads="1" /> 104 </pic:cNvPicPr> 105 </pic:nvPicPr> 106 <pic:blipFill> 107 <a:blip r:embed="rId7" cstate="print"> 108 <a:clrChange> 109 <a:clrFrom> 110 <a:srgbClr val="FFFFFF" /> 111 </a:clrFrom> 112 <a:clrTo> 113 <a:srgbClr val="FFFFFF"> 114 <a:alpha val="0" /> 115 </a:srgbClr> 116 </a:clrTo> 117 </a:clrChange> 118 <a:biLevel thresh="50000" /> 119 </a:blip> 120 <a:srcRect l="35365" t="28689" r="52846" b="65300" /> 121 <a:stretch> 122 <a:fillRect /> 123 </a:stretch> 124 </pic:blipFill> 125 <pic:spPr bwMode="auto"> 126 <a:xfrm rot="21023481"> 127 <a:off x="0" y="0" /> 128 <a:ext cx="552450" cy="209550" /> 129 </a:xfrm> 130 <a:prstGeom prst="rect"> 131 <a:avLst /> 132 </a:prstGeom> 133 <a:noFill /> 134 <a:ln w="9525"> 135 <a:noFill /> 136 <a:miter lim="800000" /> 137 <a:headEnd /> 138 <a:tailEnd /> 139 </a:ln> 140 </pic:spPr> 141 </pic:pic> 142 </a:graphicData> 143 </a:graphic> 144 </wp:anchor> 145 </w:drawing> 76 146 * 77 147 * … … 81 151 protected static Logger log = Logger.getLogger(WordXmlPictureE20.class); 82 152 153 // It'll be one or the other of these 83 154 private Inline inline; 84 85 private WordXmlPictureE20(WordprocessingMLPackage wmlPackage, NodeIterator wpInline) { 155 private Anchor anchor; 156 157 private WordXmlPictureE20(WordprocessingMLPackage wmlPackage, NodeIterator anchorOrInline) { 86 158 87 159 this.wmlPackage = wmlPackage; 88 160 89 // TODO: what if its wp:anchor instead? 90 91 if (wpInline!=null) { 92 Node n = wpInline.nextNode(); 161 if (anchorOrInline!=null) { 162 Node n = anchorOrInline.nextNode(); 93 163 if (n!=null) { 94 164 Object jaxb=null; … … 107 177 if (jb.getDeclaredType().getName().equals("org.docx4j.dml.wordprocessingDrawing.Inline")) { 108 178 this.inline = (Inline)jb.getValue(); 179 } else if (jb.getDeclaredType().getName().equals("org.docx4j.dml.wordprocessingDrawing.Anchor")) { 180 this.anchor = (Anchor)jb.getValue(); 109 181 } else { 110 182 log.error("UNEXPECTED " + … … 115 187 } else if (jaxb instanceof Inline) { 116 188 this.inline = (Inline)jaxb; 189 } else if (jaxb instanceof Anchor) { 190 this.anchor = (Anchor)jaxb; 117 191 } else { 118 192 log.error( jaxb.getClass().getName() ); … … 120 194 } 121 195 } catch (ClassCastException e) { 122 log.error("Couldn't cast " + jaxb.getClass().getName() + " to Inline");196 log.error("Couldn't cast " + jaxb.getClass().getName() + " to Anchor or Inline "); 123 197 } 124 198 } … … 137 211 * @return 138 212 */ 139 public static WordXmlPictureE20 createWordXmlPictureFromE20( 140 WordprocessingMLPackage wmlPackage, 213 public static WordXmlPictureE20 createWordXmlPictureFromE20(WordprocessingMLPackage wmlPackage, 141 214 String imageDirPath, 142 NodeIterator wpInline) {143 144 WordXmlPictureE20 converter = new WordXmlPictureE20(wmlPackage, wpInline);215 NodeIterator anchorOrInline) { 216 217 WordXmlPictureE20 converter = new WordXmlPictureE20(wmlPackage, anchorOrInline); 145 218 146 219 converter.readDimensions(); 147 220 converter.readHyperlink(); 148 221 149 if (converter.inline.getGraphic()==null150 || converter.inline.getGraphic().getGraphicData()==null151 || converter.inline.getGraphic().getGraphicData().getPic()==null) {222 223 Pic pic = converter.getPic(); 224 if (pic==null) { 152 225 log.error("pic missing!!"); 153 226 return null; 154 227 } 155 156 Pic pic = converter.inline.getGraphic().getGraphicData().getPic();157 228 158 229 if (pic.getBlipFill()==null … … 175 246 return converter; 176 247 } 248 249 private Pic getPic() { 250 251 if (inline!=null) { 252 if (inline.getGraphic()==null 253 || inline.getGraphic().getGraphicData()==null 254 || inline.getGraphic().getGraphicData().getPic()==null) { 255 log.error("pic missing!!"); 256 return null; 257 } 258 return inline.getGraphic().getGraphicData().getPic(); 259 } 260 261 if (anchor!=null) { 262 if (anchor.getGraphic()==null 263 || anchor.getGraphic().getGraphicData()==null 264 || anchor.getGraphic().getGraphicData().getPic()==null) { 265 log.error("pic missing!!"); 266 return null; 267 } 268 return anchor.getGraphic().getGraphicData().getPic(); 269 } 270 271 log.error("Anchor and inline both null!"); 272 return null; 273 } 177 274 178 275 … … 190 287 * @return 191 288 */ 192 public static DocumentFragment createHtmlImgE20( 193 WordprocessingMLPackage wmlPackage, 289 public static DocumentFragment createHtmlImgE20(WordprocessingMLPackage wmlPackage, 194 290 String imageDirPath, 195 291 NodeIterator wpInline) { … … 213 309 * @return 214 310 */ 215 public static DocumentFragment createXslFoImgE20( 216 WordprocessingMLPackage wmlPackage, 311 public static DocumentFragment createXslFoImgE20(WordprocessingMLPackage wmlPackage, 217 312 String imageDirPath, 218 313 NodeIterator wpInline) { … … 230 325 231 326 private void readDimensions() { 232 CTPositiveSize2D size2d = inline.getExtent();327 CTPositiveSize2D size2d = getExtent(); 233 328 if (size2d==null) { 234 329 log.warn("wp:inline/wp:extent missing!"); … … 245 340 } 246 341 } 342 343 344 private CTPositiveSize2D getExtent() { 345 346 if (inline!=null) { 347 return inline.getExtent(); 348 } 349 350 if (anchor!=null) { 351 return anchor.getExtent(); 352 } 353 354 log.error("Anchor and inline both null!"); 355 return null; 356 } 357 358 247 359 private final int extentToPixelConversionFactor = 12700; 248 360 249 361 private void readHyperlink() { 250 if ( inline.getDocPr()!=null251 && inline.getDocPr().getHlinkClick()!=null) {362 if (getDocPr()!=null 363 && getDocPr().getHlinkClick()!=null) { 252 364 253 String linkRelId = inline.getDocPr().getHlinkClick().getId();365 String linkRelId = getDocPr().getHlinkClick().getId(); 254 366 255 367 if ( linkRelId!=null && !linkRelId.equals("") ) … … 266 378 } 267 379 268 targetFrame = inline.getDocPr().getHlinkClick().getTgtFrame(); 269 tooltip = inline.getDocPr().getHlinkClick().getTooltip(); 270 } 271 } 380 targetFrame = getDocPr().getHlinkClick().getTgtFrame(); 381 tooltip = getDocPr().getHlinkClick().getTooltip(); 382 } 383 } 384 385 private CTNonVisualDrawingProps getDocPr() { 386 387 if (inline!=null) { 388 if (inline.getDocPr()==null) { 389 log.error("DocPr missing!!"); 390 return null; 391 } 392 return inline.getDocPr(); 393 } 394 395 if (anchor!=null) { 396 if (anchor.getDocPr()==null) { 397 log.error("DocPr missing!!"); 398 return null; 399 } 400 return anchor.getDocPr(); 401 } 402 403 log.error("Anchor and inline both null!"); 404 return null; 405 } 406 272 407 273 408 private void handleImageRel(String imgRelId, String imageDirPath) {
Note: See TracChangeset
for help on using the changeset viewer.
