FileDocCategorySizeDatePackage
StyleDescription.javaAPI DocApache Poi 3.0.17871Mon Jan 01 18:55:32 GMT 2007org.apache.poi.hwpf.model

StyleDescription

public class StyleDescription extends Object implements HDFType
Comment me
author
Ryan Ackley

Fields Summary
private static final int
PARAGRAPH_STYLE
private static final int
CHARACTER_STYLE
private int
_istd
private int
_baseLength
private short
_infoShort
private static BitField
_sti
private static BitField
_fScratch
private static BitField
_fInvalHeight
private static BitField
_fHasUpe
private static BitField
_fMassCopy
private short
_infoShort2
private static BitField
_styleTypeCode
private static BitField
_baseStyle
private short
_infoShort3
private static BitField
_numUPX
private static BitField
_nextStyle
private short
_bchUpe
private short
_infoShort4
private static BitField
_fAutoRedef
private static BitField
_fHidden
UPX[]
_upxs
String
_name
ParagraphProperties
_pap
CharacterProperties
_chp
Constructors Summary
public StyleDescription()


   
  
//      _pap = new ParagraphProperties();
//      _chp = new CharacterProperties();
  
public StyleDescription(byte[] std, int baseLength, int offset, boolean word9)

     _baseLength = baseLength;
     int nameStart = offset + baseLength;
      _infoShort = LittleEndian.getShort(std, offset);
      offset += LittleEndian.SHORT_SIZE;
      _infoShort2 = LittleEndian.getShort(std, offset);
      offset += LittleEndian.SHORT_SIZE;
      _infoShort3 = LittleEndian.getShort(std, offset);
      offset += LittleEndian.SHORT_SIZE;
      _bchUpe = LittleEndian.getShort(std, offset);
      offset += LittleEndian.SHORT_SIZE;
      _infoShort4 = LittleEndian.getShort(std, offset);
      offset += LittleEndian.SHORT_SIZE;

      //first byte(s) of variable length section of std is the length of the
      //style name and aliases string
      int nameLength = 0;
      int multiplier = 1;
      if(word9)
      {
          nameLength = LittleEndian.getShort(std, nameStart);
          multiplier = 2;
          nameStart += LittleEndian.SHORT_SIZE;
      }
      else
      {
          nameLength = std[nameStart];
      }

      try
      {
        _name = new String(std, nameStart, nameLength * multiplier, "UTF-16LE");
      }
      catch (UnsupportedEncodingException ignore)
      {
        // ignore
      }

      //length then null terminator.
      int grupxStart = ((nameLength + 1) * multiplier) + nameStart;

      // the spec only refers to two possible upxs but it mentions
      // 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;

          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)
          {
              ++varOffset;
          }

      }


  
Methods Summary
public booleanequals(java.lang.Object o)

    StyleDescription sd = (StyleDescription)o;
    if (sd._infoShort == _infoShort && sd._infoShort2 == _infoShort2 &&
        sd._infoShort3 == _infoShort3 && sd._bchUpe == _bchUpe &&
        sd._infoShort4 == _infoShort4 &&
        _name.equals(sd._name))
    {

      if (!Arrays.equals(_upxs, sd._upxs))
      {
        return false;
      }
      return true;
    }
    return false;
  
public intgetBaseStyle()

    return _baseStyle.getValue(_infoShort2);
  
public org.apache.poi.hwpf.usermodel.CharacterPropertiesgetCHP()

      return _chp;
  
public byte[]getCHPX()

    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 java.lang.StringgetName()

    return _name;
  
public org.apache.poi.hwpf.usermodel.ParagraphPropertiesgetPAP()

      return _pap;
  
public byte[]getPAPX()

    switch (_styleTypeCode.getValue(_infoShort2))
    {
      case PARAGRAPH_STYLE:
        return _upxs[0].getUPX();
      default:
        return null;
    }
  
voidsetCHP(org.apache.poi.hwpf.usermodel.CharacterProperties chp)

      _chp = chp;
  
voidsetPAP(org.apache.poi.hwpf.usermodel.ParagraphProperties pap)

      _pap = pap;
  
public byte[]toByteArray()

    // size equals _baseLength bytes for known variables plus 2 bytes for name
    // length plus name length * 2 plus 2 bytes for null plus upx's preceded by
    // length
    int size = _baseLength + 2 + ((_name.length() + 1) * 2);

    // 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 += _upxs[x-1].size() % 2;
      size += _upxs[x].size() + 2;
    }


    byte[] buf = new byte[size];

    int offset = 0;
    LittleEndian.putShort(buf, offset, _infoShort);
    offset += LittleEndian.SHORT_SIZE;
    LittleEndian.putShort(buf, offset, _infoShort2);
    offset += LittleEndian.SHORT_SIZE;
    LittleEndian.putShort(buf, offset, _infoShort3);
    offset += LittleEndian.SHORT_SIZE;
    LittleEndian.putShort(buf, offset, _bchUpe);
    offset += LittleEndian.SHORT_SIZE;
    LittleEndian.putShort(buf, offset, _infoShort4);
    offset = _baseLength;

    char[] letters = _name.toCharArray();
    LittleEndian.putShort(buf, _baseLength, (short)letters.length);
    offset += LittleEndian.SHORT_SIZE;
    for (int x = 0; x < letters.length; x++)
    {
      LittleEndian.putShort(buf, offset, (short)letters[x]);
      offset += LittleEndian.SHORT_SIZE;
    }
    // get past the null delimiter for the name.
    offset += LittleEndian.SHORT_SIZE;

    for (int x = 0; x < _upxs.length; x++)
    {
      short upxSize = (short)_upxs[x].size();
      LittleEndian.putShort(buf, offset, upxSize);
      offset += LittleEndian.SHORT_SIZE;
      System.arraycopy(_upxs[x].getUPX(), 0, buf, offset, upxSize);
      offset += upxSize + (upxSize % 2);
    }

    return buf;