poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ber...@apache.org
Subject svn commit: r1382494 - in /poi/trunk: src/java/org/apache/poi/hssf/usermodel/HSSFSimpleShape.java src/java/org/apache/poi/hssf/usermodel/HSSFTextbox.java src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java test-data/spreadsheet/46250.xls
Date Sun, 09 Sep 2012 13:21:39 GMT
Author: berlog
Date: Sun Sep  9 13:21:38 2012
New Revision: 1382494

URL: http://svn.apache.org/viewvc?rev=1382494&view=rev
Log:
fixed bug 46250

Added:
    poi/trunk/test-data/spreadsheet/46250.xls   (with props)
Modified:
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSimpleShape.java
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFTextbox.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSimpleShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSimpleShape.java?rev=1382494&r1=1382493&r2=1382494&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSimpleShape.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSimpleShape.java Sun Sep  9 13:21:38
2012
@@ -170,7 +170,8 @@ public class HSSFSimpleShape extends HSS
         HSSFRichTextString rtr = (HSSFRichTextString) string;
         // If font is not set we must set the default one
         if (rtr.numFormattingRuns() == 0) rtr.applyFont((short) 0);
-        _textObjectRecord.setStr(rtr);
+        TextObjectRecord txo = getOrCreateTextObjRecord();
+        txo.setStr(rtr);
         if (string.getString() != null){
             setPropertyValue(new EscherSimpleProperty(EscherProperties.TEXT__TEXTID, string.getString().hashCode()));
         }
@@ -234,4 +235,19 @@ public class HSSFSimpleShape extends HSS
         EscherSpRecord spRecord = getEscherContainer().getChildById(EscherSpRecord.RECORD_ID);
         spRecord.setShapeType((short) value);
     }
+    
+    private TextObjectRecord getOrCreateTextObjRecord(){
+        if (getTextObjectRecord() == null){
+            _textObjectRecord = createTextObjRecord();
+        }
+        EscherTextboxRecord escherTextbox = getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID);
+        if (null == escherTextbox){
+            escherTextbox = new EscherTextboxRecord();
+            escherTextbox.setRecordId(EscherTextboxRecord.RECORD_ID);
+            escherTextbox.setOptions((short) 0x0000);
+            getEscherContainer().addChildRecord(escherTextbox);
+            getPatriarch()._getBoundAggregate().associateShapeToObjRecord(escherTextbox,
_textObjectRecord);
+        }
+        return _textObjectRecord;
+    }
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFTextbox.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFTextbox.java?rev=1382494&r1=1382493&r2=1382494&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFTextbox.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFTextbox.java Sun Sep  9 13:21:38
2012
@@ -133,7 +133,9 @@ public class HSSFTextbox extends HSSFSim
     void afterInsert(HSSFPatriarch patriarch) {
         EscherAggregate agg = patriarch._getBoundAggregate();
         agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID),
getObjRecord());
-        agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID),
getTextObjectRecord());
+        if (getTextObjectRecord() != null){
+            agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID),
getTextObjectRecord());
+        }
     }
 
     /**
@@ -231,7 +233,7 @@ public class HSSFTextbox extends HSSFSim
 
     @Override
     protected HSSFShape cloneShape() {
-        TextObjectRecord txo = (TextObjectRecord) getTextObjectRecord().cloneViaReserialise();
+        TextObjectRecord txo = getTextObjectRecord() == null ? null : (TextObjectRecord)
getTextObjectRecord().cloneViaReserialise();
         EscherContainerRecord spContainer = new EscherContainerRecord();
         byte[] inSp = getEscherContainer().serialize();
         spContainer.fillFields(inSp, 0, new DefaultEscherRecordFactory());

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java?rev=1382494&r1=1382493&r2=1382494&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java Sun Sep  9 13:21:38
2012
@@ -2283,4 +2283,18 @@ if(1==2) {
         wb = writeOutAndReadBack((HSSFWorkbook) wb);
         assertEquals(wb.getAllPictures().size(), 1);
     }
+
+    public void test46250(){
+        Workbook wb = openSample("46250.xls");
+        Sheet sh = wb.getSheet("Template");
+        Sheet cSh = wb.cloneSheet(wb.getSheetIndex(sh));
+
+        HSSFPatriarch patriarch = (HSSFPatriarch) cSh.createDrawingPatriarch();
+        HSSFTextbox tb = (HSSFTextbox) patriarch.getChildren().get(2);
+
+        tb.setString(new HSSFRichTextString("POI test"));
+        tb.setAnchor(new HSSFClientAnchor(0,0,0,0,(short)0,0,(short)10,10));
+
+        wb = writeOutAndReadBack((HSSFWorkbook) wb);
+    }
 }

Added: poi/trunk/test-data/spreadsheet/46250.xls
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/46250.xls?rev=1382494&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/spreadsheet/46250.xls
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



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


Mime
View raw message