We had incorrect implementation for sprmCShd80 (0x4866) 0x66 processing, Shd was used instead of Shd80 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1383584 13f79535-47bb-0310-9956-ffa450edef68tags/3.10-beta1
@@ -34,6 +34,7 @@ | |||
<changes> | |||
<release version="3.9-beta1" date="2012-??-??"> | |||
<action dev="poi-developers" type="fix">53380 - ArrayIndexOutOfBounds Excetion parsing word 97 document. </action> | |||
<action dev="poi-developers" type="fix">53434 - Subtotal is not return correct value. </action> | |||
<action dev="poi-developers" type="fix">53642 - [PATCH] XLS formula evaluation logging </action> | |||
<action dev="poi-developers" type="fix">53561 - Unexpected adding of drawings into a workbook </action> |
@@ -14,17 +14,18 @@ | |||
See the License for the specific language governing permissions and | |||
limitations under the License. | |||
==================================================================== */ | |||
package org.apache.poi.hwpf.model.types; | |||
package org.apache.poi.hwpf.model.types; | |||
import org.apache.poi.util.BitField; | |||
import org.apache.poi.util.Internal; | |||
import org.apache.poi.util.LittleEndian; | |||
/** | |||
* The SHD80 is a substructure of the CHP and PAP, and TC for Word 97. <p>Class | |||
and fields descriptions are quoted from | |||
Microsoft Office Word 97-2007 Binary File Format | |||
* The Shd80 structure specifies the colors and pattern that are used for background | |||
shading. As an exception to the constraints that are specified by Ico and Ipat, a Shd80 can | |||
be set to Shd80Nil and specifies that no shading is applied. <p>Class and fields | |||
descriptions are quoted from Word (.doc) Binary File Format by Microsoft Corporation | |||
* <p> | |||
* NOTE: This source is automatically generated please do not modify this file. Either subclass or | |||
@@ -33,8 +34,7 @@ import org.apache.poi.util.LittleEndian; | |||
* This class is internal. It content or properties may change without notice | |||
* due to changes in our knowledge of internal Microsoft Word binary structures. | |||
* @author Sergey Vladimirov; according to Microsoft Office Word 97-2007 Binary File Format | |||
Specification [*.doc] | |||
* @author Sergey Vladimirov; according to Word (.doc) Binary File Format by Microsoft Corporation. | |||
*/ | |||
@Internal | |||
@@ -42,9 +42,9 @@ public abstract class SHD80AbstractType | |||
{ | |||
protected short field_1_value; | |||
/**/private static BitField icoFore = new BitField(0x001F); | |||
/**/private static BitField icoBack = new BitField(0x03E0); | |||
/**/private static BitField ipat = new BitField(0xFC00); | |||
/**/private static final BitField icoFore = new BitField(0x001F); | |||
/**/private static final BitField icoBack = new BitField(0x03E0); | |||
/**/private static final BitField ipat = new BitField(0xFC00); | |||
protected SHD80AbstractType() | |||
{ | |||
@@ -52,12 +52,19 @@ public abstract class SHD80AbstractType | |||
protected void fillFields( byte[] data, int offset ) | |||
{ | |||
field_1_value = LittleEndian.getShort(data, 0x0 + offset); | |||
field_1_value = LittleEndian.getShort( data, 0x0 + offset ); | |||
} | |||
public void serialize( byte[] data, int offset ) | |||
{ | |||
LittleEndian.putShort(data, 0x0 + offset, (short)field_1_value); | |||
LittleEndian.putShort( data, 0x0 + offset, field_1_value ); | |||
} | |||
public byte[] serialize() | |||
{ | |||
final byte[] result = new byte[ getSize() ]; | |||
serialize( result, 0 ); | |||
return result; | |||
} | |||
/** | |||
@@ -68,6 +75,30 @@ public abstract class SHD80AbstractType | |||
return 0 + 2; | |||
} | |||
@Override | |||
public boolean equals( Object obj ) | |||
{ | |||
if ( this == obj ) | |||
return true; | |||
if ( obj == null ) | |||
return false; | |||
if ( getClass() != obj.getClass() ) | |||
return false; | |||
SHD80AbstractType other = (SHD80AbstractType) obj; | |||
if ( field_1_value != other.field_1_value ) | |||
return false; | |||
return true; | |||
} | |||
@Override | |||
public int hashCode() | |||
{ | |||
final int prime = 31; | |||
int result = 1; | |||
result = prime * result + field_1_value; | |||
return result; | |||
} | |||
public String toString() | |||
{ | |||
StringBuilder builder = new StringBuilder(); |
@@ -14,6 +14,7 @@ | |||
See the License for the specific language governing permissions and | |||
limitations under the License. | |||
==================================================================== */ | |||
package org.apache.poi.hwpf.model.types; | |||
@@ -22,9 +23,9 @@ import org.apache.poi.util.Internal; | |||
import org.apache.poi.util.LittleEndian; | |||
/** | |||
* The SHD is a substructure of the CHP, PAP, and TC for Word 2000. <p>Class | |||
* The Shd structure specifies the colors and pattern that are used for background shading. <p>Class | |||
and | |||
fields descriptions are quoted from Microsoft Office Word 97-2007 Binary File Format | |||
fields descriptions are quoted from Word (.doc) Binary File Format by Microsoft Corporation | |||
* <p> | |||
* NOTE: This source is automatically generated please do not modify this file. Either subclass or | |||
@@ -33,8 +34,7 @@ import org.apache.poi.util.LittleEndian; | |||
* This class is internal. It content or properties may change without notice | |||
* due to changes in our knowledge of internal Microsoft Word binary structures. | |||
* @author Sergey Vladimirov; according to Microsoft Office Word 97-2007 Binary File Format | |||
Specification [*.doc] | |||
* @author Sergey Vladimirov; according to Word (.doc) Binary File Format by Microsoft Corporation. | |||
*/ | |||
@Internal | |||
@@ -53,16 +53,23 @@ public abstract class SHDAbstractType | |||
protected void fillFields( byte[] data, int offset ) | |||
{ | |||
field_1_cvFore = new Colorref(data, 0x0 + offset); | |||
field_2_cvBack = new Colorref(data, 0x4 + offset); | |||
field_3_ipat = LittleEndian.getShort(data, 0x8 + offset); | |||
field_1_cvFore = new Colorref( data, 0x0 + offset ); | |||
field_2_cvBack = new Colorref( data, 0x4 + offset ); | |||
field_3_ipat = LittleEndian.getShort( data, 0x8 + offset ); | |||
} | |||
public void serialize( byte[] data, int offset ) | |||
{ | |||
field_1_cvFore.serialize(data, 0x0 + offset); | |||
field_2_cvBack.serialize(data, 0x4 + offset); | |||
LittleEndian.putShort(data, 0x8 + offset, (short)field_3_ipat); | |||
field_1_cvFore.serialize( data, 0x0 + offset ); | |||
field_2_cvBack.serialize( data, 0x4 + offset ); | |||
LittleEndian.putUShort( data, 0x8 + offset, field_3_ipat ); | |||
} | |||
public byte[] serialize() | |||
{ | |||
final byte[] result = new byte[ getSize() ]; | |||
serialize( result, 0 ); | |||
return result; | |||
} | |||
/** | |||
@@ -73,6 +80,36 @@ public abstract class SHDAbstractType | |||
return 0 + 4 + 4 + 2; | |||
} | |||
@Override | |||
public boolean equals( Object obj ) | |||
{ | |||
if ( this == obj ) | |||
return true; | |||
if ( obj == null ) | |||
return false; | |||
if ( getClass() != obj.getClass() ) | |||
return false; | |||
SHDAbstractType other = (SHDAbstractType) obj; | |||
if ( field_1_cvFore != other.field_1_cvFore ) | |||
return false; | |||
if ( field_2_cvBack != other.field_2_cvBack ) | |||
return false; | |||
if ( field_3_ipat != other.field_3_ipat ) | |||
return false; | |||
return true; | |||
} | |||
@Override | |||
public int hashCode() | |||
{ | |||
final int prime = 31; | |||
int result = 1; | |||
result = prime * result + field_1_cvFore.hashCode(); | |||
result = prime * result + field_2_cvBack.hashCode(); | |||
result = prime * result + field_3_ipat; | |||
return result; | |||
} | |||
public String toString() | |||
{ | |||
StringBuilder builder = new StringBuilder(); | |||
@@ -89,7 +126,7 @@ public abstract class SHDAbstractType | |||
} | |||
/** | |||
* 24-bit foreground color. | |||
* A COLORREF that specifies the foreground color of ipat. | |||
*/ | |||
@Internal | |||
public Colorref getCvFore() | |||
@@ -98,7 +135,7 @@ public abstract class SHDAbstractType | |||
} | |||
/** | |||
* 24-bit foreground color. | |||
* A COLORREF that specifies the foreground color of ipat. | |||
*/ | |||
@Internal | |||
public void setCvFore( Colorref field_1_cvFore ) | |||
@@ -107,7 +144,7 @@ public abstract class SHDAbstractType | |||
} | |||
/** | |||
* 24-bit background color. | |||
* A COLORREF that specifies the background color of ipat. | |||
*/ | |||
@Internal | |||
public Colorref getCvBack() | |||
@@ -116,7 +153,7 @@ public abstract class SHDAbstractType | |||
} | |||
/** | |||
* 24-bit background color. | |||
* A COLORREF that specifies the background color of ipat. | |||
*/ | |||
@Internal | |||
public void setCvBack( Colorref field_2_cvBack ) | |||
@@ -125,7 +162,7 @@ public abstract class SHDAbstractType | |||
} | |||
/** | |||
* Shading pattern. | |||
* An Ipat that specifies the pattern used for shading. | |||
*/ | |||
@Internal | |||
public int getIpat() | |||
@@ -134,7 +171,7 @@ public abstract class SHDAbstractType | |||
} | |||
/** | |||
* Shading pattern. | |||
* An Ipat that specifies the pattern used for shading. | |||
*/ | |||
@Internal | |||
public void setIpat( int field_3_ipat ) |
@@ -17,6 +17,8 @@ | |||
package org.apache.poi.hwpf.sprm; | |||
import org.apache.poi.hwpf.usermodel.ShadingDescriptor80; | |||
import org.apache.poi.hwpf.model.Colorref; | |||
import org.apache.poi.hwpf.model.Hyphenation; | |||
import org.apache.poi.hwpf.usermodel.BorderCode; | |||
@@ -578,9 +580,20 @@ public final class CharacterSprmUncompressor extends SprmUncompressor | |||
case 0x65: | |||
newCHP.setBrc (new BorderCode(sprm.getGrpprl(), sprm.getGrpprlOffset())); | |||
break; | |||
case 0x66: | |||
newCHP.setShd (new ShadingDescriptor(sprm.getGrpprl(), sprm.getGrpprlOffset())); | |||
break; | |||
case 0x66: | |||
// sprmCShd80 | |||
/* | |||
* "A Shd80 structure that specifies the background shading for the text. By default, text is not shaded." | |||
* | |||
* Word (.doc) Binary File Format. Copyright (c) 2011 Microsoft | |||
* Corporation. Release: Tuesday, March 15, 2011 | |||
*/ | |||
ShadingDescriptor80 oldDescriptor = new ShadingDescriptor80( | |||
sprm.getGrpprl(), sprm.getGrpprlOffset() ); | |||
ShadingDescriptor newDescriptor = oldDescriptor | |||
.toShadingDescriptor(); | |||
newCHP.setShd( newDescriptor ); | |||
break; | |||
case 0x67: | |||
// Obsolete | |||
break; |
@@ -765,4 +765,20 @@ public class TestBugs extends TestCase | |||
{ | |||
HWPFTestDataSamples.openSampleFile( "Bug52032_3.doc" ); | |||
} | |||
/** | |||
* Bug 53380 - ArrayIndexOutOfBounds Excetion parsing word 97 document | |||
*/ | |||
public void testBug53380_1() throws Exception | |||
{ | |||
HWPFTestDataSamples.openSampleFile( "Bug53380_1.doc" ); | |||
} | |||
/** | |||
* Bug 53380 - ArrayIndexOutOfBounds Excetion parsing word 97 document | |||
*/ | |||
public void testBug53380_2() throws Exception | |||
{ | |||
HWPFTestDataSamples.openSampleFile( "Bug53380_2.doc" ); | |||
} | |||
} |
@@ -19,17 +19,17 @@ | |||
--> | |||
<record fromfile="true" name="SHD80" package="org.apache.poi.hwpf.model.types"> | |||
<suffix>AbstractType</suffix> | |||
<description>The SHD80 is a substructure of the CHP and PAP, and TC for Word 97. <p>Class | |||
and fields descriptions are quoted from | |||
Microsoft Office Word 97-2007 Binary File Format | |||
<description>The Shd80 structure specifies the colors and pattern that are used for background | |||
shading. As an exception to the constraints that are specified by Ico and Ipat, a Shd80 can | |||
be set to Shd80Nil and specifies that no shading is applied. <p>Class and fields | |||
descriptions are quoted from Word (.doc) Binary File Format by Microsoft Corporation | |||
</description> | |||
<author>Sergey Vladimirov; according to Microsoft Office Word 97-2007 Binary File Format | |||
Specification [*.doc] | |||
<author>Sergey Vladimirov; according to Word (.doc) Binary File Format by Microsoft Corporation. | |||
</author> | |||
<fields> | |||
<field type="short" size="2" name="value"> | |||
<bit number="1" mask="0x001F" name="icoFore" description="Foreground color" /> | |||
<bit number="2" mask="0x03E0" name="icoBack" description="Background color" /> | |||
<bit number="1" mask="0x001F" name="icoFore" description="Foreground color"/> | |||
<bit number="2" mask="0x03E0" name="icoBack" description="Background color"/> | |||
<bit number="3" mask="0xFC00" name="ipat" description="Shading pattern"/> | |||
</field> | |||
</fields> |
@@ -19,16 +19,15 @@ | |||
--> | |||
<record fromfile="true" name="SHD" package="org.apache.poi.hwpf.model.types"> | |||
<suffix>AbstractType</suffix> | |||
<description>The SHD is a substructure of the CHP, PAP, and TC for Word 2000. <p>Class | |||
<description>The Shd structure specifies the colors and pattern that are used for background shading. <p>Class | |||
and | |||
fields descriptions are quoted from Microsoft Office Word 97-2007 Binary File Format | |||
fields descriptions are quoted from Word (.doc) Binary File Format by Microsoft Corporation | |||
</description> | |||
<author>Sergey Vladimirov; according to Microsoft Office Word 97-2007 Binary File Format | |||
Specification [*.doc] | |||
<author>Sergey Vladimirov; according to Word (.doc) Binary File Format by Microsoft Corporation. | |||
</author> | |||
<fields> | |||
<field type="Colorref" size="4" name="cvFore" description="24-bit foreground color"/> | |||
<field type="Colorref" size="4" name="cvBack" description="24-bit background color"/> | |||
<field type="int" size="2" name="ipat" description="Shading pattern"/> | |||
<field type="Colorref" size="4" name="cvFore" description="A COLORREF that specifies the foreground color of ipat"/> | |||
<field type="Colorref" size="4" name="cvBack" description="A COLORREF that specifies the background color of ipat"/> | |||
<field type="int" size="2" name="ipat" description="An Ipat that specifies the pattern used for shading"/> | |||
</fields> | |||
</record> |