Пример #1
0
        protected virtual IPDFToken ProcessKeyword(PDFKeyword token)
        {
            switch (token.Name)
            {
            case "true": return(new PDFBoolean {
                    Value = true
                });

            case "false": return(new PDFBoolean {
                    Value = false
                });

            case "null": return(new PDFNull());

            case "obj": return(new PDFToken(PDFTokenType.StartObject));

            case "xref": return(new PDFToken(PDFTokenType.Xref));

            case "startxref": return(new PDFToken(PDFTokenType.StartXref));

            case "endobj": return(PDFObject.Parse(this));

            case "trailer": return(PDFXref.Parse(this));

            case "n": return(PDFXrefEntry.Parse(this, PDFTokenType.XrefEntryInUse));

            case "f": return(PDFXrefEntry.Parse(this, PDFTokenType.XrefEntryFree));

            case "R": return(PDFObjRef.Parse(this));

            default: throw new InvalidDataException(String.Format("Unknown keyword '{0}'", token.Name));
            }
        }
Пример #2
0
        public static PDFXrefEntry Parse(Stack <IPDFToken> tokens, PDFTokenType type)
        {
            PDFXrefEntry entry = new PDFXrefEntry();

            entry.InUse      = type == PDFTokenType.XrefEntryInUse;
            entry.Generation = (int)tokens.Pop <PDFInteger>().Value;
            entry.Offset     = (long)tokens.Pop <PDFInteger>().Value;
            return(entry);
        }
Пример #3
0
        public static PDFXref Parse(Stack <IPDFToken> tokens)
        {
            PDFXref xref = new PDFXref {
                Entries = new List <PDFXrefEntry>()
            };

            while (tokens.Count != 0 && (tokens.Peek().TokenType == PDFTokenType.XrefEntry || tokens.Peek().TokenType == PDFTokenType.Integer))
            {
                Stack <PDFXrefEntry> entries = new Stack <PDFXrefEntry>();

                PDFXrefEntry entry = null;
                while (tokens.TryPop <PDFXrefEntry>(out entry))
                {
                    entries.Push(entry);
                }


                int count = (int)tokens.Pop <PDFInteger>().Value;
                int start = (int)tokens.Pop <PDFInteger>().Value;

                while (entries.Count != 0)
                {
                    PDFXrefEntry ent = entries.Pop();
                    ent.ID = start++;
                    xref.Entries.Add(ent);
                }

                IPDFToken token;
                if (tokens.TryPop(PDFTokenType.Xref, out token))
                {
                    return(xref);
                }
            }

            throw new InvalidDataException();
        }