From 48d166276d86b74f32fda36e9db157812cc6f011 Mon Sep 17 00:00:00 2001 From: Eliot Jones Date: Fri, 28 Feb 2020 11:44:13 +0000 Subject: [PATCH] remove islenientparsing from contentstreamprocessor --- .../Graphics/ContentStreamProcessor.cs | 23 +++++-------------- src/UglyToad.PdfPig/Parser/PageFactory.cs | 9 ++++---- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs b/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs index ecb75641..56803231 100644 --- a/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs +++ b/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs @@ -43,7 +43,6 @@ private readonly IResourceStore resourceStore; private readonly UserSpaceUnit userSpaceUnit; private readonly PageRotationDegrees rotation; - private readonly bool isLenientParsing; private readonly IPdfTokenScanner pdfScanner; private readonly IPageContentParser pageContentParser; private readonly IFilterProvider filterProvider; @@ -82,7 +81,6 @@ }; public ContentStreamProcessor(PdfRectangle cropBox, IResourceStore resourceStore, UserSpaceUnit userSpaceUnit, PageRotationDegrees rotation, - bool isLenientParsing, IPdfTokenScanner pdfScanner, IPageContentParser pageContentParser, IFilterProvider filterProvider, @@ -91,7 +89,6 @@ this.resourceStore = resourceStore; this.userSpaceUnit = userSpaceUnit; this.rotation = rotation; - this.isLenientParsing = isLenientParsing; this.pdfScanner = pdfScanner ?? throw new ArgumentNullException(nameof(pdfScanner)); this.pageContentParser = pageContentParser ?? throw new ArgumentNullException(nameof(pageContentParser)); this.filterProvider = filterProvider ?? throw new ArgumentNullException(nameof(filterProvider)); @@ -490,9 +487,9 @@ 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(); @@ -502,12 +499,8 @@ { if (inlineImageBuilder == null) { - if (isLenientParsing) - { - return; - } - - throw new PdfDocumentFormatException("Begin inline image data (ID) command encountered without a corresponding begin inline image (BI) command."); + log?.Error("Begin inline image data (ID) command encountered without a corresponding begin inline image (BI) command."); + return; } inlineImageBuilder.Properties = properties; @@ -517,12 +510,8 @@ { if (inlineImageBuilder == null) { - if (isLenientParsing) - { - return; - } - - throw new PdfDocumentFormatException("End inline image (EI) command encountered without a corresponding begin inline image (BI) command."); + log?.Error("End inline image (EI) command encountered without a corresponding begin inline image (BI) command."); + return; } inlineImageBuilder.Bytes = bytes; diff --git a/src/UglyToad.PdfPig/Parser/PageFactory.cs b/src/UglyToad.PdfPig/Parser/PageFactory.cs index 02d55d07..22b839c0 100644 --- a/src/UglyToad.PdfPig/Parser/PageFactory.cs +++ b/src/UglyToad.PdfPig/Parser/PageFactory.cs @@ -109,7 +109,7 @@ } } - content = GetContent(number, bytes, cropBox, userSpaceUnit, rotation, isLenientParsing); + content = GetContent(number, bytes, cropBox, userSpaceUnit, rotation); } else { @@ -122,7 +122,7 @@ 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, @@ -138,13 +138,12 @@ } private PageContent GetContent(int pageNumber, IReadOnlyList contentBytes, CropBox cropBox, UserSpaceUnit userSpaceUnit, - PageRotationDegrees rotation, - bool isLenientParsing) + PageRotationDegrees rotation) { var operations = pageContentParser.Parse(pageNumber, new ByteArrayInputBytes(contentBytes), log); - var context = new ContentStreamProcessor(cropBox.Bounds, resourceStore, userSpaceUnit, rotation, isLenientParsing, pdfScanner, + var context = new ContentStreamProcessor(cropBox.Bounds, resourceStore, userSpaceUnit, rotation, pdfScanner, pageContentParser, filterProvider, log);