⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stylesheet.java

📁 java 读写word excel ppt
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/* ====================================================================   Licensed to the Apache Software Foundation (ASF) under one or more   contributor license agreements.  See the NOTICE file distributed with   this work for additional information regarding copyright ownership.   The ASF licenses this file to You under the Apache License, Version 2.0   (the "License"); you may not use this file except in compliance with   the License.  You may obtain a copy of the License at       http://www.apache.org/licenses/LICENSE-2.0   Unless required by applicable law or agreed to in writing, software   distributed under the License is distributed on an "AS IS" BASIS,   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   See the License for the specific language governing permissions and   limitations under the License.==================================================================== */        package org.apache.poi.hdf.model.hdftypes;import java.util.*;import org.apache.poi.util.LittleEndian;import org.apache.poi.hdf.model.hdftypes.definitions.TCAbstractType;/** * Represents a document's stylesheet. A word documents formatting is stored as * compressed styles that are based on styles contained in the stylesheet. This * class also contains static utility functions to uncompress different * formatting properties. * * @author Ryan Ackley */public class StyleSheet implements HDFType{  private static final int NIL_STYLE = 4095;  private static final int PAP_TYPE = 1;  private static final int CHP_TYPE = 2;  private static final int SEP_TYPE = 4;  private static final int TAP_TYPE = 5;  //Vector _styleDescriptions;  StyleDescription _nilStyle = new StyleDescription();  StyleDescription[] _styleDescriptions;  /**   * StyleSheet constructor. Loads a document's stylesheet information,   *   * @param styleSheet A byte array containing a document's raw stylesheet   *        info. Found by using FileInformationBlock.getFcStshf() and   *        FileInformationBLock.getLcbStshf()   */  public StyleSheet(byte[] styleSheet)  {      int stshiLength = LittleEndian.getShort(styleSheet, 0);      int stdCount = LittleEndian.getShort(styleSheet, 2);      int baseLength = LittleEndian.getShort(styleSheet, 4);      int[] rgftc = new int[3];      rgftc[0] = LittleEndian.getInt(styleSheet, 14);      rgftc[1] = LittleEndian.getInt(styleSheet, 18);      rgftc[2] = LittleEndian.getInt(styleSheet, 22);      int offset = 0;      _styleDescriptions = new StyleDescription[stdCount];      for(int x = 0; x < stdCount; x++)      {          int stdOffset = (2 + stshiLength) + offset;          int stdSize = LittleEndian.getShort(styleSheet, stdOffset);          if(stdSize > 0)          {              byte[] std = new byte[stdSize];              //get past the size              stdOffset += 2;              System.arraycopy(styleSheet, stdOffset, std, 0, stdSize);              StyleDescription aStyle = new StyleDescription(std, baseLength, true);              _styleDescriptions[x] = aStyle;          }          offset += stdSize + 2;      }      for(int x = 0; x < _styleDescriptions.length; x++)      {          if(_styleDescriptions[x] != null)          {              createPap(x);              createChp(x);          }      }  }  /**   * Creates a PartagraphProperties object from a papx stored in the   * StyleDescription at the index istd in the StyleDescription array. The PAP   * is placed in the StyleDescription at istd after its been created. Not   * every StyleDescription will contain a papx. In these cases this function   * does nothing   *   * @param istd The index of the StyleDescription to create the   *        ParagraphProperties  from (and also place the finished PAP in)   */  private void createPap(int istd)  {      StyleDescription sd = _styleDescriptions[istd];      ParagraphProperties pap = sd.getPAP();      byte[] papx = sd.getPAPX();      int baseIndex = sd.getBaseStyle();      if(pap == null && papx != null)      {          ParagraphProperties parentPAP = _nilStyle.getPAP();          if(baseIndex != NIL_STYLE)          {              parentPAP = _styleDescriptions[baseIndex].getPAP();              if(parentPAP == null)              {                  createPap(baseIndex);                  parentPAP = _styleDescriptions[baseIndex].getPAP();              }          }          pap = (ParagraphProperties)uncompressProperty(papx, parentPAP, this);          sd.setPAP(pap);      }  }  /**   * Creates a CharacterProperties object from a chpx stored in the   * StyleDescription at the index istd in the StyleDescription array. The   * CharacterProperties object is placed in the StyleDescription at istd after   * its been created. Not every StyleDescription will contain a chpx. In these   * cases this function does nothing.   *   * @param istd The index of the StyleDescription to create the   *        CharacterProperties object from.   */  private void createChp(int istd)  {      StyleDescription sd = _styleDescriptions[istd];      CharacterProperties chp = sd.getCHP();      byte[] chpx = sd.getCHPX();      int baseIndex = sd.getBaseStyle();      if(chp == null && chpx != null)      {          CharacterProperties parentCHP = _nilStyle.getCHP();          if(baseIndex != NIL_STYLE)          {              parentCHP = _styleDescriptions[baseIndex].getCHP();              if(parentCHP == null)              {                  createChp(baseIndex);                  parentCHP = _styleDescriptions[baseIndex].getCHP();              }          }          chp = (CharacterProperties)uncompressProperty(chpx, parentCHP, this);          sd.setCHP(chp);      }  }  /**   * Gets the StyleDescription at index x.   *   * @param x the index of the desired StyleDescription.   */  public StyleDescription getStyleDescription(int x)  {      return _styleDescriptions[x];  }  /**   * Used in decompression of a chpx. This performs an operation defined by   * a single sprm.   *   * @param oldCHP The base CharacterProperties.   * @param newCHP The current CharacterProperties.   * @param operand The operand defined by the sprm (See Word file format spec)   * @param param The parameter defined by the sprm (See Word file format spec)   * @param varParam The variable length parameter defined by the sprm. (See   *        Word file format spec)   * @param grpprl The entire chpx that this operation is a part of.   * @param offset The offset in the grpprl of the next sprm   * @param styleSheet The StyleSheet for this document.   */  static void doCHPOperation(CharacterProperties oldCHP, CharacterProperties newCHP,                             int operand, int param,                             byte[] varParam, byte[] grpprl, int offset,                             StyleSheet styleSheet)  {      switch(operand)      {          case 0:               newCHP.setFRMarkDel(getFlag(param));               break;          case 0x1:               newCHP.setFRMark(getFlag(param));               break;          case 0x2:               break;          case 0x3:               newCHP.setFcPic(param);               newCHP.setFSpec(true);               break;          case 0x4:               newCHP.setIbstRMark((short)param);               break;          case 0x5:               short[] dttmRMark = new short[2];               dttmRMark[0] = LittleEndian.getShort(grpprl, (offset - 4));               dttmRMark[1] = LittleEndian.getShort(grpprl, (offset - 2));               newCHP.setDttmRMark(dttmRMark);               break;          case 0x6:               newCHP.setFData(getFlag(param));               break;          case 0x7:               //don't care about this               break;          case 0x8:               short chsDiff = (short)((param & 0xff0000) >>> 8);               newCHP.setFChsDiff(getFlag(chsDiff));               newCHP.setChse((short)(param & 0xffff));               break;          case 0x9:               newCHP.setFSpec(true);               newCHP.setFtcSym((short)LittleEndian.getShort(varParam, 0));               newCHP.setXchSym((short)LittleEndian.getShort(varParam, 2));               break;          case 0xa:               newCHP.setFOle2(getFlag(param));               break;          case 0xb:               //?               break;          case 0xc:               newCHP.setIcoHighlight((byte)param);               newCHP.setFHighlight(getFlag(param));               break;          case 0xd:               break;          case 0xe:               newCHP.setFcObj(param);               break;          case 0xf:               break;          case 0x10:               //?               break;          case 0x11:               break;          case 0x12:               break;          case 0x13:               break;          case 0x14:               break;          case 0x15:               break;          case 0x16:               break;          case 0x17:               break;          case 0x18:               break;          case 0x19:               break;          case 0x1a:               break;          case 0x1b:               break;          case 0x1c:               break;          case 0x1d:               break;          case 0x1e:               break;          case 0x1f:               break;          case 0x20:               break;          case 0x21:               break;          case 0x22:               break;          case 0x23:               break;          case 0x24:               break;          case 0x25:               break;          case 0x26:               break;          case 0x27:               break;          case 0x28:               break;          case 0x29:               break;          case 0x2a:               break;          case 0x2b:               break;          case 0x2c:               break;          case 0x2d:               break;          case 0x2e:               break;          case 0x2f:               break;          case 0x30:               newCHP.setIstd(param);               break;          case 0x31:               //permutation vector for fast saves, who cares!               break;          case 0x32:               newCHP.setFBold(false);               newCHP.setFItalic(false);               newCHP.setFOutline(false);               newCHP.setFStrike(false);               newCHP.setFShadow(false);               newCHP.setFSmallCaps(false);               newCHP.setFCaps(false);               newCHP.setFVanish(false);               newCHP.setKul((byte)0);               newCHP.setIco((byte)0);               break;          case 0x33:               try               {                   newCHP = (CharacterProperties)oldCHP.clone();               }               catch(CloneNotSupportedException e)               {                   //do nothing               }               return;          case 0x34:               break;          case 0x35:               newCHP.setFBold(getCHPFlag((byte)param, oldCHP.isFBold()));               break;          case 0x36:               newCHP.setFItalic(getCHPFlag((byte)param, oldCHP.isFItalic()));               break;          case 0x37:               newCHP.setFStrike(getCHPFlag((byte)param, oldCHP.isFStrike()));               break;          case 0x38:               newCHP.setFOutline(getCHPFlag((byte)param, oldCHP.isFOutline()));               break;          case 0x39:               newCHP.setFShadow(getCHPFlag((byte)param, oldCHP.isFShadow()));               break;          case 0x3a:               newCHP.setFSmallCaps(getCHPFlag((byte)param, oldCHP.isFSmallCaps()));               break;          case 0x3b:               newCHP.setFCaps(getCHPFlag((byte)param, oldCHP.isFCaps()));               break;          case 0x3c:               newCHP.setFVanish(getCHPFlag((byte)param, oldCHP.isFVanish()));               break;          case 0x3d:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -