use LVLF to hold internal lists data
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1173731 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fb88976657
commit
c9140e56e5
96
src/scratchpad/src/org/apache/poi/hwpf/model/LVLF.java
Normal file
96
src/scratchpad/src/org/apache/poi/hwpf/model/LVLF.java
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
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 java.util.Arrays;
|
||||||
|
|
||||||
|
import org.apache.poi.hwpf.model.types.LVLFAbstractType;
|
||||||
|
import org.apache.poi.util.Internal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The LVLF structure contains formatting properties for an individual level in
|
||||||
|
* a list
|
||||||
|
*
|
||||||
|
* @author Sergey Vladimirov; according to Microsoft Office Word 97-2007 Binary
|
||||||
|
* File Format Specification [*.doc] and [MS-DOC] - v20110608 Word
|
||||||
|
* (.doc) Binary File Format
|
||||||
|
*/
|
||||||
|
@Internal
|
||||||
|
class LVLF extends LVLFAbstractType
|
||||||
|
{
|
||||||
|
|
||||||
|
public LVLF()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public LVLF( 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;
|
||||||
|
LVLF other = (LVLF) obj;
|
||||||
|
if ( field_10_grfhic != other.field_10_grfhic )
|
||||||
|
return false;
|
||||||
|
if ( field_1_iStartAt != other.field_1_iStartAt )
|
||||||
|
return false;
|
||||||
|
if ( field_2_info2 != other.field_2_info2 )
|
||||||
|
return false;
|
||||||
|
if ( !Arrays.equals( field_3_rgbxchNums, other.field_3_rgbxchNums ) )
|
||||||
|
return false;
|
||||||
|
if ( field_4_ixchFollow != other.field_4_ixchFollow )
|
||||||
|
return false;
|
||||||
|
if ( field_5_dxaIndentSav != other.field_5_dxaIndentSav )
|
||||||
|
return false;
|
||||||
|
if ( field_6_unused2 != other.field_6_unused2 )
|
||||||
|
return false;
|
||||||
|
if ( field_7_cbGrpprlChpx != other.field_7_cbGrpprlChpx )
|
||||||
|
return false;
|
||||||
|
if ( field_8_cbGrpprlPapx != other.field_8_cbGrpprlPapx )
|
||||||
|
return false;
|
||||||
|
if ( field_9_ilvlRestartLim != other.field_9_ilvlRestartLim )
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + field_10_grfhic;
|
||||||
|
result = prime * result + field_1_iStartAt;
|
||||||
|
result = prime * result + field_2_info2;
|
||||||
|
result = prime * result + Arrays.hashCode( field_3_rgbxchNums );
|
||||||
|
result = prime * result + field_4_ixchFollow;
|
||||||
|
result = prime * result + field_5_dxaIndentSav;
|
||||||
|
result = prime * result + field_6_unused2;
|
||||||
|
result = prime * result + field_7_cbGrpprlChpx;
|
||||||
|
result = prime * result + field_8_cbGrpprlPapx;
|
||||||
|
result = prime * result + field_9_ilvlRestartLim;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -19,6 +19,8 @@ package org.apache.poi.hwpf.model;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import org.apache.poi.hwpf.model.types.LVLFAbstractType;
|
||||||
|
|
||||||
import org.apache.poi.util.BitField;
|
import org.apache.poi.util.BitField;
|
||||||
import org.apache.poi.util.Internal;
|
import org.apache.poi.util.Internal;
|
||||||
import org.apache.poi.util.LittleEndian;
|
import org.apache.poi.util.LittleEndian;
|
||||||
@ -29,26 +31,25 @@ import org.apache.poi.util.LittleEndian;
|
|||||||
* See page 170 for details.
|
* See page 170 for details.
|
||||||
*/
|
*/
|
||||||
@Internal
|
@Internal
|
||||||
public final class ListLevel
|
public final class ListLevel
|
||||||
{
|
{
|
||||||
private static final int RGBXCH_NUMS_SIZE = 9;
|
// private int _iStartAt;
|
||||||
|
// private byte _nfc;
|
||||||
private int _iStartAt;
|
// private byte _info;
|
||||||
private byte _nfc;
|
// /* */private static BitField _jc;
|
||||||
private byte _info;
|
// /* */private static BitField _fLegal;
|
||||||
/* */private static BitField _jc;
|
// /* */private static BitField _fNoRestart;
|
||||||
/* */private static BitField _fLegal;
|
// /* */private static BitField _fPrev;
|
||||||
/* */private static BitField _fNoRestart;
|
// /* */private static BitField _fPrevSpace;
|
||||||
/* */private static BitField _fPrev;
|
// /* */private static BitField _fWord6;
|
||||||
/* */private static BitField _fPrevSpace;
|
// private byte[] _rgbxchNums;
|
||||||
/* */private static BitField _fWord6;
|
// private byte _ixchFollow;
|
||||||
private byte[] _rgbxchNums;
|
// private int _dxaSpace;
|
||||||
private byte _ixchFollow;
|
// private int _dxaIndent;
|
||||||
private int _dxaSpace;
|
// private int _cbGrpprlChpx;
|
||||||
private int _dxaIndent;
|
// private int _cbGrpprlPapx;
|
||||||
private int _cbGrpprlChpx;
|
// private short _reserved;
|
||||||
private int _cbGrpprlPapx;
|
private LVLF _lvlf;
|
||||||
private short _reserved;
|
|
||||||
private byte[] _grpprlPapx;
|
private byte[] _grpprlPapx;
|
||||||
private byte[] _grpprlChpx;
|
private byte[] _grpprlChpx;
|
||||||
private char[] _numberText = null;
|
private char[] _numberText = null;
|
||||||
@ -57,31 +58,16 @@ public final class ListLevel
|
|||||||
{
|
{
|
||||||
int offset = originalOffset;
|
int offset = originalOffset;
|
||||||
|
|
||||||
_iStartAt = LittleEndian.getInt( buf, offset );
|
_lvlf = new LVLF(buf, offset);
|
||||||
offset += LittleEndian.INT_SIZE;
|
offset += LVLF.getSize();
|
||||||
_nfc = buf[offset++];
|
|
||||||
_info = buf[offset++];
|
|
||||||
|
|
||||||
_rgbxchNums = new byte[RGBXCH_NUMS_SIZE];
|
_grpprlPapx = new byte[_lvlf.getCbGrpprlPapx()];
|
||||||
System.arraycopy( buf, offset, _rgbxchNums, 0, RGBXCH_NUMS_SIZE );
|
System.arraycopy( buf, offset, _grpprlPapx, 0, _lvlf.getCbGrpprlPapx() );
|
||||||
offset += RGBXCH_NUMS_SIZE;
|
offset += _lvlf.getCbGrpprlPapx();
|
||||||
|
|
||||||
_ixchFollow = buf[offset++];
|
_grpprlChpx = new byte[_lvlf.getCbGrpprlChpx()];
|
||||||
_dxaSpace = LittleEndian.getInt( buf, offset );
|
System.arraycopy( buf, offset, _grpprlChpx, 0, _lvlf.getCbGrpprlChpx() );
|
||||||
offset += LittleEndian.INT_SIZE;
|
offset += _lvlf.getCbGrpprlChpx();
|
||||||
_dxaIndent = LittleEndian.getInt( buf, offset );
|
|
||||||
offset += LittleEndian.INT_SIZE;
|
|
||||||
_cbGrpprlChpx = LittleEndian.getUnsignedByte( buf, offset++ );
|
|
||||||
_cbGrpprlPapx = LittleEndian.getUnsignedByte( buf, offset++ );
|
|
||||||
_reserved = LittleEndian.getShort( buf, offset );
|
|
||||||
offset += LittleEndian.SHORT_SIZE;
|
|
||||||
|
|
||||||
_grpprlPapx = new byte[_cbGrpprlPapx];
|
|
||||||
_grpprlChpx = new byte[_cbGrpprlChpx];
|
|
||||||
System.arraycopy( buf, offset, _grpprlPapx, 0, _cbGrpprlPapx );
|
|
||||||
offset += _cbGrpprlPapx;
|
|
||||||
System.arraycopy( buf, offset, _grpprlChpx, 0, _cbGrpprlChpx );
|
|
||||||
offset += _cbGrpprlChpx;
|
|
||||||
|
|
||||||
int numberTextLength = LittleEndian.getShort( buf, offset );
|
int numberTextLength = LittleEndian.getShort( buf, offset );
|
||||||
/* sometimes numberTextLength<0 */
|
/* sometimes numberTextLength<0 */
|
||||||
@ -101,15 +87,15 @@ public final class ListLevel
|
|||||||
|
|
||||||
public ListLevel( int level, boolean numbered )
|
public ListLevel( int level, boolean numbered )
|
||||||
{
|
{
|
||||||
_iStartAt = 1;
|
_lvlf = new LVLF();
|
||||||
|
setStartAt( 1 );
|
||||||
_grpprlPapx = new byte[0];
|
_grpprlPapx = new byte[0];
|
||||||
_grpprlChpx = new byte[0];
|
_grpprlChpx = new byte[0];
|
||||||
_numberText = new char[0];
|
_numberText = new char[0];
|
||||||
_rgbxchNums = new byte[RGBXCH_NUMS_SIZE];
|
|
||||||
|
|
||||||
if ( numbered )
|
if ( numbered )
|
||||||
{
|
{
|
||||||
_rgbxchNums[0] = 1;
|
_lvlf.getRgbxchNums()[0] = 1;
|
||||||
_numberText = new char[] { (char) level, '.' };
|
_numberText = new char[] { (char) level, '.' };
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -121,9 +107,10 @@ public final class ListLevel
|
|||||||
public ListLevel( int startAt, int numberFormatCode, int alignment,
|
public ListLevel( int startAt, int numberFormatCode, int alignment,
|
||||||
byte[] numberProperties, byte[] entryProperties, String numberText )
|
byte[] numberProperties, byte[] entryProperties, String numberText )
|
||||||
{
|
{
|
||||||
_iStartAt = startAt;
|
_lvlf = new LVLF();
|
||||||
_nfc = (byte) numberFormatCode;
|
setStartAt( startAt );
|
||||||
_jc.setValue( _info, alignment );
|
_lvlf.setNfc( (short) numberFormatCode );
|
||||||
|
_lvlf.setJc( (byte) alignment );
|
||||||
_grpprlChpx = numberProperties;
|
_grpprlChpx = numberProperties;
|
||||||
_grpprlPapx = entryProperties;
|
_grpprlPapx = entryProperties;
|
||||||
_numberText = numberText.toCharArray();
|
_numberText = numberText.toCharArray();
|
||||||
@ -135,16 +122,10 @@ public final class ListLevel
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
ListLevel lvl = (ListLevel) obj;
|
ListLevel lvl = (ListLevel) obj;
|
||||||
return _cbGrpprlChpx == lvl._cbGrpprlChpx
|
return lvl._lvlf.equals( this._lvlf )
|
||||||
&& lvl._cbGrpprlPapx == _cbGrpprlPapx
|
|
||||||
&& lvl._dxaIndent == _dxaIndent && lvl._dxaSpace == _dxaSpace
|
|
||||||
&& Arrays.equals( lvl._grpprlChpx, _grpprlChpx )
|
&& Arrays.equals( lvl._grpprlChpx, _grpprlChpx )
|
||||||
&& Arrays.equals( lvl._grpprlPapx, _grpprlPapx )
|
&& Arrays.equals( lvl._grpprlPapx, _grpprlPapx )
|
||||||
&& lvl._info == _info && lvl._iStartAt == _iStartAt
|
&& Arrays.equals( lvl._numberText, _numberText );
|
||||||
&& lvl._ixchFollow == _ixchFollow && lvl._nfc == _nfc
|
|
||||||
&& Arrays.equals( lvl._numberText, _numberText )
|
|
||||||
&& Arrays.equals( lvl._rgbxchNums, _rgbxchNums )
|
|
||||||
&& lvl._reserved == _reserved;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -152,7 +133,7 @@ public final class ListLevel
|
|||||||
*/
|
*/
|
||||||
public int getAlignment()
|
public int getAlignment()
|
||||||
{
|
{
|
||||||
return _jc.getValue( _info );
|
return _lvlf.getJc();
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getLevelProperties()
|
public byte[] getLevelProperties()
|
||||||
@ -165,7 +146,7 @@ public final class ListLevel
|
|||||||
*/
|
*/
|
||||||
public int getNumberFormat()
|
public int getNumberFormat()
|
||||||
{
|
{
|
||||||
return _nfc;
|
return _lvlf.getNfc();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNumberText()
|
public String getNumberText()
|
||||||
@ -178,9 +159,8 @@ public final class ListLevel
|
|||||||
|
|
||||||
public int getSizeInBytes()
|
public int getSizeInBytes()
|
||||||
{
|
{
|
||||||
int result = 6 // int byte byte
|
int result = LVLF.getSize() + _lvlf.getCbGrpprlChpx()
|
||||||
+ RGBXCH_NUMS_SIZE + 13 // byte int int byte byte short
|
+ _lvlf.getCbGrpprlPapx() + 2; // numberText length
|
||||||
+ _cbGrpprlChpx + _cbGrpprlPapx + 2; // numberText length
|
|
||||||
if ( _numberText != null )
|
if ( _numberText != null )
|
||||||
{
|
{
|
||||||
result += _numberText.length * LittleEndian.SHORT_SIZE;
|
result += _numberText.length * LittleEndian.SHORT_SIZE;
|
||||||
@ -190,7 +170,7 @@ public final class ListLevel
|
|||||||
|
|
||||||
public int getStartAt()
|
public int getStartAt()
|
||||||
{
|
{
|
||||||
return _iStartAt;
|
return _lvlf.getIStartAt();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -198,12 +178,12 @@ public final class ListLevel
|
|||||||
*/
|
*/
|
||||||
public byte getTypeOfCharFollowingTheNumber()
|
public byte getTypeOfCharFollowingTheNumber()
|
||||||
{
|
{
|
||||||
return this._ixchFollow;
|
return _lvlf.getIxchFollow();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAlignment( int alignment )
|
public void setAlignment( int alignment )
|
||||||
{
|
{
|
||||||
_jc.setValue( _info, alignment );
|
_lvlf.setJc( (byte) alignment );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLevelProperties( byte[] grpprl )
|
public void setLevelProperties( byte[] grpprl )
|
||||||
@ -213,7 +193,7 @@ public final class ListLevel
|
|||||||
|
|
||||||
public void setNumberFormat( int numberFormatCode )
|
public void setNumberFormat( int numberFormatCode )
|
||||||
{
|
{
|
||||||
_nfc = (byte) numberFormatCode;
|
_lvlf.setNfc( (short) numberFormatCode );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNumberProperties( byte[] grpprl )
|
public void setNumberProperties( byte[] grpprl )
|
||||||
@ -224,39 +204,28 @@ public final class ListLevel
|
|||||||
|
|
||||||
public void setStartAt( int startAt )
|
public void setStartAt( int startAt )
|
||||||
{
|
{
|
||||||
_iStartAt = startAt;
|
_lvlf.setIStartAt( startAt );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTypeOfCharFollowingTheNumber( byte value )
|
public void setTypeOfCharFollowingTheNumber( byte value )
|
||||||
{
|
{
|
||||||
this._ixchFollow = value;
|
_lvlf.setIxchFollow( value );
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] toByteArray()
|
public byte[] toByteArray()
|
||||||
{
|
{
|
||||||
byte[] buf = new byte[getSizeInBytes()];
|
byte[] buf = new byte[getSizeInBytes()];
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
LittleEndian.putInt( buf, offset, _iStartAt );
|
|
||||||
offset += LittleEndian.INT_SIZE;
|
|
||||||
buf[offset++] = _nfc;
|
|
||||||
buf[offset++] = _info;
|
|
||||||
System.arraycopy( _rgbxchNums, 0, buf, offset, RGBXCH_NUMS_SIZE );
|
|
||||||
offset += RGBXCH_NUMS_SIZE;
|
|
||||||
buf[offset++] = _ixchFollow;
|
|
||||||
LittleEndian.putInt( buf, offset, _dxaSpace );
|
|
||||||
offset += LittleEndian.INT_SIZE;
|
|
||||||
LittleEndian.putInt( buf, offset, _dxaIndent );
|
|
||||||
offset += LittleEndian.INT_SIZE;
|
|
||||||
|
|
||||||
buf[offset++] = (byte) _cbGrpprlChpx;
|
_lvlf.setCbGrpprlChpx( (short) _grpprlChpx.length );
|
||||||
buf[offset++] = (byte) _cbGrpprlPapx;
|
_lvlf.setCbGrpprlPapx( (short) _grpprlPapx.length );
|
||||||
LittleEndian.putShort( buf, offset, _reserved );
|
_lvlf.serialize( buf, offset );
|
||||||
offset += LittleEndian.SHORT_SIZE;
|
offset += LVLF.getSize();
|
||||||
|
|
||||||
System.arraycopy( _grpprlPapx, 0, buf, offset, _cbGrpprlPapx );
|
System.arraycopy( _grpprlPapx, 0, buf, offset, _grpprlPapx.length );
|
||||||
offset += _cbGrpprlPapx;
|
offset += _grpprlPapx.length;
|
||||||
System.arraycopy( _grpprlChpx, 0, buf, offset, _cbGrpprlChpx );
|
System.arraycopy( _grpprlChpx, 0, buf, offset, _grpprlChpx.length );
|
||||||
offset += _cbGrpprlChpx;
|
offset += _grpprlChpx.length;
|
||||||
|
|
||||||
if ( _numberText == null )
|
if ( _numberText == null )
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user