📄 charactersprmuncompressor.java
字号:
/* ==================================================================== 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.hwpf.sprm;import org.apache.poi.hwpf.usermodel.CharacterProperties;import org.apache.poi.hwpf.usermodel.DateAndTime;import org.apache.poi.hwpf.usermodel.BorderCode;import org.apache.poi.hwpf.usermodel.ShadingDescriptor;import org.apache.poi.hwpf.model.StyleSheet;import org.apache.poi.util.LittleEndian;public class CharacterSprmUncompressor{ public CharacterSprmUncompressor() { } public static CharacterProperties uncompressCHP(CharacterProperties parent, byte[] grpprl, int offset) { CharacterProperties newProperties = null; try { newProperties = (CharacterProperties) parent.clone(); } catch (CloneNotSupportedException cnse) { throw new RuntimeException("There is no way this exception should happen!!"); } SprmIterator sprmIt = new SprmIterator(grpprl, offset); while (sprmIt.hasNext()) { SprmOperation sprm = (SprmOperation)sprmIt.next(); unCompressCHPOperation(parent, newProperties, sprm); } return newProperties; } /** * 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 unCompressCHPOperation (CharacterProperties oldCHP, CharacterProperties newCHP, SprmOperation sprm) { switch (sprm.getOperation()) { case 0: newCHP.setFRMarkDel (getFlag (sprm.getOperand())); break; case 0x1: newCHP.setFRMark (getFlag (sprm.getOperand())); break; case 0x2: newCHP.setFFldVanish (getFlag (sprm.getOperand())); break; case 0x3: newCHP.setFcPic (sprm.getOperand()); newCHP.setFSpec (true); break; case 0x4: newCHP.setIbstRMark ((short) sprm.getOperand()); break; case 0x5: newCHP.setDttmRMark (new DateAndTime(sprm.getGrpprl(), sprm.getGrpprlOffset())); break; case 0x6: newCHP.setFData (getFlag (sprm.getOperand())); break; case 0x7: //don't care about this break; case 0x8: //short chsDiff = (short)((param & 0xff0000) >>> 16); int operand =sprm.getOperand(); short chsDiff = (short) (operand & 0x0000ff); newCHP.setFChsDiff (getFlag (chsDiff)); newCHP.setChse ((short) (operand & 0xffff00)); break; case 0x9: newCHP.setFSpec (true); newCHP.setFtcSym ((short) LittleEndian.getShort (sprm.getGrpprl(), sprm.getGrpprlOffset())); newCHP.setXchSym ((short) LittleEndian.getShort (sprm.getGrpprl(), sprm.getGrpprlOffset() + 2)); break; case 0xa: newCHP.setFOle2 (getFlag (sprm.getOperand())); break; case 0xb: // Obsolete break; case 0xc: newCHP.setIcoHighlight ((byte) sprm.getOperand()); newCHP.setFHighlight (getFlag (sprm.getOperand())); break; case 0xd: // undocumented break; case 0xe: newCHP.setFcObj (sprm.getOperand()); break; case 0xf: // undocumented break; case 0x10: // undocumented break; // undocumented till 0x30 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 (sprm.getOperand()); 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 { // preserve the fSpec setting from the original CHP boolean fSpec = newCHP.isFSpec (); newCHP = (CharacterProperties) oldCHP.clone (); newCHP.setFSpec (fSpec); } catch (CloneNotSupportedException e) { //do nothing } return; case 0x34: // undocumented break; case 0x35: newCHP.setFBold (getCHPFlag ((byte) sprm.getOperand(), oldCHP.isFBold ())); break; case 0x36: newCHP.setFItalic (getCHPFlag ((byte) sprm.getOperand(), oldCHP.isFItalic ())); break; case 0x37: newCHP.setFStrike (getCHPFlag ((byte) sprm.getOperand(), oldCHP.isFStrike ())); break; case 0x38: newCHP.setFOutline (getCHPFlag ((byte) sprm.getOperand(), oldCHP.isFOutline ())); break; case 0x39: newCHP.setFShadow (getCHPFlag ((byte) sprm.getOperand(), oldCHP.isFShadow ())); break; case 0x3a: newCHP.setFSmallCaps (getCHPFlag ((byte) sprm.getOperand(), oldCHP.isFSmallCaps ())); break; case 0x3b: newCHP.setFCaps (getCHPFlag ((byte) sprm.getOperand(), oldCHP.isFCaps ())); break; case 0x3c: newCHP.setFVanish (getCHPFlag ((byte) sprm.getOperand(), oldCHP.isFVanish ())); break; case 0x3d: newCHP.setFtcAscii ((short) sprm.getOperand()); break; case 0x3e: newCHP.setKul ((byte) sprm.getOperand()); break; case 0x3f: operand = sprm.getOperand(); int hps = operand & 0xff; if (hps != 0) { newCHP.setHps (hps); } //byte cInc = (byte)(((byte)(param & 0xfe00) >>> 4) >> 1); byte cInc = (byte) ((operand & 0xff00) >>> 8); cInc = (byte) (cInc >>> 1); if (cInc != 0) { newCHP.setHps (Math.max (newCHP.getHps () + (cInc * 2), 2)); } //byte hpsPos = (byte)((param & 0xff0000) >>> 8); byte hpsPos = (byte) ((operand & 0xff0000) >>> 16); if (hpsPos != 0x80) { newCHP.setHpsPos (hpsPos); } boolean fAdjust = (operand & 0x0100) > 0; if (fAdjust && hpsPos != 128 && hpsPos != 0 && oldCHP.getHpsPos () == 0) { newCHP.setHps (Math.max (newCHP.getHps () + ( -2), 2)); } if (fAdjust && hpsPos == 0 && oldCHP.getHpsPos () != 0) { newCHP.setHps (Math.max (newCHP.getHps () + 2, 2)); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -