예제 #1
0
        private InlineImage ParseInlineImage()
        {
            /*
             * NOTE: Inline images use a peculiar syntax that's an exception to the usual rule
             * that the data in a content stream is interpreted according to the standard PDF syntax
             * for objects.
             */
            InlineImageHeader header;
            {
                List <PdfDirectObject> operands = new List <PdfDirectObject>();
                // Parsing the image entries...
                while (MoveNext() && TokenType != TokenTypeEnum.Keyword) // Not keyword (i.e. end at image data beginning (ID operator)).
                {
                    operands.Add((PdfDirectObject)ParsePdfObject());
                }
                header = new InlineImageHeader(operands);
            }

            InlineImageBody body;

            {
                // [FIX:51,74] Wrong 'EI' token handling on inline image parsing.
                bytes::IInputStream stream = Stream;
                stream.ReadByte(); // Should be the whitespace following the 'ID' token.
                bytes::Buffer data = new bytes::Buffer();
                while (true)
                {
                    int curByte = stream.ReadByte();
                    if (((char)curByte == 'E' && (char)stream.PeekByte() == 'I'))
                    {
                        stream.ReadByte();
                        break;
                    }
                    data.Append((byte)curByte);
                }
                body = new InlineImageBody(data);
            }

            return(new InlineImage(header, body));
        }