mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-10-15 03:34:52 +08:00
move and rename the pdf stream object
This commit is contained in:
@@ -77,7 +77,7 @@
|
||||
var contentObject = dictionary.GetItemOrDefault(CosName.CONTENTS) as CosObject;
|
||||
if (contentObject != null)
|
||||
{
|
||||
var contentStream = pdfObjectParser.Parse(contentObject.ToIndirectReference(), reader, false) as RawCosStream;
|
||||
var contentStream = pdfObjectParser.Parse(contentObject.ToIndirectReference(), reader, false) as PdfRawStream;
|
||||
|
||||
if (contentStream == null)
|
||||
{
|
||||
|
@@ -1,14 +1,14 @@
|
||||
namespace UglyToad.Pdf.Cos
|
||||
namespace UglyToad.Pdf.ContentStream
|
||||
{
|
||||
using System;
|
||||
using ContentStream;
|
||||
using Cos;
|
||||
using Filters;
|
||||
|
||||
internal class RawCosStream : CosBase
|
||||
internal class PdfRawStream : CosBase
|
||||
{
|
||||
private static readonly object Lock = new object();
|
||||
|
||||
public readonly byte[] streamBytes;
|
||||
private readonly byte[] streamBytes;
|
||||
|
||||
private byte[] decodedBytes;
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
/// <summary>
|
||||
/// Combines the dictionary for the stream with the raw, encoded/filtered bytes.
|
||||
/// </summary>
|
||||
public RawCosStream(byte[] streamBytes, PdfDictionary streamDictionary)
|
||||
public PdfRawStream(byte[] streamBytes, PdfDictionary streamDictionary)
|
||||
{
|
||||
this.streamBytes = streamBytes;
|
||||
|
@@ -58,7 +58,7 @@
|
||||
{
|
||||
var toUnicodeValue = dictionary[CosName.TO_UNICODE];
|
||||
|
||||
var toUnicode = pdfObjectParser.Parse(((CosObject)toUnicodeValue).ToIndirectReference(), reader, isLenientParsing) as RawCosStream;
|
||||
var toUnicode = pdfObjectParser.Parse(((CosObject)toUnicodeValue).ToIndirectReference(), reader, isLenientParsing) as PdfRawStream;
|
||||
|
||||
var decodedUnicodeCMap = toUnicode?.Decode(filterProvider);
|
||||
|
||||
@@ -123,7 +123,7 @@
|
||||
|
||||
isCMapPredefined = true;
|
||||
}
|
||||
else if (value is RawCosStream stream)
|
||||
else if (value is PdfRawStream stream)
|
||||
{
|
||||
var decoded = stream.Decode(filterProvider);
|
||||
|
||||
|
@@ -90,7 +90,7 @@
|
||||
return;
|
||||
}
|
||||
|
||||
var fontFileStream = pdfObjectParser.Parse(descriptor.FontFile.ObjectKey, reader, isLenientParsing) as RawCosStream;
|
||||
var fontFileStream = pdfObjectParser.Parse(descriptor.FontFile.ObjectKey, reader, isLenientParsing) as PdfRawStream;
|
||||
|
||||
if (fontFileStream == null)
|
||||
{
|
||||
|
@@ -166,7 +166,7 @@
|
||||
{
|
||||
if (currentBase is PdfDictionary dictionary)
|
||||
{
|
||||
RawCosStream stream = streamParser.Parse(reader, dictionary, isLenientParsing);
|
||||
PdfRawStream stream = streamParser.Parse(reader, dictionary, isLenientParsing);
|
||||
|
||||
currentBase = stream;
|
||||
}
|
||||
@@ -201,7 +201,7 @@
|
||||
var baseStream = Parse(reader, streamObjectNumber, 0, objectPool, crossReferenceTable, bruteForceSearcher,
|
||||
isLenientParsing, true);
|
||||
|
||||
if (!(baseStream is RawCosStream stream))
|
||||
if (!(baseStream is PdfRawStream stream))
|
||||
{
|
||||
log.Warn($"Could not find a stream for the object number, defaults to returning CosNull: {streamObjectNumber}");
|
||||
|
||||
|
@@ -142,7 +142,7 @@
|
||||
{
|
||||
if (currentBase is PdfDictionary dictionary)
|
||||
{
|
||||
RawCosStream stream = streamParser.Parse(reader, dictionary, isLenientParsing);
|
||||
PdfRawStream stream = streamParser.Parse(reader, dictionary, isLenientParsing);
|
||||
|
||||
currentBase = stream;
|
||||
}
|
||||
@@ -176,7 +176,7 @@
|
||||
{
|
||||
var baseStream = Parse(new IndirectReference(streamObjectNumber, 0), reader, isLenientParsing, true);
|
||||
|
||||
if (!(baseStream is RawCosStream stream))
|
||||
if (!(baseStream is PdfRawStream stream))
|
||||
{
|
||||
log.Warn($"Could not find a stream for the object number, defaults to returning CosNull: {streamObjectNumber}");
|
||||
|
||||
|
@@ -2,6 +2,7 @@
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ContentStream;
|
||||
using ContentStream.TypedAccessors;
|
||||
using Cos;
|
||||
using Filters;
|
||||
@@ -22,7 +23,7 @@
|
||||
this.baseParser = baseParser;
|
||||
}
|
||||
|
||||
public IReadOnlyList<CosObject> Parse(RawCosStream stream, CosObjectPool pool)
|
||||
public IReadOnlyList<CosObject> Parse(PdfRawStream stream, CosObjectPool pool)
|
||||
{
|
||||
if (stream == null)
|
||||
{
|
||||
|
@@ -32,9 +32,9 @@
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
public RawCosStream Parse(IRandomAccessRead reader, PdfDictionary streamDictionary, bool isLenientParsing)
|
||||
public PdfRawStream Parse(IRandomAccessRead reader, PdfDictionary streamDictionary, bool isLenientParsing)
|
||||
{
|
||||
RawCosStream result;
|
||||
PdfRawStream result;
|
||||
|
||||
// read 'stream'; this was already tested in parseObjectsDynamically()
|
||||
ReadHelper.ReadExpectedString(reader, "stream");
|
||||
@@ -59,7 +59,7 @@
|
||||
ReadUntilEndStream(reader, writer);
|
||||
}
|
||||
|
||||
result = new RawCosStream(stream.ToArray(), streamDictionary);
|
||||
result = new PdfRawStream(stream.ToArray(), streamDictionary);
|
||||
}
|
||||
|
||||
String endStream = ReadHelper.ReadString(reader);
|
||||
|
@@ -2,6 +2,7 @@
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using ContentStream;
|
||||
using ContentStream.TypedAccessors;
|
||||
using Cos;
|
||||
using Filters;
|
||||
@@ -18,15 +19,15 @@
|
||||
/// <summary>
|
||||
/// Parses through the unfiltered stream and populates the xrefTable HashMap.
|
||||
/// </summary>
|
||||
public CrossReferenceTablePart Parse(long streamOffset, RawCosStream cosStream)
|
||||
public CrossReferenceTablePart Parse(long streamOffset, PdfRawStream stream)
|
||||
{
|
||||
var w = cosStream.Dictionary.GetDictionaryObject(CosName.W);
|
||||
var w = stream.Dictionary.GetDictionaryObject(CosName.W);
|
||||
if (!(w is COSArray format))
|
||||
{
|
||||
throw new IOException("/W array is missing in Xref stream");
|
||||
}
|
||||
|
||||
var objNums = GetObjectNumbers(cosStream);
|
||||
var objNums = GetObjectNumbers(stream);
|
||||
|
||||
/*
|
||||
* Calculating the size of the line in bytes
|
||||
@@ -36,7 +37,7 @@
|
||||
int w2 = format.getInt(2);
|
||||
int lineSize = w0 + w1 + w2;
|
||||
|
||||
var decoded = cosStream.Decode(filterProvider);
|
||||
var decoded = stream.Decode(filterProvider);
|
||||
|
||||
var lineCount = decoded.Length / lineSize;
|
||||
var lineNumber = 0;
|
||||
@@ -44,8 +45,8 @@
|
||||
var builder = new CrossReferenceTablePartBuilder
|
||||
{
|
||||
Offset = streamOffset,
|
||||
Previous = cosStream.Dictionary.GetLongOrDefault(CosName.PREV),
|
||||
Dictionary = cosStream.Dictionary,
|
||||
Previous = stream.Dictionary.GetLongOrDefault(CosName.PREV),
|
||||
Dictionary = stream.Dictionary,
|
||||
XRefType = CrossReferenceType.Stream
|
||||
};
|
||||
|
||||
@@ -141,16 +142,16 @@
|
||||
return builder.AsCrossReferenceTablePart();
|
||||
}
|
||||
|
||||
private static List<long> GetObjectNumbers(RawCosStream cosStream)
|
||||
private static List<long> GetObjectNumbers(PdfRawStream stream)
|
||||
{
|
||||
var indexArray = (COSArray) cosStream.Dictionary.GetDictionaryObject(CosName.INDEX);
|
||||
var indexArray = (COSArray) stream.Dictionary.GetDictionaryObject(CosName.INDEX);
|
||||
|
||||
// If Index doesn't exist, we will use the default values.
|
||||
if (indexArray == null)
|
||||
{
|
||||
indexArray = new COSArray();
|
||||
indexArray.add(CosInt.Zero);
|
||||
indexArray.add(cosStream.Dictionary.GetDictionaryObject(CosName.SIZE));
|
||||
indexArray.add(stream.Dictionary.GetDictionaryObject(CosName.SIZE));
|
||||
}
|
||||
|
||||
List<long> objNums = new List<long>();
|
||||
|
@@ -176,7 +176,7 @@
|
||||
|
||||
PdfDictionary dict = dictionaryParser.Parse(reader, baseParser, pool);
|
||||
|
||||
RawCosStream xrefStream = streamParser.Parse(reader, dict, isLenientParsing);
|
||||
PdfRawStream xrefStream = streamParser.Parse(reader, dict, isLenientParsing);
|
||||
CrossReferenceTablePart xrefTablePart = crossReferenceStreamParser.Parse(objByteOffset, xrefStream);
|
||||
|
||||
return xrefTablePart;
|
||||
|
Reference in New Issue
Block a user