You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ye...@apache.org on 2008/06/08 14:30:25 UTC

svn commit: r664490 - in /poi/trunk/src: java/org/apache/poi/ddf/ scratchpad/src/org/apache/poi/hslf/model/ scratchpad/src/org/apache/poi/hslf/usermodel/ scratchpad/testcases/org/apache/poi/hslf/model/

Author: yegor
Date: Sun Jun  8 05:30:25 2008
New Revision: 664490

URL: http://svn.apache.org/viewvc?rev=664490&view=rev
Log:
Correctly increment the reference count of a blip when a picture is inserted

Added:
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPicture.java   (with props)
Modified:
    poi/trunk/src/java/org/apache/poi/ddf/EscherDggRecord.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java

Modified: poi/trunk/src/java/org/apache/poi/ddf/EscherDggRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ddf/EscherDggRecord.java?rev=664490&r1=664489&r2=664490&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ddf/EscherDggRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/ddf/EscherDggRecord.java Sun Jun  8 05:30:25 2008
@@ -238,6 +238,10 @@
         return maxDgId;
     }
 
+    public void setMaxDrawingGroupId(int id){
+        maxDgId = id;
+    }
+
      public FileIdCluster[] getFileIdClusters()
     {
         return field_5_fileIdClusters;

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java?rev=664490&r1=664489&r2=664490&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java Sun Jun  8 05:30:25 2008
@@ -176,16 +176,11 @@
     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];
@@ -196,6 +191,21 @@
         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.
      *
@@ -238,6 +248,10 @@
      */
     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();
@@ -249,21 +263,8 @@
         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);
     }
 }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java?rev=664490&r1=664489&r2=664490&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java Sun Jun  8 05:30:25 2008
@@ -734,7 +734,7 @@
         else if (format == Picture.WMF) bse.setBlipTypeMacOS((byte)Picture.PICT);
         else if (format == Picture.PICT) bse.setBlipTypeWin32((byte)Picture.WMF);
 
-        bse.setRef(1);
+        bse.setRef(0);
         bse.setOffset(offset);
 
         bstore.addChildRecord(bse);

Added: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPicture.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPicture.java?rev=664490&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPicture.java (added)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPicture.java Sun Jun  8 05:30:25 2008
@@ -0,0 +1,73 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.hslf.model;
+
+import junit.framework.*;
+
+import java.io.FileOutputStream;
+import java.io.File;
+import java.awt.*;
+
+import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.HSLFSlideShow;
+import org.apache.poi.ddf.EscherBSERecord;
+
+/**
+ * Test Picture shape.
+ * 
+ * @author Yegor Kozlov
+ */
+public class TestPicture extends TestCase {
+
+    /**
+     * Test that the reference count of a blip is incremented every time the picture is inserted.
+     * This is important when the same image appears multiple times in a slide show.
+     *
+     */
+    public void testMultiplePictures() throws Exception {
+        String cwd = System.getProperty("HSLF.testdata.path");
+        SlideShow ppt = new SlideShow();
+
+        Slide s = ppt.createSlide();
+        Slide s2 = ppt.createSlide();
+        Slide s3 = ppt.createSlide();
+
+        int idx = ppt.addPicture(new File(cwd, "clock.jpg"), Picture.JPEG);
+        Picture pict = new Picture(idx);
+        Picture pict2 = new Picture(idx);
+        Picture pict3 = new Picture(idx);
+
+        pict.setAnchor(new Rectangle(10,10,100,100));
+        s.addShape(pict);
+        EscherBSERecord bse1 = pict.getEscherBSERecord();
+        assertEquals(1, bse1.getRef());
+
+        pict2.setAnchor(new Rectangle(10,10,100,100));
+        s2.addShape(pict2);
+        EscherBSERecord bse2 = pict.getEscherBSERecord();
+        assertSame(bse1, bse2);
+        assertEquals(2, bse1.getRef());
+
+        pict3.setAnchor(new Rectangle(10,10,100,100));
+        s3.addShape(pict3);
+        EscherBSERecord bse3 = pict.getEscherBSERecord();
+        assertSame(bse2, bse3);
+        assertEquals(3, bse1.getRef());
+
+    }
+
+}

Propchange: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPicture.java
------------------------------------------------------------------------------
    svn:executable = *



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org