Example #1
0
        private void LoadCharacterFormatting(Stream wordDocumentStream, PlcBteChpx plcfBteChpx)
        {
            List<CharacterFormatting> formattings = new List<CharacterFormatting>();
            for (int i = 0; i < plcfBteChpx.aPnBteChpx.Length; i++)
            {
                wordDocumentStream.Position = plcfBteChpx.aPnBteChpx[i].pn * 512;
                ChpxFkp papxFkp = BasicTypesReader.ReadChpxFkp(wordDocumentStream);
                for (int j = 0; j < papxFkp.rgb.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;

                    CharacterFormatting para = new CharacterFormatting(this,
                        (startFc - fc.Offset) / fc.BytesPerCharacter,
                        (endFc - startFc) / fc.BytesPerCharacter,
                        fc, papxFkp.rgb[j].Value);
                    formattings.Add(para);
                }
            }
            formattings.Sort(new Comparison<CharacterFormatting>(delegate(CharacterFormatting f1, CharacterFormatting f2)
            {
                return f1.Offset - f2.Offset;
            }));
            this.formattings = formattings.ToArray();
        }
        internal static PlcBteChpx ReadPlcBteChpx(Stream s, uint length)
        {
            int n = PlcBteChpx.GetLength(length);
            PlcBteChpx plcfBteChpx = new PlcBteChpx();
            plcfBteChpx.aFC = new uint[n + 1];
            for (int i = 0; i <= n; i++)
            {
                plcfBteChpx.aFC[i] = BitConverter.ToUInt32(ReadUtils.ReadExact(s, ReadUtils.DWordSize), 0);

            }
            plcfBteChpx.aPnBteChpx = new PnFkpChpx[n];
            for (int i = 0; i < n; i++)
            {
                PnFkpChpx item = new PnFkpChpx();
                item.pn = BitConverter.ToUInt32(ReadUtils.ReadExact(s, ReadUtils.DWordSize), 0);
                plcfBteChpx.aPnBteChpx[i] = item;
            }
            return plcfBteChpx;
        }