Author: yegor
Date: Mon Dec 24 01:51:14 2007
New Revision: 606685

URL: http://svn.apache.org/viewvc?rev=606685&view=rev
Log:
fix bug #43781: slide->getShapes->getTextRun returns wrong text

Added:
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/data/43781.ppt   
(with props)
Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java
    
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java?rev=606685&r1=606684&r2=606685&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java Mon Dec 
24 01:51:14 2007
@@ -153,7 +153,7 @@
      */
     protected static void findTextRuns(Record[] records, Vector found) {
         // Look for a TextHeaderAtom
-        for (int i = 0; i < (records.length - 1); i++) {
+        for (int i = 0, slwtIndex=0; i < (records.length - 1); i++) {
             if (records[i] instanceof TextHeaderAtom) {
                 TextRun trun = null;
                 TextHeaderAtom tha = (TextHeaderAtom) records[i];
@@ -179,7 +179,6 @@
                     // TextSpecInfoAtom - Safe to ignore
                 } else {
                     System.err.println("Found a TextHeaderAtom not followed by 
a TextBytesAtom or TextCharsAtom: Followed by " + records[i + 
1].getRecordType());
-                    continue;
                 }
 
                 if (trun != null) {
@@ -191,12 +190,14 @@
                     Record[] recs = new Record[lst.size()];
                     lst.toArray(recs);
                     trun._records = recs;
+                    trun.setIndex(slwtIndex);
                     
                     found.add(trun);
                     i++;
                 } else {
                     // Not a valid one, so skip on to next and look again
                 }
+                slwtIndex++;
             }
         }
     }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java?rev=606685&r1=606684&r2=606685&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java Mon Dec 
24 01:51:14 2007
@@ -196,7 +196,7 @@
         } catch (IOException e){
             throw new HSLFException(e);
         }
-        if(getAnchor().equals(new java.awt.Rectangle())) resizeToFitText();
+        if(getAnchor().equals(new java.awt.Rectangle()) && 
!"".equals(getText())) resizeToFitText();
     }
 
     /**
@@ -264,6 +264,14 @@
         EscherOptRecord opt = 
(EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
         setEscherProperty(opt, EscherProperties.TEXT__ANCHORTEXT, align);
     }
+
+    public void setHorizontalAlignment(int align){
+        _txtrun.getRichTextRuns()[0].setAlignment(align);
+    }
+    public int getHorizontalAlignment(){
+        return _txtrun.getRichTextRuns()[0].getAlignment();
+    }
+
     /**
      * Returns the distance (in points) between the bottom of the text frame
      * and the bottom of the inscribed rectangle of the shape that contains 
the text.
@@ -466,7 +474,11 @@
         TextRun[] runs = sheet.getTextRuns();
         if (ota != null) {
             int idx = ota.getTextIndex();
-            if(idx < runs.length) _txtrun = runs[idx];
+            for (int i = 0; i < runs.length; i++) {
+                if(runs[i].getIndex() == idx){
+                    _txtrun = runs[i];
+                }
+            }
             if(_txtrun == null) {
                 logger.log(POILogger.WARN, "text run not found for 
OutlineTextRefAtom.TextIndex=" + idx);
             }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java?rev=606685&r1=606684&r2=606685&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java Mon Dec 
24 01:51:14 2007
@@ -50,6 +50,7 @@
        private SlideShow slideShow;
     private Sheet sheet;
     private int shapeId;
+    private int slwtIndex; //position in the owning SlideListWithText
     /**
      * all text run records that follow TextHeaderAtom.
      * (there can be misc InteractiveInfo, TxInteractiveInfo and other records)
@@ -535,6 +536,20 @@
      */
     protected void setShapeId(int id){
         shapeId = id;
+    }
+
+    /**
+     * @return  0-based index of the text run in the SLWT container
+     */
+    protected int getIndex(){
+        return slwtIndex;
+    }
+
+    /**
+     *  @param id 0-based index of the text run in the SLWT container
+     */
+    protected void setIndex(int id){
+        slwtIndex = id;
     }
 
     /**

Added: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/data/43781.ppt
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/data/43781.ppt?rev=606685&view=auto
==============================================================================
Binary file - no diff available.

Propchange: 
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/data/43781.ppt
------------------------------------------------------------------------------
    svn:executable = *

Propchange: 
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/data/43781.ppt
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: 
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java?rev=606685&r1=606684&r2=606685&view=diff
==============================================================================
--- 
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java 
(original)
+++ 
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java 
Mon Dec 24 01:51:14 2007
@@ -25,6 +25,7 @@
 import java.io.*;
 import java.util.HashSet;
 import java.util.HashMap;
+import java.util.ArrayList;
 import java.awt.*;
 
 /**
@@ -298,4 +299,35 @@
 
     }
 
+    /**
+     * Bug 38256:  RuntimeException: Couldn't instantiate the class for type 
with id 0.
+     * ( also fixed followup: getTextRuns() returns no text )
+     */
+    public void test43781 () throws Exception {
+        FileInputStream is = new FileInputStream(new File(cwd, "43781.ppt"));
+        SlideShow ppt = new SlideShow(is);
+        is.close();
+
+        assertTrue("No Exceptions while reading file", true);
+
+        Slide slide = ppt.getSlides()[0];
+        TextRun[] tr1 = slide.getTextRuns();
+
+        ArrayList lst = new ArrayList();
+        Shape[] shape = slide.getShapes();
+        for (int i = 0; i < shape.length; i++) {
+            if( shape[i] instanceof TextBox){
+                TextRun textRun = ((TextBox)shape[i]).getTextRun();
+                if(textRun != null) lst.add(textRun);
+            }
+
+        }
+        TextRun[] tr2 = new TextRun[lst.size()];
+        lst.toArray(tr2);
+
+        assertEquals(tr1.length, tr2.length);
+        for (int i = 0; i < tr1.length; i++) {
+            assertEquals(tr1[i].getText(), tr2[i].getText());
+        }
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to