public PDFXRefTableEntry this[PDFObjectRef oref]
 {
     get
     {
         for (int i = this._sections.Count - 1; i >= 0; i--)
         {
             PDFXRefTableSection section = this._sections[i];
             if (section.Start <= oref.Number && section.Start + section.Count > oref.Number)
             {
                 PDFXRefTableEntry entry = section[oref];
                 if (null != entry)
                 {
                     return(entry);
                 }
             }
         }
         if (null != this.Previous)
         {
             return(this.Previous[oref]);
         }
         else
         {
             return(null);
         }
     }
 }
        public int Add(IIndirectObject obj)
        {
            int index = this._start + _entries.Count;

            PDFXRefTableEntry entry = new PDFXRefTableEntry(index, obj.Generation, obj.Deleted, obj);

            this._entries.Add(entry);
            obj.Number     = index;
            obj.Generation = this.Generation;
            obj.Offset     = -1;

            return(index);
        }
        public PDFXRefTableEntry this[PDFObjectRef oref]
        {
            get
            {
                PDFXRefTableEntry entry = this[oref.Number - this.Start];

                //check the generations match
                if (null != entry && entry.Generation != oref.Generation)
                {
                    entry = null;
                }

                return(entry);
            }
        }
        internal static PDFXRefTableSection Parse(string value, int offset, out int end)
        {
            if (!char.IsDigit(value, offset))
            {
                throw new PDFNativeParserException(CommonErrors.XRefTableSectionMustBe2Integers);
            }

            StringBuilder buffer = new StringBuilder();
            int           index;
            int           count;

            do
            {
                buffer.Append(value[offset++]);
            }while (char.IsDigit(value, offset));

            index = int.Parse(buffer.ToString());
            buffer.Clear();

            offset++; // past the space

            do
            {
                buffer.Append(value[offset++]);
            }while (char.IsDigit(value, offset));

            count = int.Parse(buffer.ToString());
            buffer.Clear();

            while (char.IsDigit(value, offset) == false)
            {
                offset++;
            }

            PDFXRefTableSection section = new PDFXRefTableSection(index, 0);

            for (int i = 0; i < count; i++)
            {
                PDFXRefTableEntry entry = PDFXRefTableEntry.Parse(index + i, value, offset, out end);
                section._entries.Add(entry);
                offset = end;
            }

            end = offset;
            return(section);
        }
示例#5
0
        //
        // public methods
        //

        #region public IIndirectObject GetIndirectObject(PDFObjectRef oref)

        /// <summary>
        /// Reads and returns the object data returned based on the provided reference
        /// </summary>
        /// <param name="oref"></param>
        /// <returns></returns>
        public override IParsedIndirectObject GetObject(PDFObjectRef oref)
        {
            PDFXRefTableEntry entry = this.XRefTable[oref];

            if (null != entry)
            {
                if (entry.Free == false)
                {
                    if (null == entry.Reference)
                    {
                        this.Searcher.Position = entry.Offset;
                        entry.Reference        = PDFFileIndirectObject.Parse(this.Searcher, oref.Number, oref.Generation);
                    }
                    return((IParsedIndirectObject)entry.Reference);
                }
            }
            return(null);
        }
        internal static PDFXRefTableEntry Parse(int index, string value, int offset, out int end)
        {
            string byteOffset = value.Substring(offset, XRefOffsetLength);
            string genValue   = value.Substring(offset + XRefOffsetLength + 1, XRefGenLength);
            string stateValue = value.Substring(offset + XRefOffsetLength + 1 + XRefGenLength + 1, XRefStateLength);

            int  ibyteOffset;
            int  igenValue;
            bool free;

            if (!int.TryParse(byteOffset, out ibyteOffset))
            {
                throw new PDFNativeParserException(CommonErrors.XRefTableEntryMustBeInCorrectFormat);
            }
            if (!int.TryParse(genValue, out igenValue))
            {
                throw new PDFNativeParserException(CommonErrors.XRefTableEntryMustBeInCorrectFormat);
            }

            if (stateValue == IsUsed)
            {
                free = false;
            }
            else if (stateValue == IsFree)
            {
                free = true;
            }
            else
            {
                throw new PDFNativeParserException(CommonErrors.XRefTableEntryMustBeInCorrectFormat);
            }
            PDFXRefTableEntry entry = new PDFXRefTableEntry(index, igenValue, free, null);

            entry.Offset = ibyteOffset;

            end = offset + XRefEntryLength;
            return(entry);
        }