remove islenientparsing from contentstreamprocessor

This commit is contained in:
Eliot Jones
2020-02-28 11:44:13 +00:00
parent 6fdaf054cb
commit 48d166276d
2 changed files with 10 additions and 22 deletions

View File

@@ -43,7 +43,6 @@
private readonly IResourceStore resourceStore; private readonly IResourceStore resourceStore;
private readonly UserSpaceUnit userSpaceUnit; private readonly UserSpaceUnit userSpaceUnit;
private readonly PageRotationDegrees rotation; private readonly PageRotationDegrees rotation;
private readonly bool isLenientParsing;
private readonly IPdfTokenScanner pdfScanner; private readonly IPdfTokenScanner pdfScanner;
private readonly IPageContentParser pageContentParser; private readonly IPageContentParser pageContentParser;
private readonly IFilterProvider filterProvider; private readonly IFilterProvider filterProvider;
@@ -82,7 +81,6 @@
}; };
public ContentStreamProcessor(PdfRectangle cropBox, IResourceStore resourceStore, UserSpaceUnit userSpaceUnit, PageRotationDegrees rotation, public ContentStreamProcessor(PdfRectangle cropBox, IResourceStore resourceStore, UserSpaceUnit userSpaceUnit, PageRotationDegrees rotation,
bool isLenientParsing,
IPdfTokenScanner pdfScanner, IPdfTokenScanner pdfScanner,
IPageContentParser pageContentParser, IPageContentParser pageContentParser,
IFilterProvider filterProvider, IFilterProvider filterProvider,
@@ -91,7 +89,6 @@
this.resourceStore = resourceStore; this.resourceStore = resourceStore;
this.userSpaceUnit = userSpaceUnit; this.userSpaceUnit = userSpaceUnit;
this.rotation = rotation; this.rotation = rotation;
this.isLenientParsing = isLenientParsing;
this.pdfScanner = pdfScanner ?? throw new ArgumentNullException(nameof(pdfScanner)); this.pdfScanner = pdfScanner ?? throw new ArgumentNullException(nameof(pdfScanner));
this.pageContentParser = pageContentParser ?? throw new ArgumentNullException(nameof(pageContentParser)); this.pageContentParser = pageContentParser ?? throw new ArgumentNullException(nameof(pageContentParser));
this.filterProvider = filterProvider ?? throw new ArgumentNullException(nameof(filterProvider)); this.filterProvider = filterProvider ?? throw new ArgumentNullException(nameof(filterProvider));
@@ -490,9 +487,9 @@
public void BeginInlineImage() public void BeginInlineImage()
{ {
if (inlineImageBuilder != null && !isLenientParsing) if (inlineImageBuilder != null)
{ {
throw new PdfDocumentFormatException("Begin inline image (BI) command encountered while another inline image was active."); log?.Error("Begin inline image (BI) command encountered while another inline image was active.");
} }
inlineImageBuilder = new InlineImageBuilder(); inlineImageBuilder = new InlineImageBuilder();
@@ -502,12 +499,8 @@
{ {
if (inlineImageBuilder == null) if (inlineImageBuilder == null)
{ {
if (isLenientParsing) log?.Error("Begin inline image data (ID) command encountered without a corresponding begin inline image (BI) command.");
{ return;
return;
}
throw new PdfDocumentFormatException("Begin inline image data (ID) command encountered without a corresponding begin inline image (BI) command.");
} }
inlineImageBuilder.Properties = properties; inlineImageBuilder.Properties = properties;
@@ -517,12 +510,8 @@
{ {
if (inlineImageBuilder == null) if (inlineImageBuilder == null)
{ {
if (isLenientParsing) log?.Error("End inline image (EI) command encountered without a corresponding begin inline image (BI) command.");
{ return;
return;
}
throw new PdfDocumentFormatException("End inline image (EI) command encountered without a corresponding begin inline image (BI) command.");
} }
inlineImageBuilder.Bytes = bytes; inlineImageBuilder.Bytes = bytes;

View File

@@ -109,7 +109,7 @@
} }
} }
content = GetContent(number, bytes, cropBox, userSpaceUnit, rotation, isLenientParsing); content = GetContent(number, bytes, cropBox, userSpaceUnit, rotation);
} }
else else
{ {
@@ -122,7 +122,7 @@
var bytes = contentStream.Decode(filterProvider); var bytes = contentStream.Decode(filterProvider);
content = GetContent(number, bytes, cropBox, userSpaceUnit, rotation, isLenientParsing); content = GetContent(number, bytes, cropBox, userSpaceUnit, rotation);
} }
var page = new Page(number, dictionary, mediaBox, cropBox, rotation, content, var page = new Page(number, dictionary, mediaBox, cropBox, rotation, content,
@@ -138,13 +138,12 @@
} }
private PageContent GetContent(int pageNumber, IReadOnlyList<byte> contentBytes, CropBox cropBox, UserSpaceUnit userSpaceUnit, private PageContent GetContent(int pageNumber, IReadOnlyList<byte> contentBytes, CropBox cropBox, UserSpaceUnit userSpaceUnit,
PageRotationDegrees rotation, PageRotationDegrees rotation)
bool isLenientParsing)
{ {
var operations = pageContentParser.Parse(pageNumber, new ByteArrayInputBytes(contentBytes), var operations = pageContentParser.Parse(pageNumber, new ByteArrayInputBytes(contentBytes),
log); log);
var context = new ContentStreamProcessor(cropBox.Bounds, resourceStore, userSpaceUnit, rotation, isLenientParsing, pdfScanner, var context = new ContentStreamProcessor(cropBox.Bounds, resourceStore, userSpaceUnit, rotation, pdfScanner,
pageContentParser, pageContentParser,
filterProvider, filterProvider,
log); log);