sackley     2004/03/01 22:19:04

  Modified:    src/scratchpad/src/org/apache/poi/hwpf/sprm
                        CharacterSprmCompressor.java
                        CharacterSprmUncompressor.java
                        ParagraphSprmCompressor.java
                        ParagraphSprmUncompressor.java
                        SectionSprmCompressor.java
                        SectionSprmUncompressor.java SprmBuffer.java
  Log:
  latest changes
  
  Revision  Changes    Path
  1.2       +2 -2      
jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmCompressor.java
  
  Index: CharacterSprmCompressor.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmCompressor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CharacterSprmCompressor.java      13 Nov 2003 05:24:37 -0000      1.1
  +++ CharacterSprmCompressor.java      2 Mar 2004 06:19:03 -0000       1.2
  @@ -58,7 +58,7 @@
   import java.util.List;
   import java.util.Arrays;
   
  -import org.apache.poi.hwpf.usermodel.CharacterRun;
  +import org.apache.poi.hwpf.usermodel.CharacterProperties;
   import org.apache.poi.util.LittleEndian;
   
   public class CharacterSprmCompressor
  @@ -66,7 +66,7 @@
     public CharacterSprmCompressor()
     {
     }
  -  public static byte[] compressCharacterProperty(CharacterRun newCHP, CharacterRun 
oldCHP)
  +  public static byte[] compressCharacterProperty(CharacterProperties newCHP, 
CharacterProperties oldCHP)
     {
       ArrayList sprmList = new ArrayList();
       int size = 0;
  
  
  
  1.3       +8 -8      
jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java
  
  Index: CharacterSprmUncompressor.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CharacterSprmUncompressor.java    11 Nov 2003 11:41:50 -0000      1.2
  +++ CharacterSprmUncompressor.java    2 Mar 2004 06:19:03 -0000       1.3
  @@ -54,11 +54,11 @@
   
   package org.apache.poi.hwpf.sprm;
   
  -import org.apache.poi.hwpf.usermodel.CharacterRun;
  +import org.apache.poi.hwpf.usermodel.CharacterProperties;
   import org.apache.poi.hwpf.usermodel.DateAndTime;
   import org.apache.poi.hwpf.usermodel.BorderCode;
   import org.apache.poi.hwpf.usermodel.ShadingDescriptor;
  -import org.apache.poi.hwpf.model.hdftypes.StyleSheet;
  +import org.apache.poi.hwpf.model.StyleSheet;
   import org.apache.poi.util.LittleEndian;
   
   public class CharacterSprmUncompressor
  @@ -67,14 +67,14 @@
     {
     }
   
  -  public static CharacterRun uncompressCHP(CharacterRun parent,
  +  public static CharacterProperties uncompressCHP(CharacterProperties parent,
                                                     byte[] grpprl,
                                                     int offset)
     {
  -    CharacterRun newProperties = null;
  +    CharacterProperties newProperties = null;
       try
       {
  -      newProperties = (CharacterRun) parent.clone();
  +      newProperties = (CharacterProperties) parent.clone();
       }
       catch (CloneNotSupportedException cnse)
       {
  @@ -105,8 +105,8 @@
      * @param offset The offset in the grpprl of the next sprm
      * @param styleSheet The StyleSheet for this document.
      */
  -  static void unCompressCHPOperation (CharacterRun oldCHP,
  -                                      CharacterRun newCHP,
  +  static void unCompressCHPOperation (CharacterProperties oldCHP,
  +                                      CharacterProperties newCHP,
                                         SprmOperation sprm)
     {
   
  @@ -264,7 +264,7 @@
           {
             // preserve the fSpec setting from the original CHP
             boolean fSpec = newCHP.isFSpec ();
  -          newCHP = (CharacterRun) oldCHP.clone ();
  +          newCHP = (CharacterProperties) oldCHP.clone ();
             newCHP.setFSpec (fSpec);
   
           }
  
  
  
  1.4       +22 -7     
jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmCompressor.java
  
  Index: ParagraphSprmCompressor.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmCompressor.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ParagraphSprmCompressor.java      11 Nov 2003 11:41:50 -0000      1.3
  +++ ParagraphSprmCompressor.java      2 Mar 2004 06:19:03 -0000       1.4
  @@ -60,7 +60,7 @@
   
   import org.apache.poi.util.LittleEndian;
   
  -import org.apache.poi.hwpf.usermodel.Paragraph;
  +import org.apache.poi.hwpf.usermodel.ParagraphProperties;
   
   public class ParagraphSprmCompressor
   {
  @@ -68,8 +68,8 @@
     {
     }
   
  -  public static byte[] compressParagraphProperty(Paragraph newPAP,
  -                                                 Paragraph oldPAP)
  +  public static byte[] compressParagraphProperty(ParagraphProperties newPAP,
  +                                                 ParagraphProperties oldPAP)
     {
       ArrayList sprmList = new ArrayList();
       int size = 0;
  @@ -297,13 +297,13 @@
         }
         size += SprmUtils.addSprm((short)0x442B, val, null, sprmList);
       }
  -    if (newPAP.getShd() != oldPAP.getShd())
  +    if (newPAP.getShd() != null && !newPAP.getShd().equals(oldPAP.getShd()))
       {
  -      size += SprmUtils.addSprm((short)0x442D, newPAP.getShd(), null, sprmList);
  +      size += SprmUtils.addSprm((short)0x442D, newPAP.getShd().toShort(), null, 
sprmList);
       }
  -    if (newPAP.getDcs() != oldPAP.getDcs())
  +    if (newPAP.getDcs() != null && !newPAP.getDcs().equals(oldPAP.getDcs()))
       {
  -      size += SprmUtils.addSprm((short)0x442C, newPAP.getDcs(), null, sprmList);
  +      size += SprmUtils.addSprm((short)0x442C, newPAP.getDcs().toShort(), null, 
sprmList);
       }
       if (newPAP.getLvl() != oldPAP.getLvl())
       {
  @@ -326,6 +326,21 @@
       if (!Arrays.equals(newPAP.getNumrm(), oldPAP.getNumrm()))
       {
         size += SprmUtils.addSprm((short)0xC645, 0, newPAP.getNumrm(), sprmList);
  +    }
  +
  +    if (newPAP.getTableLevel() != oldPAP.getTableLevel())
  +    {
  +      size += SprmUtils.addSprm((short)0x6649, newPAP.getTableLevel(), null, 
sprmList);
  +    }
  +
  +    if (newPAP.getEmbeddedCellMark() != oldPAP.getEmbeddedCellMark())
  +    {
  +      size += SprmUtils.addSprm((short)0x244b, newPAP.getEmbeddedCellMark(), null, 
sprmList);
  +    }
  +
  +    if (newPAP.getFTtpEmbedded() != oldPAP.getFTtpEmbedded())
  +    {
  +      size += SprmUtils.addSprm((short)0x244c, newPAP.getFTtpEmbedded(), null, 
sprmList);
       }
   
       return SprmUtils.getGrpprl(sprmList, size);
  
  
  
  1.3       +30 -12    
jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java
  
  Index: ParagraphSprmUncompressor.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ParagraphSprmUncompressor.java    11 Nov 2003 11:41:50 -0000      1.2
  +++ ParagraphSprmUncompressor.java    2 Mar 2004 06:19:03 -0000       1.3
  @@ -54,10 +54,12 @@
   
   package org.apache.poi.hwpf.sprm;
   
  -import org.apache.poi.hwpf.usermodel.Paragraph;
  +import org.apache.poi.hwpf.usermodel.ParagraphProperties;
   import org.apache.poi.hwpf.usermodel.BorderCode;
   import org.apache.poi.hwpf.usermodel.DateAndTime;
   import org.apache.poi.hwpf.usermodel.LineSpacingDescriptor;
  +import org.apache.poi.hwpf.usermodel.ShadingDescriptor;
  +import org.apache.poi.hwpf.usermodel.DropCapSpecifier;
   import org.apache.poi.util.LittleEndian;
   
   import java.util.HashMap;
  @@ -73,14 +75,14 @@
     {
     }
   
  -  public static Paragraph uncompressPAP(Paragraph parent,
  +  public static ParagraphProperties uncompressPAP(ParagraphProperties parent,
                                                     byte[] grpprl,
                                                     int offset)
     {
  -    Paragraph newProperties = null;
  +    ParagraphProperties newProperties = null;
       try
       {
  -      newProperties = (Paragraph) parent.clone();
  +      newProperties = (ParagraphProperties) parent.clone();
       }
       catch (CloneNotSupportedException cnse)
       {
  @@ -91,7 +93,13 @@
       while (sprmIt.hasNext())
       {
         SprmOperation sprm = (SprmOperation)sprmIt.next();
  -      unCompressPAPOperation(newProperties, sprm);
  +
  +      // PAPXs can contain table sprms if the paragraph marks the end of a
  +      // table row
  +      if (sprm.getType() == SprmOperation.PAP_TYPE)
  +      {
  +        unCompressPAPOperation(newProperties, sprm);
  +      }
       }
   
       return newProperties;
  @@ -109,7 +117,7 @@
      * @param offset The current offset in the papx.
      * @param spra A part of the sprm that defined this operation.
      */
  -  static void unCompressPAPOperation (Paragraph newPAP, SprmOperation sprm)
  +  static void unCompressPAPOperation (ParagraphProperties newPAP, SprmOperation 
sprm)
     {
       switch (sprm.getOperation())
       {
  @@ -292,10 +300,10 @@
           newPAP.setDyaHeight (sprm.getOperand());
           break;
         case 0x2c:
  -        newPAP.setDcs ((short) sprm.getOperand());
  +        newPAP.setDcs (new DropCapSpecifier((short)sprm.getOperand()));
           break;
         case 0x2d:
  -        newPAP.setShd ((short) sprm.getOperand());
  +        newPAP.setShd (new ShadingDescriptor((short)sprm.getOperand()));
           break;
         case 0x2e:
           newPAP.setDyaFromText (sprm.getOperand());
  @@ -405,12 +413,21 @@
         case 0x48:
           newPAP.setFAdjustRight ((byte) sprm.getOperand());
           break;
  +      case 0x49:
  +        newPAP.setTableLevel((byte)sprm.getOperand());
  +        break;
  +      case 0x4b:
  +        newPAP.setEmbeddedCellMark((byte)sprm.getOperand());
  +        break;
  +      case 0x4c:
  +        newPAP.setFTtpEmbedded((byte)sprm.getOperand());
  +        break;
         default:
           break;
       }
     }
   
  -  private static void handleTabs(Paragraph pap, SprmOperation sprm)
  +  private static void handleTabs(ParagraphProperties pap, SprmOperation sprm)
     {
       byte[] grpprl = sprm.getGrpprl();
       int offset = sprm.getGrpprlOffset();
  @@ -431,12 +448,13 @@
       }
   
       int addSize = grpprl[offset++];
  +    int start = offset;
       for (int x = 0; x < addSize; x++)
       {
  -      Integer key = new Integer(LittleEndian.getInt(grpprl, offset));
  -      Byte val = new Byte(grpprl[(LittleEndian.INT_SIZE * (addSize - x)) + x]);
  +      Integer key = new Integer(LittleEndian.getShort(grpprl, offset));
  +      Byte val = new Byte(grpprl[start + ((LittleEndian.SHORT_SIZE * addSize) + 
x)]);
         tabMap.put(key, val);
  -      offset += LittleEndian.INT_SIZE;
  +      offset += LittleEndian.SHORT_SIZE;
       }
   
       tabPositions = new int[tabMap.size()];
  
  
  
  1.4       +5 -6      
jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmCompressor.java
  
  Index: SectionSprmCompressor.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmCompressor.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SectionSprmCompressor.java        12 Nov 2003 01:34:30 -0000      1.3
  +++ SectionSprmCompressor.java        2 Mar 2004 06:19:03 -0000       1.4
  @@ -58,7 +58,7 @@
   //import java.util.ArrayList;
   //import java.util.Arrays;
   //
  -//import org.apache.poi.hwpf.model.hdftypes.definitions.SEPAbstractType;
  +//import org.apache.poi.hwpf.model.types.SEPAbstractType;
   //import org.apache.poi.hwpf.usermodel.SectionProperties;
   //import org.apache.poi.util.LittleEndian;
   //
  @@ -276,19 +276,18 @@
   import java.util.ArrayList;
   import java.util.Arrays;
   
  -import org.apache.poi.hwpf.model.hdftypes.definitions.SEPAbstractType;
  -import org.apache.poi.hwpf.usermodel.Section;
  +import org.apache.poi.hwpf.model.types.SEPAbstractType;
  +import org.apache.poi.hwpf.usermodel.SectionProperties;
   import org.apache.poi.util.LittleEndian;
   
   
   public class SectionSprmCompressor
   {
  -  private final static Section DEFAULT_SEP = new Section();
  +  private final static SectionProperties DEFAULT_SEP = new SectionProperties();
     public SectionSprmCompressor()
     {
     }
  -  public static byte[] compressSectionProperty(Section newSEP,
  -                                               Section oldSEP)
  +  public static byte[] compressSectionProperty(SectionProperties newSEP)
     {
       int size = 0;
       ArrayList sprmList = new ArrayList();
  
  
  
  1.3       +5 -14     
jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmUncompressor.java
  
  Index: SectionSprmUncompressor.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmUncompressor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SectionSprmUncompressor.java      11 Nov 2003 11:41:50 -0000      1.2
  +++ SectionSprmUncompressor.java      2 Mar 2004 06:19:03 -0000       1.3
  @@ -54,7 +54,7 @@
   
   package org.apache.poi.hwpf.sprm;
   
  -import org.apache.poi.hwpf.usermodel.Section;
  +import org.apache.poi.hwpf.usermodel.SectionProperties;
   import org.apache.poi.hwpf.usermodel.BorderCode;
   
   public class SectionSprmUncompressor extends SprmUncompressor
  @@ -62,19 +62,10 @@
     public SectionSprmUncompressor()
     {
     }
  -  public static Section uncompressSEP(Section parent,
  -                                                  byte[] grpprl,
  -                                                  int offset)
  +  public static SectionProperties uncompressSEP(byte[] grpprl, int offset)
     {
  -    Section newProperties = null;
  -    try
  -    {
  -      newProperties = (Section) parent.clone();
  -    }
  -    catch (CloneNotSupportedException cnse)
  -    {
  -      throw new RuntimeException("There is no way this exception should happen!!");
  -    }
  +    SectionProperties newProperties = new SectionProperties();
  +
       SprmIterator sprmIt = new SprmIterator(grpprl, offset);
   
       while (sprmIt.hasNext())
  @@ -95,7 +86,7 @@
      * @param param The operation's parameter.
      * @param varParam The operation variable length parameter.
      */
  -  static void unCompressSEPOperation (Section newSEP, SprmOperation sprm)
  +  static void unCompressSEPOperation (SectionProperties newSEP, SprmOperation sprm)
     {
       switch (sprm.getOperation())
       {
  
  
  
  1.3       +37 -3     
jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmBuffer.java
  
  Index: SprmBuffer.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmBuffer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SprmBuffer.java   12 Nov 2003 01:34:30 -0000      1.2
  +++ SprmBuffer.java   2 Mar 2004 06:19:03 -0000       1.3
  @@ -56,17 +56,30 @@
   
   import org.apache.poi.util.LittleEndian;
   
  +import java.util.Arrays;
  +
   public class SprmBuffer
  +  implements Cloneable
   {
     byte[] _buf;
     int _offset;
  +  boolean _istd;
   
  -  public SprmBuffer(byte[] buf)
  +  public SprmBuffer(byte[] buf, boolean istd)
     {
       _offset = buf.length;
       _buf = buf;
  +    _istd = istd;
  +  }
  +  public SprmBuffer(byte[] buf)
  +  {
  +    this(buf, false);
  +  }
  +  public SprmBuffer()
  +  {
  +    _buf = new byte[4];
  +    _offset = 0;
     }
  -
     public void addSprm(short opcode, byte operand)
     {
       int addition = LittleEndian.SHORT_SIZE + LittleEndian.BYTE_SIZE;
  @@ -108,6 +121,27 @@
       return _buf;
     }
   
  +  public boolean equals(Object obj)
  +  {
  +    SprmBuffer sprmBuf = (SprmBuffer)obj;
  +    return (Arrays.equals(_buf, sprmBuf._buf));
  +  }
  +
  +  public void append(byte[] grpprl)
  +  {
  +    ensureCapacity(grpprl.length);
  +    System.arraycopy(grpprl, 0, _buf, _offset, grpprl.length);
  +  }
  +
  +  public Object clone()
  +    throws CloneNotSupportedException
  +  {
  +    SprmBuffer retVal = (SprmBuffer)super.clone();
  +    retVal._buf = new byte[_buf.length];
  +    System.arraycopy(_buf, 0, retVal._buf, 0, _buf.length);
  +    return retVal;
  +  }
  +
     private void ensureCapacity(int addition)
     {
       if (_offset + addition >= _buf.length)
  @@ -115,7 +149,7 @@
         // add 6 more than they need for use the next iteration
         byte[] newBuf = new byte[_offset + addition + 6];
         System.arraycopy(_buf, 0, newBuf, 0, _buf.length);
  +      _buf = newBuf;
       }
     }
  -
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to