pdfxrefsection.cs

来自「PDF文件格式解析库源代码」· CS 代码 · 共 53 行

CS
53
字号
using System;
using System.Collections.Generic;
using System.Text;

namespace AnotherPDFLib
{
    public class PdfXrefSection
    {
        /// <summary>
        /// Each cross-reference subsection contains entries for a contiguous range of object numbers.
        /// </summary>
        public List<PdfXrefEntry> Entries;
        public UInt32 StartNumber;

        public PdfXrefSection(UInt32 startObjectNumber)
        {
            Entries = new List<PdfXrefEntry>();
            StartNumber = startObjectNumber;
        }

        public void Output(PdfWriter writer)
        {
            writer.WriteLine(StartNumber + " " + Entries.Count);
            foreach (PdfXrefEntry entry in Entries)
            {
                entry.Output(writer);
            }
        }

        public bool Contains(uint id, ushort gen)
        {
            if (id >= StartNumber && id < StartNumber + Entries.Count)
            {
                PdfXrefEntry entry = GetXrefEntry(id);
                if (entry is PdfXrefEntryNoraml || entry is PdfXrefEntryFree)
                {
                    return entry.SecondComponent == gen;
                }
                else if (entry is PdfXrefEntryCompressed)
                {
                    return gen == 0;
                }
            }
            return false;
        }

        public PdfXrefEntry GetXrefEntry(uint id)
        {
            return Entries[(int)(id - StartNumber)];
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?