load images eagerly for marked content

when a marked content region contains an image we load it eagerly since we won't have access to the necessary classes at evaluation time. we also default image colorspace to the active graphics state colorspace if the dictionary doesn't contain a valid entry.
This commit is contained in:
Eliot Jones
2020-01-10 13:52:21 +00:00
parent 2a579afd4d
commit 17b7cf2f61
7 changed files with 51 additions and 44 deletions

View File

@@ -16,8 +16,7 @@
{
public static XObjectImage ReadImage(XObjectContentRecord xObject, IPdfTokenScanner pdfScanner,
IFilterProvider filterProvider,
IResourceStore resourceStore,
bool isLenientParsing)
IResourceStore resourceStore)
{
if (xObject == null)
{
@@ -87,25 +86,19 @@
{
colorSpace = colorSpaceResult;
}
else if (dictionary.TryGet(NameToken.ColorSpace, pdfScanner, out ArrayToken colorSpaceArrayToken))
else if (dictionary.TryGet(NameToken.ColorSpace, pdfScanner, out ArrayToken colorSpaceArrayToken)
&& colorSpaceArrayToken.Length > 0)
{
if (colorSpaceArrayToken.Length == 0)
{
throw new PdfDocumentFormatException($"Empty ColorSpace array defined for image XObject: {dictionary}.");
}
var first = colorSpaceArrayToken.Data[0];
if (!(first is NameToken firstColorSpaceName) || !TryMapColorSpace(firstColorSpaceName, resourceStore, out colorSpaceResult))
if ((first is NameToken firstColorSpaceName) && TryMapColorSpace(firstColorSpaceName, resourceStore, out colorSpaceResult))
{
throw new PdfDocumentFormatException($"Invalid ColorSpace array defined for image XObject: {colorSpaceArrayToken}.");
colorSpace = colorSpaceResult;
}
colorSpace = colorSpaceResult;
}
else if (!isJpxDecode)
{
throw new PdfDocumentFormatException($"No ColorSpace defined for image XObject: {dictionary}.");
colorSpace = xObject.DefaultColorSpace;
}
}