You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by sa...@apache.org on 2003/11/10 12:51:01 UTC
cvs commit: jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes StyleDescription.java
sackley 2003/11/10 03:51:01
Modified: src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes
StyleDescription.java
Log:
latest changes...still not working though!
Revision Changes Path
1.6 +68 -88 jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/StyleDescription.java
Index: StyleDescription.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/StyleDescription.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- StyleDescription.java 17 Jul 2003 03:01:03 -0000 1.5
+++ StyleDescription.java 10 Nov 2003 11:51:01 -0000 1.6
@@ -59,6 +59,8 @@
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
+import org.apache.poi.hwpf.usermodel.CharacterProperties;
+import org.apache.poi.hwpf.usermodel.ParagraphProperties;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.BitField;
/**
@@ -70,8 +72,8 @@
public class StyleDescription implements HDFType
{
- private static int PARAGRAPH_STYLE = 1;
- private static int CHARACTER_STYLE = 2;
+ private final static int PARAGRAPH_STYLE = 1;
+ private final static int CHARACTER_STYLE = 2;
private int _istd;
private int _baseLength;
@@ -92,11 +94,10 @@
private static BitField _fAutoRedef = new BitField(0x1);
private static BitField _fHidden = new BitField(0x2);
- byte[] _papx;
- byte[] _chpx;
+ UPX[] _upxs;
String _name;
-// ParagraphProperties _pap;
-// CharacterProperties _chp;
+ ParagraphProperties _pap;
+ CharacterProperties _chp;
public StyleDescription()
{
@@ -149,33 +150,17 @@
// that more may be added in the future
int varOffset = grupxStart;
int numUPX = _numUPX.getValue(_infoShort3);
+ _upxs = new UPX[numUPX];
for(int x = 0; x < numUPX; x++)
{
int upxSize = LittleEndian.getShort(std, varOffset);
varOffset += LittleEndian.SHORT_SIZE;
- if(_styleTypeCode.getValue(_infoShort2) == PARAGRAPH_STYLE)
- {
- if(x == 0)
- {
- _istd = LittleEndian.getShort(std, varOffset);
- //varOffset += LittleEndian.SHORT_SIZE;
- int grrprlSize = upxSize;
- _papx = new byte[grrprlSize];
- System.arraycopy(std, varOffset, _papx, 0, grrprlSize);
- varOffset += grrprlSize;
- }
- else if(x == 1)
- {
- _chpx = new byte[upxSize];
- System.arraycopy(std, varOffset, _chpx, 0, upxSize);
- varOffset += upxSize;
- }
- }
- else if(_styleTypeCode.getValue(_infoShort2) == CHARACTER_STYLE && x == 0)
- {
- _chpx = new byte[upxSize];
- System.arraycopy(std, varOffset, _chpx, 0, upxSize);
- }
+
+ byte[] upx = new byte[upxSize];
+ System.arraycopy(std, varOffset, upx, 0, upxSize);
+ _upxs[x] = new UPX(upx);
+ varOffset += upxSize;
+
// the upx will always start on a word boundary.
if(upxSize % 2 == 1)
@@ -189,32 +174,52 @@
}
public int getBaseStyle()
{
- return _baseStyle.getValue(_infoShort2);
+ return _baseStyle.getValue(_infoShort2);
}
public byte[] getCHPX()
{
- return _chpx;
+ switch (_styleTypeCode.getValue(_infoShort2))
+ {
+ case PARAGRAPH_STYLE:
+ if (_upxs.length > 1)
+ {
+ return _upxs[1].getUPX();
+ }
+ return null;
+ case CHARACTER_STYLE:
+ return _upxs[0].getUPX();
+ default:
+ return null;
+ }
+
}
public byte[] getPAPX()
{
- return _papx;
+ switch (_styleTypeCode.getValue(_infoShort2))
+ {
+ case PARAGRAPH_STYLE:
+ return _upxs[0].getUPX();
+ default:
+ return null;
+ }
+ }
+ public ParagraphProperties getPAP()
+ {
+ return _pap;
+ }
+ public CharacterProperties getCHP()
+ {
+ return _chp;
+ }
+ void setPAP(ParagraphProperties pap)
+ {
+ _pap = pap;
+ }
+ void setCHP(CharacterProperties chp)
+ {
+ _chp = chp;
}
-// public ParagraphProperties getPAP()
-// {
-// return _pap;
-// }
-// public CharacterProperties getCHP()
-// {
-// return _chp;
-// }
-// public void setPAP(ParagraphProperties pap)
-// {
-// _pap = pap;
-// }
-// public void setCHP(CharacterProperties chp)
-// {
-// _chp = chp;
-// }
+
public byte[] toByteArray()
{
// size equals _baseLength bytes for known variables plus 2 bytes for name
@@ -222,20 +227,16 @@
// length
int size = _baseLength + 2 + ((_name.length() + 1) * 2);
- //only worry about papx and chpx for upxs
- if(_styleTypeCode.getValue(_infoShort2) == PARAGRAPH_STYLE)
- {
- size += _papx.length + 2 + (_papx.length % 2);
- if (_chpx != null)
- {
- size += _chpx.length + 2;
- }
- }
- else if (_styleTypeCode.getValue(_infoShort2) == CHARACTER_STYLE)
+ // determine the size needed for the upxs. They always fall on word
+ // boundaries.
+ size += _upxs[0].size() + 2;
+ for (int x = 1; x < _upxs.length; x++)
{
- size += _chpx.length + 2;
+ size += _upxs[x-1].size() % 2;
+ size += _upxs[x].size() + 2;
}
+
byte[] buf = new byte[size];
int offset = 0;
@@ -248,10 +249,10 @@
LittleEndian.putShort(buf, offset, _bchUpe);
offset += LittleEndian.SHORT_SIZE;
LittleEndian.putShort(buf, offset, _infoShort4);
- offset += LittleEndian.SHORT_SIZE;
+ offset = _baseLength;
char[] letters = _name.toCharArray();
- LittleEndian.putShort(buf, offset, (short)letters.length);
+ LittleEndian.putShort(buf, _baseLength, (short)letters.length);
offset += LittleEndian.SHORT_SIZE;
for (int x = 0; x < letters.length; x++)
{
@@ -261,28 +262,13 @@
// get past the null delimiter for the name.
offset += LittleEndian.SHORT_SIZE;
- //only worry about papx and chpx for upxs
- if(_styleTypeCode.getValue(_infoShort2) == PARAGRAPH_STYLE)
- {
- LittleEndian.putShort(buf, offset, (short)(_papx.length));
- offset += LittleEndian.SHORT_SIZE;
- System.arraycopy(_papx, 0, buf, offset, _papx.length);
- offset += _papx.length + (_papx.length % 2);
-
- if (_chpx != null)
- {
- LittleEndian.putShort(buf, offset, (short) _chpx.length);
- offset += LittleEndian.SHORT_SIZE;
- System.arraycopy(_chpx, 0, buf, offset, _chpx.length);
- offset += _chpx.length;
- }
- }
- else if (_styleTypeCode.getValue(_infoShort2) == CHARACTER_STYLE)
+ for (int x = 0; x < _upxs.length; x++)
{
- LittleEndian.putShort(buf, offset, (short)_chpx.length);
+ short upxSize = (short)_upxs[x].size();
+ LittleEndian.putShort(buf, offset, upxSize);
offset += LittleEndian.SHORT_SIZE;
- System.arraycopy(_chpx, 0, buf, offset, _chpx.length);
- offset += _chpx.length;
+ System.arraycopy(_upxs[x].getUPX(), 0, buf, offset, upxSize);
+ offset += upxSize + (upxSize % 2);
}
return buf;
@@ -297,16 +283,10 @@
_name.equals(sd._name))
{
- if (!Arrays.equals(_chpx, sd._chpx))
+ if (!Arrays.equals(_upxs, sd._upxs))
{
return false;
}
-
- if (!Arrays.equals(_papx, sd._papx))
- {
- return false;
- }
-
return true;
}
return false;
---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: poi-dev-help@jakarta.apache.org