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.model.hdftypes;
019:
020: import org.apache.poi.util.LittleEndian;
021:
022: /**
023: * Comment me
024: *
025: * @author Ryan Ackley
026: */
027:
028: public class StyleDescription implements HDFType {
029:
030: private static int PARAGRAPH_STYLE = 1;
031: private static int CHARACTER_STYLE = 2;
032:
033: int _baseStyleIndex;
034: int _styleTypeCode;
035: int _numUPX;
036: byte[] _papx;
037: byte[] _chpx;
038: ParagraphProperties _pap;
039: CharacterProperties _chp;
040:
041: public StyleDescription() {
042: _pap = new ParagraphProperties();
043: _chp = new CharacterProperties();
044: }
045:
046: public StyleDescription(byte[] std, int baseLength, boolean word9) {
047: int infoShort = LittleEndian.getShort(std, 2);
048: _styleTypeCode = (infoShort & 0xf);
049: _baseStyleIndex = (infoShort & 0xfff0) >> 4;
050:
051: infoShort = LittleEndian.getShort(std, 4);
052: _numUPX = infoShort & 0xf;
053:
054: //first byte(s) of variable length section of std is the length of the
055: //style name and aliases string
056: int nameLength = 0;
057: int multiplier = 1;
058: if (word9) {
059: nameLength = LittleEndian.getShort(std, baseLength);
060: multiplier = 2;
061: } else {
062: nameLength = std[baseLength];
063: }
064: //2 bytes for length, length then null terminator.
065: int grupxStart = multiplier + ((nameLength + 1) * multiplier)
066: + baseLength;
067:
068: int offset = 0;
069: for (int x = 0; x < _numUPX; x++) {
070: int upxSize = LittleEndian.getShort(std, grupxStart
071: + offset);
072: if (_styleTypeCode == PARAGRAPH_STYLE) {
073: if (x == 0) {
074: _papx = new byte[upxSize];
075: System.arraycopy(std, grupxStart + offset + 2,
076: _papx, 0, upxSize);
077: } else if (x == 1) {
078: _chpx = new byte[upxSize];
079: System.arraycopy(std, grupxStart + offset + 2,
080: _chpx, 0, upxSize);
081: }
082: } else if (_styleTypeCode == CHARACTER_STYLE && x == 0) {
083: _chpx = new byte[upxSize];
084: System.arraycopy(std, grupxStart + offset + 2, _chpx,
085: 0, upxSize);
086: }
087:
088: if (upxSize % 2 == 1) {
089: ++upxSize;
090: }
091: offset += 2 + upxSize;
092: }
093:
094: }
095:
096: public int getBaseStyle() {
097: return _baseStyleIndex;
098: }
099:
100: public byte[] getCHPX() {
101: return _chpx;
102: }
103:
104: public byte[] getPAPX() {
105: return _papx;
106: }
107:
108: public ParagraphProperties getPAP() {
109: return _pap;
110: }
111:
112: public CharacterProperties getCHP() {
113: return _chp;
114: }
115:
116: public void setPAP(ParagraphProperties pap) {
117: _pap = pap;
118: }
119:
120: public void setCHP(CharacterProperties chp) {
121: _chp = chp;
122: }
123: }
|