コード例 #1
0
        private void buildHierarchy(List <CharacterPropertyExceptions> hierarchy, StyleSheet styleSheet, UInt16 istdStart)
        {
            int  istd = (int)istdStart;
            bool goOn = true;

            while (goOn)
            {
                try
                {
                    CharacterPropertyExceptions baseChpx = styleSheet.Styles[istd].chpx;
                    if (baseChpx != null)
                    {
                        hierarchy.Add(baseChpx);
                        istd = (int)styleSheet.Styles[istd].istdBase;
                    }
                    else
                    {
                        goOn = false;
                    }
                }
                catch (Exception)
                {
                    goOn = false;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Parses the CHPX for a fcPic an loads the PictureDescriptor at this offset
        /// </summary>
        /// <param name="chpx">The CHPX that holds a SPRM for fcPic</param>
        public PictureDescriptor(CharacterPropertyExceptions chpx, VirtualStream stream)
        {
            //Get start and length of the PICT
            Int32 fc = GetFcPic(chpx);

            if (fc >= 0)
            {
                parse(stream, fc);
            }
        }
コード例 #3
0
        public NilPicfAndBinData(CharacterPropertyExceptions chpx, VirtualStream dataStream)
        {
            //Get start of the NilPicfAndBinData structure
            Int32 fc = PictureDescriptor.GetFcPic(chpx);

            if (fc >= 0)
            {
                parse(dataStream, fc);
            }
        }
コード例 #4
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));
        }
コード例 #5
0
        public FormattedDiskPageCHPX(VirtualStream wordStream, Int32 offset)
        {
            this.Type       = FKPType.Character;
            this.WordStream = wordStream;

            //read the 512 bytes (FKP)
            byte[] bytes = new byte[512];
            wordStream.Read(bytes, 0, 512, offset);

            //get the count first
            this.crun = bytes[511];

            //create and fill the array with the adresses
            this.rgfc = new Int32[this.crun + 1];
            int j = 0;

            for (int i = 0; i < rgfc.Length; i++)
            {
                rgfc[i] = System.BitConverter.ToInt32(bytes, j);
                j      += 4;
            }

            //create arrays
            this.rgb     = new byte[this.crun];
            this.grpchpx = new CharacterPropertyExceptions[this.crun];

            j = 4 * (this.crun + 1);
            for (int i = 0; i < rgb.Length; i++)
            {
                //fill the rgb array
                byte wordOffset = bytes[j];
                this.rgb[i] = wordOffset;
                j++;

                if (wordOffset != 0)
                {
                    //read first byte of CHPX
                    //it's the count of bytes
                    byte cb = bytes[wordOffset * 2];

                    //read the bytes of chpx
                    byte[] chpx = new byte[cb];
                    Array.Copy(bytes, (wordOffset * 2) + 1, chpx, 0, chpx.Length);

                    //parse CHPX and fill grpchpx
                    grpchpx[i] = new CharacterPropertyExceptions(chpx);
                }
                else
                {
                    //create a CHPX which doesn't modify anything
                    grpchpx[i] = new CharacterPropertyExceptions();
                }
            }
        }
コード例 #6
0
        private int getIsdt(CharacterPropertyExceptions chpx)
        {
            int ret = 10; //default value for istd

            foreach (SinglePropertyModifier sprm in chpx.grpprl)
            {
                if (sprm.OpCode == SinglePropertyModifier.OperationCode.sprmCIstd)
                {
                    ret = (int)System.BitConverter.ToInt16(sprm.Arguments, 0);
                    break;
                }
            }
            return(ret);
        }
コード例 #7
0
        /// <summary>
        /// Returns the fcPic into the "data" stream, where the PIC begins.
        /// Returns -1 if the CHPX has no fcPic.
        /// </summary>
        /// <param name="chpx">The CHPX</param>
        /// <returns></returns>
        public static Int32 GetFcPic(CharacterPropertyExceptions chpx)
        {
            Int32 ret = -1;

            foreach (SinglePropertyModifier sprm in chpx.grpprl)
            {
                switch (sprm.OpCode)
                {
                case SinglePropertyModifier.OperationCode.sprmCPicLocation:
                    ret = System.BitConverter.ToInt32(sprm.Arguments, 0);
                    break;

                case SinglePropertyModifier.OperationCode.sprmCHsp:
                    ret = System.BitConverter.ToInt32(sprm.Arguments, 0);
                    break;

                case SinglePropertyModifier.OperationCode.sprmCFData:
                    break;
                }
            }
            return(ret);
        }
コード例 #8
0
        /// <summary>
        /// Builds a CHP based on a CHPX
        /// </summary>
        /// <param name="styles">The stylesheet</param>
        /// <param name="chpx">The CHPX</param>
        public CharacterProperties(StyleSheet styleSheet, CharacterPropertyExceptions chpx, ParagraphPropertyExceptions parentPapx)
        {
            setDefaultValues();

            //get all CHPX in the hierarchy
            List <CharacterPropertyExceptions> chpxHierarchy = new List <CharacterPropertyExceptions>();

            chpxHierarchy.Add(chpx);

            //add parent character styles
            buildHierarchy(chpxHierarchy, styleSheet, (UInt16)getIsdt(chpx));

            //add parent paragraph styles
            buildHierarchy(chpxHierarchy, styleSheet, parentPapx.istd);

            chpxHierarchy.Reverse();

            //apply the CHPX hierarchy to this CHP
            foreach (CharacterPropertyExceptions c in chpxHierarchy)
            {
                applyChpx(c);
            }
        }
