001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hdf.extractor;
019:
020: /**
021: * Comment me
022: *
023: * @author Ryan Ackley
024: */
025:
026: public class StyleDescription {
027:
028: private static int PARAGRAPH_STYLE = 1;
029: private static int CHARACTER_STYLE = 2;
030:
031: int _baseStyleIndex;
032: int _styleTypeCode;
033: int _numUPX;
034: byte[] _papx;
035: byte[] _chpx;
036: PAP _pap;
037: CHP _chp;
038:
039: public StyleDescription() {
040: _pap = new PAP();
041: _chp = new CHP();
042: }
043:
044: public StyleDescription(byte[] std, int baseLength, boolean word9) {
045: int infoShort = Utils.convertBytesToShort(std, 2);
046: _styleTypeCode = (infoShort & 0xf);
047: _baseStyleIndex = (infoShort & 0xfff0) >> 4;
048:
049: infoShort = Utils.convertBytesToShort(std, 4);
050: _numUPX = infoShort & 0xf;
051:
052: //first byte(s) of variable length section of std is the length of the
053: //style name and aliases string
054: int nameLength = 0;
055: int multiplier = 1;
056: if (word9) {
057: nameLength = Utils.convertBytesToShort(std, baseLength);
058: multiplier = 2;
059: } else {
060: nameLength = std[baseLength];
061: }
062: //2 bytes for length, length then null terminator.
063: int grupxStart = multiplier + ((nameLength + 1) * multiplier)
064: + baseLength;
065:
066: int offset = 0;
067: for (int x = 0; x < _numUPX; x++) {
068: int upxSize = Utils.convertBytesToShort(std, grupxStart
069: + offset);
070: if (_styleTypeCode == PARAGRAPH_STYLE) {
071: if (x == 0) {
072: _papx = new byte[upxSize];
073: System.arraycopy(std, grupxStart + offset + 2,
074: _papx, 0, upxSize);
075: } else if (x == 1) {
076: _chpx = new byte[upxSize];
077: System.arraycopy(std, grupxStart + offset + 2,
078: _chpx, 0, upxSize);
079: }
080: } else if (_styleTypeCode == CHARACTER_STYLE && x == 0) {
081: _chpx = new byte[upxSize];
082: System.arraycopy(std, grupxStart + offset + 2, _chpx,
083: 0, upxSize);
084: }
085:
086: if (upxSize % 2 == 1) {
087: ++upxSize;
088: }
089: offset += 2 + upxSize;
090: }
091:
092: }
093:
094: public int getBaseStyle() {
095: return _baseStyleIndex;
096: }
097:
098: public byte[] getCHPX() {
099: return _chpx;
100: }
101:
102: public byte[] getPAPX() {
103: return _papx;
104: }
105:
106: public PAP getPAP() {
107: return _pap;
108: }
109:
110: public CHP getCHP() {
111: return _chp;
112: }
113:
114: public void setPAP(PAP pap) {
115: _pap = pap;
116: }
117:
118: public void setCHP(CHP chp) {
119: _chp = chp;
120: }
121: }
|