add is supported flag to filters and add missing doc comment

This commit is contained in:
Eliot Jones
2019-10-08 15:53:42 +01:00
parent 77f968b6ea
commit 81ab414c56
11 changed files with 76 additions and 1 deletions

View File

@@ -5,6 +5,7 @@
using System.IO;
using Tokens;
/// <inheritdoc />
/// <summary>
/// ASCII 85 (Base85) is a binary to text encoding using 5 ASCII characters per 4 bytes of data.
/// </summary>
@@ -24,6 +25,10 @@
85 * 85 * 85 *85
};
/// <inheritdoc />
public bool IsSupported { get; } = true;
/// <inheritdoc />
public byte[] Decode(IReadOnlyList<byte> input, DictionaryToken streamDictionary, int filterIndex)
{
var asciiBuffer = new byte[5];

View File

@@ -5,6 +5,10 @@
using System.IO;
using Tokens;
/// <inheritdoc />
/// <summary>
/// Encodes/decodes data using the ASCII hexadecimal encoding where each byte is represented by two ASCII characters.
/// </summary>
internal class AsciiHexDecodeFilter : IFilter
{
private static readonly short[] ReverseHex =
@@ -22,6 +26,10 @@
/* 100 */ 13, 14, 15
};
/// <inheritdoc />
public bool IsSupported { get; } = true;
/// <inheritdoc />
public byte[] Decode(IReadOnlyList<byte> input, DictionaryToken streamDictionary, int filterIndex)
{
var pair = new byte[2];

View File

@@ -6,6 +6,10 @@
internal class CcittFaxDecodeFilter : IFilter
{
/// <inheritdoc />
public bool IsSupported { get; } = false;
/// <inheritdoc />
public byte[] Decode(IReadOnlyList<byte> input, DictionaryToken streamDictionary, int filterIndex)
{
throw new NotSupportedException("The CCITT Fax Filter for image data is not currently supported. " +

View File

@@ -6,6 +6,10 @@
internal class DctDecodeFilter : IFilter
{
/// <inheritdoc />
public bool IsSupported { get; } = false;
/// <inheritdoc />
public byte[] Decode(IReadOnlyList<byte> input, DictionaryToken streamDictionary, int filterIndex)
{
throw new NotSupportedException("The DST (Discrete Cosine Transform) Filter indicates data is encoded in JPEG format. " +

View File

@@ -9,8 +9,12 @@
using Tokens;
using Util;
/// <inheritdoc />
/// <summary>
///
/// The Flate filter is based on the public-domain zlib/deflate compression method, a variable-length Lempel-Ziv
/// adaptive compression method cascaded with adaptive Huffman coding.
/// It is fully defined in Internet RFCs 1950, ZLIB Compressed Data Format Specification, and
/// 1951, DEFLATE Compressed Data Format Specification
/// </summary>
/// <remarks>
/// See section 3.3.3 of the spec (version 1.7) for details on the FlateDecode filter.
@@ -34,6 +38,10 @@
this.log = log;
}
/// <inheritdoc />
public bool IsSupported { get; } = true;
/// <inheritdoc />
public byte[] Decode(IReadOnlyList<byte> input, DictionaryToken streamDictionary, int filterIndex)
{
if (input == null)

View File

@@ -3,8 +3,24 @@
using System.Collections.Generic;
using Tokens;
/// <summary>
/// A filter is used in a PDF to encode/decode data either to compress it
/// or derive an ASCII representation of the data.
/// </summary>
internal interface IFilter
{
/// <summary>
/// Whether this library can decode information encoded using this filter.
/// </summary>
bool IsSupported { get; }
/// <summary>
/// Decodes data encoded using this filter type.
/// </summary>
/// <param name="input">The encoded bytes which were encoded using this filter.</param>
/// <param name="streamDictionary">The dictionary of the <see cref="StreamToken"/> (or other dictionary types, e.g. inline images) containing these bytes.</param>
/// <param name="filterIndex">The position of this filter in the pipeline used to encode data.</param>
/// <returns>The decoded bytes.</returns>
byte[] Decode(IReadOnlyList<byte> input, DictionaryToken streamDictionary, int filterIndex);
}
}

View File

@@ -6,6 +6,10 @@
internal class Jbig2DecodeFilter : IFilter
{
/// <inheritdoc />
public bool IsSupported { get; } = false;
/// <inheritdoc />
public byte[] Decode(IReadOnlyList<byte> input, DictionaryToken streamDictionary, int filterIndex)
{
throw new NotSupportedException("The JBIG2 Filter for monochrome image data is not currently supported. " +

View File

@@ -6,6 +6,10 @@
internal class JpxDecodeFilter : IFilter
{
/// <inheritdoc />
public bool IsSupported { get; } = false;
/// <inheritdoc />
public byte[] Decode(IReadOnlyList<byte> input, DictionaryToken streamDictionary, int filterIndex)
{
throw new NotSupportedException("The JPX Filter (JPEG2000) for image data is not currently supported. " +

View File

@@ -5,6 +5,11 @@
using Tokens;
using Util;
/// <inheritdoc />
/// <summary>
/// The LZW (Lempel-Ziv-Welch) filter is a variable-length, adaptive compression method
/// that has been adopted as one of the standard compression methods in the Tag Image File Format (TIFF) standard.
/// </summary>
internal class LzwFilter : IFilter
{
private const int DefaultColors = 1;
@@ -27,6 +32,10 @@
this.pngPredictor = pngPredictor ?? throw new ArgumentNullException(nameof(pngPredictor));
}
/// <inheritdoc />
public bool IsSupported { get; } = true;
/// <inheritdoc />
public byte[] Decode(IReadOnlyList<byte> input, DictionaryToken streamDictionary, int filterIndex)
{
var parameters = decodeParameterResolver.GetFilterParameters(streamDictionary, filterIndex);

View File

@@ -4,10 +4,19 @@
using System.IO;
using Tokens;
/// <inheritdoc />
/// <summary>
/// The Run Length filterencodes data in a simple byte-oriented format based on run length.
/// The encoded data is a sequence of runs, where each run consists of a length byte followed by 1 to 128 bytes of data.
/// </summary>
internal class RunLengthFilter : IFilter
{
private const byte EndOfDataLength = 128;
/// <inheritdoc />
public bool IsSupported { get; } = true;
/// <inheritdoc />
public byte[] Decode(IReadOnlyList<byte> input, DictionaryToken streamDictionary, int filterIndex)
{
using (var memoryStream = new MemoryStream())

View File

@@ -211,6 +211,10 @@ namespace UglyToad.PdfPig.Geometry
commands.Add(new Close());
}
/// <summary>
/// Gets a <see cref="PdfRectangle"/> which entirely contains the geometry of the defined path.
/// </summary>
/// <returns>For paths which don't define any geometry this returns <see langword="null"/>.</returns>
public PdfRectangle? GetBoundingRectangle()
{
if (commands.Count == 0)