public PictureData getPictureData(){
SlideShow ppt = getSheet().getSlideShow();
PictureData[] pict = ppt.getPictureData();
- Document doc = ppt.getDocumentRecord();
- EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer();
- EscherContainerRecord bstore = (EscherContainerRecord)Shape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER);
- List lst = bstore.getChildRecords();
- int idx = getPictureIndex();
- if (idx == 0){
+ EscherBSERecord bse = getEscherBSERecord();
+ if (bse == null){
logger.log(POILogger.ERROR, "no reference to picture data found ");
} else {
- EscherBSERecord bse = (EscherBSERecord)lst.get(idx-1);
for ( int i = 0; i < pict.length; i++ ) {
if (pict[i].getOffset() == bse.getOffset()){
return pict[i];
return null;
}
+ protected EscherBSERecord getEscherBSERecord(){
+ SlideShow ppt = getSheet().getSlideShow();
+ Document doc = ppt.getDocumentRecord();
+ EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer();
+ EscherContainerRecord bstore = (EscherContainerRecord)Shape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER);
+
+ List lst = bstore.getChildRecords();
+ int idx = getPictureIndex();
+ if (idx == 0){
+ return null;
+ } else {
+ return (EscherBSERecord)lst.get(idx-1);
+ }
+ }
+
/**
* Name of this picture.
*
*/
protected void afterInsert(Sheet sh){
super.afterInsert(sh);
+
+ EscherBSERecord bse = getEscherBSERecord();
+ bse.setRef(bse.getRef() + 1);
+
java.awt.Rectangle anchor = getAnchor();
if (anchor.equals(new java.awt.Rectangle())){
setDefaultSize();
ShapePainter.paint(this, graphics);
PictureData data = getPictureData();
- if (data instanceof Bitmap){
- BufferedImage img = null;
- try {
- img = ImageIO.read(new ByteArrayInputStream(data.getData()));
- }
- catch (Exception e){
- logger.log(POILogger.WARN, "ImageIO failed to create image. image.type: " + data.getType());
- return;
- }
- Rectangle anchor = getAnchor();
- Image scaledImg = img.getScaledInstance(anchor.width, anchor.height, Image.SCALE_SMOOTH);
- graphics.drawImage(scaledImg, anchor.x, anchor.y, null);
- } else {
- logger.log(POILogger.WARN, "Rendering of metafiles is not yet supported. image.type: " + (data == null ? "NA" : data.getClass().getName()));
- }
+ data.draw(graphics, this);
+
graphics.setTransform(at);
}
}
--- /dev/null
+/* ====================================================================\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to You under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+==================================================================== */\r
+package org.apache.poi.hslf.model;\r
+\r
+import junit.framework.*;\r
+\r
+import java.io.FileOutputStream;\r
+import java.io.File;\r
+import java.awt.*;\r
+\r
+import org.apache.poi.hslf.usermodel.SlideShow;\r
+import org.apache.poi.hslf.HSLFSlideShow;\r
+import org.apache.poi.ddf.EscherBSERecord;\r
+\r
+/**\r
+ * Test Picture shape.\r
+ * \r
+ * @author Yegor Kozlov\r
+ */\r
+public class TestPicture extends TestCase {\r
+\r
+ /**\r
+ * Test that the reference count of a blip is incremented every time the picture is inserted.\r
+ * This is important when the same image appears multiple times in a slide show.\r
+ *\r
+ */\r
+ public void testMultiplePictures() throws Exception {\r
+ String cwd = System.getProperty("HSLF.testdata.path");\r
+ SlideShow ppt = new SlideShow();\r
+\r
+ Slide s = ppt.createSlide();\r
+ Slide s2 = ppt.createSlide();\r
+ Slide s3 = ppt.createSlide();\r
+\r
+ int idx = ppt.addPicture(new File(cwd, "clock.jpg"), Picture.JPEG);\r
+ Picture pict = new Picture(idx);\r
+ Picture pict2 = new Picture(idx);\r
+ Picture pict3 = new Picture(idx);\r
+\r
+ pict.setAnchor(new Rectangle(10,10,100,100));\r
+ s.addShape(pict);\r
+ EscherBSERecord bse1 = pict.getEscherBSERecord();\r
+ assertEquals(1, bse1.getRef());\r
+\r
+ pict2.setAnchor(new Rectangle(10,10,100,100));\r
+ s2.addShape(pict2);\r
+ EscherBSERecord bse2 = pict.getEscherBSERecord();\r
+ assertSame(bse1, bse2);\r
+ assertEquals(2, bse1.getRef());\r
+\r
+ pict3.setAnchor(new Rectangle(10,10,100,100));\r
+ s3.addShape(pict3);\r
+ EscherBSERecord bse3 = pict.getEscherBSERecord();\r
+ assertSame(bse2, bse3);\r
+ assertEquals(3, bse1.getRef());\r
+\r
+ }\r
+\r
+}\r