mirror of https://github.com/apache/poi.git
use StdfBase structure in StyleDescription
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1173550 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fa3c093c13
commit
caacbbdabc
|
@ -0,0 +1,78 @@
|
||||||
|
/* ====================================================================
|
||||||
|
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.hwpf.model;
|
||||||
|
|
||||||
|
import org.apache.poi.hwpf.model.types.StdfBaseAbstractType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The StdfBase structure specifies general information about a style.
|
||||||
|
*/
|
||||||
|
public class StdfBase extends StdfBaseAbstractType
|
||||||
|
{
|
||||||
|
|
||||||
|
public StdfBase()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public StdfBase( byte[] std, int offset )
|
||||||
|
{
|
||||||
|
fillFields( std, offset );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals( Object obj )
|
||||||
|
{
|
||||||
|
if ( this == obj )
|
||||||
|
return true;
|
||||||
|
if ( obj == null )
|
||||||
|
return false;
|
||||||
|
if ( getClass() != obj.getClass() )
|
||||||
|
return false;
|
||||||
|
StdfBase other = (StdfBase) obj;
|
||||||
|
if ( field_1_info1 != other.field_1_info1 )
|
||||||
|
return false;
|
||||||
|
if ( field_2_info2 != other.field_2_info2 )
|
||||||
|
return false;
|
||||||
|
if ( field_3_info3 != other.field_3_info3 )
|
||||||
|
return false;
|
||||||
|
if ( field_4_bchUpe != other.field_4_bchUpe )
|
||||||
|
return false;
|
||||||
|
if ( field_5_grfstd != other.field_5_grfstd )
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + field_1_info1;
|
||||||
|
result = prime * result + field_2_info2;
|
||||||
|
result = prime * result + field_3_info3;
|
||||||
|
result = prime * result + field_4_bchUpe;
|
||||||
|
result = prime * result + field_5_grfstd;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] serialize()
|
||||||
|
{
|
||||||
|
byte[] result = new byte[getSize()];
|
||||||
|
serialize( result, 0 );
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,10 +22,9 @@ import java.util.Arrays;
|
||||||
|
|
||||||
import org.apache.poi.hwpf.usermodel.CharacterProperties;
|
import org.apache.poi.hwpf.usermodel.CharacterProperties;
|
||||||
import org.apache.poi.hwpf.usermodel.ParagraphProperties;
|
import org.apache.poi.hwpf.usermodel.ParagraphProperties;
|
||||||
import org.apache.poi.util.BitField;
|
|
||||||
import org.apache.poi.util.BitFieldFactory;
|
|
||||||
import org.apache.poi.util.Internal;
|
import org.apache.poi.util.Internal;
|
||||||
import org.apache.poi.util.LittleEndian;
|
import org.apache.poi.util.LittleEndian;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comment me
|
* Comment me
|
||||||
*
|
*
|
||||||
|
@ -37,25 +36,11 @@ public final class StyleDescription implements HDFType
|
||||||
|
|
||||||
private final static int PARAGRAPH_STYLE = 1;
|
private final static int PARAGRAPH_STYLE = 1;
|
||||||
private final static int CHARACTER_STYLE = 2;
|
private final static int CHARACTER_STYLE = 2;
|
||||||
|
private final static int TABLE_STYLE = 3;
|
||||||
|
private final static int NUMBERING_STYLE = 4;
|
||||||
|
|
||||||
private int _istd;
|
|
||||||
private int _baseLength;
|
private int _baseLength;
|
||||||
private short _infoShort;
|
private StdfBase _stdfBase;
|
||||||
private static BitField _sti = BitFieldFactory.getInstance(0xfff);
|
|
||||||
private static BitField _fScratch = BitFieldFactory.getInstance(0x1000);
|
|
||||||
private static BitField _fInvalHeight = BitFieldFactory.getInstance(0x2000);
|
|
||||||
private static BitField _fHasUpe = BitFieldFactory.getInstance(0x4000);
|
|
||||||
private static BitField _fMassCopy = BitFieldFactory.getInstance(0x8000);
|
|
||||||
private short _infoShort2;
|
|
||||||
private static BitField _styleTypeCode = BitFieldFactory.getInstance(0xf);
|
|
||||||
private static BitField _baseStyle = BitFieldFactory.getInstance(0xfff0);
|
|
||||||
private short _infoShort3;
|
|
||||||
private static BitField _numUPX = BitFieldFactory.getInstance(0xf);
|
|
||||||
private static BitField _nextStyle = BitFieldFactory.getInstance(0xfff0);
|
|
||||||
private short _bchUpe;
|
|
||||||
private short _infoShort4;
|
|
||||||
private static BitField _fAutoRedef = BitFieldFactory.getInstance(0x1);
|
|
||||||
private static BitField _fHidden = BitFieldFactory.getInstance(0x2);
|
|
||||||
|
|
||||||
UPX[] _upxs;
|
UPX[] _upxs;
|
||||||
String _name;
|
String _name;
|
||||||
|
@ -71,16 +56,9 @@ public final class StyleDescription implements HDFType
|
||||||
{
|
{
|
||||||
_baseLength = baseLength;
|
_baseLength = baseLength;
|
||||||
int nameStart = offset + baseLength;
|
int nameStart = offset + baseLength;
|
||||||
_infoShort = LittleEndian.getShort(std, offset);
|
|
||||||
offset += LittleEndian.SHORT_SIZE;
|
_stdfBase = new StdfBase(std, offset);
|
||||||
_infoShort2 = LittleEndian.getShort(std, offset);
|
offset += StdfBase.getSize();
|
||||||
offset += LittleEndian.SHORT_SIZE;
|
|
||||||
_infoShort3 = LittleEndian.getShort(std, offset);
|
|
||||||
offset += LittleEndian.SHORT_SIZE;
|
|
||||||
_bchUpe = LittleEndian.getShort(std, offset);
|
|
||||||
offset += LittleEndian.SHORT_SIZE;
|
|
||||||
_infoShort4 = LittleEndian.getShort(std, offset);
|
|
||||||
offset += LittleEndian.SHORT_SIZE;
|
|
||||||
|
|
||||||
//first byte(s) of variable length section of std is the length of the
|
//first byte(s) of variable length section of std is the length of the
|
||||||
//style name and aliases string
|
//style name and aliases string
|
||||||
|
@ -112,9 +90,9 @@ public final class StyleDescription implements HDFType
|
||||||
// the spec only refers to two possible upxs but it mentions
|
// the spec only refers to two possible upxs but it mentions
|
||||||
// that more may be added in the future
|
// that more may be added in the future
|
||||||
int varOffset = grupxStart;
|
int varOffset = grupxStart;
|
||||||
int numUPX = _numUPX.getValue(_infoShort3);
|
int countOfUPX = _stdfBase.getCupx();
|
||||||
_upxs = new UPX[numUPX];
|
_upxs = new UPX[countOfUPX];
|
||||||
for(int x = 0; x < numUPX; x++)
|
for(int x = 0; x < countOfUPX; x++)
|
||||||
{
|
{
|
||||||
int upxSize = LittleEndian.getShort(std, varOffset);
|
int upxSize = LittleEndian.getShort(std, varOffset);
|
||||||
varOffset += LittleEndian.SHORT_SIZE;
|
varOffset += LittleEndian.SHORT_SIZE;
|
||||||
|
@ -137,11 +115,11 @@ public final class StyleDescription implements HDFType
|
||||||
}
|
}
|
||||||
public int getBaseStyle()
|
public int getBaseStyle()
|
||||||
{
|
{
|
||||||
return _baseStyle.getValue(_infoShort2);
|
return _stdfBase.getIstdBase();
|
||||||
}
|
}
|
||||||
public byte[] getCHPX()
|
public byte[] getCHPX()
|
||||||
{
|
{
|
||||||
switch (_styleTypeCode.getValue(_infoShort2))
|
switch (_stdfBase.getStk())
|
||||||
{
|
{
|
||||||
case PARAGRAPH_STYLE:
|
case PARAGRAPH_STYLE:
|
||||||
if (_upxs.length > 1)
|
if (_upxs.length > 1)
|
||||||
|
@ -158,7 +136,7 @@ public final class StyleDescription implements HDFType
|
||||||
}
|
}
|
||||||
public byte[] getPAPX()
|
public byte[] getPAPX()
|
||||||
{
|
{
|
||||||
switch (_styleTypeCode.getValue(_infoShort2))
|
switch (_stdfBase.getStk())
|
||||||
{
|
{
|
||||||
case PARAGRAPH_STYLE:
|
case PARAGRAPH_STYLE:
|
||||||
return _upxs[0].getUPX();
|
return _upxs[0].getUPX();
|
||||||
|
@ -206,18 +184,9 @@ public final class StyleDescription implements HDFType
|
||||||
|
|
||||||
|
|
||||||
byte[] buf = new byte[size];
|
byte[] buf = new byte[size];
|
||||||
|
_stdfBase.serialize( buf, 0 );
|
||||||
|
|
||||||
int offset = 0;
|
int offset = _baseLength;
|
||||||
LittleEndian.putShort(buf, offset, _infoShort);
|
|
||||||
offset += LittleEndian.SHORT_SIZE;
|
|
||||||
LittleEndian.putShort(buf, offset, _infoShort2);
|
|
||||||
offset += LittleEndian.SHORT_SIZE;
|
|
||||||
LittleEndian.putShort(buf, offset, _infoShort3);
|
|
||||||
offset += LittleEndian.SHORT_SIZE;
|
|
||||||
LittleEndian.putShort(buf, offset, _bchUpe);
|
|
||||||
offset += LittleEndian.SHORT_SIZE;
|
|
||||||
LittleEndian.putShort(buf, offset, _infoShort4);
|
|
||||||
offset = _baseLength;
|
|
||||||
|
|
||||||
char[] letters = _name.toCharArray();
|
char[] letters = _name.toCharArray();
|
||||||
LittleEndian.putShort(buf, _baseLength, (short)letters.length);
|
LittleEndian.putShort(buf, _baseLength, (short)letters.length);
|
||||||
|
@ -242,21 +211,44 @@ public final class StyleDescription implements HDFType
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals(Object o)
|
@Override
|
||||||
{
|
public int hashCode()
|
||||||
StyleDescription sd = (StyleDescription)o;
|
|
||||||
if (sd._infoShort == _infoShort && sd._infoShort2 == _infoShort2 &&
|
|
||||||
sd._infoShort3 == _infoShort3 && sd._bchUpe == _bchUpe &&
|
|
||||||
sd._infoShort4 == _infoShort4 &&
|
|
||||||
_name.equals(sd._name))
|
|
||||||
{
|
{
|
||||||
|
final int prime = 31;
|
||||||
if (!Arrays.equals(_upxs, sd._upxs))
|
int result = 1;
|
||||||
{
|
result = prime * result + ( ( _name == null ) ? 0 : _name.hashCode() );
|
||||||
return false;
|
result = prime * result
|
||||||
}
|
+ ( ( _stdfBase == null ) ? 0 : _stdfBase.hashCode() );
|
||||||
return true;
|
result = prime * result + Arrays.hashCode( _upxs );
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals( Object obj )
|
||||||
|
{
|
||||||
|
if ( this == obj )
|
||||||
|
return true;
|
||||||
|
if ( obj == null )
|
||||||
|
return false;
|
||||||
|
if ( getClass() != obj.getClass() )
|
||||||
|
return false;
|
||||||
|
StyleDescription other = (StyleDescription) obj;
|
||||||
|
if ( _name == null )
|
||||||
|
{
|
||||||
|
if ( other._name != null )
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if ( !_name.equals( other._name ) )
|
||||||
|
return false;
|
||||||
|
if ( _stdfBase == null )
|
||||||
|
{
|
||||||
|
if ( other._stdfBase != null )
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if ( !_stdfBase.equals( other._stdfBase ) )
|
||||||
|
return false;
|
||||||
|
if ( !Arrays.equals( _upxs, other._upxs ) )
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue