1
#region PDFsharp - A .NET library for processing PDF
4
// Stefan Lange (mailto:Stefan.Lange@pdfsharp.com)
6
// Copyright (c) 2005-2008 empira Software GmbH, Cologne (Germany)
8
// http://www.pdfsharp.com
9
// http://sourceforge.net/projects/pdfsharp
11
// Permission is hereby granted, free of charge, to any person obtaining a
12
// copy of this software and associated documentation files (the "Software"),
13
// to deal in the Software without restriction, including without limitation
14
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
15
// and/or sell copies of the Software, and to permit persons to whom the
16
// Software is furnished to do so, subject to the following conditions:
18
// The above copyright notice and this permission notice shall be included
19
// in all copies or substantial portions of the Software.
21
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27
// DEALINGS IN THE SOFTWARE.
31
using System.Diagnostics;
32
using PdfSharp.Internal;
33
using PdfSharp.Pdf.IO;
34
using PdfSharp.Pdf.Internal;
36
namespace PdfSharp.Pdf.Filters
39
/// Reserved for future extension.
41
public class FilterParms
47
/// Base class for all stream filters
49
public abstract class Filter
52
/// When implemented in a derived class encodes the specified data.
54
public abstract byte[] Encode(byte[] data);
57
/// Encodes a raw string.
59
public virtual byte[] Encode(string rawString)
61
byte[] bytes = PdfEncoders.RawEncoding.GetBytes(rawString);
62
bytes = Encode(bytes);
67
/// When implemented in a derived class decodes the specified data.
69
public abstract byte[] Decode(byte[] data, FilterParms parms);
72
/// Decodes the specified data.
74
public byte[] Decode(byte[] data)
76
return Decode(data, null);
80
/// Decodes to a raw string.
82
public virtual string DecodeToString(byte[] data, FilterParms parms)
84
byte[] bytes = Decode(data, parms);
85
string text = PdfEncoders.RawEncoding.GetString(bytes);
90
/// Decodes to a raw string.
92
public string DecodeToString(byte[] data)
94
return DecodeToString(data, null);
98
/// Removes all white spaces from the data. The function assumes that the bytes are characters.
100
protected byte[] RemoveWhiteSpace(byte[] data)
102
int count = data.Length;
104
for (int i = 0; i < count; i++, j++)
108
case (byte)Chars.NUL: // 0 Null
109
case (byte)Chars.HT: // 9 Tab
110
case (byte)Chars.LF: // 10 Line feed
111
case (byte)Chars.FF: // 12 Form feed
112
case (byte)Chars.CR: // 13 Carriage return
113
case (byte)Chars.SP: // 32 Space
126
for (int idx = 0; idx < j; idx++)
127
data[idx] = temp[idx];