Esempio n. 1
0
        /**
         * <summary>Parses the current PDF object [PDF:1.6:3.2].</summary>
         */
        public virtual PdfDataObject ParsePdfObject(
            )
        {
            switch (TokenType)
            {
            case TokenTypeEnum.Integer:
                return(PdfInteger.Get((int)Token));

            case TokenTypeEnum.Name:
                return(new PdfName((string)Token, true));

            case TokenTypeEnum.DictionaryBegin:
            {
                var dictionary = new PdfDictionary();
                dictionary.Updateable = false;
                while (true)
                {
                    // Key.
                    MoveNext();
                    if (TokenType == TokenTypeEnum.DictionaryEnd)
                    {
                        break;
                    }
                    var key = (PdfName)ParsePdfObject();
                    // Value.
                    MoveNext();
                    var value = (PdfDirectObject)ParsePdfObject();
                    // Add the current entry to the dictionary!
                    dictionary[key] = value;
                }

                dictionary.Updateable = true;
                return(dictionary);
            }

            case TokenTypeEnum.ArrayBegin:
            {
                var array = new PdfArray();
                array.Updateable = false;
                while (true)
                {
                    // Value.
                    MoveNext();
                    if (TokenType == TokenTypeEnum.ArrayEnd)
                    {
                        break;
                    }
                    // Add the current item to the array!
                    array.Add((PdfDirectObject)ParsePdfObject());
                }

                array.Updateable = true;
                return(array);
            }

            case TokenTypeEnum.Literal:
                if (Token is DateTime)
                {
                    return(PdfDate.Get((DateTime)Token));
                }
                else
                {
                    return(new PdfTextString(
                               Encoding.Pdf.Encode((string)Token)
                               ));
                }

            case TokenTypeEnum.Hex:
                return(new PdfTextString(
                           (string)Token,
                           PdfString.SerializationModeEnum.Hex
                           ));

            case TokenTypeEnum.Real:
                return(PdfReal.Get((double)Token));

            case TokenTypeEnum.Boolean:
                return(PdfBoolean.Get((bool)Token));

            case TokenTypeEnum.Null:
                return(null);

            default:
                throw new Exception("Unknown type: " + TokenType);
            }
        }