mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-12-20 04:00:03 +08:00
Refactor XObjectFactory
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
namespace UglyToad.PdfPig.XObjects
|
namespace UglyToad.PdfPig.XObjects
|
||||||
{
|
{
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Content;
|
using Content;
|
||||||
using Core;
|
using Core;
|
||||||
@@ -21,7 +20,8 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Read the XObject image.
|
/// Read the XObject image.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static XObjectImage ReadImage(XObjectContentRecord xObject, IPdfTokenScanner pdfScanner,
|
public static XObjectImage ReadImage(XObjectContentRecord xObject,
|
||||||
|
IPdfTokenScanner pdfScanner,
|
||||||
ILookupFilterProvider filterProvider,
|
ILookupFilterProvider filterProvider,
|
||||||
IResourceStore resourceStore)
|
IResourceStore resourceStore)
|
||||||
{
|
{
|
||||||
@@ -42,11 +42,14 @@
|
|||||||
var width = dictionary.Get<NumericToken>(NameToken.Width, pdfScanner).Int;
|
var width = dictionary.Get<NumericToken>(NameToken.Width, pdfScanner).Int;
|
||||||
var height = dictionary.Get<NumericToken>(NameToken.Height, pdfScanner).Int;
|
var height = dictionary.Get<NumericToken>(NameToken.Height, pdfScanner).Int;
|
||||||
|
|
||||||
var isImageMask = dictionary.TryGet(NameToken.ImageMask, pdfScanner, out BooleanToken? isMaskToken)
|
bool isImageMask = false;
|
||||||
&& isMaskToken.Data;
|
if (dictionary.TryGet(NameToken.ImageMask, pdfScanner, out BooleanToken? isMaskToken))
|
||||||
|
{
|
||||||
|
dictionary = dictionary.With(NameToken.ImageMask, isMaskToken);
|
||||||
|
isImageMask = isMaskToken.Data;
|
||||||
|
}
|
||||||
|
|
||||||
var isJpxDecode = dictionary.TryGet(NameToken.Filter, out var token)
|
var isJpxDecode = dictionary.TryGet(NameToken.Filter, pdfScanner, out NameToken filterName)
|
||||||
&& token is NameToken filterName
|
|
||||||
&& filterName.Equals(NameToken.JpxDecode);
|
&& filterName.Equals(NameToken.JpxDecode);
|
||||||
|
|
||||||
int bitsPerComponent = 0;
|
int bitsPerComponent = 0;
|
||||||
@@ -65,7 +68,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
var intent = xObject.DefaultRenderingIntent;
|
var intent = xObject.DefaultRenderingIntent;
|
||||||
if (dictionary.TryGet(NameToken.Intent, out NameToken renderingIntentToken))
|
if (dictionary.TryGet(NameToken.Intent, pdfScanner, out NameToken renderingIntentToken))
|
||||||
{
|
{
|
||||||
intent = renderingIntentToken.Data.ToRenderingIntent();
|
intent = renderingIntentToken.Data.ToRenderingIntent();
|
||||||
}
|
}
|
||||||
@@ -73,35 +76,26 @@
|
|||||||
var interpolate = dictionary.TryGet(NameToken.Interpolate, pdfScanner, out BooleanToken? interpolateToken)
|
var interpolate = dictionary.TryGet(NameToken.Interpolate, pdfScanner, out BooleanToken? interpolateToken)
|
||||||
&& interpolateToken.Data;
|
&& interpolateToken.Data;
|
||||||
|
|
||||||
DictionaryToken? filterDictionary = xObject.Stream.StreamDictionary;
|
if (dictionary.TryGet(NameToken.Filter, out var filterToken) && filterToken is IndirectReferenceToken)
|
||||||
if (xObject.Stream.StreamDictionary.TryGet(NameToken.Filter, out var filterToken)
|
|
||||||
&& filterToken is IndirectReferenceToken)
|
|
||||||
{
|
{
|
||||||
if (filterDictionary.TryGet(NameToken.Filter, pdfScanner, out ArrayToken? filterArray))
|
if (dictionary.TryGet(NameToken.Filter, pdfScanner, out ArrayToken? filterArray))
|
||||||
{
|
{
|
||||||
filterDictionary = filterDictionary.With(NameToken.Filter, filterArray);
|
dictionary = dictionary.With(NameToken.Filter, filterArray);
|
||||||
}
|
}
|
||||||
else if (filterDictionary.TryGet(NameToken.Filter, pdfScanner, out NameToken? filterNameToken))
|
else if (dictionary.TryGet(NameToken.Filter, pdfScanner, out NameToken? filterNameToken))
|
||||||
{
|
{
|
||||||
filterDictionary = filterDictionary.With(NameToken.Filter, filterNameToken);
|
dictionary = dictionary.With(NameToken.Filter, filterNameToken);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
filterDictionary = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var supportsFilters = filterDictionary != null;
|
var supportsFilters = true;
|
||||||
if (filterDictionary != null)
|
var filters = filterProvider.GetFilters(dictionary, pdfScanner);
|
||||||
|
foreach (var filter in filters)
|
||||||
{
|
{
|
||||||
var filters = filterProvider.GetFilters(filterDictionary, pdfScanner);
|
if (!filter.IsSupported)
|
||||||
foreach (var filter in filters)
|
|
||||||
{
|
{
|
||||||
if (!filter.IsSupported)
|
supportsFilters = false;
|
||||||
{
|
break;
|
||||||
supportsFilters = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,7 +103,19 @@
|
|||||||
if (decodeParams is IndirectReferenceToken refToken)
|
if (decodeParams is IndirectReferenceToken refToken)
|
||||||
{
|
{
|
||||||
dictionary = dictionary.With(NameToken.DecodeParms, pdfScanner.Get(refToken.Data).Data);
|
dictionary = dictionary.With(NameToken.DecodeParms, pdfScanner.Get(refToken.Data).Data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var jbig2GlobalsParams = dictionary.GetObjectOrDefault(NameToken.Jbig2Globals);
|
||||||
|
if (jbig2GlobalsParams is IndirectReferenceToken jbig2RefToken)
|
||||||
|
{
|
||||||
|
dictionary = dictionary.With(NameToken.Jbig2Globals, pdfScanner.Get(jbig2RefToken.Data).Data);
|
||||||
|
}
|
||||||
|
|
||||||
|
var imParams = dictionary.GetObjectOrDefault(NameToken.Im);
|
||||||
|
if (imParams is IndirectReferenceToken imRefToken)
|
||||||
|
{
|
||||||
|
dictionary = dictionary.With(NameToken.Im, pdfScanner.Get(imRefToken.Data).Data);
|
||||||
|
}
|
||||||
|
|
||||||
var streamToken = new StreamToken(dictionary, xObject.Stream.Data);
|
var streamToken = new StreamToken(dictionary, xObject.Stream.Data);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user