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 2004/03/10 05:18:54 UTC
cvs commit: jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model Ffn.java FileInformationBlock.java FontTable.java PAPBinTable.java PAPFormattedDiskPage.java PAPX.java StyleDescription.java
sackley 2004/03/09 20:18:54
Modified: src/scratchpad/src/org/apache/poi/hwpf/model Ffn.java
FileInformationBlock.java FontTable.java
PAPBinTable.java PAPFormattedDiskPage.java
PAPX.java StyleDescription.java
Log:
patch from piers and other minor changes
Revision Changes Path
1.2 +82 -84 jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/Ffn.java
Index: Ffn.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/Ffn.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Ffn.java 2 Mar 2004 06:22:01 -0000 1.1
+++ Ffn.java 10 Mar 2004 04:18:53 -0000 1.2
@@ -67,121 +67,119 @@
*/
public class Ffn
{
- private int field_1_cbFfnM1;//total length of FFN - 1.
- private byte field_2;
- private static BitField _prq = new BitField(0x0003);// pitch request
- private static BitField _fTrueType = new BitField(0x0004);// when 1, font is a TrueType font
- private static BitField _ff = new BitField(0x0070);
- private short field_3_wWeight;// base weight of font
- private byte field_4_chs;// character set identifier
- private byte field_5_ixchSzAlt; // index into ffn.szFfn to the name of
+ private int _cbFfnM1;//total length of FFN - 1.
+ private byte _info;
+ private static BitField _prq = new BitField(0x0003);// pitch request
+ private static BitField _fTrueType = new BitField(0x0004);// when 1, font is a TrueType font
+ private static BitField _ff = new BitField(0x0070);
+ private short _wWeight;// base weight of font
+ private byte _chs;// character set identifier
+ private byte _ixchSzAlt; // index into ffn.szFfn to the name of
// the alternate font
- private byte [] field_6_panose = new byte[10];//????
- private byte [] field_7_fontSig = new byte[24];//????
+ private byte [] _panose = new byte[10];//????
+ private byte [] _fontSig = new byte[24];//????
// zero terminated string that records name of font, cuurently not
// supporting Extended chars
- private char [] field_8_xszFfn;
+ private char [] _xszFfn;
// extra facilitator members
- private int xszFfnLength;
+ private int _xszFfnLength;
public Ffn(byte[] buf, int offset)
{
- int offsetTmp = offset;
+ int offsetTmp = offset;
- field_1_cbFfnM1 = LittleEndian.getUnsignedByte(buf,offset);
+ _cbFfnM1 = LittleEndian.getUnsignedByte(buf,offset);
offset += LittleEndian.BYTE_SIZE;
- field_2 = buf[offset];
+ _info = buf[offset];
offset += LittleEndian.BYTE_SIZE;
- field_3_wWeight = LittleEndian.getShort(buf, offset);
+ _wWeight = LittleEndian.getShort(buf, offset);
offset += LittleEndian.SHORT_SIZE;
- field_4_chs = buf[offset];
+ _chs = buf[offset];
offset += LittleEndian.BYTE_SIZE;
- field_5_ixchSzAlt = buf[offset];
+ _ixchSzAlt = buf[offset];
offset += LittleEndian.BYTE_SIZE;
// read panose and fs so we can write them back out.
- System.arraycopy(buf, offset, field_6_panose, 0, field_6_panose.length);
- offset += field_6_panose.length;
- System.arraycopy(buf, offset, field_7_fontSig, 0, field_7_fontSig.length);
- offset += field_7_fontSig.length;
-
- offsetTmp = offset - offsetTmp;
- xszFfnLength = this.getSize() - offsetTmp;
- field_8_xszFfn = new char[xszFfnLength];
+ System.arraycopy(buf, offset, _panose, 0, _panose.length);
+ offset += _panose.length;
+ System.arraycopy(buf, offset, _fontSig, 0, _fontSig.length);
+ offset += _fontSig.length;
+
+ offsetTmp = offset - offsetTmp;
+ _xszFfnLength = this.getSize() - offsetTmp;
+ _xszFfn = new char[_xszFfnLength];
- for(int i = 0; i < xszFfnLength; i++)
+ for(int i = 0; i < _xszFfnLength; i++)
{
- field_8_xszFfn[i] = (char)LittleEndian.getUnsignedByte(buf, offset);
- offset += LittleEndian.BYTE_SIZE;
+ _xszFfn[i] = (char)LittleEndian.getShort(buf, offset);
+ offset += LittleEndian.SHORT_SIZE;
}
}
- public int getField_1_cbFfnM1()
+ public int get_cbFfnM1()
{
- return field_1_cbFfnM1;
+ return _cbFfnM1;
}
- public byte getField_2()
+ public short getWeight()
{
- return field_2;
+ return _wWeight;
}
- public short getField_3_wWeight()
+ public byte getChs()
{
- return field_3_wWeight;
+ return _chs;
}
- public byte getField_4_chs()
+ public byte [] getPanose()
{
- return field_4_chs;
+ return _panose;
}
- public byte getField_5_ixchSzAlt()
+ public byte [] getFontSig()
{
- return field_5_ixchSzAlt;
- }
-
- public byte [] getField_6_panose()
- {
- return field_6_panose;
- }
-
- public byte [] getField_7_fontSig()
- {
- return field_7_fontSig;
- }
-
- public char [] getField_8_xszFfn()
- {
- return field_8_xszFfn;
+ return _fontSig;
}
public int getSize()
{
- return (field_1_cbFfnM1 + 1);
+ return (_cbFfnM1 + 1);
}
- public char [] getMainFontName()
+ public String getMainFontName()
{
- char [] temp = new char[field_5_ixchSzAlt];
- System.arraycopy(field_8_xszFfn,0,temp,0,temp.length);
- return temp;
+ int index = 0;
+ for (;index < _xszFfnLength; index++)
+ {
+ if (_xszFfn[index] == '\0')
+ {
+ break;
+ }
+ }
+ return new String(_xszFfn, 0, index);
}
- public char [] getAltFontName()
+ public String getAltFontName()
{
- char [] temp = new char[xszFfnLength - field_5_ixchSzAlt];
- System.arraycopy(field_8_xszFfn, field_5_ixchSzAlt, temp, 0, temp.length);
- return temp;
+ int index = _ixchSzAlt;
+ for (;index < _xszFfnLength; index++)
+ {
+ if (_xszFfn[index] == '\0')
+ {
+ break;
+ }
+ }
+ return new String(_xszFfn, _ixchSzAlt, index);
+
}
- public void setField_1_cbFfnM1(int field_1_cbFfnM1)
+ public void set_cbFfnM1(int _cbFfnM1)
{
- this.field_1_cbFfnM1 = field_1_cbFfnM1;
+ this._cbFfnM1 = _cbFfnM1;
}
// changed protected to public
@@ -190,25 +188,25 @@
int offset = 0;
byte[] buf = new byte[this.getSize()];
- buf[offset] = (byte)field_1_cbFfnM1;
+ buf[offset] = (byte)_cbFfnM1;
offset += LittleEndian.BYTE_SIZE;
- buf[offset] = field_2;
+ buf[offset] = _info;
offset += LittleEndian.BYTE_SIZE;
- LittleEndian.putShort(buf, offset, field_3_wWeight);
+ LittleEndian.putShort(buf, offset, _wWeight);
offset += LittleEndian.SHORT_SIZE;
- buf[offset] = field_4_chs;
+ buf[offset] = _chs;
offset += LittleEndian.BYTE_SIZE;
- buf[offset] = field_5_ixchSzAlt;
+ buf[offset] = _ixchSzAlt;
offset += LittleEndian.BYTE_SIZE;
- System.arraycopy(field_6_panose,0,buf, offset,field_6_panose.length);
- offset += field_6_panose.length;
- System.arraycopy(field_7_fontSig,0,buf, offset, field_7_fontSig.length);
- offset += field_7_fontSig.length;
+ System.arraycopy(_panose,0,buf, offset,_panose.length);
+ offset += _panose.length;
+ System.arraycopy(_fontSig,0,buf, offset, _fontSig.length);
+ offset += _fontSig.length;
- for(int i = 0; i < field_8_xszFfn.length; i++)
+ for(int i = 0; i < _xszFfn.length; i++)
{
- buf[offset] = (byte)field_8_xszFfn[i];
+ buf[offset] = (byte)_xszFfn[i];
offset += LittleEndian.BYTE_SIZE;
}
@@ -220,21 +218,21 @@
{
boolean retVal = true;
- if (((Ffn)o).getField_1_cbFfnM1() == field_1_cbFfnM1)
+ if (((Ffn)o).get_cbFfnM1() == _cbFfnM1)
{
- if(((Ffn)o).getField_2() == field_2)
+ if(((Ffn)o)._info == _info)
{
- if(((Ffn)o).getField_3_wWeight() == field_3_wWeight)
+ if(((Ffn)o)._wWeight == _wWeight)
{
- if(((Ffn)o).getField_4_chs() == field_4_chs)
+ if(((Ffn)o)._chs == _chs)
{
- if(((Ffn)o).getField_5_ixchSzAlt() == field_5_ixchSzAlt)
+ if(((Ffn)o)._ixchSzAlt == _ixchSzAlt)
{
- if(Arrays.equals(((Ffn)o).getField_6_panose(),field_6_panose))
+ if(Arrays.equals(((Ffn)o)._panose,_panose))
{
- if(Arrays.equals(((Ffn)o).getField_7_fontSig(),field_7_fontSig))
+ if(Arrays.equals(((Ffn)o)._fontSig,_fontSig))
{
- if(!(Arrays.equals(((Ffn)o).getField_8_xszFfn(),field_8_xszFfn)))
+ if(!(Arrays.equals(((Ffn)o)._xszFfn,_xszFfn)))
retVal = false;
}
else
1.2 +11 -0 jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java
Index: FileInformationBlock.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FileInformationBlock.java 2 Mar 2004 06:22:01 -0000 1.1
+++ FileInformationBlock.java 10 Mar 2004 04:18:53 -0000 1.2
@@ -96,6 +96,7 @@
fieldSet.add(new Integer(FIBFieldHandler.PLCFSED));
fieldSet.add(new Integer(FIBFieldHandler.PLCFLST));
fieldSet.add(new Integer(FIBFieldHandler.PLFLFO));
+ fieldSet.add(new Integer(FIBFieldHandler.PLCFFLDMOM));
fieldSet.add(new Integer(FIBFieldHandler.STTBFFFN));
fieldSet.add(new Integer(FIBFieldHandler.MODIFIED));
@@ -315,6 +316,16 @@
public void clearOffsetsSizes()
{
_fieldHandler.clearFields();
+ }
+
+ public int getFcPlcffldMom()
+ {
+ return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFFLDMOM);
+ }
+
+ public int getLcbPlcffldMom()
+ {
+ return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFFLDMOM);
}
public void writeTo (byte[] mainStream, HWPFOutputStream tableStream)
1.2 +2 -2 jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java
Index: FontTable.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FontTable.java 2 Mar 2004 06:22:01 -0000 1.1
+++ FontTable.java 10 Mar 2004 04:18:53 -0000 1.2
@@ -119,7 +119,7 @@
return lcbSttbfffn;
}
- public char [] getMainFont(int chpFtc )
+ public String getMainFont(int chpFtc )
{
if(chpFtc >= _stringCount)
{
@@ -130,7 +130,7 @@
return _fontNames[chpFtc].getMainFontName();
}
- public char [] getAltFont(int chpFtc )
+ public String getAltFont(int chpFtc )
{
if(chpFtc >= _stringCount)
{
1.2 +7 -5 jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java
Index: PAPBinTable.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PAPBinTable.java 2 Mar 2004 06:22:01 -0000 1.1
+++ PAPBinTable.java 10 Mar 2004 04:18:53 -0000 1.2
@@ -68,8 +68,9 @@
public class PAPBinTable
{
ArrayList _paragraphs = new ArrayList();
+ byte[] _dataStream;
- public PAPBinTable(byte[] documentStream, byte[] tableStream, int offset,
+ public PAPBinTable(byte[] documentStream, byte[] tableStream, byte[] dataStream, int offset,
int size, int fcMin)
{
PlexOfCps binTable = new PlexOfCps(tableStream, offset, size, 4);
@@ -83,7 +84,7 @@
int pageOffset = POIFSConstants.BIG_BLOCK_SIZE * pageNum;
PAPFormattedDiskPage pfkp = new PAPFormattedDiskPage(documentStream,
- pageOffset, fcMin);
+ dataStream, pageOffset, fcMin);
int fkpSize = pfkp.size();
@@ -92,11 +93,12 @@
_paragraphs.add(pfkp.getPAPX(y));
}
}
+ _dataStream = dataStream;
}
public void insert(int listIndex, int cpStart, SprmBuffer buf)
{
- PAPX forInsert = new PAPX(cpStart, cpStart, buf);
+ PAPX forInsert = new PAPX(cpStart, cpStart, buf, _dataStream);
if (listIndex == _paragraphs.size())
{
_paragraphs.add(forInsert);
@@ -116,7 +118,7 @@
exc.printStackTrace();
}
currentPap.setEnd(cpStart);
- PAPX splitPap = new PAPX(cpStart, currentPap.getEnd(), clonedBuf);
+ PAPX splitPap = new PAPX(cpStart, currentPap.getEnd(), clonedBuf, _dataStream);
_paragraphs.add(++listIndex, forInsert);
_paragraphs.add(++listIndex, splitPap);
}
@@ -220,7 +222,7 @@
PropertyNode startingProp = (PropertyNode)overflow.get(0);
int start = startingProp.getStart() + fcMin;
- PAPFormattedDiskPage pfkp = new PAPFormattedDiskPage();
+ PAPFormattedDiskPage pfkp = new PAPFormattedDiskPage(_dataStream);
pfkp.fill(overflow);
byte[] bufFkp = pfkp.toByteArray(fcMin);
1.2 +47 -5 jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/PAPFormattedDiskPage.java
Index: PAPFormattedDiskPage.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/PAPFormattedDiskPage.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PAPFormattedDiskPage.java 2 Mar 2004 06:22:01 -0000 1.1
+++ PAPFormattedDiskPage.java 10 Mar 2004 04:18:53 -0000 1.2
@@ -84,11 +84,12 @@
private ArrayList _papxList = new ArrayList();
private ArrayList _overFlow;
+ private byte[] _dataStream;
- public PAPFormattedDiskPage()
+ public PAPFormattedDiskPage(byte[] dataStream)
{
-
+ _dataStream = dataStream;
}
/**
@@ -96,15 +97,16 @@
*
* @param fkp a 512 byte array.
*/
- public PAPFormattedDiskPage(byte[] documentStream, int offset, int fcMin)
+ public PAPFormattedDiskPage(byte[] documentStream, byte[] dataStream, int offset, int fcMin)
{
super(documentStream, offset);
for (int x = 0; x < _crun; x++)
{
- _papxList.add(new PAPX(getStart(x) - fcMin, getEnd(x) - fcMin, getGrpprl(x), getParagraphHeight(x)));
+ _papxList.add(new PAPX(getStart(x) - fcMin, getEnd(x) - fcMin, getGrpprl(x), getParagraphHeight(x), dataStream));
}
_fkp = null;
+ _dataStream = dataStream;
}
public void fill(List filler)
@@ -164,6 +166,12 @@
byte[] grpprl = ((PAPX)_papxList.get(index)).getGrpprl();
int grpprlLength = grpprl.length;
+ // is grpprl huge?
+ if(grpprlLength > 488)
+ {
+ grpprlLength = 8; // set equal to size of sprmPHugePapx grpprl
+ }
+
// check to see if we have enough room for an FC, a BX, and the grpprl
// and the 1 byte size of the grpprl.
int addition = 0;
@@ -219,6 +227,40 @@
byte[] phe = papx.getParagraphHeight().toByteArray();
byte[] grpprl = papx.getGrpprl();
+ // is grpprl huge?
+ if(grpprl.length > 488)
+ {
+ // if so do we have storage at getHugeGrpprlOffset()
+ int hugeGrpprlOffset = papx.getHugeGrpprlOffset();
+ if(hugeGrpprlOffset == -1) // then we have no storage...
+ {
+ throw new UnsupportedOperationException(
+ "This Paragraph has no dataStream storage.");
+ }
+ else // we have some storage...
+ {
+ // get the size of the existing storage
+ int maxHugeGrpprlSize = LittleEndian.getUShort(_dataStream,
+ hugeGrpprlOffset);
+
+ if (maxHugeGrpprlSize < grpprl.length)
+ throw new UnsupportedOperationException(
+ "This Paragraph's dataStream storage is too small.");
+ }
+
+ // store grpprl at hugeGrpprlOffset
+ System.arraycopy(grpprl, 2, _dataStream, hugeGrpprlOffset + 2,
+ grpprl.length - 2);
+ LittleEndian.putUShort(_dataStream, hugeGrpprlOffset, grpprl.length);
+
+ // grpprl = grpprl containing only a sprmPHugePapx2
+ int istd = LittleEndian.getUShort(grpprl, 0);
+ grpprl = new byte[8];
+ LittleEndian.putUShort(grpprl, 0, istd);
+ LittleEndian.putUShort(grpprl, 2, 0x6646); // sprmPHugePapx2
+ LittleEndian.putInt(grpprl, 4, hugeGrpprlOffset);
+ }
+
boolean same = Arrays.equals(lastGrpprl, grpprl);
if (!same)
{
@@ -252,7 +294,7 @@
fcOffset += FC_SIZE;
}
- // put the last papx's end in
+
LittleEndian.putInt(buf, fcOffset, papx.getEnd() + fcMin);
return buf;
}
1.2 +46 -2 jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/PAPX.java
Index: PAPX.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/PAPX.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PAPX.java 2 Mar 2004 06:22:01 -0000 1.1
+++ PAPX.java 10 Mar 2004 04:18:53 -0000 1.2
@@ -61,6 +61,7 @@
import org.apache.poi.hwpf.usermodel.ParagraphProperties;
import org.apache.poi.hwpf.sprm.ParagraphSprmUncompressor;
import org.apache.poi.hwpf.sprm.SprmBuffer;
+import org.apache.poi.hwpf.sprm.SprmOperation;
/**
* Comment me
@@ -72,17 +73,55 @@
{
private ParagraphHeight _phe;
+ private int _hugeGrpprlOffset = -1;
- public PAPX(int fcStart, int fcEnd, byte[] papx, ParagraphHeight phe)
+ public PAPX(int fcStart, int fcEnd, byte[] papx, ParagraphHeight phe, byte[] dataStream)
{
super(fcStart, fcEnd, new SprmBuffer(papx));
_phe = phe;
+ SprmBuffer buf = findHuge(new SprmBuffer(papx), dataStream);
+ if(buf != null)
+ _buf = buf;
}
- public PAPX(int fcStart, int fcEnd, SprmBuffer buf)
+ public PAPX(int fcStart, int fcEnd, SprmBuffer buf, byte[] dataStream)
{
super(fcStart, fcEnd, buf);
_phe = new ParagraphHeight();
+ buf = findHuge(buf, dataStream);
+ if(buf != null)
+ _buf = buf;
+ }
+
+ private SprmBuffer findHuge(SprmBuffer buf, byte[] datastream)
+ {
+ byte[] grpprl = buf.toByteArray();
+ if(grpprl.length==8 && datastream!=null) // then check for sprmPHugePapx
+ {
+ SprmOperation sprm = new SprmOperation(grpprl, 2);
+ if ((sprm.getOperation()==0x45 || sprm.getOperation()==0x46)
+ && sprm.getSizeCode() == 3)
+ {
+ int hugeGrpprlOffset = sprm.getOperand();
+ if(hugeGrpprlOffset+1 < datastream.length)
+ {
+ int grpprlSize = LittleEndian.getShort(datastream, hugeGrpprlOffset);
+ if( hugeGrpprlOffset+grpprlSize < datastream.length)
+ {
+ byte[] hugeGrpprl = new byte[grpprlSize];
+ // copy original istd into huge Grpprl
+ hugeGrpprl[0] = grpprl[0]; hugeGrpprl[1] = grpprl[1];
+ // copy Grpprl from dataStream
+ System.arraycopy(datastream, hugeGrpprlOffset + 2, hugeGrpprl, 2,
+ grpprlSize-2);
+ // save a pointer to where we got the huge Grpprl from
+ _hugeGrpprlOffset = hugeGrpprlOffset;
+ return new SprmBuffer(hugeGrpprl);
+ }
+ }
+ }
+ }
+ return null;
}
@@ -94,6 +133,11 @@
public byte[] getGrpprl()
{
return ((SprmBuffer)_buf).toByteArray();
+ }
+
+ public int getHugeGrpprlOffset()
+ {
+ return _hugeGrpprlOffset;
}
public short getIstd()
1.2 +5 -0 jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/StyleDescription.java
Index: StyleDescription.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/StyleDescription.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- StyleDescription.java 2 Mar 2004 06:22:01 -0000 1.1
+++ StyleDescription.java 10 Mar 2004 04:18:53 -0000 1.2
@@ -220,6 +220,11 @@
_chp = chp;
}
+ public String getName()
+ {
+ return _name;
+ }
+
public byte[] toByteArray()
{
// size equals _baseLength bytes for known variables plus 2 bytes for name
---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: poi-dev-help@jakarta.apache.org