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(ParsePdfObject()); } header = new InlineImageHeader(operands); } InlineImageBody body; { MoveNext(); bytes::Buffer data = new bytes::Buffer(); byte c1 = 0, c2 = 0; do { try { while (true) { c1 = (byte)stream.ReadByte(); c2 = (byte)stream.ReadByte(); if (c1 == 'E' && c2 == 'I') { break; } data.Append(c1); data.Append(c2); } break; } catch { /* NOTE: Current stream has finished. */ // Move to the next stream! MoveNextStream(); } } while(stream != null); body = new InlineImageBody(data); } return(new InlineImage( header, body )); }
public InlineImage( InlineImageHeader header, InlineImageBody body ) { objects.Add(header); objects.Add(body); }
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 curByte1 = stream.ReadByte(); if (curByte1 == -1) { break; } int curByte2 = stream.ReadByte(); if (curByte2 == -1) { break; } if (((char)curByte1 == 'E' && (char)curByte2 == 'I')) { break; } if (((char)curByte1 == ' ' && (char)curByte2 == 'E')) { break; } data.Append((byte)curByte1); data.Append((byte)curByte2); } body = new InlineImageBody(data); } return(new InlineImage(header, body)); }
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; { bytes::IInputStream stream = Stream; MoveNext(); bytes::Buffer data = new bytes::Buffer(); byte prevByte = 0; while (true) { byte curByte = (byte)stream.ReadByte(); if (prevByte == 'E' && curByte == 'I') { break; } data.Append(prevByte = curByte); } body = new InlineImageBody(data); } return(new InlineImage( header, body )); }
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; { bytes::IInputStream stream = Stream; MoveNext(); bytes::Buffer data = new bytes::Buffer(); while(true) { byte c1 = (byte)stream.ReadByte(); byte c2 = (byte)stream.ReadByte(); if(c1 == 'E' && c2 == 'I') break; data.Append(c1); data.Append(c2); } body = new InlineImageBody(data); } return new InlineImage( header, body ); }
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(); var endChunkBuffer = new sysIO::MemoryStream(3); int endChunkIndex = -1; while (true) { int curByte = stream.ReadByte(); if (curByte == -1) { throw new PostScriptParseException("No 'EI' token found to close inline image data stream."); } if (endChunkIndex == -1) { if (IsWhitespace(curByte)) { /* * NOTE: Whitespace characters may announce the beginning of the end image operator. */ endChunkBuffer.WriteByte((byte)curByte); endChunkIndex++; } else { data.Append((byte)curByte); } } else if (endChunkIndex == 0 && IsWhitespace(curByte)) { /* * NOTE: Only the last whitespace character may announce the beginning of the end image * operator. */ data.Append(endChunkBuffer.ToArray()); endChunkBuffer.SetLength(0); endChunkBuffer.WriteByte((byte)curByte); } else if ((endChunkIndex == 0 && curByte == 'E') || (endChunkIndex == 1 && curByte == 'I')) { /* * NOTE: End image operator characters. */ endChunkBuffer.WriteByte((byte)curByte); endChunkIndex++; } else if (endChunkIndex == 2 && IsWhitespace(curByte)) { /* * NOTE: The whitespace character after the end image operator completes the pattern. */ break; } else { if (endChunkIndex > -1) { data.Append(endChunkBuffer.ToArray()); endChunkBuffer.SetLength(0); endChunkIndex = -1; } data.Append((byte)curByte); } } body = new InlineImageBody(data); } return(new InlineImage( header, body )); }