private void applyChpx(PropertyExceptions chpx, WordDocument parentDocument)
        {
            foreach (SinglePropertyModifier 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;
                }
            }
        }
Beispiel #2
0
        /// <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 = _reader.BaseStream.Position;

            //parse the fix part
            this.iStartAt = _reader.ReadInt32();
            this.nfc      = _reader.ReadByte();
            int flag = _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++)
            {
                rgbxchNums[i] = _reader.ReadByte();
            }
            this.ixchFollow = (FollowingChar)_reader.ReadByte();

            this.dxaSpace  = _reader.ReadInt32();
            this.dxaIndent = _reader.ReadInt32();

            this.cbGrpprlChpx = _reader.ReadByte();
            this.cbGrpprlPapx = _reader.ReadByte();

            this.ilvlRestartLim = _reader.ReadByte();
            this.grfhic         = _reader.ReadByte();

            //parse the variable part

            //read the group of papx sprms
            //this papx has no istd, so use PX to parse it
            PropertyExceptions px = new PropertyExceptions(_reader.ReadBytes(this.cbGrpprlPapx));

            this.grpprlPapx        = new ParagraphPropertyExceptions();
            this.grpprlPapx.grpprl = px.grpprl;

            //read the group of chpx sprms
            this.grpprlChpx = new CharacterPropertyExceptions(_reader.ReadBytes(this.cbGrpprlChpx));

            //read the number text
            Int16 strLen = _reader.ReadInt16();

            this.xst = Encoding.Unicode.GetString(_reader.ReadBytes(strLen * 2));

            long endPos = _reader.BaseStream.Position;

            _reader.BaseStream.Seek(startPos, System.IO.SeekOrigin.Begin);
            _rawBytes = _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 (SinglePropertyModifier 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
                    UInt32 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);
                    byte[] sizebytes  = reader.ReadBytes(fc, 2);
                    UInt16 grpprlSize = System.BitConverter.ToUInt16(sizebytes, 0);

                    //read the grpprl
                    //byte[] grpprlBytes = new byte[grpprlSize];
                    //dataStream.Read(grpprlBytes);
                    byte[] grpprlBytes = reader.ReadBytes(grpprlSize);

                    //parse the grpprl
                    PropertyExceptions externalPx = new PropertyExceptions(grpprlBytes);

                    foreach (SinglePropertyModifier 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 (SinglePropertyModifier sprm in this.grpprl)
            {
                if (sprm.OpCode == SinglePropertyModifier.OperationCode.sprmPHugePapx || (int)sprm.OpCode == 0x6646)
                {
                    IStreamReader reader = new VirtualStreamReader(dataStream);
                    UInt32        fc     = System.BitConverter.ToUInt32(sprm.Arguments, 0);

                    //parse the size of the external grpprl
                    byte[] sizebytes = new byte[2];
                    dataStream.Read(sizebytes, 0, 2, (int)fc);
                    UInt16 size = System.BitConverter.ToUInt16(sizebytes, 0);

                    //parse the external grpprl
                    //byte[] grpprlBytes = new byte[size];
                    //dataStream.Read(grpprlBytes);
                    byte[]             grpprlBytes = reader.ReadBytes(size);
                    PropertyExceptions externalPx  = new PropertyExceptions(grpprlBytes);

                    //assign the external grpprl
                    this.grpprl = externalPx.grpprl;

                    //remove the sprmPHugePapx
                    this.grpprl.Remove(sprm);
                }
            }
        }