Prefer is null to == null

ensures that an equals overload isn't use, and we don't compare structs
This commit is contained in:
Jason Nelson
2024-03-15 11:04:58 -07:00
committed by BobLd
parent d19e6ad510
commit 95f0459900
97 changed files with 234 additions and 238 deletions

View File

@@ -213,7 +213,7 @@
var fieldFlags = (uint) (fieldFlagsToken?.Long ?? 0);
AcroFieldBase result;
if (fieldType == null)
if (fieldType is null)
{
result = new AcroNonTerminalField(fieldDictionary, "Non-Terminal Field", fieldFlags, information, AcroFieldType.Unknown, children);
}
@@ -562,7 +562,7 @@
continue;
}
if (selectedOptionIndices == null)
if (selectedOptionIndices is null)
{
return true;
}

View File

@@ -50,7 +50,7 @@
{
string AppendIfNotNull(string val, string label, string result)
{
if (val == null)
if (val is null)
{
return result;
}

View File

@@ -53,7 +53,7 @@
/// <exception cref="ArgumentOutOfRangeException"></exception>
public StreamToken Get(string state)
{
if (appearanceStreamsByState == null)
if (appearanceStreamsByState is null)
{
throw new Exception("Cannot get appearance by state when this is a stateless appearance stream");
}

View File

@@ -23,7 +23,7 @@
/// </summary>
public QuadPointsQuadrilateral(IReadOnlyList<PdfPoint> points)
{
if (points == null)
if (points is null)
{
throw new ArgumentNullException(nameof(points));
}

View File

@@ -66,7 +66,7 @@
public TPage Create(int number, DictionaryToken dictionary, PageTreeMembers pageTreeMembers,
NamedDestinations namedDestinations)
{
if (dictionary == null)
if (dictionary is null)
{
throw new ArgumentNullException(nameof(dictionary));
}
@@ -131,7 +131,7 @@
var contentStream = DirectObjectFinder.Get<StreamToken>(obj, PdfScanner);
if (contentStream == null)
if (contentStream is null)
{
throw new InvalidOperationException($"Could not find the contents for object {obj}.");
}
@@ -150,7 +150,7 @@
{
var contentStream = DirectObjectFinder.Get<StreamToken>(contents, PdfScanner);
if (contentStream == null)
if (contentStream is null)
{
throw new InvalidOperationException("Failed to parse the content for the page: " + number);
}
@@ -181,7 +181,7 @@
{
IReadOnlyList<IGraphicsStateOperation> operations;
if (contentBytes == null || contentBytes.Count == 0)
if (contentBytes is null || contentBytes.Count == 0)
{
operations = Array.Empty<IGraphicsStateOperation>();
}
@@ -293,7 +293,7 @@
{
mediaBox = pageTreeMembers.MediaBox;
if (mediaBox == null)
if (mediaBox is null)
{
ParsingOptions.Logger.Error(
$"The MediaBox was the wrong missing for page {number}. Using US Letter.");

View File

@@ -124,7 +124,7 @@
private static void AppendPart(string name, string value, StringBuilder builder)
{
if (value == null)
if (value is null)
{
return;
}

View File

@@ -108,7 +108,7 @@
public bool TryGetBytes(out IReadOnlyList<byte> bytes)
{
bytes = null;
if (bytesFactory == null)
if (bytesFactory is null)
{
return false;
}

View File

@@ -122,7 +122,7 @@
private static string GetText(PageContent content)
{
if (content?.Letters == null)
if (content?.Letters is null)
{
return string.Empty;
}

View File

@@ -49,7 +49,7 @@
/// <summary>
/// Whether this node is the root node.
/// </summary>
public bool IsRoot => Parent == null;
public bool IsRoot => Parent is null;
/// <summary>
/// Create a new <see cref="PageTreeNode"/>.

View File

@@ -132,7 +132,7 @@
typeof(ParsingOptions)
});
if (constructor == null)
if (constructor is null)
{
throw new InvalidOperationException($"Could not find valid constructor for page factory of type '{typeof(TPageFactory)}'. " +
"The page factory should have a constructor with the following parameters: " +

View File

@@ -200,7 +200,7 @@
var fontObject = DirectObjectFinder.Get<DictionaryToken>(objectKey, scanner);
if (fontObject == null)
if (fontObject is null)
{
//This is a valid use case
continue;
@@ -269,7 +269,7 @@
{
namedToken = default(ResourceColorSpace);
if (name == null)
if (name is null)
{
throw new ArgumentNullException(nameof(name));
}
@@ -286,7 +286,7 @@
public ColorSpaceDetails GetColorSpaceDetails(NameToken name, DictionaryToken dictionary)
{
if (dictionary == null)
if (dictionary is null)
{
dictionary = new DictionaryToken(new Dictionary<NameToken, IToken>());
}

View File

@@ -42,7 +42,7 @@
/// <param name="letters">The letters contained in the word, in the correct order.</param>
public Word(IReadOnlyList<Letter> letters)
{
if (letters == null)
if (letters is null)
{
throw new ArgumentNullException(nameof(letters));
}

View File

@@ -44,7 +44,7 @@
TrailerDictionary trailer,
IReadOnlyList<CrossReferenceOffset> crossReferenceOffsets)
{
if (objectOffsets == null)
if (objectOffsets is null)
{
throw new ArgumentNullException(nameof(objectOffsets));
}

View File

@@ -20,7 +20,7 @@
public void Add(CrossReferenceTablePart part)
{
if (part == null)
if (part is null)
{
throw new ArgumentNullException(nameof(part));
}
@@ -38,7 +38,7 @@
var currentPart = parts.FirstOrDefault(x => x.Offset == firstCrossReferenceOffset);
if (currentPart == null)
if (currentPart is null)
{
// no XRef at given position
log.Warn($"Did not find an XRef object at the specified startxref position {firstCrossReferenceOffset}");
@@ -73,7 +73,7 @@
}
currentPart = parts.FirstOrDefault(x => x.Offset == prevBytePos || x.Offset == prevBytePos + offsetCorrection);
if (currentPart == null)
if (currentPart is null)
{
log.Warn("Did not found XRef object pointed to by 'Prev' key at position " + prevBytePos);
break;

View File

@@ -56,7 +56,7 @@
/// <param name="dictionary">The parsed dictionary from the document.</param>
internal TrailerDictionary(DictionaryToken dictionary)
{
if (dictionary == null)
if (dictionary is null)
{
throw new ArgumentNullException(nameof(dictionary));
}

View File

@@ -15,12 +15,12 @@
public CryptHandler(DictionaryToken cryptDictionary,
NameToken streamName, NameToken stringName)
{
if (streamName == null)
if (streamName is null)
{
throw new ArgumentNullException(nameof(streamName));
}
if (stringName == null)
if (stringName is null)
{
throw new ArgumentNullException(nameof(stringName));
}
@@ -32,7 +32,7 @@
public CryptDictionary GetNamedCryptDictionary(NameToken name)
{
if (name == null)
if (name is null)
{
throw new ArgumentNullException(nameof(name));
}

View File

@@ -11,7 +11,7 @@
{
public static EncryptionDictionary Read(DictionaryToken encryptionDictionary, IPdfTokenScanner tokenScanner)
{
if (encryptionDictionary == null)
if (encryptionDictionary is null)
{
throw new ArgumentNullException(nameof(encryptionDictionary));
}

View File

@@ -70,7 +70,7 @@
documentIdBytes = [];
}
if (encryptionDictionary == null)
if (encryptionDictionary is null)
{
return;
}
@@ -329,7 +329,7 @@
public IToken Decrypt(IndirectReference reference, IToken token)
{
if (token == null)
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
@@ -728,7 +728,7 @@
private static byte[] GetPaddedPassword(byte[] password)
{
if (password == null || password.Length == 0)
if (password is null || password.Length == 0)
{
return PaddingBytes;
}
@@ -771,7 +771,7 @@
private static byte[] ComputeStupidIsoHash(byte[] password, byte[] salt, byte[] vector)
{
// There are some details here https://web.archive.org/web/20180311160224/esec-lab.sogeti.com/posts/2011/09/14/the-undocumented-password-validation-algorithm-of-adobe-reader-x.html
if (vector == null)
if (vector is null)
{
vector = [];
}

View File

@@ -115,7 +115,7 @@
{
node = node.Walk(ReadBit());
if (node == null)
if (node is null)
{
goto mode;
}
@@ -224,7 +224,7 @@
{
node = node.Walk(ReadBit());
if (node == null)
if (node is null)
{
goto eof;
}
@@ -347,7 +347,7 @@
var bit = ReadBit();
node = node.Walk(bit);
if (node == null)
if (node is null)
{
throw new InvalidOperationException("Unknown code in Huffman RLE stream");
}
@@ -495,7 +495,7 @@
var isSet = ((path >> bitPos) & 1) == 1;
var next = current.Walk(isSet);
if (next == null)
if (next is null)
{
next = new Node();
@@ -531,7 +531,7 @@
var isSet = ((path >> bitPos) & 1) == 1;
var next = current.Walk(isSet);
if (next == null)
if (next is null)
{
if (i == depth - 1)
{

View File

@@ -9,7 +9,7 @@
{
public static DictionaryToken GetFilterParameters(DictionaryToken streamDictionary, int index)
{
if (streamDictionary == null)
if (streamDictionary is null)
{
throw new ArgumentNullException(nameof(streamDictionary));
}

View File

@@ -56,13 +56,13 @@
/// <inheritdoc />
public IReadOnlyList<IFilter> GetFilters(DictionaryToken dictionary)
{
if (dictionary == null)
if (dictionary is null)
{
throw new ArgumentNullException(nameof(dictionary));
}
var token = dictionary.GetObjectOrDefault(NameToken.Filter, NameToken.F);
if (token == null)
if (token is null)
{
return Array.Empty<IFilter>();
}
@@ -89,7 +89,7 @@
/// <inheritdoc />
public IReadOnlyList<IFilter> GetNamedFilters(IReadOnlyList<NameToken> names)
{
if (names == null)
if (names is null)
{
throw new ArgumentNullException(nameof(names));
}

View File

@@ -29,13 +29,13 @@
public IReadOnlyList<IFilter> GetFilters(DictionaryToken dictionary, IPdfTokenScanner scanner)
{
if (dictionary == null)
if (dictionary is null)
{
throw new ArgumentNullException(nameof(dictionary));
}
var token = dictionary.GetObjectOrDefault(NameToken.Filter, NameToken.F);
if (token == null)
if (token is null)
{
return Array.Empty<IFilter>();
}
@@ -57,7 +57,7 @@
case IndirectReferenceToken irt:
if (DirectObjectFinder.TryGet<NameToken>(irt, scanner, out var indirectName))
{
return GetNamedFilters(new []{ indirectName });
return GetNamedFilters(new[] { indirectName });
}
else if (DirectObjectFinder.TryGet<ArrayToken>(irt, scanner, out var indirectArray))
{

View File

@@ -36,7 +36,7 @@
/// <inheritdoc />
public byte[] Decode(IReadOnlyList<byte> input, DictionaryToken streamDictionary, int filterIndex)
{
if (input == null)
if (input is null)
{
throw new ArgumentNullException(nameof(input));
}

View File

@@ -9,7 +9,7 @@
{
public static byte[] Decode(byte[] inputBytes, int predictor, int colors, int bitsPerComponent, int columns)
{
if (inputBytes == null)
if (inputBytes is null)
{
throw new ArgumentNullException(nameof(inputBytes));
}
@@ -22,8 +22,8 @@
int bitsPerPixel = colors * bitsPerComponent;
int bytesPerPixel = (bitsPerPixel + 7) / 8;
int rowlength = (columns * bitsPerPixel + 7) / 8;
byte[] actline = new byte[rowlength];
byte[] lastline = new byte[rowlength];
var actline = new byte[rowlength];
var lastline = new byte[rowlength];
int linepredictor = predictor;

View File

@@ -84,7 +84,7 @@
{
if (numberOfOutputValues == -1)
{
if (RangeValues == null)
if (RangeValues is null)
{
numberOfOutputValues = 0;
}

View File

@@ -254,7 +254,7 @@
/// <returns>an array with all samples.</returns>
private int[][] GetSamples()
{
if (samples == null)
if (samples is null)
{
int arraySize = 1;
int nIn = NumberOfInputParameters;

View File

@@ -40,7 +40,7 @@
// exponential interpolation
double xToN = Math.Pow(input[0], N); // x^exponent
double[] result = new double[Math.Min(C0.Length, C1.Length)];
var result = new double[Math.Min(C0.Length, C1.Length)];
for (int j = 0; j < result.Length; j++)
{
double c0j = ((NumericToken)C0[j]).Double;

View File

@@ -20,7 +20,7 @@
internal PdfFunctionType3(DictionaryToken function, ArrayToken domain, ArrayToken range, IReadOnlyList<PdfFunction> functionsArray, ArrayToken bounds, ArrayToken encode)
: base(function, domain, range)
{
if (functionsArray == null || functionsArray.Count == 0)
if (functionsArray is null || functionsArray.Count == 0)
{
throw new ArgumentNullException(nameof(functionsArray));
}
@@ -36,7 +36,7 @@
internal PdfFunctionType3(StreamToken function, ArrayToken domain, ArrayToken range, IReadOnlyList<PdfFunction> functionsArray, ArrayToken bounds, ArrayToken encode)
: base(function, domain, range)
{
if (functionsArray == null || functionsArray.Count == 0)
if (functionsArray is null || functionsArray.Count == 0)
{
throw new ArgumentNullException(nameof(functionsArray));
}
@@ -77,7 +77,7 @@
int boundsSize = boundsValues.Length;
// create a combined array containing the domain and the bounds values
// domain.min, bounds[0], bounds[1], ...., bounds[boundsSize-1], domain.max
double[] partitionValues = new double[boundsSize + 2];
var partitionValues = new double[boundsSize + 2];
int partitionValuesSize = partitionValues.Length;
partitionValues[0] = domain.Min;
partitionValues[partitionValuesSize - 1] = domain.Max;
@@ -95,11 +95,11 @@
}
}
}
if (function == null)
if (function is null)
{
throw new IOException("partition not found in type 3 function");
}
double[] functionValues = new double[] { x };
var functionValues = new double[] { x };
// calculate the output values using the chosen function
double[] functionResult = function.Eval(functionValues);
// clip to range if available

View File

@@ -24,9 +24,9 @@
/// <summary>
/// Generates the result of applying a clipping path to another path.
/// </summary>
public static PdfPath Clip(this PdfPath clipping, PdfPath subject, ILog log = null)
public static PdfPath Clip(this PdfPath clipping, PdfPath subject, ILog? log = null)
{
if (clipping == null)
if (clipping is null)
{
throw new ArgumentNullException(nameof(clipping), $"{nameof(Clip)}: the clipping path cannot be null.");
}
@@ -36,7 +36,7 @@
throw new ArgumentException($"{nameof(Clip)}: the clipping path does not have the IsClipping flag set to true.", nameof(clipping));
}
if (subject == null)
if (subject is null)
{
throw new ArgumentNullException(nameof(subject), $"{nameof(Clip)}: the subject path cannot be null.");
}

View File

@@ -70,7 +70,7 @@
/// </param>
private static PdfRectangle ParametricPerpendicularProjection(IReadOnlyList<PdfPoint> polygon)
{
if (polygon == null || polygon.Count == 0)
if (polygon is null || polygon.Count == 0)
{
throw new ArgumentException("ParametricPerpendicularProjection(): polygon cannot be null and must contain at least one point.", nameof(polygon));
}
@@ -208,7 +208,7 @@
/// <param name="points">The points.</param>
public static PdfRectangle OrientedBoundingBox(IReadOnlyList<PdfPoint> points)
{
if (points == null || points.Count < 2)
if (points is null || points.Count < 2)
{
throw new ArgumentException("OrientedBoundingBox(): points cannot be null and must contain at least two points.", nameof(points));
}
@@ -881,7 +881,7 @@
private static PdfPoint[] Intersect(BezierCurve bezierCurve, PdfPoint p1, PdfPoint p2)
{
var ts = IntersectT(bezierCurve, p1, p2);
if (ts == null || ts.Length == 0) return [];
if (ts is null || ts.Length == 0) return [];
List<PdfPoint> points = new List<PdfPoint>();
foreach (var t in ts)

View File

@@ -213,7 +213,7 @@
? ActiveExtendedGraphicsStateFont
: ResourceStore.GetFont(currentState.FontState.FontName);
if (font == null)
if (font is null)
{
if (ParsingOptions.SkipMissingFonts)
{
@@ -248,7 +248,7 @@
var foundUnicode = font.TryGetUnicode(code, out var unicode);
if (!foundUnicode || unicode == null)
if (!foundUnicode || unicode is null)
{
ParsingOptions.Logger.Warn(
$"We could not find the corresponding character with code {code} in font {font.Name}.");
@@ -342,7 +342,7 @@
var horizontalScaling = textState.HorizontalScaling / 100.0;
var font = ResourceStore.GetFont(textState.FontName);
if (font == null)
if (font is null)
{
if (ParsingOptions.SkipMissingFonts)
{
@@ -766,7 +766,7 @@
/// <inheritdoc/>
public virtual void SetInlineImageProperties(IReadOnlyDictionary<NameToken, IToken> properties)
{
if (InlineImageBuilder == null)
if (InlineImageBuilder is null)
{
ParsingOptions.Logger.Error(
"Begin inline image data (ID) command encountered without a corresponding begin inline image (BI) command.");
@@ -779,7 +779,7 @@
/// <inheritdoc/>
public virtual void EndInlineImage(IReadOnlyList<byte> bytes)
{
if (InlineImageBuilder == null)
if (InlineImageBuilder is null)
{
ParsingOptions.Logger.Error(
"End inline image (EI) command encountered without a corresponding begin inline image (BI) command.");

View File

@@ -104,7 +104,7 @@
/// <inheritdoc/>
public override IColor GetColor(params double[] values)
{
if (values == null || values.Length != NumberOfColorComponents)
if (values is null || values.Length != NumberOfColorComponents)
{
throw new ArgumentException($"Invalid number of inputs, expecting {NumberOfColorComponents} but got {values.Length}", nameof(values));
}
@@ -166,7 +166,7 @@
/// <inheritdoc/>
public override IColor GetColor(params double[] values)
{
if (values == null || values.Length != NumberOfColorComponents)
if (values is null || values.Length != NumberOfColorComponents)
{
throw new ArgumentException($"Invalid number of inputs, expecting {NumberOfColorComponents} but got {values.Length}", nameof(values));
}
@@ -228,7 +228,7 @@
/// <inheritdoc/>
public override IColor GetColor(params double[] values)
{
if (values == null || values.Length != NumberOfColorComponents)
if (values is null || values.Length != NumberOfColorComponents)
{
throw new ArgumentException($"Invalid number of inputs, expecting {NumberOfColorComponents} but got {values.Length}", nameof(values));
}
@@ -330,7 +330,7 @@
/// <inheritdoc/>
public override IColor GetColor(params double[] values)
{
if (values == null || values.Length != NumberOfColorComponents)
if (values is null || values.Length != NumberOfColorComponents)
{
throw new ArgumentException($"Invalid number of inputs, expecting {NumberOfColorComponents} but got {values.Length}", nameof(values));
}
@@ -518,7 +518,7 @@
/// <inheritdoc/>
public override IColor GetColor(params double[] values)
{
if (values == null || values.Length != NumberOfColorComponents)
if (values is null || values.Length != NumberOfColorComponents)
{
throw new ArgumentException($"Invalid number of inputs, expecting {NumberOfColorComponents} but got {values.Length}", nameof(values));
}
@@ -688,7 +688,7 @@
/// <inheritdoc/>
public override IColor GetColor(params double[] values)
{
if (values == null || values.Length != NumberOfColorComponents)
if (values is null || values.Length != NumberOfColorComponents)
{
throw new ArgumentException($"Invalid number of inputs, expecting {NumberOfColorComponents} but got {values.Length}", nameof(values));
}
@@ -838,7 +838,7 @@
/// <inheritdoc/>
public override IColor GetColor(params double[] values)
{
if (values == null || values.Length != NumberOfColorComponents)
if (values is null || values.Length != NumberOfColorComponents)
{
throw new ArgumentException($"Invalid number of inputs, expecting {NumberOfColorComponents} but got {values.Length}", nameof(values));
}
@@ -979,7 +979,7 @@
/// <inheritdoc/>
public override IColor GetColor(params double[] values)
{
if (values == null || values.Length != NumberOfColorComponents)
if (values is null || values.Length != NumberOfColorComponents)
{
throw new ArgumentException($"Invalid number of inputs, expecting {NumberOfColorComponents} but got {values.Length}", nameof(values));
}
@@ -1120,7 +1120,7 @@
/// <inheritdoc/>
public override IColor GetColor(params double[] values)
{
if (values == null || values.Length != NumberOfColorComponents)
if (values is null || values.Length != NumberOfColorComponents)
{
throw new ArgumentException($"Invalid number of inputs, expecting {NumberOfColorComponents} but got {values.Length}", nameof(values));
}
@@ -1232,7 +1232,7 @@
/// <inheritdoc/>
public override IColor GetColor(params double[] values)
{
if (values == null || values.Length != NumberOfColorComponents)
if (values is null || values.Length != NumberOfColorComponents)
{
throw new ArgumentException($"Invalid number of inputs, expecting {NumberOfColorComponents} but got {values.Length}", nameof(values));
}

View File

@@ -82,7 +82,7 @@
/// </summary>
public double[] Eval(params double[] input)
{
if (Functions == null || Functions.Length == 0)
if (Functions is null || Functions.Length == 0)
{
return input;
}

View File

@@ -136,7 +136,7 @@
}
// If we did not create a letter for a combined diacritic, create one here.
if (letter == null)
if (letter is null)
{
letter = new Letter(
unicode,
@@ -167,7 +167,7 @@
public override void BeginSubpath()
{
if (CurrentPath == null)
if (CurrentPath is null)
{
CurrentPath = new PdfPath();
}
@@ -178,7 +178,7 @@
public override PdfPoint? CloseSubpath()
{
if (CurrentSubpath == null)
if (CurrentSubpath is null)
{
return null;
}
@@ -200,7 +200,7 @@
public void AddCurrentSubpath() // Not an override
{
if (CurrentSubpath == null)
if (CurrentSubpath is null)
{
return;
}
@@ -211,7 +211,7 @@
public override void StrokePath(bool close)
{
if (CurrentPath == null)
if (CurrentPath is null)
{
return;
}
@@ -228,7 +228,7 @@
public override void FillPath(FillingRule fillingRule, bool close)
{
if (CurrentPath == null)
if (CurrentPath is null)
{
return;
}
@@ -245,7 +245,7 @@
public override void FillStrokePath(FillingRule fillingRule, bool close)
{
if (CurrentPath == null)
if (CurrentPath is null)
{
return;
}
@@ -271,7 +271,7 @@
public override void BezierCurveTo(double x2, double y2, double x3, double y3)
{
if (CurrentSubpath == null)
if (CurrentSubpath is null)
{
return;
}
@@ -290,7 +290,7 @@
public override void BezierCurveTo(double x1, double y1, double x2, double y2, double x3, double y3)
{
if (CurrentSubpath == null)
if (CurrentSubpath is null)
{
return;
}
@@ -310,7 +310,7 @@
public override void LineTo(double x, double y)
{
if (CurrentSubpath == null)
if (CurrentSubpath is null)
{
return;
}
@@ -333,7 +333,7 @@
public override void EndPath()
{
if (CurrentPath == null)
if (CurrentPath is null)
{
return;
}
@@ -403,7 +403,7 @@
public override void ModifyClippingIntersect(FillingRule clippingRule)
{
if (CurrentPath == null)
if (CurrentPath is null)
{
return;
}
@@ -417,7 +417,7 @@
currentClipping.SetClipping(clippingRule);
var newClippings = CurrentPath.Clip(currentClipping, ParsingOptions.Logger);
if (newClippings == null)
if (newClippings is null)
{
ParsingOptions.Logger.Warn("Empty clipping path found. Clipping path not updated.");
}

View File

@@ -30,7 +30,7 @@
RenderingIntent defaultRenderingIntent,
IResourceStore resourceStore)
{
if (Properties == null || Bytes == null)
if (Properties is null || Bytes is null)
{
throw new InvalidOperationException($"Inline image builder not completely defined before calling {nameof(CreateInlineImage)}.");
}
@@ -54,7 +54,7 @@
{
colorSpaceName = GetByKeys<NameToken>(NameToken.ColorSpace, NameToken.Cs, false);
if (colorSpaceName == null)
if (colorSpaceName is null)
{
var colorSpaceArray = GetByKeys<ArrayToken>(NameToken.ColorSpace, NameToken.Cs, true);
@@ -82,7 +82,7 @@
var filterName = GetByKeys<NameToken>(NameToken.Filter, NameToken.F, false);
if (filterName == null)
if (filterName is null)
{
var filterArray = GetByKeys<ArrayToken>(NameToken.Filter, NameToken.F, false);

View File

@@ -28,7 +28,7 @@
/// <param name="value">The 6 transformation matrix values.</param>
public ModifyCurrentTransformationMatrix(double[] value)
{
if (value == null)
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}

View File

@@ -62,7 +62,7 @@
/// <inheritdoc />
public void Write(Stream stream)
{
if (Bytes == null)
if (Bytes is null)
{
stream.WriteText($"({Text}) {Symbol}");
stream.WriteNewLine();

View File

@@ -36,7 +36,7 @@
/// <param name="array">The array elements.</param>
public ShowTextsWithPositioning(IReadOnlyList<IToken> array)
{
if (array == null)
if (array is null)
{
throw new ArgumentNullException(nameof(array));
}

View File

@@ -40,7 +40,7 @@ namespace UglyToad.PdfPig.Graphics
{
var symbol = assemblyType.GetField("Symbol");
if (symbol == null)
if (symbol is null)
{
throw new InvalidOperationException("An operation type was defined without the public const Symbol being declared. Type was: " + assemblyType.FullName);
}

View File

@@ -424,7 +424,7 @@
*/
private void CheckClosed()
{
if (currentBuffer == null)
if (currentBuffer is null)
{
// consider that the rab is closed if there is no current buffer
throw new ObjectDisposedException("RandomAccessBuffer already closed");
@@ -438,7 +438,7 @@
public bool IsClosed()
{
return currentBuffer == null;
return currentBuffer is null;
}
/**

View File

@@ -19,12 +19,12 @@
/// </summary>
public static byte[] Convert(ColorSpaceDetails details, IReadOnlyList<byte> decoded, int bitsPerComponent, int imageWidth, int imageHeight)
{
if (decoded == null)
if (decoded is null)
{
return [];
}
if (details == null)
if (details is null)
{
return decoded.ToArray();
}

View File

@@ -10,7 +10,7 @@
public static JpegInformation GetInformation(Stream stream)
{
if (stream == null)
if (stream is null)
{
throw new ArgumentNullException(nameof(stream));
}

View File

@@ -15,7 +15,7 @@
public static Png Open(Stream stream, PngOpenerSettings settings)
{
if (stream == null)
if (stream is null)
{
throw new ArgumentNullException(nameof(stream));
}

View File

@@ -133,7 +133,7 @@
current = DirectObjectFinder.Get<DictionaryToken>(nextReference, pdfScanner);
if (current == null)
if (current is null)
{
break;
}

View File

@@ -77,7 +77,7 @@
{
destination = null;
if (explicitDestinationArray == null || explicitDestinationArray.Length == 0)
if (explicitDestinationArray is null || explicitDestinationArray.Length == 0)
{
return false;
}
@@ -111,7 +111,7 @@
return false;
}
var page = pages.GetPageByReference(pageIndirectReferenceToken.Data);
if (page?.PageNumber == null)
if (page?.PageNumber is null)
{
return false;
}
@@ -136,7 +136,7 @@
{
destTypeToken = explicitDestinationArray[1] as NameToken;
}
if (destTypeToken == null)
if (destTypeToken is null)
{
var errorMessage = $"Missing name token as second argument to explicit destination: {explicitDestinationArray}.";

View File

@@ -14,7 +14,7 @@
public static Catalog Create(IndirectReference rootReference, DictionaryToken dictionary,
IPdfTokenScanner scanner, PageFactory pageFactory, ILog log, bool isLenientParsing)
{
if (dictionary == null)
if (dictionary is null)
{
throw new ArgumentNullException(nameof(dictionary));
}

View File

@@ -65,7 +65,7 @@
private static string GetEntryOrDefault(DictionaryToken infoDictionary, NameToken key, IPdfTokenScanner pdfTokenScanner)
{
if (infoDictionary == null)
if (infoDictionary is null)
{
return null;
}

View File

@@ -54,7 +54,7 @@
private static bool ValidateXrefOffsets(IInputBytes bytes, IReadOnlyDictionary<IndirectReference, long> objectOffsets, ILog log)
{
if (objectOffsets == null)
if (objectOffsets is null)
{
return true;
}

View File

@@ -262,7 +262,7 @@
var streamObjectToken = (ObjectToken)pdfScanner.CurrentToken;
if (streamObjectToken == null || !(streamObjectToken.Data is StreamToken objectStream))
if (streamObjectToken is null || !(streamObjectToken.Data is StreamToken objectStream))
{
log.Error($"When reading a cross reference stream object found a non-stream object: {streamObjectToken?.Data}");

View File

@@ -31,7 +31,7 @@
[NotNull]
public static HeaderVersion Parse([NotNull] ISeekableTokenScanner scanner, IInputBytes inputBytes, bool isLenientParsing, ILog log)
{
if (scanner == null)
if (scanner is null)
{
throw new ArgumentNullException(nameof(scanner));
}
@@ -57,7 +57,7 @@
comment = scanner.CurrentToken as CommentToken;
attempts++;
} while (comment == null);
} while (comment is null);
return GetHeaderVersionAndResetScanner(comment, scanner, isLenientParsing, log);
}

View File

@@ -30,12 +30,12 @@
public static long GetFirstCrossReferenceOffset(IInputBytes bytes, ISeekableTokenScanner scanner, bool isLenientParsing)
{
if (bytes == null)
if (bytes is null)
{
throw new ArgumentNullException(nameof(bytes));
}
if (scanner == null)
if (scanner is null)
{
throw new ArgumentNullException(nameof(scanner));
}
@@ -68,7 +68,7 @@
}
}
if (numeric == null)
if (numeric is null)
{
throw new PdfDocumentFormatException($"Could not find the numeric value following 'startxref'. Searching from position {startXrefPosition}.");
}

View File

@@ -72,7 +72,7 @@
? graphicsStateOperations[graphicsStateOperations.Count - 1]
: null;
if (lastEndImageOffset == null || lastOperation == null || !(lastOperation is EndInlineImage lastEndImage))
if (lastEndImageOffset is null || lastOperation is null || !(lastOperation is EndInlineImage lastEndImage))
{
throw new PdfDocumentFormatException("Encountered End Image token outside an inline image on " +
$"page {pageNumber} at offset in content: {scanner.CurrentPosition}.");

View File

@@ -41,7 +41,7 @@
namedDestinations,
ParsingOptions.Logger);
if (operations == null || operations.Count == 0)
if (operations is null || operations.Count == 0)
{
PageContent emptyContent = new PageContent(
Array.Empty<IGraphicsStateOperation>(),

View File

@@ -1,10 +1,10 @@
namespace UglyToad.PdfPig.Parser.Parts
{
using Core;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using Core;
using Util.JetBrains.Annotations;
/// <summary>
@@ -22,7 +22,7 @@
[NotNull]
public static IReadOnlyDictionary<IndirectReference, long> GetObjectLocations(IInputBytes bytes)
{
if (bytes == null)
if (bytes is null)
{
throw new ArgumentNullException(nameof(bytes));
}
@@ -198,7 +198,7 @@
return long.MaxValue;
}
private static bool IsStartObjMarker(byte[] data)
private static bool IsStartObjMarker(ReadOnlySpan<byte> data)
{
if (!ReadHelper.IsWhitespace(data[0]))
{

View File

@@ -32,7 +32,7 @@
public CrossReferenceStreamFieldSize(DictionaryToken dictionary)
{
if (dictionary == null)
if (dictionary is null)
{
throw new ArgumentNullException(nameof(dictionary));
}

View File

@@ -236,7 +236,7 @@
private static EncryptionDictionary GetEncryptionDictionary(CrossReferenceTable crossReferenceTable, IPdfTokenScanner pdfTokenScanner)
{
if (crossReferenceTable.Trailer.EncryptionToken == null)
if (crossReferenceTable.Trailer.EncryptionToken is null)
{
return null;
}

View File

@@ -20,7 +20,7 @@
private static FontDetails GetDetails(CompactFontFormatFont font)
{
if (font == null)
if (font is null)
{
return FontDetails.GetDefault();
}
@@ -82,7 +82,7 @@
{
var font = GetFont();
var name = font.GetCharacterName(characterCode, true);
if (name == null)
if (name is null)
{
matrix = null;
return false;

View File

@@ -85,7 +85,7 @@
return defaultWidth.Value;
}
if (Descriptor == null)
if (Descriptor is null)
{
return 1000;
}
@@ -101,7 +101,7 @@
throw new ArgumentException($"The provided character identifier was negative: {characterIdentifier}.");
}
if (fontProgram == null)
if (fontProgram is null)
{
return Descriptor?.BoundingBox ?? new PdfRectangle(0, 0, 1000, 1.0 / scale);
}
@@ -138,7 +138,7 @@
public TransformationMatrix GetFontMatrix(int characterIdentifier)
{
if (fontProgram == null)
if (fontProgram is null)
{
return FontMatrix;
}
@@ -149,7 +149,7 @@
public bool TryGetPath(int characterCode, out IReadOnlyList<PdfSubpath> path)
{
path = null;
if (fontProgram == null)
if (fontProgram is null)
{
return false;
}
@@ -160,7 +160,7 @@
public bool TryGetPath(int characterCode, Func<int, int?> characterCodeToGlyphId, out IReadOnlyList<PdfSubpath> path)
{
path = null;
if (fontProgram == null)
if (fontProgram is null)
{
return false;
}
@@ -171,7 +171,7 @@
public bool TryGetNormalisedPath(int characterCode, out IReadOnlyList<PdfSubpath> path)
{
path = null;
if (fontProgram == null)
if (fontProgram is null)
{
return false;
}
@@ -188,7 +188,7 @@
public bool TryGetNormalisedPath(int characterCode, Func<int, int?> characterCodeToGlyphId, out IReadOnlyList<PdfSubpath> path)
{
path = null;
if (fontProgram == null)
if (fontProgram is null)
{
return false;
}

View File

@@ -66,7 +66,7 @@
public double GetWidthFromFont(int characterIdentifier)
{
if (fontProgram == null)
if (fontProgram is null)
{
return GetWidthFromDictionary(characterIdentifier);
}
@@ -97,7 +97,7 @@
public PdfRectangle GetBoundingBox(int characterIdentifier)
{
if (fontProgram == null)
if (fontProgram is null)
{
return Descriptor.BoundingBox;
}
@@ -132,7 +132,7 @@
public bool TryGetPath(int characterCode, Func<int, int?> characterCodeToGlyphId, out IReadOnlyList<PdfSubpath> path)
{
path = null;
if (fontProgram == null)
if (fontProgram is null)
{
return false;
}
@@ -148,7 +148,7 @@
public bool TryGetNormalisedPath(int characterCode, Func<int, int?> characterCodeToGlyphId, out IReadOnlyList<PdfSubpath> path)
{
path = null;
if (fontProgram == null)
if (fontProgram is null)
{
return false;
}

View File

@@ -73,7 +73,7 @@
IReadOnlyList<CidRange> cidRanges,
IReadOnlyList<CidCharacterMapping> cidCharacterMappings)
{
if (cidCharacterMappings == null)
if (cidCharacterMappings is null)
{
throw new ArgumentNullException(nameof(cidCharacterMappings));
}

View File

@@ -37,7 +37,7 @@
public static CMap Parse(IInputBytes bytes)
{
if (bytes == null)
if (bytes is null)
{
throw new ArgumentNullException(nameof(bytes));
}

View File

@@ -115,17 +115,17 @@
private static IReadOnlyList<T> Combine<T>(IReadOnlyList<T> a, IReadOnlyList<T> b)
{
if (a == null && b == null)
if (a is null && b is null)
{
return new T[0];
}
if (a == null)
if (a is null)
{
return b;
}
if (b == null)
if (b is null)
{
return a;
}

View File

@@ -50,7 +50,7 @@
/// </summary>
public bool Matches(byte[] code)
{
if (code == null)
if (code is null)
{
throw new ArgumentNullException(nameof(code));
}
@@ -63,7 +63,7 @@
/// </summary>
public bool IsFullMatch(byte[] code, int codeLength)
{
if (code == null)
if (code is null)
{
throw new ArgumentNullException(nameof(code));
}

View File

@@ -133,7 +133,7 @@
var resource = resources.FirstOrDefault(x =>
x.EndsWith("CMap." + name, StringComparison.InvariantCultureIgnoreCase));
if (resource == null)
if (resource is null)
{
return false;
}
@@ -141,7 +141,7 @@
byte[] bytes;
using (var stream = typeof(CMapParser).Assembly.GetManifestResourceStream(resource))
{
if (stream == null)
if (stream is null)
{
return false;
}

View File

@@ -57,7 +57,7 @@
private Encoding ReadEncodingDictionary(DictionaryToken encodingDictionary, Encoding fontEncoding)
{
if (encodingDictionary == null)
if (encodingDictionary is null)
{
return null;
}

View File

@@ -57,7 +57,7 @@
// Can use the AFM descriptor despite not being Type 1!
var standard14Font = Standard14.GetAdobeFontMetrics(baseFont.Data);
if (standard14Font == null)
if (standard14Font is null)
{
throw new InvalidFontFormatException($"The provided TrueType font dictionary did not have a /FirstChar and did not match a Standard 14 font: {dictionary}.");
}
@@ -66,7 +66,7 @@
var thisEncoding = encodingReader.Read(dictionary);
if (thisEncoding == null)
if (thisEncoding is null)
{
thisEncoding = new AdobeFontMetricsEncoding(standard14Font);
}
@@ -97,7 +97,7 @@
var font = ParseTrueTypeFont(descriptor, out var actualHandler);
if (font == null && actualHandler != null)
if (font is null && actualHandler != null)
{
return actualHandler.Generate(dictionary);
}
@@ -126,7 +126,7 @@
Encoding encoding = encodingReader.Read(dictionary, descriptor);
if (encoding == null && font?.TableRegister?.CMapTable != null
if (encoding is null && font?.TableRegister?.CMapTable != null
&& font.TableRegister.PostScriptTable?.GlyphNames != null)
{
var postscript = font.TableRegister.PostScriptTable;
@@ -161,7 +161,7 @@
{
actualHandler = null;
if (descriptor.FontFile == null)
if (descriptor.FontFile is null)
{
try
{

View File

@@ -193,7 +193,7 @@
var encodingName = dictionary.GetNameOrDefault(NameToken.Encoding);
if (encodingName == null)
if (encodingName is null)
{
return (null, false);
}

View File

@@ -116,7 +116,7 @@
var encoding = encodingReader.Read(dictionary, descriptor, fromFont);
if (encoding == null && font != null && font.TryGetFirst(out var t1FontReplacment))
if (encoding is null && font != null && font.TryGetFirst(out var t1FontReplacment))
{
encoding = new BuiltInEncoding(t1FontReplacment.Encoding);
}
@@ -126,7 +126,7 @@
private Union<Type1Font, CompactFontFormatFontCollection> ParseFontProgram(FontDescriptor descriptor)
{
if (descriptor?.FontFile == null)
if (descriptor?.FontFile is null)
{
return null;
}

View File

@@ -90,14 +90,14 @@
private ICidFontProgram ReadDescriptorFile(FontDescriptor descriptor)
{
if (descriptor?.FontFile == null)
if (descriptor?.FontFile is null)
{
return null;
}
var fontFileStream = DirectObjectFinder.Get<StreamToken>(descriptor.FontFile.ObjectKey, pdfScanner);
if (fontFileStream == null)
if (fontFileStream is null)
{
return null;
}

View File

@@ -11,7 +11,7 @@
{
public static FontDescriptor Generate(DictionaryToken dictionary, IPdfTokenScanner pdfScanner)
{
if (dictionary == null)
if (dictionary is null)
{
throw new ArgumentNullException(nameof(dictionary));
}

View File

@@ -87,7 +87,7 @@
return true;
}
if (encoding == null)
if (encoding is null)
{
return false;
}
@@ -194,7 +194,7 @@
{
fromFont = true;
if (font == null)
if (font is null)
{
return descriptor.BoundingBox;
}
@@ -221,11 +221,11 @@
return (value & target) == target;
}
if (descriptor == null || !unicodeValuesCache.TryGetValue(characterCode, out var unicode)
|| font.TableRegister.CMapTable == null
|| encoding == null
if (descriptor is null || !unicodeValuesCache.TryGetValue(characterCode, out var unicode)
|| font.TableRegister.CMapTable is null
|| encoding is null
|| !encoding.CodeToNameMap.TryGetValue(characterCode, out var name)
|| name == null)
|| name is null)
{
return null;
}
@@ -326,7 +326,7 @@
/// <inheritdoc/>
public bool TryGetPath(int characterCode, out IReadOnlyList<PdfSubpath> path)
{
if (font == null)
if (font is null)
{
path = null;
return false;

View File

@@ -37,7 +37,7 @@
this.font = font;
this.overrides = overrides;
Name = name;
Details = fontMetrics == null ? FontDetails.GetDefault(Name?.Data) : new FontDetails(Name?.Data,
Details = fontMetrics is null ? FontDetails.GetDefault(Name?.Data) : new FontDetails(Name?.Data,
fontMetrics.Weight == "Bold",
fontMetrics.Weight == "Bold" ? 700 : FontDetails.DefaultWeight,
fontMetrics.ItalicAngle != 0);
@@ -137,7 +137,7 @@
public bool TryGetPath(int characterCode, out IReadOnlyList<PdfSubpath> path)
{
path = null;
if (font == null)
if (font is null)
{
return false;
}

View File

@@ -55,7 +55,7 @@
return true;
}
if (bruteForcedOffsets == null)
if (bruteForcedOffsets is null)
{
bruteForcedOffsets = BruteForceSearcher.GetObjectLocations(bytes);
}
@@ -75,7 +75,7 @@
public void Cache(ObjectToken objectToken, bool force = false)
{
if (objectToken == null)
if (objectToken is null)
{
throw new ArgumentNullException();
}

View File

@@ -138,7 +138,7 @@ SOFTWARE. */
/// </summary>
/// <example><code>
/// void Foo(string param) {
/// if (param == null)
/// if (param is null)
/// throw new ArgumentNullException("par"); // Warning: Cannot resolve symbol
/// }
/// </code></example>

View File

@@ -6,7 +6,7 @@
{
public static void Fill<T>(T[] array, int start, int end, T value)
{
if (array == null)
if (array is null)
{
throw new ArgumentNullException(nameof(array));
}

View File

@@ -85,7 +85,7 @@
var first = colorSpaceArray[0] as NameToken;
if (first == null || !ColorSpaceMapper.TryMap(first, resourceStore, out var innerColorSpace)
if (first is null || !ColorSpaceMapper.TryMap(first, resourceStore, out var innerColorSpace)
|| innerColorSpace != ColorSpace.CalGray)
{
return UnsupportedColorSpaceDetails.Instance;
@@ -128,7 +128,7 @@
var first = colorSpaceArray[0] as NameToken;
if (first == null || !ColorSpaceMapper.TryMap(first, resourceStore, out var innerColorSpace)
if (first is null || !ColorSpaceMapper.TryMap(first, resourceStore, out var innerColorSpace)
|| innerColorSpace != ColorSpace.CalRGB)
{
return UnsupportedColorSpaceDetails.Instance;
@@ -178,7 +178,7 @@
var first = colorSpaceArray[0] as NameToken;
if (first == null || !ColorSpaceMapper.TryMap(first, resourceStore, out var innerColorSpace)
if (first is null || !ColorSpaceMapper.TryMap(first, resourceStore, out var innerColorSpace)
|| innerColorSpace != ColorSpace.Lab)
{
return UnsupportedColorSpaceDetails.Instance;
@@ -221,7 +221,7 @@
var first = colorSpaceArray[0] as NameToken;
if (first == null || !ColorSpaceMapper.TryMap(first, resourceStore, out var innerColorSpace)
if (first is null || !ColorSpaceMapper.TryMap(first, resourceStore, out var innerColorSpace)
|| innerColorSpace != ColorSpace.ICCBased)
{
return UnsupportedColorSpaceDetails.Instance;
@@ -277,7 +277,7 @@
var first = colorSpaceArray[0] as NameToken;
if (first == null || !ColorSpaceMapper.TryMap(first, resourceStore, out var innerColorSpace)
if (first is null || !ColorSpaceMapper.TryMap(first, resourceStore, out var innerColorSpace)
|| innerColorSpace != ColorSpace.Indexed)
{
return UnsupportedColorSpaceDetails.Instance;

View File

@@ -35,7 +35,7 @@
return val >= min && val <= max;
}
if (s == null || s.Length < 4)
if (s is null || s.Length < 4)
{
return false;
}

View File

@@ -38,7 +38,7 @@
lastX = letter.Location.X;
}
if (lastLetter == null)
if (lastLetter is null)
{
if (string.IsNullOrWhiteSpace(letter.Value))
{

View File

@@ -43,7 +43,7 @@
{
result = null;
if (previous == null)
if (previous is null)
{
return false;
}

View File

@@ -38,7 +38,7 @@
public static int GetInt(this DictionaryToken token, NameToken name)
{
if (token == null)
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
@@ -50,7 +50,7 @@
public static int GetIntOrDefault(this DictionaryToken token, NameToken name, int defaultValue = 0)
{
if (token == null)
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
@@ -62,7 +62,7 @@
public static int GetIntOrDefault(this DictionaryToken token, NameToken first, NameToken second, int defaultValue = 0)
{
if (token == null)
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
@@ -74,7 +74,7 @@
public static long? GetLongOrDefault(this DictionaryToken token, NameToken name)
{
if (token == null)
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
@@ -86,7 +86,7 @@
public static bool GetBooleanOrDefault(this DictionaryToken token, NameToken name, bool defaultValue)
{
if (token == null)
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
@@ -99,7 +99,7 @@
[CanBeNull]
public static NameToken GetNameOrDefault(this DictionaryToken token, NameToken name)
{
if (token == null)
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
@@ -142,7 +142,7 @@
{
public static NumericToken GetNumeric(this ArrayToken array, int index)
{
if (array == null)
if (array is null)
{
throw new ArgumentNullException(nameof(array));
}
@@ -162,7 +162,7 @@
public static PdfRectangle ToRectangle(this ArrayToken array, IPdfTokenScanner tokenScanner)
{
if (array == null)
if (array is null)
{
throw new ArgumentNullException(nameof(array));
}
@@ -180,7 +180,7 @@
public static PdfRectangle ToIntRectangle(this ArrayToken array, IPdfTokenScanner tokenScanner)
{
if (array == null)
if (array is null)
{
throw new ArgumentNullException(nameof(array));
}

View File

@@ -23,11 +23,6 @@
/// </summary>
public static string GetString(ReadOnlySpan<byte> bytes)
{
if (bytes == null)
{
throw new ArgumentNullException(nameof(bytes));
}
var stringBuilder = new StringBuilder(bytes.Length * 2);
foreach (var b in bytes)

View File

@@ -11,9 +11,9 @@
throw new ArgumentOutOfRangeException(nameof(offset), $"Offset cannot be negative: {offset}");
}
if (value == null)
if (value is null)
{
if (start == null && offset == 0)
if (start is null && offset == 0)
{
return true;
}

View File

@@ -162,7 +162,7 @@ namespace UglyToad.PdfPig.Util
public bool Equals(Matrix3x3 other)
{
if (other == null)
if (other is null)
{
return false;
}

View File

@@ -42,7 +42,7 @@
switch (functionType)
{
case 0:
if (functionStream == null)
if (functionStream is null)
{
throw new NotImplementedException("PdfFunctionType0 not stream");
}
@@ -55,7 +55,7 @@
return CreatePdfFunctionType3(functionDictionary, domain, range, scanner, filterProvider);
case 4:
if (functionStream == null)
if (functionStream is null)
{
throw new NotImplementedException("PdfFunctionType4 not stream");
}
@@ -68,7 +68,7 @@
private static PdfFunctionType0 CreatePdfFunctionType0(StreamToken functionStream, ArrayToken domain, ArrayToken range, IPdfTokenScanner scanner)
{
if (range == null)
if (range is null)
{
throw new ArgumentException("Could not retrieve Range in type 0 function.");
}
@@ -89,7 +89,7 @@
order = orderToken.Int;
}
if (!functionStream.StreamDictionary.TryGet<ArrayToken>(NameToken.Encode, scanner, out var encode) || encode == null)
if (!functionStream.StreamDictionary.TryGet<ArrayToken>(NameToken.Encode, scanner, out var encode) || encode is null)
{
// The default value is [0 (size[0]-1) 0 (size[1]-1) ...]
var values = new List<NumericToken>();
@@ -102,7 +102,7 @@
encode = new ArrayToken(values);
}
if (!functionStream.StreamDictionary.TryGet<ArrayToken>(NameToken.Decode, scanner, out var decode) || decode == null)
if (!functionStream.StreamDictionary.TryGet<ArrayToken>(NameToken.Decode, scanner, out var decode) || decode is null)
{
// if decode is null, the default values are the range values
decode = range;
@@ -172,7 +172,7 @@
private static PdfFunctionType4 CreatePdfFunctionType4(StreamToken functionStream, ArrayToken domain, ArrayToken range, IPdfTokenScanner scanner)
{
if (range == null)
if (range is null)
{
throw new ArgumentException("Could not retrieve Range in type 4 function.");
}

View File

@@ -28,11 +28,12 @@
shadingDictionary = fd;
}
if (shadingDictionary.TryGet<NumericToken>(NameToken.ShadingType, scanner, out ShadingType shadingTypeToken))
ShadingType shadingType;
if (shadingDictionary.TryGet<NumericToken>(NameToken.ShadingType, scanner, out var shadingTypeToken))
{
// Shading types 4 to 7 shall be defined by a stream containing descriptive data characterizing
// the shading's gradient fill.
if (shadingTypeToken.Int >= 4 && shadingStream == null)
if (shadingTypeToken.Int >= 4 && shadingStream is null)
{
throw new ArgumentNullException(nameof(shadingStream), $"Shading type '{(ShadingType)shadingTypeToken.Int}' is not properly defined. Shading types 4 to 7 shall be defined by a stream.");
}

View File

@@ -14,7 +14,7 @@
var resource = resources.FirstOrDefault(x =>
x.EndsWith("sRGB2014.icc", StringComparison.InvariantCultureIgnoreCase));
if (resource == null)
if (resource is null)
{
throw new InvalidOperationException("Could not find the sRGB ICC color profile stream.");
}

View File

@@ -38,7 +38,7 @@
.Where(v => v.Value.CharacterCode == code)
.Select(v => v.Value)
.FirstOrDefault();
if (characterMetric == null)
if (characterMetric is null)
{
Debug.WriteLine($"Font '{metrics.FontName}' does NOT have character '{character}' (0x{(int)character:X}).");
return false;
@@ -106,7 +106,7 @@
.Where(v => v.Value.CharacterCode == characterCode)
.Select(v => v.Value)
.FirstOrDefault();
if (characterMetric == null)
if (characterMetric is null)
{
throw new NotSupportedException($"Font '{metrics.FontName}' does NOT have character '{character}' (0x{(int)character:X}).");
}

View File

@@ -80,7 +80,7 @@
};
var os2 = font.TableRegister.Os2Table;
if (os2 == null)
if (os2 is null)
{
throw new InvalidFontFormatException("Embedding TrueType font requires OS/2 table.");
}

View File

@@ -133,7 +133,7 @@ namespace UglyToad.PdfPig.Writer
reasons = reasonsMutable;
try
{
if (fontFileBytes == null)
if (fontFileBytes is null)
{
reasonsMutable.Add("Provided bytes were null.");
return false;
@@ -147,19 +147,19 @@ namespace UglyToad.PdfPig.Writer
var font = TrueTypeFontParser.Parse(new TrueTypeDataBytes(new ByteArrayInputBytes(fontFileBytes)));
if (font.TableRegister.CMapTable == null)
if (font.TableRegister.CMapTable is null)
{
reasonsMutable.Add("The provided font did not contain a cmap table, used to map character codes to glyph codes.");
return false;
}
if (font.TableRegister.Os2Table == null)
if (font.TableRegister.Os2Table is null)
{
reasonsMutable.Add("The provided font did not contain an OS/2 table, used to fill in the font descriptor dictionary.");
return false;
}
if (font.TableRegister.PostScriptTable == null)
if (font.TableRegister.PostScriptTable is null)
{
reasonsMutable.Add("The provided font did not contain a post PostScript table, used to map character codes to glyph codes.");
return false;
@@ -248,7 +248,7 @@ namespace UglyToad.PdfPig.Writer
}
}
if (builder == null)
if (builder is null)
{
builder = new PdfPageBuilder(pages.Count + 1, this);
}
@@ -436,7 +436,7 @@ namespace UglyToad.PdfPig.Writer
if (kvp.Value is IndirectReferenceToken ir)
{
ObjectToken tk = document.Structure.TokenScanner.Get(ir.Data);
if (tk == null)
if (tk is null)
{
// malformed
continue;
@@ -455,7 +455,7 @@ namespace UglyToad.PdfPig.Writer
foreach (var annot in arr.Data)
{
DictionaryToken tk = GetRemoteDict(annot);
if (tk == null)
if (tk is null)
{
// malformed
continue;
@@ -463,21 +463,21 @@ namespace UglyToad.PdfPig.Writer
if (tk.TryGet(NameToken.Subtype, out var st) && st is NameToken nm && nm == NameToken.Link)
{
if (copyLink == null)
if (copyLink is null)
{
// ingore link if don't know how to copy
continue;
}
var link = page.annotationProvider.GetAction(tk);
if (link == null)
if (link is null)
{
// ignore unknown link actions
continue;
}
var copiedLink = copyLink(link);
if (copiedLink == null)
if (copiedLink is null)
{
// ignore if caller wants to skip the link
continue;
@@ -513,7 +513,7 @@ namespace UglyToad.PdfPig.Writer
void CopyResourceDict(IToken token, Dictionary<NameToken, IToken> destinationDict)
{
DictionaryToken dict = GetRemoteDict(token);
if (dict == null)
if (dict is null)
{
return;
}
@@ -545,7 +545,7 @@ namespace UglyToad.PdfPig.Writer
var subDict = GetRemoteDict(item.Value);
var destSubDict = destinationDict[NameToken.Create(item.Key)] as DictionaryToken;
if (destSubDict == null || subDict == null)
if (destSubDict is null || subDict is null)
{
// not a dict.. just overwrite with more important one? should maybe check arrays?
if (item.Value is IndirectReferenceToken ir)
@@ -1144,7 +1144,7 @@ namespace UglyToad.PdfPig.Writer
foreach (var pair in CustomMetadata)
{
if (pair.Key == null || pair.Value == null)
if (pair.Key is null || pair.Value is null)
{
continue;
}

View File

@@ -155,7 +155,7 @@
var basePageNumber = document.Pages.Count;
if (pages == null)
if (pages is null)
{
for (var i = 1; i <= existing.NumberOfPages; i++)
{
@@ -182,14 +182,14 @@
PdfAction CopyLink(PdfAction action, Func<int, int?> getPageNumber)
{
var link = action as AbstractGoToAction;
if (link == null)
if (link is null)
{
// copy the link if it is not a link to PDF documents
return action;
}
var newPageNumber = getPageNumber(link.Destination.PageNumber);
if (newPageNumber == null)
if (newPageNumber is null)
{
// ignore the link if the target page does not exist in the PDF document
return null;

View File

@@ -36,7 +36,7 @@
private string ExtractPrefix(string name)
{
if (name == null)
if (name is null)
return prefix;
var i = 0;
while (i < name.Length && (name[i] < '0' || name[i] > '9'))
@@ -431,12 +431,12 @@
/// <returns>The letters from the input text with their corresponding size and position.</returns>
public IReadOnlyList<Letter> MeasureText(string text, double fontSize, PdfPoint position, PdfDocumentBuilder.AddedFont font)
{
if (font == null)
if (font is null)
{
throw new ArgumentNullException(nameof(font));
}
if (text == null)
if (text is null)
{
throw new ArgumentNullException(nameof(text));
}
@@ -476,12 +476,12 @@
/// <returns>The letters from the input text with their corresponding size and position.</returns>
public IReadOnlyList<Letter> AddText(string text, double fontSize, PdfPoint position, PdfDocumentBuilder.AddedFont font)
{
if (font == null)
if (font is null)
{
throw new ArgumentNullException(nameof(font));
}
if (text == null)
if (text is null)
{
throw new ArgumentNullException(nameof(text));
}

View File

@@ -86,7 +86,7 @@ namespace UglyToad.PdfPig.Writer
var tokenWriter = new NoTextTokenWriter();
using (var document = new PdfDocumentBuilder(output, false, PdfWriterType.Default, file.Version, tokenWriter: tokenWriter))
{
if (pagesBundle == null)
if (pagesBundle is null)
{
for (var i = 1; i <= file.NumberOfPages; i++)
{

View File

@@ -92,7 +92,7 @@
/// <param name="outputStream">The stream to write the token to.</param>
public void WriteToken(IToken token, Stream outputStream)
{
if (token == null)
if (token is null)
{
WriteNullToken(outputStream);
return;
@@ -378,7 +378,7 @@
WriteName(pair.Key, outputStream);
// handle scenario where PdfPig has a null value under some circumstances
if (pair.Value == null)
if (pair.Value is null)
{
WriteToken(NullToken.Instance, outputStream);
}

View File

@@ -74,7 +74,7 @@
public static IToken CopyToken(IPdfStreamWriter writer, IToken tokenToCopy, IPdfTokenScanner tokenScanner,
IDictionary<IndirectReference, IndirectReferenceToken> referencesFromDocument, Dictionary<IndirectReference, IndirectReferenceToken> callstack=null)
{
if (callstack == null)
if (callstack is null)
{
callstack = new Dictionary<IndirectReference, IndirectReferenceToken>();
}
@@ -111,7 +111,7 @@
return newReferenceToken;
}
if (callstack.ContainsKey(referenceToken.Data) && callstack[referenceToken.Data] == null)
if (callstack.ContainsKey(referenceToken.Data) && callstack[referenceToken.Data] is null)
{
newReferenceToken = writer.ReserveObjectNumber();
callstack[referenceToken.Data] = newReferenceToken;
@@ -166,7 +166,7 @@
internal static IEnumerable<(DictionaryToken, IReadOnlyList<DictionaryToken>)> WalkTree(PageTreeNode node, List<DictionaryToken> parents=null)
{
if (parents == null)
if (parents is null)
{
parents = new List<DictionaryToken>();
}

View File

@@ -111,7 +111,7 @@ namespace UglyToad.PdfPig.Writer.Xmp
{
var value = mapper.ValueFunc(builder);
if (value == null)
if (value is null)
{
continue;
}

View File

@@ -25,7 +25,7 @@
ILookupFilterProvider filterProvider,
IResourceStore resourceStore)
{
if (xObject == null)
if (xObject is null)
{
throw new ArgumentNullException(nameof(xObject));
}

View File

@@ -99,7 +99,7 @@
public bool TryGetBytes(out IReadOnlyList<byte> bytes)
{
bytes = null;
if (bytesFactory == null)
if (bytesFactory is null)
{
return false;
}