Save This Page
Home » poi-src-3.2-FINAL-20081019 » org.apache » poi » hwpf » model » [javadoc | source]
    1   
    2   /* ====================================================================
    3      Licensed to the Apache Software Foundation (ASF) under one or more
    4      contributor license agreements.  See the NOTICE file distributed with
    5      this work for additional information regarding copyright ownership.
    6      The ASF licenses this file to You under the Apache License, Version 2.0
    7      (the "License"); you may not use this file except in compliance with
    8      the License.  You may obtain a copy of the License at
    9   
   10          http://www.apache.org/licenses/LICENSE-2.0
   11   
   12      Unless required by applicable law or agreed to in writing, software
   13      distributed under the License is distributed on an "AS IS" BASIS,
   14      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   15      See the License for the specific language governing permissions and
   16      limitations under the License.
   17   ==================================================================== */
   18           
   19   
   20   
   21   package org.apache.poi.hwpf.model;
   22   
   23   
   24   import org.apache.poi.util.LittleEndian;
   25   
   26   import org.apache.poi.hwpf.usermodel.ParagraphProperties;
   27   import org.apache.poi.hwpf.sprm.ParagraphSprmUncompressor;
   28   import org.apache.poi.hwpf.sprm.SprmBuffer;
   29   import org.apache.poi.hwpf.sprm.SprmOperation;
   30   
   31   /**
   32    * Comment me
   33    *
   34    * @author Ryan Ackley
   35    */
   36   
   37   public class PAPX extends PropertyNode
   38   {
   39   
   40     private ParagraphHeight _phe;
   41     private int _hugeGrpprlOffset = -1;
   42   
   43     public PAPX(int fcStart, int fcEnd, byte[] papx, ParagraphHeight phe, byte[] dataStream)
   44     {
   45       super(fcStart, fcEnd, new SprmBuffer(papx));
   46       _phe = phe;
   47       SprmBuffer buf = findHuge(new SprmBuffer(papx), dataStream);
   48       if(buf != null)
   49         _buf = buf;
   50     }
   51   
   52     public PAPX(int fcStart, int fcEnd, SprmBuffer buf, byte[] dataStream)
   53     {
   54       super(fcStart, fcEnd, buf);
   55       _phe = new ParagraphHeight();
   56       buf = findHuge(buf, dataStream);
   57       if(buf != null)
   58         _buf = buf;
   59     }
   60   
   61     private SprmBuffer findHuge(SprmBuffer buf, byte[] datastream)
   62     {
   63       byte[] grpprl = buf.toByteArray();
   64       if(grpprl.length==8 && datastream!=null) // then check for sprmPHugePapx
   65       {
   66         SprmOperation sprm = new SprmOperation(grpprl, 2);
   67         if ((sprm.getOperation()==0x45 || sprm.getOperation()==0x46)
   68             && sprm.getSizeCode() == 3)
   69         {
   70           int hugeGrpprlOffset = sprm.getOperand();
   71           if(hugeGrpprlOffset+1 < datastream.length)
   72           {
   73             int grpprlSize = LittleEndian.getShort(datastream, hugeGrpprlOffset);
   74             if( hugeGrpprlOffset+grpprlSize < datastream.length)
   75             {
   76               byte[] hugeGrpprl = new byte[grpprlSize + 2];
   77               // copy original istd into huge Grpprl
   78               hugeGrpprl[0] = grpprl[0]; hugeGrpprl[1] = grpprl[1];
   79               // copy Grpprl from dataStream
   80               System.arraycopy(datastream, hugeGrpprlOffset + 2, hugeGrpprl, 2,
   81                                grpprlSize);
   82               // save a pointer to where we got the huge Grpprl from
   83               _hugeGrpprlOffset = hugeGrpprlOffset;
   84               return new SprmBuffer(hugeGrpprl);
   85             }
   86           }
   87         }
   88       }
   89       return null;
   90     }
   91   
   92   
   93     public ParagraphHeight getParagraphHeight()
   94     {
   95       return _phe;
   96     }
   97   
   98     public byte[] getGrpprl()
   99     {
  100       return ((SprmBuffer)_buf).toByteArray();
  101     }
  102   
  103     public int getHugeGrpprlOffset()
  104     {
  105       return _hugeGrpprlOffset;
  106     }
  107   
  108     public short getIstd()
  109     {
  110       byte[] buf = getGrpprl();
  111       if (buf.length == 0)
  112       {
  113         return 0;
  114       }
  115       else
  116       {
  117         return LittleEndian.getShort(buf);
  118       }
  119     }
  120   
  121     public SprmBuffer getSprmBuf()
  122     {
  123       return (SprmBuffer)_buf;
  124     }
  125   
  126     public ParagraphProperties getParagraphProperties(StyleSheet ss)
  127     {
  128       short istd = getIstd();
  129       ParagraphProperties baseStyle = ss.getParagraphStyle(istd);
  130       ParagraphProperties props = ParagraphSprmUncompressor.uncompressPAP(baseStyle, getGrpprl(), 2);
  131       return props;
  132     }
  133   
  134     public boolean equals(Object o)
  135     {
  136       if (super.equals(o))
  137       {
  138         return _phe.equals(((PAPX)o)._phe);
  139       }
  140       return false;
  141     }
  142   }

Save This Page
Home » poi-src-3.2-FINAL-20081019 » org.apache » poi » hwpf » model » [javadoc | source]