Exemplo n.º 1
0
        /// <summary>Reads a dictionary.</summary>
        /// <remarks>
        /// Reads a dictionary. The tokeniser must be positioned past the
        /// <c>"&lt;&lt;"</c>
        /// token.
        /// </remarks>
        /// <returns>the dictionary</returns>
        /// <exception cref="System.IO.IOException">on error</exception>
        public virtual CMapObject ReadDictionary()
        {
            IDictionary <String, CMapObject> dic = new Dictionary <String, CMapObject>();

            while (true)
            {
                if (!NextValidToken())
                {
                    throw new iText.IO.IOException("Unexpected end of file.");
                }
                if (tokeniser.GetTokenType() == PdfTokenizer.TokenType.EndDic)
                {
                    break;
                }
                if (tokeniser.GetTokenType() == PdfTokenizer.TokenType.Other && "def".Equals(tokeniser.GetStringValue()))
                {
                    continue;
                }
                if (tokeniser.GetTokenType() != PdfTokenizer.TokenType.Name)
                {
                    throw new iText.IO.IOException("Dictionary key {0} is not a name.").SetMessageParams(tokeniser.GetStringValue
                                                                                                             ());
                }
                String     name = tokeniser.GetStringValue();
                CMapObject obj  = ReadObject();
                if (obj.IsToken())
                {
                    if (obj.ToString().Equals(">>"))
                    {
                        tokeniser.ThrowError(iText.IO.IOException.UnexpectedGtGt);
                    }
                    if (obj.ToString().Equals("]"))
                    {
                        tokeniser.ThrowError(iText.IO.IOException.UnexpectedCloseBracket);
                    }
                }
                dic.Put(name, obj);
            }
            return(new CMapObject(CMapObject.DICTIONARY, dic));
        }
Exemplo n.º 2
0
        /// <summary>Reads an array.</summary>
        /// <remarks>Reads an array. The tokeniser must be positioned past the "[" token.</remarks>
        /// <returns>an array</returns>
        /// <exception cref="System.IO.IOException">on error</exception>
        public virtual CMapObject ReadArray()
        {
            IList <CMapObject> array = new List <CMapObject>();

            while (true)
            {
                CMapObject obj = ReadObject();
                if (obj.IsToken())
                {
                    if (obj.ToString().Equals("]"))
                    {
                        break;
                    }
                    if (obj.ToString().Equals(">>"))
                    {
                        tokeniser.ThrowError(iText.IO.IOException.UnexpectedGtGt);
                    }
                }
                array.Add(obj);
            }
            return(new CMapObject(CMapObject.ARRAY, array));
        }