Ejemplo n.º 1
0
        private void LoadParagraphs(Stream wordDocumentStream, Clx clx, PlcBtePapx plcfBtePapx)
        {
            List<Paragraph> paragraphs = new List<Paragraph>();
            for (int i = 0; i < plcfBtePapx.aPnBtePapx.Length; i++)
            {
                wordDocumentStream.Position = plcfBtePapx.aPnBtePapx[i].pn * 512;
                PapxFkp papxFkp = BasicTypesReader.ReadPapxFkp(wordDocumentStream);
                for (int j = 0; j < papxFkp.rgbx.Length; j++)
                {
                    int startFc = (int)papxFkp.rgfc[j];
                    int endFc = (int)papxFkp.rgfc[j + 1];
                    FileCharacterPosition fc = Array.Find(fileCharacterPositions, new Predicate<FileCharacterPosition>(delegate(FileCharacterPosition f)
                    {
                        return !(endFc <= f.Offset || f.Offset + f.BytesPerCharacter * f.Length < startFc);
                    }));
                    if (fc == null) continue; // invalid section

                    if (startFc < fc.Offset) startFc = fc.Offset;
                    if (endFc > fc.Offset + fc.BytesPerCharacter * fc.Length)
                        endFc = fc.Offset + fc.BytesPerCharacter * fc.Length;

                    Paragraph para = new Paragraph(this,
                        (startFc - fc.Offset) / fc.BytesPerCharacter,
                        (endFc - startFc) / fc.BytesPerCharacter,
                        fc, papxFkp.rgbx[j].Value);
                    paragraphs.Add(para);
                }
            }
            paragraphs.Sort(new Comparison<Paragraph>(delegate(Paragraph p1, Paragraph p2)
                {
                    return p1.Offset - p2.Offset;
                }));
            this.paragraphs = paragraphs.ToArray();
        }
Ejemplo n.º 2
0
        private Prl[] ExpandPrm(Prm prm, Clx clx)
        {
            if (prm.fComplex)
            {
                int index = prm.igrpprl;
                return clx.RgPrc[index].GrpPrl;
            }
            else if (prm.prm != 0x0000)
            {
                ushort sprm;
                if (!SinglePropertyModifiers.prm0Map.TryGetValue(prm.isprm, out sprm))
                    throw new WordFileReaderException("Invalid Prm: isprm");
                byte value = prm.val;

                Prl prl = new Prl();
                prl.sprm = new Sprm(sprm);
                prl.operand = new byte[] { value };
                return new Prl[] { prl };
            }
            else
                return new Prl[0];
        }
Ejemplo n.º 3
0
        private void LoadCharacters(Stream wordDocumentStream, Clx clx)
        {
            PlcPcd plcPcd = clx.Pcdt.PlcPcd;
            char[] text = new char[plcPcd.CPs[plcPcd.CPs.Length - 1]];
            FileCharacterPosition[] fileCharacters = new FileCharacterPosition[plcPcd.Pcds.Length];
            int position = 0;
            for (int i = 0; i < plcPcd.Pcds.Length; i++)
            {
                int length = (int)(plcPcd.CPs[i + 1] - plcPcd.CPs[i]);
                int offset = plcPcd.Pcds[i].fc.fc;

                bool compressed = plcPcd.Pcds[i].fc.fCompressed;
                if (compressed)
                {
                    wordDocumentStream.Position = offset / 2;
                    byte[] data = ReadUtils.ReadExact(wordDocumentStream, length);
                    FcCompressedMapping.GetChars(data, 0, length, text, position);
                }
                else
                {
                    wordDocumentStream.Position = offset;
                    byte[] data = ReadUtils.ReadExact(wordDocumentStream, length * 2);
                    Encoding.Unicode.GetChars(data, 0, length, text, position);
                }

                FileCharacterPosition fc = new FileCharacterPosition();
                fc.Offset = compressed ? offset / 2 : offset;
                fc.BytesPerCharacter = compressed ? 1 : 2;
                fc.Length = length;
                fc.CharacterIndex = position;
                fc.Prls = ExpandPrm(plcPcd.Pcds[i].prm, clx);

                fileCharacters[i] = fc;

                position += length;
            }
            Array.Sort(fileCharacters, new Comparison<FileCharacterPosition>(delegate(FileCharacterPosition fc1, FileCharacterPosition fc2)
            {
                return fc1.Offset - fc2.Offset;
            }));
            this.fileCharacterPositions = fileCharacters;
            this.characters = text;
        }
Ejemplo n.º 4
0
        internal static Clx ReadClx(Stream s, int length)
        {
            int position = 0;
            List<Prc> prcs = new List<Prc>();
            if (length < 1)
                throw new WordFileReaderException("Invalid Clx: length");
            byte clxt = ReadUtils.ReadByte(s);
            position++;
            while (clxt == Prc.DefaultClxt)
            {
                int read;
                prcs.Add(ReadPrcWithoutCltx(s, length - position, out read));
                position += read;

                if (position >= length)
                    throw new WordFileReaderException("Invalid Clx: length");
                clxt = ReadUtils.ReadByte(s);
                position++;
            }
            if (clxt != Pcdt.DefaultClxt)
                throw new WordFileReaderException("Invalid Pcdt: signature");
            Pcdt pcdt = ReadPcdtWithoutClxt(s, length - position);

            Clx clx = new Clx();
            clx.RgPrc = prcs.ToArray();
            clx.Pcdt = pcdt;
            return clx;
        }