コード例 #9
0
        /// <summary>
        /// Parses the bytes to retrieve a StyleSheetDescription
        /// </summary>
        /// <param name="bytes">The bytes</param>
        /// <param name="cbStdBase"></param>
        /// <param name="dataStream">The "Data" stream (optional, can be null)</param>
        public StyleSheetDescription(byte[] bytes, int cbStdBase, VirtualStream dataStream)
        {
            BitArray bits = new BitArray(bytes);

            //parsing the base (fix part)

            if (cbStdBase >= 2)
            {
                //sti
                BitArray stiBits = Utils.BitArrayCopy(bits, 0, 12);
                this.sti = (StyleIdentifier)Utils.BitArrayToUInt32(stiBits);
                //flags
                this.fScratch     = bits[12];
                this.fInvalHeight = bits[13];
                this.fHasUpe      = bits[14];
                this.fMassCopy    = bits[15];
            }
            if (cbStdBase >= 4)
            {
                //stk
                BitArray stkBits = Utils.BitArrayCopy(bits, 16, 4);
                this.stk = (StyleKind)Utils.BitArrayToUInt32(stkBits);
                //istdBase
                BitArray istdBits = Utils.BitArrayCopy(bits, 20, 12);
                this.istdBase = (UInt32)Utils.BitArrayToUInt32(istdBits);
            }
            if (cbStdBase >= 6)
            {
                //cupx
                BitArray cupxBits = Utils.BitArrayCopy(bits, 32, 4);
                this.cupx = (UInt16)Utils.BitArrayToUInt32(cupxBits);
                //istdNext
                BitArray istdNextBits = Utils.BitArrayCopy(bits, 36, 12);
                this.istdNext = (UInt32)Utils.BitArrayToUInt32(istdNextBits);
            }
            if (cbStdBase >= 8)
            {
                //bchUpe
                BitArray bchBits = Utils.BitArrayCopy(bits, 48, 16);
                this.bchUpe = (UInt16)Utils.BitArrayToUInt32(bchBits);
            }
            if (cbStdBase >= 10)
            {
                //flags
                this.fAutoRedef       = bits[64];
                this.fHidden          = bits[65];
                this.f97LidsSet       = bits[66];
                this.fCopyLang        = bits[67];
                this.fPersonalCompose = bits[68];
                this.fPersonalReply   = bits[69];
                this.fPersonal        = bits[70];
                this.fNoHtmlExport    = bits[71];
                this.fSemiHidden      = bits[72];
                this.fLocked          = bits[73];
                this.fInternalUse     = bits[74];
            }
            if (cbStdBase >= 12)
            {
                //istdLink
                BitArray istdLinkBits = Utils.BitArrayCopy(bits, 80, 12);
                this.istdLink = (UInt32)Utils.BitArrayToUInt32(istdLinkBits);
                //fHasOriginalStyle
                this.fHasOriginalStyle = bits[92];
            }
            if (cbStdBase >= 16)
            {
                //rsid
                BitArray rsidBits = Utils.BitArrayCopy(bits, 96, 32);
                this.rsid = Utils.BitArrayToUInt32(rsidBits);
            }

            //parsing the variable part

            //xstz
            byte characterCount = bytes[cbStdBase];

            //characters are zero-terminated, so 1 char has 2 bytes:
            byte[] name = new byte[characterCount * 2];
            Array.Copy(bytes, cbStdBase + 2, name, 0, name.Length);
            //remove zero-termination
            this.xstzName = Encoding.Unicode.GetString(name);

            //parse the UPX structs
            int upxOffset = cbStdBase + 1 + (characterCount * 2) + 2;

            for (int i = 0; i < this.cupx; i++)
            {
                //find the next even byte border
                if (upxOffset % 2 != 0)
                {
                    upxOffset++;
                }

                //get the count of bytes for UPX
                UInt16 cbUPX = System.BitConverter.ToUInt16(bytes, upxOffset);

                if (cbUPX > 0)
                {
                    //copy the bytes
                    byte[] upxBytes = new byte[cbUPX];
                    Array.Copy(bytes, upxOffset + 2, upxBytes, 0, upxBytes.Length);

                    if (this.stk == StyleKind.table)
                    {
                        //first upx is TAPX; second PAPX, third CHPX
                        switch (i)
                        {
                        case 0:
                            this.tapx = new TablePropertyExceptions(upxBytes);
                            break;

                        case 1:
                            this.papx = new ParagraphPropertyExceptions(upxBytes, dataStream);
                            break;

                        case 2:
                            this.chpx = new CharacterPropertyExceptions(upxBytes);
                            break;
                        }
                    }
                    else if (this.stk == StyleKind.paragraph)
                    {
                        //first upx is PAPX, second CHPX
                        switch (i)
                        {
                        case 0:
                            this.papx = new ParagraphPropertyExceptions(upxBytes, dataStream);
                            break;

                        case 1:
                            this.chpx = new CharacterPropertyExceptions(upxBytes);
                            break;
                        }
                    }
                    else if (this.stk == StyleKind.list)
                    {
                        //list styles have only one PAPX
                        switch (i)
                        {
                        case 0: this.papx = new ParagraphPropertyExceptions(upxBytes, dataStream); break;
                        }
                    }
                    else if (this.stk == StyleKind.character)
                    {
                        //character styles have only one CHPX
                        switch (i)
                        {
                        case 0: this.chpx = new CharacterPropertyExceptions(upxBytes); break;
                        }
                    }
                }

                //increase the offset for the next run
                upxOffset += (2 + cbUPX);
            }
        }