private bool MovePreviousStream( ) { if (streamIndex == 0) { streamIndex--; stream = null; } if (streamIndex == -1) { return(false); } streamIndex--; /* NOTE: A content stream may be made up of multiple streams [PDF:1.6:3.6.2]. */ // Is the content stream just a single stream? if (contentStream is PdfStream) // Single stream. { stream = ((PdfStream)contentStream).Body; basePosition = 0; } else // Array of streams. { PdfArray streams = (PdfArray)contentStream; stream = ((PdfStream)((PdfReference)streams[streamIndex]).DataObject).Body; basePosition -= stream.Length; } return(true); }
internal OpenFontParser(bytes::IInputStream fontData) { FontData = fontData; FontData.ByteOrder = ByteOrderEnum.BigEndian; // Ensures that proper endianness is applied. Load(); }
/** * <summary>Creates a new embedded file inside the document.</summary> * <param name="context">Document context.</param> * <param name="stream">File stream to embed.</param> */ public static EmbeddedFile Get( Document context, bytes::IInputStream stream ) { return(new EmbeddedFile(context, stream)); }
/** <summary>Gets the character map extracted from the given data.</summary> <param name="stream">Character map data.</param> */ public static IDictionary<ByteArray,int> Get( bytes::IInputStream stream ) { CMapParser parser = new CMapParser(stream); return parser.Parse(); }
internal OpenFontParser( bytes::IInputStream fontData ) { FontData = fontData; FontData.ByteOrder = ByteOrderEnum.BigEndian; // Ensures that proper endianness is applied. Load(); }
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 EmbeddedFile(Document context, bytes::IInputStream stream) : base( context, new PdfStream( new PdfDictionary( new PdfName[] { PdfName.Type }, new PdfDirectObject[] { PdfName.EmbeddedFile } ), new bytes::Buffer(stream.ToByteArray()) ) ) { }
new public static CompositeFont Get(Document context, bytes::IInputStream fontData) { OpenFontParser parser = new OpenFontParser(fontData); switch (parser.OutlineFormat) { case OpenFontParser.OutlineFormatEnum.PostScript: return(new Type0Font(context, parser)); case OpenFontParser.OutlineFormatEnum.TrueType: return(new Type2Font(context, parser)); } throw new NotSupportedException("Unknown composite font format."); }
/** * <summary>Gets whether the given data represents a valid Open Font.</summary> */ public static bool IsOpenFont( bytes::IInputStream fontData ) { long position = fontData.Position; fontData.Position = 0; try { GetOutlineFormat(fontData.ReadInt()); } catch (NotSupportedException) { return(false); } finally { fontData.Position = position; } return(true); }
private bool MoveNextStream( ) { // Is the content stream just a single stream? /* * NOTE: A content stream may be made up of multiple streams [PDF:1.6:3.6.2]. */ if (contentStream is PdfStream) // Single stream. { if (streamIndex < 1) { streamIndex++; basePosition = (streamIndex == 0 ? 0 : basePosition + stream.Length); stream = (streamIndex < 1 ? ((PdfStream)contentStream).Body : null); } } else // Multiple streams. { PdfArray streams = (PdfArray)contentStream; if (streamIndex < streams.Count) { streamIndex++; basePosition = (streamIndex == 0 ? 0 : basePosition + stream.Length); stream = (streamIndex < streams.Count ? ((PdfStream)streams.Resolve(streamIndex)).Body : null); } } if (stream == null) { return(false); } stream.Position = 0; return(true); }
/** * <summary>Gets whether the given data represents a valid Open Font.</summary> */ public static bool IsOpenFont( bytes::IInputStream fontData ) { long position = fontData.Position; try { fontData.Position = 0; GetOutlineFormat(fontData.ReadInt()); // NOTE: An exception is expected to be thrown in case of wrong file format. return(true); } catch { return(false); } finally { fontData.Position = position; } }
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 )); }
/** * <summary>Gets whether the given data represents a valid Open Font.</summary> */ public static bool IsOpenFont(bytes::IInputStream fontData) { long position = fontData.Position; fontData.Seek(0); try { switch (fontData.ReadInt()) { case (0x00010000): // TrueType (standard/Windows). case (0x74727565): // TrueType (legacy/Apple). case (0x4F54544F): // CFF (Type 1). return(true); default: return(false); } } finally { fontData.Seek(position); } }
public CMapParser(bytes::IInputStream stream) : base(stream) { }
/** * <summary>Gets the character map extracted from the given data.</summary> * <param name="stream">Character map data.</param> */ public static CMap Get(bytes::IInputStream stream) { CMapParser parser = new CMapParser(stream); return(parser.Parse()); }
public CMapParser( bytes::IInputStream stream ) { this.stream = stream; }
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 )); }
internal ContentParser( bytes::IInputStream stream ) : base(stream) { }