diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java index 8776cb3dd..6f6d3b9cd 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java @@ -1,18 +1,18 @@ /* ==================================================================== - 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 + 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 + 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. + 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; @@ -37,83 +37,83 @@ import org.apache.poi.util.POILogger; @Internal public final class FontTable { - private final static POILogger _logger = POILogFactory.getLogger(FontTable.class); - private short _stringCount;// how many strings are included in the string table - private short _extraDataSz;// size in bytes of the extra data + private final static POILogger _logger = POILogFactory.getLogger(FontTable.class); + private short _stringCount;// how many strings are included in the string table + private short _extraDataSz;// size in bytes of the extra data - // added extra facilitator members - private int lcbSttbfffn;// count of bytes in sttbfffn - private int fcSttbfffn;// table stream offset for sttbfffn + // added extra facilitator members + private int lcbSttbfffn;// count of bytes in sttbfffn + private int fcSttbfffn;// table stream offset for sttbfffn - // FFN structure containing strings of font names - private Ffn[] _fontNames = null; + // FFN structure containing strings of font names + private Ffn[] _fontNames = null; - public FontTable(byte[] buf, int offset, int lcbSttbfffn) - { - this.lcbSttbfffn = lcbSttbfffn; - this.fcSttbfffn = offset; - - _stringCount = LittleEndian.getShort(buf, offset); - offset += LittleEndian.SHORT_SIZE; - _extraDataSz = LittleEndian.getShort(buf, offset); - offset += LittleEndian.SHORT_SIZE; - - _fontNames = new Ffn[_stringCount]; //Ffn corresponds to a Pascal style String in STTBF. - - for(int i = 0;i<_stringCount; i++) + public FontTable(byte[] buf, int offset, int lcbSttbfffn) { - _fontNames[i] = new Ffn(buf,offset); - offset += _fontNames[i].getSize(); - } - } + this.lcbSttbfffn = lcbSttbfffn; + this.fcSttbfffn = offset; - public short getStringCount() - { - return _stringCount; - } + _stringCount = LittleEndian.getShort(buf, offset); + offset += LittleEndian.SHORT_SIZE; + _extraDataSz = LittleEndian.getShort(buf, offset); + offset += LittleEndian.SHORT_SIZE; - public short getExtraDataSz() - { - return _extraDataSz; - } + _fontNames = new Ffn[_stringCount]; //Ffn corresponds to a Pascal style String in STTBF. - public Ffn[] getFontNames() - { - return _fontNames; - } - - public int getSize() - { - return lcbSttbfffn; - } - - public String getMainFont(int chpFtc ) - { - if(chpFtc >= _stringCount) - { - _logger.log(POILogger.INFO, "Mismatch in chpFtc with stringCount"); - return null; + for(int i = 0;i<_stringCount; i++) + { + _fontNames[i] = new Ffn(buf,offset); + offset += _fontNames[i].getSize(); + } } - return _fontNames[chpFtc].getMainFontName(); - } - - public String getAltFont(int chpFtc ) - { - if(chpFtc >= _stringCount) + public short getStringCount() { - _logger.log(POILogger.INFO, "Mismatch in chpFtc with stringCount"); - return null; + return _stringCount; } - return _fontNames[chpFtc].getAltFontName(); - } + public short getExtraDataSz() + { + return _extraDataSz; + } - public void setStringCount(short stringCount) - { - this._stringCount = stringCount; - } + public Ffn[] getFontNames() + { + return _fontNames; + } + + public int getSize() + { + return lcbSttbfffn; + } + + public String getMainFont(int chpFtc ) + { + if(chpFtc >= _stringCount) + { + _logger.log(POILogger.INFO, "Mismatch in chpFtc with stringCount"); + return null; + } + + return _fontNames[chpFtc].getMainFontName(); + } + + public String getAltFont(int chpFtc ) + { + if(chpFtc >= _stringCount) + { + _logger.log(POILogger.INFO, "Mismatch in chpFtc with stringCount"); + return null; + } + + return _fontNames[chpFtc].getAltFontName(); + } + + public void setStringCount(short stringCount) + { + this._stringCount = stringCount; + } @Deprecated public void writeTo( HWPFFileSystem sys ) throws IOException @@ -124,40 +124,40 @@ public final class FontTable public void writeTo( HWPFOutputStream tableStream ) throws IOException { - byte[] buf = new byte[LittleEndian.SHORT_SIZE]; - LittleEndian.putShort(buf, 0, _stringCount); - tableStream.write(buf); - LittleEndian.putShort(buf, 0, _extraDataSz); - tableStream.write(buf); + byte[] buf = new byte[LittleEndian.SHORT_SIZE]; + LittleEndian.putShort(buf, 0, _stringCount); + tableStream.write(buf); + LittleEndian.putShort(buf, 0, _extraDataSz); + tableStream.write(buf); - for(int i = 0; i < _fontNames.length; i++) - { - tableStream.write(_fontNames[i].toByteArray()); - } + for(int i = 0; i < _fontNames.length; i++) + { + tableStream.write(_fontNames[i].toByteArray()); + } - } + } - @Override - public boolean equals(Object other) { - if (!(other instanceof FontTable)) return false; - FontTable o = (FontTable)other; + @Override + public boolean equals(Object other) { + if (!(other instanceof FontTable)) return false; + FontTable o = (FontTable)other; - if (o._stringCount != this._stringCount - || o._extraDataSz != this._extraDataSz - || o._fontNames.length != this._fontNames.length - ) return false; - - for (int i=0; i { - private ParagraphHeight _phe; + private ParagraphHeight _phe; - public PAPX(int fcStart, int fcEnd, CharIndexTranslator translator, byte[] papx, ParagraphHeight phe, byte[] dataStream) - { - super(fcStart, fcEnd, translator, new SprmBuffer(papx, 2)); - _phe = phe; - SprmBuffer buf = findHuge(new SprmBuffer(papx, 2), dataStream); - if(buf != null) - _buf = buf; - } + public PAPX(int fcStart, int fcEnd, CharIndexTranslator translator, byte[] papx, ParagraphHeight phe, byte[] dataStream) + { + super(fcStart, fcEnd, translator, new SprmBuffer(papx, 2)); + _phe = phe; + SprmBuffer buf = findHuge(new SprmBuffer(papx, 2), dataStream); + if(buf != null) + _buf = buf; + } public PAPX( int charStart, int charEnd, byte[] papx, ParagraphHeight phe, byte[] dataStream ) @@ -60,14 +60,14 @@ public final class PAPX extends BytePropertyNode { } @Deprecated - public PAPX(int fcStart, int fcEnd, CharIndexTranslator translator, SprmBuffer buf, byte[] dataStream) - { - super(fcStart, fcEnd, translator, buf); - _phe = new ParagraphHeight(); - buf = findHuge(buf, dataStream); - if(buf != null) - _buf = buf; - } + public PAPX(int fcStart, int fcEnd, CharIndexTranslator translator, SprmBuffer buf, byte[] dataStream) + { + super(fcStart, fcEnd, translator, buf); + _phe = new ParagraphHeight(); + buf = findHuge(buf, dataStream); + if(buf != null) + _buf = buf; + } public PAPX( int charStart, int charEnd, SprmBuffer buf ) { @@ -75,105 +75,105 @@ public final class PAPX extends BytePropertyNode { _phe = new ParagraphHeight(); } - private SprmBuffer findHuge(SprmBuffer buf, byte[] datastream) - { - byte[] grpprl = buf.toByteArray(); - if(grpprl.length==8 && datastream!=null) // then check for sprmPHugePapx + private SprmBuffer findHuge(SprmBuffer buf, byte[] datastream) { - 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) + byte[] grpprl = buf.toByteArray(); + if(grpprl.length==8 && datastream!=null) // then check for sprmPHugePapx { - int grpprlSize = LittleEndian.getShort(datastream, hugeGrpprlOffset); - if( hugeGrpprlOffset+grpprlSize < datastream.length) - { - byte[] hugeGrpprl = new byte[grpprlSize + 2]; - // 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); - return new SprmBuffer(hugeGrpprl, 2); - } + 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 + 2]; + // 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); + return new SprmBuffer(hugeGrpprl, 2); + } + } + } } - } + return null; } - return null; - } - public ParagraphHeight getParagraphHeight() - { - return _phe; - } + public ParagraphHeight getParagraphHeight() + { + return _phe; + } - public byte[] getGrpprl() - { - if (_buf == null) - return new byte[0]; + public byte[] getGrpprl() + { + if (_buf == null) + return new byte[0]; - return ((SprmBuffer)_buf).toByteArray(); - } + return ((SprmBuffer)_buf).toByteArray(); + } public short getIstd() { if ( _buf == null ) return 0; + + byte[] buf = getGrpprl(); + if (buf.length == 0) + { + return 0; + } + if (buf.length == 1) + { + return LittleEndian.getUByte(buf, 0); + } + return LittleEndian.getShort(buf); + } - byte[] buf = getGrpprl(); - if (buf.length == 0) + public SprmBuffer getSprmBuf() { - return 0; + return (SprmBuffer)_buf; } - if (buf.length == 1) + + @Deprecated + @Internal + public ParagraphProperties getParagraphProperties(StyleSheet ss) { - return LittleEndian.getUByte(buf, 0); + if(ss == null) { + // TODO Fix up for Word 6/95 + return new ParagraphProperties(); + } + + short istd = getIstd(); + ParagraphProperties baseStyle = ss.getParagraphStyle(istd); + ParagraphProperties props = ParagraphSprmUncompressor.uncompressPAP(baseStyle, getGrpprl(), 2); + return props; } - return LittleEndian.getShort(buf); - } - public SprmBuffer getSprmBuf() - { - return (SprmBuffer)_buf; - } - - @Deprecated - @Internal - public ParagraphProperties getParagraphProperties(StyleSheet ss) - { - if(ss == null) { - // TODO Fix up for Word 6/95 - return new ParagraphProperties(); - } - - short istd = getIstd(); - ParagraphProperties baseStyle = ss.getParagraphStyle(istd); - ParagraphProperties props = ParagraphSprmUncompressor.uncompressPAP(baseStyle, getGrpprl(), 2); - return props; - } - - @Override - public boolean equals(Object o) - { - if (super.equals(o)) + @Override + public boolean equals(Object o) { - return _phe.equals(((PAPX)o)._phe); + if (super.equals(o)) + { + return _phe.equals(((PAPX)o)._phe); + } + return false; } - return false; - } - @Override - public int hashCode() { - assert false : "hashCode not designed"; - return 42; // any arbitrary constant will do - } + @Override + public int hashCode() { + assert false : "hashCode not designed"; + return 42; // any arbitrary constant will do + } public String toString() { return "PAPX from " + getStart() + " to " + getEnd() + " (in bytes " - + getStartBytes() + " to " + getEndBytes() + ")"; + + getStartBytes() + " to " + getEndBytes() + ")"; } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java index ea2bef98a..ec93d56e5 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java @@ -1,18 +1,18 @@ /* ==================================================================== - 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 + 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 + 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. + 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; @@ -35,34 +35,34 @@ import org.apache.poi.util.POILogger; @Internal public class SectionTable { - private final static POILogger _logger = POILogFactory.getLogger(SectionTable.class); - private static final int SED_SIZE = 12; + private final static POILogger _logger = POILogFactory.getLogger(SectionTable.class); + private static final int SED_SIZE = 12; - protected List _sections = new ArrayList(); - protected List _text; + protected List _sections = new ArrayList(); + protected List _text; - /** So we can know if things are unicode or not */ - //private TextPieceTable tpt; + /** So we can know if things are unicode or not */ + //private TextPieceTable tpt; - public SectionTable() - { - } - - - public SectionTable(byte[] documentStream, byte[] tableStream, int offset, - int size, int fcMin, - TextPieceTable tpt, int mainLength) - { - PlexOfCps sedPlex = new PlexOfCps(tableStream, offset, size, SED_SIZE); - //this.tpt = tpt; - this._text = tpt.getTextPieces(); - - int length = sedPlex.length(); - - for (int x = 0; x < length; x++) + public SectionTable() { - GenericPropertyNode node = sedPlex.getProperty(x); - SectionDescriptor sed = new SectionDescriptor(node.getBytes(), 0); + } + + + public SectionTable( + byte[] documentStream, byte[] tableStream, + int offset, int size, int fcMin, TextPieceTable tpt, int mainLength) + { + PlexOfCps sedPlex = new PlexOfCps(tableStream, offset, size, SED_SIZE); + //this.tpt = tpt; + this._text = tpt.getTextPieces(); + + int length = sedPlex.length(); + + for (int x = 0; x < length; x++) + { + GenericPropertyNode node = sedPlex.getProperty(x); + SectionDescriptor sed = new SectionDescriptor(node.getBytes(), 0); int fileOffset = sed.getFc(); // int startAt = CPtoFC(node.getStart()); @@ -70,41 +70,41 @@ public class SectionTable int startAt = node.getStart(); int endAt = node.getEnd(); - // check for the optimization - if (fileOffset == 0xffffffff) - { - _sections.add(new SEPX(sed, startAt, endAt, new byte[0])); - } - else - { - // The first short at the offset is the size of the grpprl. - int sepxSize = LittleEndian.getShort(documentStream, fileOffset); - byte[] buf = new byte[sepxSize]; - fileOffset += LittleEndian.SHORT_SIZE; - System.arraycopy(documentStream, fileOffset, buf, 0, buf.length); - _sections.add(new SEPX(sed, startAt, endAt, buf)); - } - } + // check for the optimization + if (fileOffset == 0xffffffff) + { + _sections.add(new SEPX(sed, startAt, endAt, new byte[0])); + } + else + { + // The first short at the offset is the size of the grpprl. + int sepxSize = LittleEndian.getShort(documentStream, fileOffset); + byte[] buf = new byte[sepxSize]; + fileOffset += LittleEndian.SHORT_SIZE; + System.arraycopy(documentStream, fileOffset, buf, 0, buf.length); + _sections.add(new SEPX(sed, startAt, endAt, buf)); + } + } - // Some files seem to lie about their unicode status, which - // is very very pesky. Try to work around these, but this - // is getting on for black magic... - int mainEndsAt = mainLength; - boolean matchAt = false; - boolean matchHalf = false; - for(int i=0; i<_sections.size(); i++) { - SEPX s = _sections.get(i); - if(s.getEnd() == mainEndsAt) { - matchAt = true; - } else if(s.getEnd() == mainEndsAt || s.getEnd() == mainEndsAt-1) { - matchHalf = true; - } - } - if(! matchAt && matchHalf) { - _logger.log(POILogger.WARN, "Your document seemed to be mostly unicode, but the section definition was in bytes! Trying anyway, but things may well go wrong!"); - for(int i=0; i<_sections.size(); i++) { - SEPX s = _sections.get(i); - GenericPropertyNode node = sedPlex.getProperty(i); + // Some files seem to lie about their unicode status, which + // is very very pesky. Try to work around these, but this + // is getting on for black magic... + int mainEndsAt = mainLength; + boolean matchAt = false; + boolean matchHalf = false; + for (int i=0; i<_sections.size(); i++) { + SEPX s = _sections.get(i); + if (s.getEnd() == mainEndsAt) { + matchAt = true; + } else if(s.getEnd() == mainEndsAt || s.getEnd() == mainEndsAt-1) { + matchHalf = true; + } + } + if(! matchAt && matchHalf) { + _logger.log(POILogger.WARN, "Your document seemed to be mostly unicode, but the section definition was in bytes! Trying anyway, but things may well go wrong!"); + for(int i=0; i<_sections.size(); i++) { + SEPX s = _sections.get(i); + GenericPropertyNode node = sedPlex.getProperty(i); // s.setStart( CPtoFC(node.getStart()) ); // s.setEnd( CPtoFC(node.getEnd()) ); @@ -112,33 +112,33 @@ public class SectionTable int endAt = node.getEnd(); s.setStart( startAt ); s.setEnd( endAt ); + } + } + + Collections.sort( _sections, PropertyNode.StartComparator.instance ); + } + + public void adjustForInsert(int listIndex, int length) + { + int size = _sections.size(); + SEPX sepx = _sections.get(listIndex); + sepx.setEnd(sepx.getEnd() + length); + + for (int x = listIndex + 1; x < size; x++) + { + sepx = _sections.get(x); + sepx.setStart(sepx.getStart() + length); + sepx.setEnd(sepx.getEnd() + length); } } - Collections.sort( _sections, PropertyNode.StartComparator.instance ); - } - - public void adjustForInsert(int listIndex, int length) - { - int size = _sections.size(); - SEPX sepx = _sections.get(listIndex); - sepx.setEnd(sepx.getEnd() + length); - - for (int x = listIndex + 1; x < size; x++) - { - sepx = _sections.get(x); - sepx.setStart(sepx.getStart() + length); - sepx.setEnd(sepx.getEnd() + length); - } - } - - // goss version of CPtoFC - this takes into account non-contiguous textpieces - // that we have come across in real world documents. Tests against the example - // code in HWPFDocument show no variation to Ryan's version of the code in - // normal use, but this version works with our non-contiguous test case. - // So far unable to get this test case to be written out as well due to - // other issues. - piers - // + // goss version of CPtoFC - this takes into account non-contiguous textpieces + // that we have come across in real world documents. Tests against the example + // code in HWPFDocument show no variation to Ryan's version of the code in + // normal use, but this version works with our non-contiguous test case. + // So far unable to get this test case to be written out as well due to + // other issues. - piers + // // i'm commenting this out, because it just doesn't work with non-contiguous // textpieces :( Usual (as for PAPX and CHPX) call to TextPiecesTable does. // private int CPtoFC(int CP) @@ -160,10 +160,10 @@ public class SectionTable // return FC; // } - public List getSections() - { - return _sections; - } + public List getSections() + { + return _sections; + } @Deprecated public void writeTo( HWPFFileSystem sys, int fcMin ) throws IOException @@ -174,36 +174,37 @@ public class SectionTable writeTo( docStream, tableStream ); } - public void writeTo( HWPFOutputStream wordDocumentStream, + public void writeTo( + HWPFOutputStream wordDocumentStream, HWPFOutputStream tableStream ) throws IOException { - int offset = wordDocumentStream.getOffset(); - int len = _sections.size(); - PlexOfCps plex = new PlexOfCps(SED_SIZE); + int offset = wordDocumentStream.getOffset(); + int len = _sections.size(); + PlexOfCps plex = new PlexOfCps(SED_SIZE); - for (int x = 0; x < len; x++) - { - SEPX sepx = _sections.get(x); - byte[] grpprl = sepx.getGrpprl(); + for (int x = 0; x < len; x++) + { + SEPX sepx = _sections.get(x); + byte[] grpprl = sepx.getGrpprl(); - // write the sepx to the document stream. starts with a 2 byte size - // followed by the grpprl - byte[] shortBuf = new byte[2]; - LittleEndian.putShort(shortBuf, 0, (short)grpprl.length); + // write the sepx to the document stream. starts with a 2 byte size + // followed by the grpprl + byte[] shortBuf = new byte[2]; + LittleEndian.putShort(shortBuf, 0, (short)grpprl.length); - wordDocumentStream.write(shortBuf); - wordDocumentStream.write(grpprl); + wordDocumentStream.write(shortBuf); + wordDocumentStream.write(grpprl); - // set the fc in the section descriptor - SectionDescriptor sed = sepx.getSectionDescriptor(); - sed.setFc(offset); + // set the fc in the section descriptor + SectionDescriptor sed = sepx.getSectionDescriptor(); + sed.setFc(offset); - // add the section descriptor bytes to the PlexOfCps. + // add the section descriptor bytes to the PlexOfCps. /* original line */ GenericPropertyNode property = new GenericPropertyNode( - sepx.getStart(), sepx.getEnd(), sed.toByteArray() ); + sepx.getStart(), sepx.getEnd(), sed.toByteArray() ); /* * Line using Ryan's FCtoCP() conversion method - unable to observe * any effect on our testcases when using this code - piers @@ -217,10 +218,10 @@ public class SectionTable // tpt.getCharIndex( sepx.getStartBytes() ), // tpt.getCharIndex( sepx.getEndBytes() ), sed.toByteArray() ); - plex.addProperty(property); + plex.addProperty(property); - offset = wordDocumentStream.getOffset(); + offset = wordDocumentStream.getOffset(); + } + tableStream.write(plex.toByteArray()); } - tableStream.write(plex.toByteArray()); - } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmCompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmCompressor.java index 723ab994e..8d20a7490 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmCompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmCompressor.java @@ -1,18 +1,18 @@ /* ==================================================================== - 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 + 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 + 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. + 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.sprm; @@ -28,209 +28,209 @@ import org.apache.poi.util.LittleEndian; @Internal public final class SectionSprmCompressor { - private final static SectionProperties DEFAULT_SEP = new SectionProperties(); - public SectionSprmCompressor() - { - } - public static byte[] compressSectionProperty(SectionProperties newSEP) - { - int size = 0; - List sprmList = new ArrayList(); + private final static SectionProperties DEFAULT_SEP = new SectionProperties(); + public SectionSprmCompressor() + { + } + public static byte[] compressSectionProperty(SectionProperties newSEP) + { + int size = 0; + List sprmList = new ArrayList(); - if (newSEP.getCnsPgn() != DEFAULT_SEP.getCnsPgn()) - { - size += SprmUtils.addSprm((short)0x3000, newSEP.getCnsPgn(), null, sprmList); - } - if (newSEP.getIHeadingPgn() != DEFAULT_SEP.getIHeadingPgn()) - { - size += SprmUtils.addSprm((short)0x3001, newSEP.getIHeadingPgn(), null, sprmList); - } - if (!Arrays.equals(newSEP.getOlstAnm(), DEFAULT_SEP.getOlstAnm())) - { - size += SprmUtils.addSprm((short)0xD202, 0, newSEP.getOlstAnm(), sprmList); - } - if (newSEP.getFEvenlySpaced() != DEFAULT_SEP.getFEvenlySpaced()) - { - size += SprmUtils.addSprm((short)0x3005, newSEP.getFEvenlySpaced() ? 1 : 0, null, sprmList); - } - if (newSEP.getFUnlocked() != DEFAULT_SEP.getFUnlocked()) - { - size += SprmUtils.addSprm((short)0x3006, newSEP.getFUnlocked() ? 1 :0, null, sprmList); - } - if (newSEP.getDmBinFirst() != DEFAULT_SEP.getDmBinFirst()) - { - size += SprmUtils.addSprm((short)0x5007, newSEP.getDmBinFirst(), null, sprmList); - } - if (newSEP.getDmBinOther() != DEFAULT_SEP.getDmBinOther()) - { - size += SprmUtils.addSprm((short)0x5008, newSEP.getDmBinOther(), null, sprmList); - } - if (newSEP.getBkc() != DEFAULT_SEP.getBkc()) - { - size += SprmUtils.addSprm((short)0x3009, newSEP.getBkc(), null, sprmList); - } - if (newSEP.getFTitlePage() != DEFAULT_SEP.getFTitlePage()) - { - size += SprmUtils.addSprm((short)0x300A, newSEP.getFTitlePage() ? 1 : 0, null, sprmList); - } - if (newSEP.getCcolM1() != DEFAULT_SEP.getCcolM1()) - { - size += SprmUtils.addSprm((short)0x500B, newSEP.getCcolM1(), null, sprmList); - } - if (newSEP.getDxaColumns() != DEFAULT_SEP.getDxaColumns()) - { - size += SprmUtils.addSprm((short)0x900C, newSEP.getDxaColumns(), null, sprmList); - } - if (newSEP.getFAutoPgn() != DEFAULT_SEP.getFAutoPgn()) - { - size += SprmUtils.addSprm((short)0x300D, newSEP.getFAutoPgn() ? 1 : 0, null, sprmList); - } - if (newSEP.getNfcPgn() != DEFAULT_SEP.getNfcPgn()) - { - size += SprmUtils.addSprm((short)0x300E, newSEP.getNfcPgn(), null, sprmList); - } - if (newSEP.getDyaPgn() != DEFAULT_SEP.getDyaPgn()) - { - size += SprmUtils.addSprm((short)0xB00F, newSEP.getDyaPgn(), null, sprmList); - } - if (newSEP.getDxaPgn() != DEFAULT_SEP.getDxaPgn()) - { - size += SprmUtils.addSprm((short)0xB010, newSEP.getDxaPgn(), null, sprmList); - } - if (newSEP.getFPgnRestart() != DEFAULT_SEP.getFPgnRestart()) - { - size += SprmUtils.addSprm((short)0x3011, newSEP.getFPgnRestart() ? 1 : 0, null, sprmList); - } - if (newSEP.getFEndNote() != DEFAULT_SEP.getFEndNote()) - { - size += SprmUtils.addSprm((short)0x3012, newSEP.getFEndNote() ? 1 : 0, null, sprmList); - } - if (newSEP.getLnc() != DEFAULT_SEP.getLnc()) - { - size += SprmUtils.addSprm((short)0x3013, newSEP.getLnc(), null, sprmList); - } - if (newSEP.getGrpfIhdt() != DEFAULT_SEP.getGrpfIhdt()) - { - size += SprmUtils.addSprm((short)0x3014, newSEP.getGrpfIhdt(), null, sprmList); - } - if (newSEP.getNLnnMod() != DEFAULT_SEP.getNLnnMod()) - { - size += SprmUtils.addSprm((short)0x5015, newSEP.getNLnnMod(), null, sprmList); - } - if (newSEP.getDxaLnn() != DEFAULT_SEP.getDxaLnn()) - { - size += SprmUtils.addSprm((short)0x9016, newSEP.getDxaLnn(), null, sprmList); - } - if (newSEP.getDyaHdrTop() != DEFAULT_SEP.getDyaHdrTop()) - { - size += SprmUtils.addSprm((short)0xB017, newSEP.getDyaHdrTop(), null, sprmList); - } - if (newSEP.getDyaHdrBottom() != DEFAULT_SEP.getDyaHdrBottom()) - { - size += SprmUtils.addSprm((short)0xB018, newSEP.getDyaHdrBottom(), null, sprmList); - } - if (newSEP.getFLBetween() != DEFAULT_SEP.getFLBetween()) - { - size += SprmUtils.addSprm((short)0x3019, newSEP.getFLBetween() ? 1 : 0, null, sprmList); - } - if (newSEP.getVjc() != DEFAULT_SEP.getVjc()) - { - size += SprmUtils.addSprm((short)0x301A, newSEP.getVjc(), null, sprmList); - } - if (newSEP.getLnnMin() != DEFAULT_SEP.getLnnMin()) - { - size += SprmUtils.addSprm((short)0x501B, newSEP.getLnnMin(), null, sprmList); - } - if (newSEP.getPgnStart() != DEFAULT_SEP.getPgnStart()) - { - size += SprmUtils.addSprm((short)0x501C, newSEP.getPgnStart(), null, sprmList); - } - if (newSEP.getDmOrientPage() != DEFAULT_SEP.getDmOrientPage()) - { - size += SprmUtils.addSprm((short)0x301D, newSEP.getDmOrientPage() ? 1 : 0, null, sprmList); - } - if (newSEP.getXaPage() != DEFAULT_SEP.getXaPage()) - { - size += SprmUtils.addSprm((short)0xB01F, newSEP.getXaPage(), null, sprmList); - } - if (newSEP.getYaPage() != DEFAULT_SEP.getYaPage()) - { - size += SprmUtils.addSprm((short)0xB020, newSEP.getYaPage(), null, sprmList); - } - if (newSEP.getDxaLeft() != DEFAULT_SEP.getDxaLeft()) - { - size += SprmUtils.addSprm((short)0xB021, newSEP.getDxaLeft(), null, sprmList); - } - if (newSEP.getDxaRight() != DEFAULT_SEP.getDxaRight()) - { - size += SprmUtils.addSprm((short)0xB022, newSEP.getDxaRight(), null, sprmList); - } - if (newSEP.getDyaTop() != DEFAULT_SEP.getDyaTop()) - { - size += SprmUtils.addSprm((short)0x9023, newSEP.getDyaTop(), null, sprmList); - } - if (newSEP.getDyaBottom() != DEFAULT_SEP.getDyaBottom()) - { - size += SprmUtils.addSprm((short)0x9024, newSEP.getDyaBottom(), null, sprmList); - } - if (newSEP.getDzaGutter() != DEFAULT_SEP.getDzaGutter()) - { - size += SprmUtils.addSprm((short)0xB025, newSEP.getDzaGutter(), null, sprmList); - } - if (newSEP.getDmPaperReq() != DEFAULT_SEP.getDmPaperReq()) - { - size += SprmUtils.addSprm((short)0x5026, newSEP.getDmPaperReq(), null, sprmList); - } - if (newSEP.getFPropMark() != DEFAULT_SEP.getFPropMark() || - newSEP.getIbstPropRMark() != DEFAULT_SEP.getIbstPropRMark() || - !newSEP.getDttmPropRMark().equals(DEFAULT_SEP.getDttmPropRMark())) - { - byte[] buf = new byte[7]; - buf[0] = (byte)(newSEP.getFPropMark() ? 1 : 0); - int offset = LittleEndian.BYTE_SIZE; - LittleEndian.putShort(buf, 0, (short)newSEP.getIbstPropRMark()); - offset += LittleEndian.SHORT_SIZE; - newSEP.getDttmPropRMark().serialize(buf, offset); - size += SprmUtils.addSprm((short)0xD227, -1, buf, sprmList); - } - if (!newSEP.getBrcTop().equals( DEFAULT_SEP.getBrcTop())) - { - size += SprmUtils.addSprm((short)0x702B, newSEP.getBrcTop().toInt(), null, sprmList); - } - if (!newSEP.getBrcLeft().equals(DEFAULT_SEP.getBrcLeft())) - { - size += SprmUtils.addSprm((short)0x702C, newSEP.getBrcLeft().toInt(), null, sprmList); - } - if (!newSEP.getBrcBottom().equals(DEFAULT_SEP.getBrcBottom())) - { - size += SprmUtils.addSprm((short)0x702D, newSEP.getBrcBottom().toInt(), null, sprmList); - } - if (!newSEP.getBrcRight().equals(DEFAULT_SEP.getBrcRight())) - { - size += SprmUtils.addSprm((short)0x702E, newSEP.getBrcRight().toInt(), null, sprmList); - } - if (newSEP.getPgbProp() != DEFAULT_SEP.getPgbProp()) - { - size += SprmUtils.addSprm((short)0x522F, newSEP.getPgbProp(), null, sprmList); - } - if (newSEP.getDxtCharSpace() != DEFAULT_SEP.getDxtCharSpace()) - { - size += SprmUtils.addSprm((short)0x7030, newSEP.getDxtCharSpace(), null, sprmList); - } - if (newSEP.getDyaLinePitch() != DEFAULT_SEP.getDyaLinePitch()) - { - size += SprmUtils.addSprm((short)0x9031, newSEP.getDyaLinePitch(), null, sprmList); - } - if (newSEP.getClm() != DEFAULT_SEP.getClm()) - { - size += SprmUtils.addSprm((short)0x5032, newSEP.getClm(), null, sprmList); - } - if (newSEP.getWTextFlow() != DEFAULT_SEP.getWTextFlow()) - { - size += SprmUtils.addSprm((short)0x5033, newSEP.getWTextFlow(), null, sprmList); - } + if (newSEP.getCnsPgn() != DEFAULT_SEP.getCnsPgn()) + { + size += SprmUtils.addSprm((short)0x3000, newSEP.getCnsPgn(), null, sprmList); + } + if (newSEP.getIHeadingPgn() != DEFAULT_SEP.getIHeadingPgn()) + { + size += SprmUtils.addSprm((short)0x3001, newSEP.getIHeadingPgn(), null, sprmList); + } + if (!Arrays.equals(newSEP.getOlstAnm(), DEFAULT_SEP.getOlstAnm())) + { + size += SprmUtils.addSprm((short)0xD202, 0, newSEP.getOlstAnm(), sprmList); + } + if (newSEP.getFEvenlySpaced() != DEFAULT_SEP.getFEvenlySpaced()) + { + size += SprmUtils.addSprm((short)0x3005, newSEP.getFEvenlySpaced() ? 1 : 0, null, sprmList); + } + if (newSEP.getFUnlocked() != DEFAULT_SEP.getFUnlocked()) + { + size += SprmUtils.addSprm((short)0x3006, newSEP.getFUnlocked() ? 1 :0, null, sprmList); + } + if (newSEP.getDmBinFirst() != DEFAULT_SEP.getDmBinFirst()) + { + size += SprmUtils.addSprm((short)0x5007, newSEP.getDmBinFirst(), null, sprmList); + } + if (newSEP.getDmBinOther() != DEFAULT_SEP.getDmBinOther()) + { + size += SprmUtils.addSprm((short)0x5008, newSEP.getDmBinOther(), null, sprmList); + } + if (newSEP.getBkc() != DEFAULT_SEP.getBkc()) + { + size += SprmUtils.addSprm((short)0x3009, newSEP.getBkc(), null, sprmList); + } + if (newSEP.getFTitlePage() != DEFAULT_SEP.getFTitlePage()) + { + size += SprmUtils.addSprm((short)0x300A, newSEP.getFTitlePage() ? 1 : 0, null, sprmList); + } + if (newSEP.getCcolM1() != DEFAULT_SEP.getCcolM1()) + { + size += SprmUtils.addSprm((short)0x500B, newSEP.getCcolM1(), null, sprmList); + } + if (newSEP.getDxaColumns() != DEFAULT_SEP.getDxaColumns()) + { + size += SprmUtils.addSprm((short)0x900C, newSEP.getDxaColumns(), null, sprmList); + } + if (newSEP.getFAutoPgn() != DEFAULT_SEP.getFAutoPgn()) + { + size += SprmUtils.addSprm((short)0x300D, newSEP.getFAutoPgn() ? 1 : 0, null, sprmList); + } + if (newSEP.getNfcPgn() != DEFAULT_SEP.getNfcPgn()) + { + size += SprmUtils.addSprm((short)0x300E, newSEP.getNfcPgn(), null, sprmList); + } + if (newSEP.getDyaPgn() != DEFAULT_SEP.getDyaPgn()) + { + size += SprmUtils.addSprm((short)0xB00F, newSEP.getDyaPgn(), null, sprmList); + } + if (newSEP.getDxaPgn() != DEFAULT_SEP.getDxaPgn()) + { + size += SprmUtils.addSprm((short)0xB010, newSEP.getDxaPgn(), null, sprmList); + } + if (newSEP.getFPgnRestart() != DEFAULT_SEP.getFPgnRestart()) + { + size += SprmUtils.addSprm((short)0x3011, newSEP.getFPgnRestart() ? 1 : 0, null, sprmList); + } + if (newSEP.getFEndNote() != DEFAULT_SEP.getFEndNote()) + { + size += SprmUtils.addSprm((short)0x3012, newSEP.getFEndNote() ? 1 : 0, null, sprmList); + } + if (newSEP.getLnc() != DEFAULT_SEP.getLnc()) + { + size += SprmUtils.addSprm((short)0x3013, newSEP.getLnc(), null, sprmList); + } + if (newSEP.getGrpfIhdt() != DEFAULT_SEP.getGrpfIhdt()) + { + size += SprmUtils.addSprm((short)0x3014, newSEP.getGrpfIhdt(), null, sprmList); + } + if (newSEP.getNLnnMod() != DEFAULT_SEP.getNLnnMod()) + { + size += SprmUtils.addSprm((short)0x5015, newSEP.getNLnnMod(), null, sprmList); + } + if (newSEP.getDxaLnn() != DEFAULT_SEP.getDxaLnn()) + { + size += SprmUtils.addSprm((short)0x9016, newSEP.getDxaLnn(), null, sprmList); + } + if (newSEP.getDyaHdrTop() != DEFAULT_SEP.getDyaHdrTop()) + { + size += SprmUtils.addSprm((short)0xB017, newSEP.getDyaHdrTop(), null, sprmList); + } + if (newSEP.getDyaHdrBottom() != DEFAULT_SEP.getDyaHdrBottom()) + { + size += SprmUtils.addSprm((short)0xB018, newSEP.getDyaHdrBottom(), null, sprmList); + } + if (newSEP.getFLBetween() != DEFAULT_SEP.getFLBetween()) + { + size += SprmUtils.addSprm((short)0x3019, newSEP.getFLBetween() ? 1 : 0, null, sprmList); + } + if (newSEP.getVjc() != DEFAULT_SEP.getVjc()) + { + size += SprmUtils.addSprm((short)0x301A, newSEP.getVjc(), null, sprmList); + } + if (newSEP.getLnnMin() != DEFAULT_SEP.getLnnMin()) + { + size += SprmUtils.addSprm((short)0x501B, newSEP.getLnnMin(), null, sprmList); + } + if (newSEP.getPgnStart() != DEFAULT_SEP.getPgnStart()) + { + size += SprmUtils.addSprm((short)0x501C, newSEP.getPgnStart(), null, sprmList); + } + if (newSEP.getDmOrientPage() != DEFAULT_SEP.getDmOrientPage()) + { + size += SprmUtils.addSprm((short)0x301D, newSEP.getDmOrientPage() ? 1 : 0, null, sprmList); + } + if (newSEP.getXaPage() != DEFAULT_SEP.getXaPage()) + { + size += SprmUtils.addSprm((short)0xB01F, newSEP.getXaPage(), null, sprmList); + } + if (newSEP.getYaPage() != DEFAULT_SEP.getYaPage()) + { + size += SprmUtils.addSprm((short)0xB020, newSEP.getYaPage(), null, sprmList); + } + if (newSEP.getDxaLeft() != DEFAULT_SEP.getDxaLeft()) + { + size += SprmUtils.addSprm((short)0xB021, newSEP.getDxaLeft(), null, sprmList); + } + if (newSEP.getDxaRight() != DEFAULT_SEP.getDxaRight()) + { + size += SprmUtils.addSprm((short)0xB022, newSEP.getDxaRight(), null, sprmList); + } + if (newSEP.getDyaTop() != DEFAULT_SEP.getDyaTop()) + { + size += SprmUtils.addSprm((short)0x9023, newSEP.getDyaTop(), null, sprmList); + } + if (newSEP.getDyaBottom() != DEFAULT_SEP.getDyaBottom()) + { + size += SprmUtils.addSprm((short)0x9024, newSEP.getDyaBottom(), null, sprmList); + } + if (newSEP.getDzaGutter() != DEFAULT_SEP.getDzaGutter()) + { + size += SprmUtils.addSprm((short)0xB025, newSEP.getDzaGutter(), null, sprmList); + } + if (newSEP.getDmPaperReq() != DEFAULT_SEP.getDmPaperReq()) + { + size += SprmUtils.addSprm((short)0x5026, newSEP.getDmPaperReq(), null, sprmList); + } + if (newSEP.getFPropMark() != DEFAULT_SEP.getFPropMark() || + newSEP.getIbstPropRMark() != DEFAULT_SEP.getIbstPropRMark() || + !newSEP.getDttmPropRMark().equals(DEFAULT_SEP.getDttmPropRMark())) + { + byte[] buf = new byte[7]; + buf[0] = (byte)(newSEP.getFPropMark() ? 1 : 0); + int offset = LittleEndian.BYTE_SIZE; + LittleEndian.putShort(buf, 0, (short)newSEP.getIbstPropRMark()); + offset += LittleEndian.SHORT_SIZE; + newSEP.getDttmPropRMark().serialize(buf, offset); + size += SprmUtils.addSprm((short)0xD227, -1, buf, sprmList); + } + if (!newSEP.getBrcTop().equals( DEFAULT_SEP.getBrcTop())) + { + size += SprmUtils.addSprm((short)0x702B, newSEP.getBrcTop().toInt(), null, sprmList); + } + if (!newSEP.getBrcLeft().equals(DEFAULT_SEP.getBrcLeft())) + { + size += SprmUtils.addSprm((short)0x702C, newSEP.getBrcLeft().toInt(), null, sprmList); + } + if (!newSEP.getBrcBottom().equals(DEFAULT_SEP.getBrcBottom())) + { + size += SprmUtils.addSprm((short)0x702D, newSEP.getBrcBottom().toInt(), null, sprmList); + } + if (!newSEP.getBrcRight().equals(DEFAULT_SEP.getBrcRight())) + { + size += SprmUtils.addSprm((short)0x702E, newSEP.getBrcRight().toInt(), null, sprmList); + } + if (newSEP.getPgbProp() != DEFAULT_SEP.getPgbProp()) + { + size += SprmUtils.addSprm((short)0x522F, newSEP.getPgbProp(), null, sprmList); + } + if (newSEP.getDxtCharSpace() != DEFAULT_SEP.getDxtCharSpace()) + { + size += SprmUtils.addSprm((short)0x7030, newSEP.getDxtCharSpace(), null, sprmList); + } + if (newSEP.getDyaLinePitch() != DEFAULT_SEP.getDyaLinePitch()) + { + size += SprmUtils.addSprm((short)0x9031, newSEP.getDyaLinePitch(), null, sprmList); + } + if (newSEP.getClm() != DEFAULT_SEP.getClm()) + { + size += SprmUtils.addSprm((short)0x5032, newSEP.getClm(), null, sprmList); + } + if (newSEP.getWTextFlow() != DEFAULT_SEP.getWTextFlow()) + { + size += SprmUtils.addSprm((short)0x5033, newSEP.getWTextFlow(), null, sprmList); + } - return SprmUtils.getGrpprl(sprmList, size); - } + return SprmUtils.getGrpprl(sprmList, size); + } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmUtils.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmUtils.java index c155be566..338342788 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmUtils.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmUtils.java @@ -26,31 +26,31 @@ import org.apache.poi.util.LittleEndian; @Internal public final class SprmUtils { - public SprmUtils() - { - } - - public static byte[] shortArrayToByteArray(short[] convert) - { - byte[] buf = new byte[convert.length * LittleEndian.SHORT_SIZE]; - - for (int x = 0; x < convert.length; x++) + public SprmUtils() { - LittleEndian.putShort(buf, x * LittleEndian.SHORT_SIZE, convert[x]); } - return buf; - } + public static byte[] shortArrayToByteArray(short[] convert) + { + byte[] buf = new byte[convert.length * LittleEndian.SHORT_SIZE]; - public static int addSpecialSprm(short instruction, byte[] varParam, List list) - { - byte[] sprm = new byte[varParam.length + 4]; - System.arraycopy(varParam, 0, sprm, 4, varParam.length); - LittleEndian.putShort(sprm, 0, instruction); - LittleEndian.putShort(sprm, 2, (short)(varParam.length + 1)); - list.add(sprm); - return sprm.length; - } + for (int x = 0; x < convert.length; x++) + { + LittleEndian.putShort(buf, x * LittleEndian.SHORT_SIZE, convert[x]); + } + + return buf; + } + + public static int addSpecialSprm(short instruction, byte[] varParam, List list) + { + byte[] sprm = new byte[varParam.length + 4]; + System.arraycopy(varParam, 0, sprm, 4, varParam.length); + LittleEndian.putShort(sprm, 0, instruction); + LittleEndian.putShort(sprm, 2, (short)(varParam.length + 1)); + list.add(sprm); + return sprm.length; + } public static int addSprm( short instruction, boolean param, List list ) @@ -58,74 +58,74 @@ public final class SprmUtils return addSprm( instruction, param ? 1 : 0, null, list ); } - public static int addSprm(short instruction, int param, byte[] varParam, List list) - { - int type = (instruction & 0xe000) >> 13; - - byte[] sprm = null; - switch(type) + public static int addSprm(short instruction, int param, byte[] varParam, List list) { - case 0: - case 1: - sprm = new byte[3]; - sprm[2] = (byte)param; - break; - case 2: - sprm = new byte[4]; - LittleEndian.putShort(sprm, 2, (short)param); - break; - case 3: - sprm = new byte[6]; - LittleEndian.putInt(sprm, 2, param); - break; - case 4: - case 5: - sprm = new byte[4]; - LittleEndian.putShort(sprm, 2, (short)param); - break; - case 6: - sprm = new byte[3 + varParam.length]; - sprm[2] = (byte)varParam.length; - System.arraycopy(varParam, 0, sprm, 3, varParam.length); - break; - case 7: - sprm = new byte[5]; - // this is a three byte int so it has to be handled special - byte[] temp = new byte[4]; - LittleEndian.putInt(temp, 0, param); - System.arraycopy(temp, 0, sprm, 2, 3); - break; - default: - //should never happen - throw new RuntimeException("Invalid sprm type"); - } - LittleEndian.putShort(sprm, 0, instruction); - list.add(sprm); - return sprm.length; - } + int type = (instruction & 0xe000) >> 13; - public static byte[] getGrpprl(List sprmList, int size) - { - // spit out the final grpprl - byte[] grpprl = new byte[size]; - int listSize = sprmList.size() - 1; - int index = 0; - for (; listSize >= 0; listSize--) - { - byte[] sprm = sprmList.remove(0); - System.arraycopy(sprm, 0, grpprl, index, sprm.length); - index += sprm.length; + byte[] sprm = null; + switch(type) + { + case 0: + case 1: + sprm = new byte[3]; + sprm[2] = (byte)param; + break; + case 2: + sprm = new byte[4]; + LittleEndian.putShort(sprm, 2, (short)param); + break; + case 3: + sprm = new byte[6]; + LittleEndian.putInt(sprm, 2, param); + break; + case 4: + case 5: + sprm = new byte[4]; + LittleEndian.putShort(sprm, 2, (short)param); + break; + case 6: + sprm = new byte[3 + varParam.length]; + sprm[2] = (byte)varParam.length; + System.arraycopy(varParam, 0, sprm, 3, varParam.length); + break; + case 7: + sprm = new byte[5]; + // this is a three byte int so it has to be handled special + byte[] temp = new byte[4]; + LittleEndian.putInt(temp, 0, param); + System.arraycopy(temp, 0, sprm, 2, 3); + break; + default: + //should never happen + throw new RuntimeException("Invalid sprm type"); + } + LittleEndian.putShort(sprm, 0, instruction); + list.add(sprm); + return sprm.length; } - return grpprl; + public static byte[] getGrpprl(List sprmList, int size) + { + // spit out the final grpprl + byte[] grpprl = new byte[size]; + int listSize = sprmList.size() - 1; + int index = 0; + for (; listSize >= 0; listSize--) + { + byte[] sprm = sprmList.remove(0); + System.arraycopy(sprm, 0, grpprl, index, sprm.length); + index += sprm.length; + } - } + return grpprl; - public static int convertBrcToInt(short[] brc) - { - byte[] buf = new byte[4]; - LittleEndian.putShort(buf, 0, brc[0]); - LittleEndian.putShort(buf, LittleEndian.SHORT_SIZE, brc[1]); - return LittleEndian.getInt(buf); - } + } + + public static int convertBrcToInt(short[] brc) + { + byte[] buf = new byte[4]; + LittleEndian.putShort(buf, 0, brc[0]); + LittleEndian.putShort(buf, LittleEndian.SHORT_SIZE, brc[1]); + return LittleEndian.getInt(buf); + } }