private void applyChpx(PropertyExceptions chpx, WordDocument parentDocument) { foreach (var sprm in chpx.grpprl) { switch (sprm.OpCode) { //style id case SinglePropertyModifier.OperationCode.sprmCIstd: this.istd = System.BitConverter.ToUInt16(sprm.Arguments, 0); break; //font name ASCII case SinglePropertyModifier.OperationCode.sprmCRgFtc0: this.FontAscii = (FontFamilyName)parentDocument.FontTable.Data[System.BitConverter.ToUInt16(sprm.Arguments, 0)]; break; //font size case SinglePropertyModifier.OperationCode.sprmCHps: this.hps = sprm.Arguments[0]; break; // color case SinglePropertyModifier.OperationCode.sprmCCv: this.cv = new RGBColor(System.BitConverter.ToInt32(sprm.Arguments, 0), RGBColor.ByteOrder.RedFirst); break; //bold case SinglePropertyModifier.OperationCode.sprmCFBold: this.fBold = handleToogleValue(this.fBold, sprm.Arguments[0]); break; //italic case SinglePropertyModifier.OperationCode.sprmCFItalic: this.fItalic = handleToogleValue(this.fItalic, sprm.Arguments[0]); break; //outline case SinglePropertyModifier.OperationCode.sprmCFOutline: this.fOutline = Utils.ByteToBool(sprm.Arguments[0]); break; //shadow case SinglePropertyModifier.OperationCode.sprmCFShadow: this.fShadow = Utils.ByteToBool(sprm.Arguments[0]); break; //strike through case SinglePropertyModifier.OperationCode.sprmCFStrike: this.fStrike = Utils.ByteToBool(sprm.Arguments[0]); break; // underline case SinglePropertyModifier.OperationCode.sprmCKul: this.UnderlineStyle = (Global.UnderlineCode)sprm.Arguments[0]; break; } } }
/// <summary> /// Parses the given StreamReader to retrieve a LVL struct /// </summary> /// <param name="bytes"></param> public ListLevel(VirtualStreamReader reader, int length) : base(reader, length) { long startPos = this._reader.BaseStream.Position; //parse the fix part this.iStartAt = this._reader.ReadInt32(); this.nfc = this._reader.ReadByte(); int flag = this._reader.ReadByte(); this.jc = (byte)(flag & 0x03); this.fLegal = Utils.BitmaskToBool(flag, 0x04); this.fNoRestart = Utils.BitmaskToBool(flag, 0x08); this.fPrev = Utils.BitmaskToBool(flag, 0x10); this.fPrevSpace = Utils.BitmaskToBool(flag, 0x20); this.fWord6 = Utils.BitmaskToBool(flag, 0x40); this.rgbxchNums = new byte[9]; for (int i = 0; i < 9; i++) { this.rgbxchNums[i] = this._reader.ReadByte(); } this.ixchFollow = (FollowingChar)this._reader.ReadByte(); this.dxaSpace = this._reader.ReadInt32(); this.dxaIndent = this._reader.ReadInt32(); this.cbGrpprlChpx = this._reader.ReadByte(); this.cbGrpprlPapx = this._reader.ReadByte(); this.ilvlRestartLim = this._reader.ReadByte(); this.grfhic = this._reader.ReadByte(); //parse the variable part //read the group of papx sprms //this papx has no istd, so use PX to parse it var px = new PropertyExceptions(this._reader.ReadBytes(this.cbGrpprlPapx)); this.grpprlPapx = new ParagraphPropertyExceptions { grpprl = px.grpprl }; //read the group of chpx sprms this.grpprlChpx = new CharacterPropertyExceptions(this._reader.ReadBytes(this.cbGrpprlChpx)); //read the number text short strLen = this._reader.ReadInt16(); this.xst = Encoding.Unicode.GetString(this._reader.ReadBytes(strLen * 2)); long endPos = this._reader.BaseStream.Position; this._reader.BaseStream.Seek(startPos, System.IO.SeekOrigin.Begin); this._rawBytes = this._reader.ReadBytes((int)(endPos - startPos)); }
/// <summary> /// Extracts the TAPX SPRMs out of a PAPX /// </summary> /// <param name="papx"></param> public TablePropertyExceptions(ParagraphPropertyExceptions papx, VirtualStream dataStream) { this.grpprl = new List <SinglePropertyModifier>(); foreach (var sprm in papx.grpprl) { if (sprm.Type == SinglePropertyModifier.SprmType.TAP) { this.grpprl.Add(sprm); } else if ((int)sprm.OpCode == 0x646b) { IStreamReader reader = new VirtualStreamReader(dataStream); //there is a native TAP in the data stream uint fc = System.BitConverter.ToUInt32(sprm.Arguments, 0); //get the size of the following grpprl //byte[] sizebytes = new byte[2]; //dataStream.Read(sizebytes, 2, (int)fc); var sizebytes = reader.ReadBytes(fc, 2); ushort grpprlSize = System.BitConverter.ToUInt16(sizebytes, 0); //read the grpprl //byte[] grpprlBytes = new byte[grpprlSize]; //dataStream.Read(grpprlBytes); var grpprlBytes = reader.ReadBytes(grpprlSize); //parse the grpprl var externalPx = new PropertyExceptions(grpprlBytes); foreach (var sprmExternal in externalPx.grpprl) { if (sprmExternal.Type == SinglePropertyModifier.SprmType.TAP) { this.grpprl.Add(sprmExternal); } } } } }
/// <summary> /// Parses the bytes to retrieve a PAPX /// </summary> /// <param name="bytes">The bytes starting with the istd</param> public ParagraphPropertyExceptions(byte[] bytes, VirtualStream dataStream) : base(new List <byte>(bytes).GetRange(2, bytes.Length - 2).ToArray()) { if (bytes.Length != 0) { this.istd = System.BitConverter.ToUInt16(bytes, 0); } //There is a SPRM that points to an offset in the data stream, //where a list of SPRM is saved. foreach (var sprm in this.grpprl) { if (sprm.OpCode == SinglePropertyModifier.OperationCode.sprmPHugePapx || (int)sprm.OpCode == 0x6646) { IStreamReader reader = new VirtualStreamReader(dataStream); uint fc = System.BitConverter.ToUInt32(sprm.Arguments, 0); //parse the size of the external grpprl var sizebytes = new byte[2]; dataStream.Read(sizebytes, 0, 2, (int)fc); ushort size = System.BitConverter.ToUInt16(sizebytes, 0); //parse the external grpprl //byte[] grpprlBytes = new byte[size]; //dataStream.Read(grpprlBytes); var grpprlBytes = reader.ReadBytes(size); var externalPx = new PropertyExceptions(grpprlBytes); //assign the external grpprl this.grpprl = externalPx.grpprl; //remove the sprmPHugePapx this.grpprl.Remove(sprm); } } }