From 95f045990026d8a0f22b7dee5e31c72afc09da45 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Fri, 15 Mar 2024 11:04:58 -0700 Subject: [PATCH] Prefer is null to == null ensures that an equals overload isn't use, and we don't compare structs --- .../AcroForms/AcroFormFactory.cs | 4 +-- .../Fields/AcroFieldCommonInformation.cs | 2 +- .../Annotations/AppearanceStream.cs | 2 +- .../Annotations/QuadPointsQuadrilateral.cs | 2 +- .../Content/BasePageFactory.cs | 10 +++---- .../Content/DocumentInformation.cs | 2 +- src/UglyToad.PdfPig/Content/InlineImage.cs | 2 +- src/UglyToad.PdfPig/Content/Page.cs | 2 +- src/UglyToad.PdfPig/Content/PageTreeNode.cs | 2 +- src/UglyToad.PdfPig/Content/Pages.cs | 2 +- src/UglyToad.PdfPig/Content/ResourceStore.cs | 6 ++--- src/UglyToad.PdfPig/Content/Word.cs | 2 +- .../CrossReference/CrossReferenceTable.cs | 2 +- .../CrossReferenceTableBuilder.cs | 6 ++--- .../CrossReference/TrailerDictionary.cs | 2 +- .../Encryption/CryptHandler.cs | 6 ++--- .../Encryption/EncryptionDictionaryFactory.cs | 2 +- .../Encryption/EncryptionHandler.cs | 8 +++--- .../Filters/CcittFaxDecoderStream.cs | 10 +++---- .../Filters/DecodeParameterResolver.cs | 2 +- .../Filters/DefaultFilterProvider.cs | 6 ++--- .../Filters/FilterProviderWithLookup.cs | 6 ++--- src/UglyToad.PdfPig/Filters/FlateFilter.cs | 2 +- src/UglyToad.PdfPig/Filters/PngPredictor.cs | 6 ++--- src/UglyToad.PdfPig/Functions/PdfFunction.cs | 2 +- .../Functions/PdfFunctionType0.cs | 2 +- .../Functions/PdfFunctionType2.cs | 2 +- .../Functions/PdfFunctionType3.cs | 10 +++---- .../Geometry/ClippingExtensions.cs | 6 ++--- .../Geometry/GeometryExtensions.cs | 6 ++--- .../Graphics/BaseStreamProcessor.cs | 10 +++---- .../Graphics/Colors/ColorSpaceDetails.cs | 20 +++++++------- .../Graphics/Colors/Shading.cs | 2 +- .../Graphics/ContentStreamProcessor.cs | 26 +++++++++---------- .../Graphics/InlineImageBuilder.cs | 6 ++--- .../ModifyCurrentTransformationMatrix.cs | 2 +- .../TextShowing/MoveToNextLineShowText.cs | 2 +- .../TextShowing/ShowTextsWithPositioning.cs | 2 +- ...ReflectionGraphicsStateOperationFactory.cs | 2 +- src/UglyToad.PdfPig/IO/RandomAccessBuffer.cs | 4 +-- .../Images/ColorSpaceDetailsByteConverter.cs | 4 +-- src/UglyToad.PdfPig/Images/JpegHandler.cs | 2 +- src/UglyToad.PdfPig/Images/Png/PngOpener.cs | 2 +- .../Outline/BookmarksProvider.cs | 2 +- .../Destinations/NamedDestinationsProvider.cs | 6 ++--- src/UglyToad.PdfPig/Parser/CatalogFactory.cs | 2 +- .../Parser/DocumentInformationFactory.cs | 2 +- .../CrossReferenceObjectOffsetValidator.cs | 2 +- .../FileStructure/CrossReferenceParser.cs | 2 +- .../Parser/FileStructure/FileHeaderParser.cs | 4 +-- .../Parser/FileStructure/FileTrailerParser.cs | 6 ++--- .../Parser/PageContentParser.cs | 2 +- src/UglyToad.PdfPig/Parser/PageFactory.cs | 2 +- .../Parser/Parts/BruteForceSearcher.cs | 6 ++--- .../CrossReferenceStreamFieldSize.cs | 2 +- .../Parser/PdfDocumentFactory.cs | 2 +- .../CidFonts/PdfCidCompactFontFormatFont.cs | 4 +-- .../PdfFonts/CidFonts/Type0CidFont.cs | 14 +++++----- .../PdfFonts/CidFonts/Type2CidFont.cs | 8 +++--- src/UglyToad.PdfPig/PdfFonts/Cmap/CMap.cs | 2 +- .../PdfFonts/Cmap/CMapCache.cs | 2 +- .../PdfFonts/Cmap/CharacterMapBuilder.cs | 6 ++--- .../PdfFonts/Cmap/CodespaceRange.cs | 4 +-- .../PdfFonts/Parser/CMapParser.cs | 4 +-- .../PdfFonts/Parser/EncodingReader.cs | 2 +- .../Parser/Handlers/TrueTypeFontHandler.cs | 10 +++---- .../Parser/Handlers/Type0FontHandler.cs | 2 +- .../Parser/Handlers/Type1FontHandler.cs | 4 +-- .../PdfFonts/Parser/Parts/CidFontFactory.cs | 4 +-- .../Parser/Parts/FontDescriptorFactory.cs | 2 +- .../PdfFonts/Simple/TrueTypeSimpleFont.cs | 14 +++++----- .../TrueTypeStandard14FallbackSimpleFont.cs | 4 +-- .../Scanner/ObjectLocationProvider.cs | 4 +-- src/UglyToad.PdfPig/Util/Annotations.cs | 2 +- src/UglyToad.PdfPig/Util/ArrayHelper.cs | 2 +- .../Util/ColorSpaceDetailsParser.cs | 10 +++---- src/UglyToad.PdfPig/Util/DateFormatHelper.cs | 2 +- .../Util/DefaultWordExtractor.cs | 2 +- src/UglyToad.PdfPig/Util/Diacritics.cs | 2 +- .../Util/DictionaryTokenExtensions.cs | 18 ++++++------- src/UglyToad.PdfPig/Util/Hex.cs | 5 ---- .../Util/InternalStringExtensions.cs | 4 +-- src/UglyToad.PdfPig/Util/Matrix3x3.cs | 2 +- src/UglyToad.PdfPig/Util/PdfFunctionParser.cs | 12 ++++----- src/UglyToad.PdfPig/Util/ShadingParser.cs | 5 ++-- .../Writer/Colors/ProfileStreamReader.cs | 2 +- .../Writer/Fonts/Standard14WritingFont.cs | 4 +-- .../Writer/Fonts/TrueTypeWritingFont.cs | 2 +- .../Writer/PdfDocumentBuilder.cs | 26 +++++++++---------- src/UglyToad.PdfPig/Writer/PdfMerger.cs | 6 ++--- src/UglyToad.PdfPig/Writer/PdfPageBuilder.cs | 10 +++---- src/UglyToad.PdfPig/Writer/PdfTextRemover.cs | 2 +- src/UglyToad.PdfPig/Writer/TokenWriter.cs | 4 +-- src/UglyToad.PdfPig/Writer/WriterUtil.cs | 6 ++--- src/UglyToad.PdfPig/Writer/Xmp/XmpWriter.cs | 2 +- .../XObjects/XObjectFactory.cs | 2 +- src/UglyToad.PdfPig/XObjects/XObjectImage.cs | 2 +- 97 files changed, 234 insertions(+), 238 deletions(-) diff --git a/src/UglyToad.PdfPig/AcroForms/AcroFormFactory.cs b/src/UglyToad.PdfPig/AcroForms/AcroFormFactory.cs index d168c3bdf..2d5102236 100644 --- a/src/UglyToad.PdfPig/AcroForms/AcroFormFactory.cs +++ b/src/UglyToad.PdfPig/AcroForms/AcroFormFactory.cs @@ -213,7 +213,7 @@ private AcroFieldBase GetAcroField(DictionaryToken fieldDictionary, Catalog cata 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 @@ private static bool IsChoiceSelected(IReadOnlyList selectedOptionNames, continue; } - if (selectedOptionIndices == null) + if (selectedOptionIndices is null) { return true; } diff --git a/src/UglyToad.PdfPig/AcroForms/Fields/AcroFieldCommonInformation.cs b/src/UglyToad.PdfPig/AcroForms/Fields/AcroFieldCommonInformation.cs index e4a3c6046..9f63adc3f 100644 --- a/src/UglyToad.PdfPig/AcroForms/Fields/AcroFieldCommonInformation.cs +++ b/src/UglyToad.PdfPig/AcroForms/Fields/AcroFieldCommonInformation.cs @@ -50,7 +50,7 @@ public override string ToString() { string AppendIfNotNull(string val, string label, string result) { - if (val == null) + if (val is null) { return result; } diff --git a/src/UglyToad.PdfPig/Annotations/AppearanceStream.cs b/src/UglyToad.PdfPig/Annotations/AppearanceStream.cs index 5e7cd65c5..6d1ab5a05 100644 --- a/src/UglyToad.PdfPig/Annotations/AppearanceStream.cs +++ b/src/UglyToad.PdfPig/Annotations/AppearanceStream.cs @@ -53,7 +53,7 @@ internal AppearanceStream(IDictionary appearanceStreamsBySt /// 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"); } diff --git a/src/UglyToad.PdfPig/Annotations/QuadPointsQuadrilateral.cs b/src/UglyToad.PdfPig/Annotations/QuadPointsQuadrilateral.cs index 51df4ad0f..5b11e8813 100644 --- a/src/UglyToad.PdfPig/Annotations/QuadPointsQuadrilateral.cs +++ b/src/UglyToad.PdfPig/Annotations/QuadPointsQuadrilateral.cs @@ -23,7 +23,7 @@ public class QuadPointsQuadrilateral /// public QuadPointsQuadrilateral(IReadOnlyList points) { - if (points == null) + if (points is null) { throw new ArgumentNullException(nameof(points)); } diff --git a/src/UglyToad.PdfPig/Content/BasePageFactory.cs b/src/UglyToad.PdfPig/Content/BasePageFactory.cs index 416e13222..608a62930 100644 --- a/src/UglyToad.PdfPig/Content/BasePageFactory.cs +++ b/src/UglyToad.PdfPig/Content/BasePageFactory.cs @@ -66,7 +66,7 @@ protected BasePageFactory( 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 @@ public TPage Create(int number, DictionaryToken dictionary, PageTreeMembers page var contentStream = DirectObjectFinder.Get(obj, PdfScanner); - if (contentStream == null) + if (contentStream is null) { throw new InvalidOperationException($"Could not find the contents for object {obj}."); } @@ -150,7 +150,7 @@ public TPage Create(int number, DictionaryToken dictionary, PageTreeMembers page { var contentStream = DirectObjectFinder.Get(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 @@ private TPage ProcessPageInternal( { IReadOnlyList operations; - if (contentBytes == null || contentBytes.Count == 0) + if (contentBytes is null || contentBytes.Count == 0) { operations = Array.Empty(); } @@ -293,7 +293,7 @@ protected MediaBox GetMediaBox(int number, DictionaryToken dictionary, PageTreeM { 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."); diff --git a/src/UglyToad.PdfPig/Content/DocumentInformation.cs b/src/UglyToad.PdfPig/Content/DocumentInformation.cs index 377be91f3..5c7a7e9a8 100644 --- a/src/UglyToad.PdfPig/Content/DocumentInformation.cs +++ b/src/UglyToad.PdfPig/Content/DocumentInformation.cs @@ -124,7 +124,7 @@ public override string ToString() private static void AppendPart(string name, string value, StringBuilder builder) { - if (value == null) + if (value is null) { return; } diff --git a/src/UglyToad.PdfPig/Content/InlineImage.cs b/src/UglyToad.PdfPig/Content/InlineImage.cs index 03d72b0a1..8fec607b4 100644 --- a/src/UglyToad.PdfPig/Content/InlineImage.cs +++ b/src/UglyToad.PdfPig/Content/InlineImage.cs @@ -108,7 +108,7 @@ internal InlineImage(PdfRectangle bounds, int widthInSamples, int heightInSample public bool TryGetBytes(out IReadOnlyList bytes) { bytes = null; - if (bytesFactory == null) + if (bytesFactory is null) { return false; } diff --git a/src/UglyToad.PdfPig/Content/Page.cs b/src/UglyToad.PdfPig/Content/Page.cs index 686b69a7f..2b6ddd365 100644 --- a/src/UglyToad.PdfPig/Content/Page.cs +++ b/src/UglyToad.PdfPig/Content/Page.cs @@ -122,7 +122,7 @@ internal Page(int number, DictionaryToken dictionary, MediaBox mediaBox, CropBox private static string GetText(PageContent content) { - if (content?.Letters == null) + if (content?.Letters is null) { return string.Empty; } diff --git a/src/UglyToad.PdfPig/Content/PageTreeNode.cs b/src/UglyToad.PdfPig/Content/PageTreeNode.cs index 7215372a8..69e23dc90 100644 --- a/src/UglyToad.PdfPig/Content/PageTreeNode.cs +++ b/src/UglyToad.PdfPig/Content/PageTreeNode.cs @@ -49,7 +49,7 @@ public class PageTreeNode /// /// Whether this node is the root node. /// - public bool IsRoot => Parent == null; + public bool IsRoot => Parent is null; /// /// Create a new . diff --git a/src/UglyToad.PdfPig/Content/Pages.cs b/src/UglyToad.PdfPig/Content/Pages.cs index 1bb12fec6..21d39089b 100644 --- a/src/UglyToad.PdfPig/Content/Pages.cs +++ b/src/UglyToad.PdfPig/Content/Pages.cs @@ -132,7 +132,7 @@ internal void AddPageFactory() where TPageFactory : IPageFa 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: " + diff --git a/src/UglyToad.PdfPig/Content/ResourceStore.cs b/src/UglyToad.PdfPig/Content/ResourceStore.cs index 0fb807035..31d50a662 100644 --- a/src/UglyToad.PdfPig/Content/ResourceStore.cs +++ b/src/UglyToad.PdfPig/Content/ResourceStore.cs @@ -200,7 +200,7 @@ private void LoadFontDictionary(DictionaryToken fontDictionary) var fontObject = DirectObjectFinder.Get(objectKey, scanner); - if (fontObject == null) + if (fontObject is null) { //This is a valid use case continue; @@ -269,7 +269,7 @@ public bool TryGetNamedColorSpace(NameToken name, out ResourceColorSpace namedTo { namedToken = default(ResourceColorSpace); - if (name == null) + if (name is null) { throw new ArgumentNullException(nameof(name)); } @@ -286,7 +286,7 @@ public bool TryGetNamedColorSpace(NameToken name, out ResourceColorSpace namedTo public ColorSpaceDetails GetColorSpaceDetails(NameToken name, DictionaryToken dictionary) { - if (dictionary == null) + if (dictionary is null) { dictionary = new DictionaryToken(new Dictionary()); } diff --git a/src/UglyToad.PdfPig/Content/Word.cs b/src/UglyToad.PdfPig/Content/Word.cs index 831985e28..2d93a067c 100644 --- a/src/UglyToad.PdfPig/Content/Word.cs +++ b/src/UglyToad.PdfPig/Content/Word.cs @@ -42,7 +42,7 @@ public class Word /// The letters contained in the word, in the correct order. public Word(IReadOnlyList letters) { - if (letters == null) + if (letters is null) { throw new ArgumentNullException(nameof(letters)); } diff --git a/src/UglyToad.PdfPig/CrossReference/CrossReferenceTable.cs b/src/UglyToad.PdfPig/CrossReference/CrossReferenceTable.cs index c470742c3..aa08be61c 100644 --- a/src/UglyToad.PdfPig/CrossReference/CrossReferenceTable.cs +++ b/src/UglyToad.PdfPig/CrossReference/CrossReferenceTable.cs @@ -44,7 +44,7 @@ internal CrossReferenceTable(CrossReferenceType type, IReadOnlyDictionary crossReferenceOffsets) { - if (objectOffsets == null) + if (objectOffsets is null) { throw new ArgumentNullException(nameof(objectOffsets)); } diff --git a/src/UglyToad.PdfPig/CrossReference/CrossReferenceTableBuilder.cs b/src/UglyToad.PdfPig/CrossReference/CrossReferenceTableBuilder.cs index 8b5c2a623..f222cb8fc 100644 --- a/src/UglyToad.PdfPig/CrossReference/CrossReferenceTableBuilder.cs +++ b/src/UglyToad.PdfPig/CrossReference/CrossReferenceTableBuilder.cs @@ -20,7 +20,7 @@ internal class CrossReferenceTableBuilder public void Add(CrossReferenceTablePart part) { - if (part == null) + if (part is null) { throw new ArgumentNullException(nameof(part)); } @@ -38,7 +38,7 @@ public CrossReferenceTable Build(long firstCrossReferenceOffset, long offsetCorr 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 @@ public CrossReferenceTable Build(long firstCrossReferenceOffset, long offsetCorr } 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; diff --git a/src/UglyToad.PdfPig/CrossReference/TrailerDictionary.cs b/src/UglyToad.PdfPig/CrossReference/TrailerDictionary.cs index 520f03872..93ecaa1c7 100644 --- a/src/UglyToad.PdfPig/CrossReference/TrailerDictionary.cs +++ b/src/UglyToad.PdfPig/CrossReference/TrailerDictionary.cs @@ -56,7 +56,7 @@ public class TrailerDictionary /// The parsed dictionary from the document. internal TrailerDictionary(DictionaryToken dictionary) { - if (dictionary == null) + if (dictionary is null) { throw new ArgumentNullException(nameof(dictionary)); } diff --git a/src/UglyToad.PdfPig/Encryption/CryptHandler.cs b/src/UglyToad.PdfPig/Encryption/CryptHandler.cs index d3ecd60ed..19816d02a 100644 --- a/src/UglyToad.PdfPig/Encryption/CryptHandler.cs +++ b/src/UglyToad.PdfPig/Encryption/CryptHandler.cs @@ -15,12 +15,12 @@ internal class CryptHandler 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 CryptHandler(DictionaryToken cryptDictionary, public CryptDictionary GetNamedCryptDictionary(NameToken name) { - if (name == null) + if (name is null) { throw new ArgumentNullException(nameof(name)); } diff --git a/src/UglyToad.PdfPig/Encryption/EncryptionDictionaryFactory.cs b/src/UglyToad.PdfPig/Encryption/EncryptionDictionaryFactory.cs index 77688dd14..9e248ae19 100644 --- a/src/UglyToad.PdfPig/Encryption/EncryptionDictionaryFactory.cs +++ b/src/UglyToad.PdfPig/Encryption/EncryptionDictionaryFactory.cs @@ -11,7 +11,7 @@ internal static class EncryptionDictionaryFactory { public static EncryptionDictionary Read(DictionaryToken encryptionDictionary, IPdfTokenScanner tokenScanner) { - if (encryptionDictionary == null) + if (encryptionDictionary is null) { throw new ArgumentNullException(nameof(encryptionDictionary)); } diff --git a/src/UglyToad.PdfPig/Encryption/EncryptionHandler.cs b/src/UglyToad.PdfPig/Encryption/EncryptionHandler.cs index 4acfacdd2..1906b11f7 100644 --- a/src/UglyToad.PdfPig/Encryption/EncryptionHandler.cs +++ b/src/UglyToad.PdfPig/Encryption/EncryptionHandler.cs @@ -70,7 +70,7 @@ public EncryptionHandler(EncryptionDictionary encryptionDictionary, TrailerDicti documentIdBytes = []; } - if (encryptionDictionary == null) + if (encryptionDictionary is null) { return; } @@ -329,7 +329,7 @@ private static bool IsOwnerPasswordRevision5And6(byte[] passwordBytes, Encryptio 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 void UpdateMd5(MD5 md5, byte[] data) 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[] TruncatePasswordTo127Bytes(byte[] password) 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 = []; } diff --git a/src/UglyToad.PdfPig/Filters/CcittFaxDecoderStream.cs b/src/UglyToad.PdfPig/Filters/CcittFaxDecoderStream.cs index 89982af1f..0440f7bc2 100644 --- a/src/UglyToad.PdfPig/Filters/CcittFaxDecoderStream.cs +++ b/src/UglyToad.PdfPig/Filters/CcittFaxDecoderStream.cs @@ -115,7 +115,7 @@ private void Decode2D() { node = node.Walk(ReadBit()); - if (node == null) + if (node is null) { goto mode; } @@ -224,7 +224,7 @@ private void DecodeRowType4() { node = node.Walk(ReadBit()); - if (node == null) + if (node is null) { goto eof; } @@ -347,7 +347,7 @@ private int DecodeRun(Tree tree) 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 @@ public void Fill(int depth, int path, int value) 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 @@ public void Fill(int depth, int path, Node node) var isSet = ((path >> bitPos) & 1) == 1; var next = current.Walk(isSet); - if (next == null) + if (next is null) { if (i == depth - 1) { diff --git a/src/UglyToad.PdfPig/Filters/DecodeParameterResolver.cs b/src/UglyToad.PdfPig/Filters/DecodeParameterResolver.cs index 2446abdc6..32d10a9c6 100644 --- a/src/UglyToad.PdfPig/Filters/DecodeParameterResolver.cs +++ b/src/UglyToad.PdfPig/Filters/DecodeParameterResolver.cs @@ -9,7 +9,7 @@ internal static class DecodeParameterResolver { public static DictionaryToken GetFilterParameters(DictionaryToken streamDictionary, int index) { - if (streamDictionary == null) + if (streamDictionary is null) { throw new ArgumentNullException(nameof(streamDictionary)); } diff --git a/src/UglyToad.PdfPig/Filters/DefaultFilterProvider.cs b/src/UglyToad.PdfPig/Filters/DefaultFilterProvider.cs index 21be0de57..f6049216a 100644 --- a/src/UglyToad.PdfPig/Filters/DefaultFilterProvider.cs +++ b/src/UglyToad.PdfPig/Filters/DefaultFilterProvider.cs @@ -56,13 +56,13 @@ private DefaultFilterProvider() /// public IReadOnlyList 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(); } @@ -89,7 +89,7 @@ public IReadOnlyList GetFilters(DictionaryToken dictionary) /// public IReadOnlyList GetNamedFilters(IReadOnlyList names) { - if (names == null) + if (names is null) { throw new ArgumentNullException(nameof(names)); } diff --git a/src/UglyToad.PdfPig/Filters/FilterProviderWithLookup.cs b/src/UglyToad.PdfPig/Filters/FilterProviderWithLookup.cs index 197d13a94..a478dfcb8 100644 --- a/src/UglyToad.PdfPig/Filters/FilterProviderWithLookup.cs +++ b/src/UglyToad.PdfPig/Filters/FilterProviderWithLookup.cs @@ -29,13 +29,13 @@ public IReadOnlyList GetAllFilters() public IReadOnlyList 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(); } @@ -57,7 +57,7 @@ public IReadOnlyList GetFilters(DictionaryToken dictionary, IPdfTokenSc case IndirectReferenceToken irt: if (DirectObjectFinder.TryGet(irt, scanner, out var indirectName)) { - return GetNamedFilters(new []{ indirectName }); + return GetNamedFilters(new[] { indirectName }); } else if (DirectObjectFinder.TryGet(irt, scanner, out var indirectArray)) { diff --git a/src/UglyToad.PdfPig/Filters/FlateFilter.cs b/src/UglyToad.PdfPig/Filters/FlateFilter.cs index 511080b34..a28c717e9 100644 --- a/src/UglyToad.PdfPig/Filters/FlateFilter.cs +++ b/src/UglyToad.PdfPig/Filters/FlateFilter.cs @@ -36,7 +36,7 @@ internal class FlateFilter : IFilter /// public byte[] Decode(IReadOnlyList input, DictionaryToken streamDictionary, int filterIndex) { - if (input == null) + if (input is null) { throw new ArgumentNullException(nameof(input)); } diff --git a/src/UglyToad.PdfPig/Filters/PngPredictor.cs b/src/UglyToad.PdfPig/Filters/PngPredictor.cs index 507f9c055..bac1168cb 100644 --- a/src/UglyToad.PdfPig/Filters/PngPredictor.cs +++ b/src/UglyToad.PdfPig/Filters/PngPredictor.cs @@ -9,7 +9,7 @@ internal static class PngPredictor { 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 @@ public static byte[] Decode(byte[] inputBytes, int predictor, int colors, int bi 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; diff --git a/src/UglyToad.PdfPig/Functions/PdfFunction.cs b/src/UglyToad.PdfPig/Functions/PdfFunction.cs index afbe9ba77..70a24146d 100644 --- a/src/UglyToad.PdfPig/Functions/PdfFunction.cs +++ b/src/UglyToad.PdfPig/Functions/PdfFunction.cs @@ -84,7 +84,7 @@ public int NumberOfOutputParameters { if (numberOfOutputValues == -1) { - if (RangeValues == null) + if (RangeValues is null) { numberOfOutputValues = 0; } diff --git a/src/UglyToad.PdfPig/Functions/PdfFunctionType0.cs b/src/UglyToad.PdfPig/Functions/PdfFunctionType0.cs index ffcd8687c..4ca7fe0d7 100644 --- a/src/UglyToad.PdfPig/Functions/PdfFunctionType0.cs +++ b/src/UglyToad.PdfPig/Functions/PdfFunctionType0.cs @@ -254,7 +254,7 @@ private int CalcSampleIndex(int[] vector) /// an array with all samples. private int[][] GetSamples() { - if (samples == null) + if (samples is null) { int arraySize = 1; int nIn = NumberOfInputParameters; diff --git a/src/UglyToad.PdfPig/Functions/PdfFunctionType2.cs b/src/UglyToad.PdfPig/Functions/PdfFunctionType2.cs index 98d76a493..89a8bbbdf 100644 --- a/src/UglyToad.PdfPig/Functions/PdfFunctionType2.cs +++ b/src/UglyToad.PdfPig/Functions/PdfFunctionType2.cs @@ -40,7 +40,7 @@ public override double[] Eval(params double[] input) // 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; diff --git a/src/UglyToad.PdfPig/Functions/PdfFunctionType3.cs b/src/UglyToad.PdfPig/Functions/PdfFunctionType3.cs index 7ccb9ef9c..3e4422122 100644 --- a/src/UglyToad.PdfPig/Functions/PdfFunctionType3.cs +++ b/src/UglyToad.PdfPig/Functions/PdfFunctionType3.cs @@ -20,7 +20,7 @@ internal sealed class PdfFunctionType3 : PdfFunction internal PdfFunctionType3(DictionaryToken function, ArrayToken domain, ArrayToken range, IReadOnlyList 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(DictionaryToken function, ArrayToken domain, ArrayToke internal PdfFunctionType3(StreamToken function, ArrayToken domain, ArrayToken range, IReadOnlyList 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 @@ public override double[] Eval(params double[] input) 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 @@ public override double[] Eval(params double[] input) } } } - 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 diff --git a/src/UglyToad.PdfPig/Geometry/ClippingExtensions.cs b/src/UglyToad.PdfPig/Geometry/ClippingExtensions.cs index 26bc9d452..76f40abb7 100644 --- a/src/UglyToad.PdfPig/Geometry/ClippingExtensions.cs +++ b/src/UglyToad.PdfPig/Geometry/ClippingExtensions.cs @@ -24,9 +24,9 @@ internal static class ClippingExtensions /// /// Generates the result of applying a clipping path to another path. /// - 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 @@ public static PdfPath Clip(this PdfPath clipping, PdfPath subject, ILog log = nu 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."); } diff --git a/src/UglyToad.PdfPig/Geometry/GeometryExtensions.cs b/src/UglyToad.PdfPig/Geometry/GeometryExtensions.cs index cbec7502f..3bff69627 100644 --- a/src/UglyToad.PdfPig/Geometry/GeometryExtensions.cs +++ b/src/UglyToad.PdfPig/Geometry/GeometryExtensions.cs @@ -70,7 +70,7 @@ public static PdfPoint Subtract(this PdfPoint point1, PdfPoint point2) /// private static PdfRectangle ParametricPerpendicularProjection(IReadOnlyList 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 @@ public static PdfRectangle MinimumAreaRectangle(IEnumerable points) /// The points. public static PdfRectangle OrientedBoundingBox(IReadOnlyList 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 @@ public static PdfPoint[] Intersect(this BezierCurve bezierCurve, Line line) 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 points = new List(); foreach (var t in ts) diff --git a/src/UglyToad.PdfPig/Graphics/BaseStreamProcessor.cs b/src/UglyToad.PdfPig/Graphics/BaseStreamProcessor.cs index 79a5e0954..21ad43172 100644 --- a/src/UglyToad.PdfPig/Graphics/BaseStreamProcessor.cs +++ b/src/UglyToad.PdfPig/Graphics/BaseStreamProcessor.cs @@ -213,7 +213,7 @@ public void ShowText(IInputBytes bytes) ? ActiveExtendedGraphicsStateFont : ResourceStore.GetFont(currentState.FontState.FontName); - if (font == null) + if (font is null) { if (ParsingOptions.SkipMissingFonts) { @@ -248,7 +248,7 @@ public void ShowText(IInputBytes bytes) 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 @@ public virtual void ShowPositionedText(IReadOnlyList tokens) 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 @@ public virtual void BeginInlineImage() /// public virtual void SetInlineImageProperties(IReadOnlyDictionary 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 @@ public virtual void SetInlineImageProperties(IReadOnlyDictionary public virtual void EndInlineImage(IReadOnlyList 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."); diff --git a/src/UglyToad.PdfPig/Graphics/Colors/ColorSpaceDetails.cs b/src/UglyToad.PdfPig/Graphics/Colors/ColorSpaceDetails.cs index 75fb4d7d6..d46fa3d3f 100644 --- a/src/UglyToad.PdfPig/Graphics/Colors/ColorSpaceDetails.cs +++ b/src/UglyToad.PdfPig/Graphics/Colors/ColorSpaceDetails.cs @@ -104,7 +104,7 @@ internal override double[] Process(params double[] values) /// 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 @@ internal override double[] Process(params double[] values) /// 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 @@ internal override double[] Process(params double[] values) /// 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 @@ internal override double[] Process(params double[] values) /// 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 @@ internal override double[] Process(params double[] values) /// 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 @@ internal override double[] Process(params double[] values) /// 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 @@ internal override double[] Process(params double[] values) /// 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 @@ internal override double[] Process(params double[] values) /// 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 @@ internal override double[] Process(params double[] values) /// 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 @@ internal override double[] Process(params double[] values) /// 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)); } diff --git a/src/UglyToad.PdfPig/Graphics/Colors/Shading.cs b/src/UglyToad.PdfPig/Graphics/Colors/Shading.cs index e51e877ef..49dc7e957 100644 --- a/src/UglyToad.PdfPig/Graphics/Colors/Shading.cs +++ b/src/UglyToad.PdfPig/Graphics/Colors/Shading.cs @@ -82,7 +82,7 @@ protected internal Shading(ShadingType shadingType, bool antiAlias, DictionaryTo /// public double[] Eval(params double[] input) { - if (Functions == null || Functions.Length == 0) + if (Functions is null || Functions.Length == 0) { return input; } diff --git a/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs b/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs index 18c29249a..a3353de4a 100644 --- a/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs +++ b/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs @@ -136,7 +136,7 @@ public override void RenderGlyph(IFont font, } // 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 @@ protected override void RenderXObjectImage(XObjectContentRecord xObjectContentRe public override void BeginSubpath() { - if (CurrentPath == null) + if (CurrentPath is null) { CurrentPath = new PdfPath(); } @@ -178,7 +178,7 @@ public override void BeginSubpath() public override PdfPoint? CloseSubpath() { - if (CurrentSubpath == null) + if (CurrentSubpath is null) { return null; } @@ -200,7 +200,7 @@ public override void BeginSubpath() public void AddCurrentSubpath() // Not an override { - if (CurrentSubpath == null) + if (CurrentSubpath is null) { return; } @@ -211,7 +211,7 @@ public void AddCurrentSubpath() // Not an override public override void StrokePath(bool close) { - if (CurrentPath == null) + if (CurrentPath is null) { return; } @@ -228,7 +228,7 @@ public override void StrokePath(bool close) public override void FillPath(FillingRule fillingRule, bool close) { - if (CurrentPath == null) + if (CurrentPath is null) { return; } @@ -245,7 +245,7 @@ public override void FillPath(FillingRule fillingRule, bool close) public override void FillStrokePath(FillingRule fillingRule, bool close) { - if (CurrentPath == null) + if (CurrentPath is null) { return; } @@ -271,7 +271,7 @@ public override void MoveTo(double x, double y) 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 x2, double y2, double x3, double y3) 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 BezierCurveTo(double x1, double y1, double x2, double y2, d public override void LineTo(double x, double y) { - if (CurrentSubpath == null) + if (CurrentSubpath is null) { return; } @@ -333,7 +333,7 @@ public override void Rectangle(double x, double y, double width, double height) public override void EndPath() { - if (CurrentPath == null) + if (CurrentPath is null) { return; } @@ -403,7 +403,7 @@ public override void ClosePath() public override void ModifyClippingIntersect(FillingRule clippingRule) { - if (CurrentPath == null) + if (CurrentPath is null) { return; } @@ -417,7 +417,7 @@ public override void ModifyClippingIntersect(FillingRule clippingRule) 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."); } diff --git a/src/UglyToad.PdfPig/Graphics/InlineImageBuilder.cs b/src/UglyToad.PdfPig/Graphics/InlineImageBuilder.cs index cd03f0a13..641b99ab9 100644 --- a/src/UglyToad.PdfPig/Graphics/InlineImageBuilder.cs +++ b/src/UglyToad.PdfPig/Graphics/InlineImageBuilder.cs @@ -30,7 +30,7 @@ internal InlineImage CreateInlineImage(TransformationMatrix transformationMatrix 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 @@ internal InlineImage CreateInlineImage(TransformationMatrix transformationMatrix { colorSpaceName = GetByKeys(NameToken.ColorSpace, NameToken.Cs, false); - if (colorSpaceName == null) + if (colorSpaceName is null) { var colorSpaceArray = GetByKeys(NameToken.ColorSpace, NameToken.Cs, true); @@ -82,7 +82,7 @@ internal InlineImage CreateInlineImage(TransformationMatrix transformationMatrix var filterName = GetByKeys(NameToken.Filter, NameToken.F, false); - if (filterName == null) + if (filterName is null) { var filterArray = GetByKeys(NameToken.Filter, NameToken.F, false); diff --git a/src/UglyToad.PdfPig/Graphics/Operations/SpecialGraphicsState/ModifyCurrentTransformationMatrix.cs b/src/UglyToad.PdfPig/Graphics/Operations/SpecialGraphicsState/ModifyCurrentTransformationMatrix.cs index 4e754a7f0..c9d188937 100644 --- a/src/UglyToad.PdfPig/Graphics/Operations/SpecialGraphicsState/ModifyCurrentTransformationMatrix.cs +++ b/src/UglyToad.PdfPig/Graphics/Operations/SpecialGraphicsState/ModifyCurrentTransformationMatrix.cs @@ -28,7 +28,7 @@ public class ModifyCurrentTransformationMatrix : IGraphicsStateOperation /// The 6 transformation matrix values. public ModifyCurrentTransformationMatrix(double[] value) { - if (value == null) + if (value is null) { throw new ArgumentNullException(nameof(value)); } diff --git a/src/UglyToad.PdfPig/Graphics/Operations/TextShowing/MoveToNextLineShowText.cs b/src/UglyToad.PdfPig/Graphics/Operations/TextShowing/MoveToNextLineShowText.cs index fe6eb9ddc..21af2144a 100644 --- a/src/UglyToad.PdfPig/Graphics/Operations/TextShowing/MoveToNextLineShowText.cs +++ b/src/UglyToad.PdfPig/Graphics/Operations/TextShowing/MoveToNextLineShowText.cs @@ -62,7 +62,7 @@ public void Run(IOperationContext operationContext) /// public void Write(Stream stream) { - if (Bytes == null) + if (Bytes is null) { stream.WriteText($"({Text}) {Symbol}"); stream.WriteNewLine(); diff --git a/src/UglyToad.PdfPig/Graphics/Operations/TextShowing/ShowTextsWithPositioning.cs b/src/UglyToad.PdfPig/Graphics/Operations/TextShowing/ShowTextsWithPositioning.cs index 086952386..15b223638 100644 --- a/src/UglyToad.PdfPig/Graphics/Operations/TextShowing/ShowTextsWithPositioning.cs +++ b/src/UglyToad.PdfPig/Graphics/Operations/TextShowing/ShowTextsWithPositioning.cs @@ -36,7 +36,7 @@ public class ShowTextsWithPositioning : IGraphicsStateOperation /// The array elements. public ShowTextsWithPositioning(IReadOnlyList array) { - if (array == null) + if (array is null) { throw new ArgumentNullException(nameof(array)); } diff --git a/src/UglyToad.PdfPig/Graphics/ReflectionGraphicsStateOperationFactory.cs b/src/UglyToad.PdfPig/Graphics/ReflectionGraphicsStateOperationFactory.cs index ef52e41ca..8c1f36753 100644 --- a/src/UglyToad.PdfPig/Graphics/ReflectionGraphicsStateOperationFactory.cs +++ b/src/UglyToad.PdfPig/Graphics/ReflectionGraphicsStateOperationFactory.cs @@ -40,7 +40,7 @@ public ReflectionGraphicsStateOperationFactory() { 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); } diff --git a/src/UglyToad.PdfPig/IO/RandomAccessBuffer.cs b/src/UglyToad.PdfPig/IO/RandomAccessBuffer.cs index d41da9eff..69ce8e167 100644 --- a/src/UglyToad.PdfPig/IO/RandomAccessBuffer.cs +++ b/src/UglyToad.PdfPig/IO/RandomAccessBuffer.cs @@ -424,7 +424,7 @@ private void NextBuffer() */ 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 @@ private void CheckClosed() public bool IsClosed() { - return currentBuffer == null; + return currentBuffer is null; } /** diff --git a/src/UglyToad.PdfPig/Images/ColorSpaceDetailsByteConverter.cs b/src/UglyToad.PdfPig/Images/ColorSpaceDetailsByteConverter.cs index b91ea654e..a29e3296a 100644 --- a/src/UglyToad.PdfPig/Images/ColorSpaceDetailsByteConverter.cs +++ b/src/UglyToad.PdfPig/Images/ColorSpaceDetailsByteConverter.cs @@ -19,12 +19,12 @@ public static class ColorSpaceDetailsByteConverter /// public static byte[] Convert(ColorSpaceDetails details, IReadOnlyList 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(); } diff --git a/src/UglyToad.PdfPig/Images/JpegHandler.cs b/src/UglyToad.PdfPig/Images/JpegHandler.cs index 77b833333..8e67b3932 100644 --- a/src/UglyToad.PdfPig/Images/JpegHandler.cs +++ b/src/UglyToad.PdfPig/Images/JpegHandler.cs @@ -10,7 +10,7 @@ internal static class JpegHandler public static JpegInformation GetInformation(Stream stream) { - if (stream == null) + if (stream is null) { throw new ArgumentNullException(nameof(stream)); } diff --git a/src/UglyToad.PdfPig/Images/Png/PngOpener.cs b/src/UglyToad.PdfPig/Images/Png/PngOpener.cs index 623d5a936..f3a8f300d 100644 --- a/src/UglyToad.PdfPig/Images/Png/PngOpener.cs +++ b/src/UglyToad.PdfPig/Images/Png/PngOpener.cs @@ -15,7 +15,7 @@ internal static class PngOpener public static Png Open(Stream stream, PngOpenerSettings settings) { - if (stream == null) + if (stream is null) { throw new ArgumentNullException(nameof(stream)); } diff --git a/src/UglyToad.PdfPig/Outline/BookmarksProvider.cs b/src/UglyToad.PdfPig/Outline/BookmarksProvider.cs index fc0d611e1..962b7099c 100644 --- a/src/UglyToad.PdfPig/Outline/BookmarksProvider.cs +++ b/src/UglyToad.PdfPig/Outline/BookmarksProvider.cs @@ -133,7 +133,7 @@ private void ReadBookmarksRecursively(DictionaryToken nodeDictionary, int level, current = DirectObjectFinder.Get(nextReference, pdfScanner); - if (current == null) + if (current is null) { break; } diff --git a/src/UglyToad.PdfPig/Outline/Destinations/NamedDestinationsProvider.cs b/src/UglyToad.PdfPig/Outline/Destinations/NamedDestinationsProvider.cs index 5ef2ae840..6ea1c9f9f 100644 --- a/src/UglyToad.PdfPig/Outline/Destinations/NamedDestinationsProvider.cs +++ b/src/UglyToad.PdfPig/Outline/Destinations/NamedDestinationsProvider.cs @@ -77,7 +77,7 @@ internal static bool TryGetExplicitDestination(ArrayToken explicitDestinationArr { destination = null; - if (explicitDestinationArray == null || explicitDestinationArray.Length == 0) + if (explicitDestinationArray is null || explicitDestinationArray.Length == 0) { return false; } @@ -111,7 +111,7 @@ internal static bool TryGetExplicitDestination(ArrayToken explicitDestinationArr return false; } var page = pages.GetPageByReference(pageIndirectReferenceToken.Data); - if (page?.PageNumber == null) + if (page?.PageNumber is null) { return false; } @@ -136,7 +136,7 @@ internal static bool TryGetExplicitDestination(ArrayToken explicitDestinationArr { destTypeToken = explicitDestinationArray[1] as NameToken; } - if (destTypeToken == null) + if (destTypeToken is null) { var errorMessage = $"Missing name token as second argument to explicit destination: {explicitDestinationArray}."; diff --git a/src/UglyToad.PdfPig/Parser/CatalogFactory.cs b/src/UglyToad.PdfPig/Parser/CatalogFactory.cs index 4d8ce6732..8b2a35165 100644 --- a/src/UglyToad.PdfPig/Parser/CatalogFactory.cs +++ b/src/UglyToad.PdfPig/Parser/CatalogFactory.cs @@ -14,7 +14,7 @@ internal static class CatalogFactory 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)); } diff --git a/src/UglyToad.PdfPig/Parser/DocumentInformationFactory.cs b/src/UglyToad.PdfPig/Parser/DocumentInformationFactory.cs index c99da2ca6..0683f091f 100644 --- a/src/UglyToad.PdfPig/Parser/DocumentInformationFactory.cs +++ b/src/UglyToad.PdfPig/Parser/DocumentInformationFactory.cs @@ -65,7 +65,7 @@ public static DocumentInformation Create(IPdfTokenScanner pdfTokenScanner, Trail private static string GetEntryOrDefault(DictionaryToken infoDictionary, NameToken key, IPdfTokenScanner pdfTokenScanner) { - if (infoDictionary == null) + if (infoDictionary is null) { return null; } diff --git a/src/UglyToad.PdfPig/Parser/FileStructure/CrossReferenceObjectOffsetValidator.cs b/src/UglyToad.PdfPig/Parser/FileStructure/CrossReferenceObjectOffsetValidator.cs index 63d85dd83..54eea31d0 100644 --- a/src/UglyToad.PdfPig/Parser/FileStructure/CrossReferenceObjectOffsetValidator.cs +++ b/src/UglyToad.PdfPig/Parser/FileStructure/CrossReferenceObjectOffsetValidator.cs @@ -54,7 +54,7 @@ public static bool ValidateCrossReferenceOffsets(IInputBytes bytes, CrossReferen private static bool ValidateXrefOffsets(IInputBytes bytes, IReadOnlyDictionary objectOffsets, ILog log) { - if (objectOffsets == null) + if (objectOffsets is null) { return true; } diff --git a/src/UglyToad.PdfPig/Parser/FileStructure/CrossReferenceParser.cs b/src/UglyToad.PdfPig/Parser/FileStructure/CrossReferenceParser.cs index e27610a47..bdf46e26e 100644 --- a/src/UglyToad.PdfPig/Parser/FileStructure/CrossReferenceParser.cs +++ b/src/UglyToad.PdfPig/Parser/FileStructure/CrossReferenceParser.cs @@ -262,7 +262,7 @@ private bool TryParseCrossReferenceStream( 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}"); diff --git a/src/UglyToad.PdfPig/Parser/FileStructure/FileHeaderParser.cs b/src/UglyToad.PdfPig/Parser/FileStructure/FileHeaderParser.cs index 050dd1031..8d0950299 100644 --- a/src/UglyToad.PdfPig/Parser/FileStructure/FileHeaderParser.cs +++ b/src/UglyToad.PdfPig/Parser/FileStructure/FileHeaderParser.cs @@ -31,7 +31,7 @@ internal static class FileHeaderParser [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 @@ public static HeaderVersion Parse([NotNull] ISeekableTokenScanner scanner, IInpu comment = scanner.CurrentToken as CommentToken; attempts++; - } while (comment == null); + } while (comment is null); return GetHeaderVersionAndResetScanner(comment, scanner, isLenientParsing, log); } diff --git a/src/UglyToad.PdfPig/Parser/FileStructure/FileTrailerParser.cs b/src/UglyToad.PdfPig/Parser/FileStructure/FileTrailerParser.cs index 3595f9912..9613eb613 100644 --- a/src/UglyToad.PdfPig/Parser/FileStructure/FileTrailerParser.cs +++ b/src/UglyToad.PdfPig/Parser/FileStructure/FileTrailerParser.cs @@ -30,12 +30,12 @@ internal static class FileTrailerParser 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 @@ public static long GetFirstCrossReferenceOffset(IInputBytes bytes, ISeekableToke } } - if (numeric == null) + if (numeric is null) { throw new PdfDocumentFormatException($"Could not find the numeric value following 'startxref'. Searching from position {startXrefPosition}."); } diff --git a/src/UglyToad.PdfPig/Parser/PageContentParser.cs b/src/UglyToad.PdfPig/Parser/PageContentParser.cs index 8f383e937..9a5780888 100644 --- a/src/UglyToad.PdfPig/Parser/PageContentParser.cs +++ b/src/UglyToad.PdfPig/Parser/PageContentParser.cs @@ -72,7 +72,7 @@ public IReadOnlyList Parse( ? 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}."); diff --git a/src/UglyToad.PdfPig/Parser/PageFactory.cs b/src/UglyToad.PdfPig/Parser/PageFactory.cs index 67e1e94fa..473c76a3f 100644 --- a/src/UglyToad.PdfPig/Parser/PageFactory.cs +++ b/src/UglyToad.PdfPig/Parser/PageFactory.cs @@ -41,7 +41,7 @@ protected override Page ProcessPage(int pageNumber, namedDestinations, ParsingOptions.Logger); - if (operations == null || operations.Count == 0) + if (operations is null || operations.Count == 0) { PageContent emptyContent = new PageContent( Array.Empty(), diff --git a/src/UglyToad.PdfPig/Parser/Parts/BruteForceSearcher.cs b/src/UglyToad.PdfPig/Parser/Parts/BruteForceSearcher.cs index ae91268c3..6278aa075 100644 --- a/src/UglyToad.PdfPig/Parser/Parts/BruteForceSearcher.cs +++ b/src/UglyToad.PdfPig/Parser/Parts/BruteForceSearcher.cs @@ -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; /// @@ -22,7 +22,7 @@ internal static class BruteForceSearcher [NotNull] public static IReadOnlyDictionary GetObjectLocations(IInputBytes bytes) { - if (bytes == null) + if (bytes is null) { throw new ArgumentNullException(nameof(bytes)); } @@ -198,7 +198,7 @@ private static long GetLastEndOfFileMarker(IInputBytes bytes) return long.MaxValue; } - private static bool IsStartObjMarker(byte[] data) + private static bool IsStartObjMarker(ReadOnlySpan data) { if (!ReadHelper.IsWhitespace(data[0])) { diff --git a/src/UglyToad.PdfPig/Parser/Parts/CrossReference/CrossReferenceStreamFieldSize.cs b/src/UglyToad.PdfPig/Parser/Parts/CrossReference/CrossReferenceStreamFieldSize.cs index 1be0e2159..dc698eed0 100644 --- a/src/UglyToad.PdfPig/Parser/Parts/CrossReference/CrossReferenceStreamFieldSize.cs +++ b/src/UglyToad.PdfPig/Parser/Parts/CrossReference/CrossReferenceStreamFieldSize.cs @@ -32,7 +32,7 @@ internal class CrossReferenceStreamFieldSize public CrossReferenceStreamFieldSize(DictionaryToken dictionary) { - if (dictionary == null) + if (dictionary is null) { throw new ArgumentNullException(nameof(dictionary)); } diff --git a/src/UglyToad.PdfPig/Parser/PdfDocumentFactory.cs b/src/UglyToad.PdfPig/Parser/PdfDocumentFactory.cs index 348bda8ea..a18e0bc92 100644 --- a/src/UglyToad.PdfPig/Parser/PdfDocumentFactory.cs +++ b/src/UglyToad.PdfPig/Parser/PdfDocumentFactory.cs @@ -236,7 +236,7 @@ private static (IndirectReference, DictionaryToken) ParseTrailer(CrossReferenceT private static EncryptionDictionary GetEncryptionDictionary(CrossReferenceTable crossReferenceTable, IPdfTokenScanner pdfTokenScanner) { - if (crossReferenceTable.Trailer.EncryptionToken == null) + if (crossReferenceTable.Trailer.EncryptionToken is null) { return null; } diff --git a/src/UglyToad.PdfPig/PdfFonts/CidFonts/PdfCidCompactFontFormatFont.cs b/src/UglyToad.PdfPig/PdfFonts/CidFonts/PdfCidCompactFontFormatFont.cs index 5018eefbc..1e7f50408 100644 --- a/src/UglyToad.PdfPig/PdfFonts/CidFonts/PdfCidCompactFontFormatFont.cs +++ b/src/UglyToad.PdfPig/PdfFonts/CidFonts/PdfCidCompactFontFormatFont.cs @@ -20,7 +20,7 @@ public PdfCidCompactFontFormatFont(CompactFontFormatFontCollection fontCollectio private static FontDetails GetDetails(CompactFontFormatFont font) { - if (font == null) + if (font is null) { return FontDetails.GetDefault(); } @@ -82,7 +82,7 @@ public bool TryGetFontMatrix(int characterCode, out TransformationMatrix? matrix { var font = GetFont(); var name = font.GetCharacterName(characterCode, true); - if (name == null) + if (name is null) { matrix = null; return false; diff --git a/src/UglyToad.PdfPig/PdfFonts/CidFonts/Type0CidFont.cs b/src/UglyToad.PdfPig/PdfFonts/CidFonts/Type0CidFont.cs index 5ba7b9ad9..dc159da40 100644 --- a/src/UglyToad.PdfPig/PdfFonts/CidFonts/Type0CidFont.cs +++ b/src/UglyToad.PdfPig/PdfFonts/CidFonts/Type0CidFont.cs @@ -85,7 +85,7 @@ public double GetWidthFromDictionary(int cid) return defaultWidth.Value; } - if (Descriptor == null) + if (Descriptor is null) { return 1000; } @@ -101,7 +101,7 @@ public PdfRectangle GetBoundingBox(int characterIdentifier) 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 PdfVector GetDisplacementVector(int characterIdentifier) public TransformationMatrix GetFontMatrix(int characterIdentifier) { - if (fontProgram == null) + if (fontProgram is null) { return FontMatrix; } @@ -149,7 +149,7 @@ public TransformationMatrix GetFontMatrix(int characterIdentifier) public bool TryGetPath(int characterCode, out IReadOnlyList path) { path = null; - if (fontProgram == null) + if (fontProgram is null) { return false; } @@ -160,7 +160,7 @@ public bool TryGetPath(int characterCode, out IReadOnlyList path) public bool TryGetPath(int characterCode, Func characterCodeToGlyphId, out IReadOnlyList path) { path = null; - if (fontProgram == null) + if (fontProgram is null) { return false; } @@ -171,7 +171,7 @@ public bool TryGetPath(int characterCode, Func characterCodeToGlyphId public bool TryGetNormalisedPath(int characterCode, out IReadOnlyList path) { path = null; - if (fontProgram == null) + if (fontProgram is null) { return false; } @@ -188,7 +188,7 @@ public bool TryGetNormalisedPath(int characterCode, out IReadOnlyList characterCodeToGlyphId, out IReadOnlyList path) { path = null; - if (fontProgram == null) + if (fontProgram is null) { return false; } diff --git a/src/UglyToad.PdfPig/PdfFonts/CidFonts/Type2CidFont.cs b/src/UglyToad.PdfPig/PdfFonts/CidFonts/Type2CidFont.cs index 97dfd7f69..24667a5ed 100644 --- a/src/UglyToad.PdfPig/PdfFonts/CidFonts/Type2CidFont.cs +++ b/src/UglyToad.PdfPig/PdfFonts/CidFonts/Type2CidFont.cs @@ -66,7 +66,7 @@ public Type2CidFont(NameToken type, public double GetWidthFromFont(int characterIdentifier) { - if (fontProgram == null) + if (fontProgram is null) { return GetWidthFromDictionary(characterIdentifier); } @@ -97,7 +97,7 @@ public double GetWidthFromDictionary(int characterIdentifier) public PdfRectangle GetBoundingBox(int characterIdentifier) { - if (fontProgram == null) + if (fontProgram is null) { return Descriptor.BoundingBox; } @@ -132,7 +132,7 @@ public TransformationMatrix GetFontMatrix(int characterIdentifier) public bool TryGetPath(int characterCode, Func characterCodeToGlyphId, out IReadOnlyList path) { path = null; - if (fontProgram == null) + if (fontProgram is null) { return false; } @@ -148,7 +148,7 @@ public bool TryGetNormalisedPath(int characterCode, out IReadOnlyList characterCodeToGlyphId, out IReadOnlyList path) { path = null; - if (fontProgram == null) + if (fontProgram is null) { return false; } diff --git a/src/UglyToad.PdfPig/PdfFonts/Cmap/CMap.cs b/src/UglyToad.PdfPig/PdfFonts/Cmap/CMap.cs index 074c369ac..ee47dc2be 100644 --- a/src/UglyToad.PdfPig/PdfFonts/Cmap/CMap.cs +++ b/src/UglyToad.PdfPig/PdfFonts/Cmap/CMap.cs @@ -73,7 +73,7 @@ public CMap(CharacterIdentifierSystemInfo info, int type, int wMode, string name IReadOnlyList cidRanges, IReadOnlyList cidCharacterMappings) { - if (cidCharacterMappings == null) + if (cidCharacterMappings is null) { throw new ArgumentNullException(nameof(cidCharacterMappings)); } diff --git a/src/UglyToad.PdfPig/PdfFonts/Cmap/CMapCache.cs b/src/UglyToad.PdfPig/PdfFonts/Cmap/CMapCache.cs index b2083c831..d4202d0ee 100644 --- a/src/UglyToad.PdfPig/PdfFonts/Cmap/CMapCache.cs +++ b/src/UglyToad.PdfPig/PdfFonts/Cmap/CMapCache.cs @@ -37,7 +37,7 @@ public static bool TryGet(string name, out CMap result) public static CMap Parse(IInputBytes bytes) { - if (bytes == null) + if (bytes is null) { throw new ArgumentNullException(nameof(bytes)); } diff --git a/src/UglyToad.PdfPig/PdfFonts/Cmap/CharacterMapBuilder.cs b/src/UglyToad.PdfPig/PdfFonts/Cmap/CharacterMapBuilder.cs index bf254fa49..83b9af915 100644 --- a/src/UglyToad.PdfPig/PdfFonts/Cmap/CharacterMapBuilder.cs +++ b/src/UglyToad.PdfPig/PdfFonts/Cmap/CharacterMapBuilder.cs @@ -115,17 +115,17 @@ public void UseCMap(CMap other) private static IReadOnlyList Combine(IReadOnlyList a, IReadOnlyList 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; } diff --git a/src/UglyToad.PdfPig/PdfFonts/Cmap/CodespaceRange.cs b/src/UglyToad.PdfPig/PdfFonts/Cmap/CodespaceRange.cs index 1b8feae13..77acc16b6 100644 --- a/src/UglyToad.PdfPig/PdfFonts/Cmap/CodespaceRange.cs +++ b/src/UglyToad.PdfPig/PdfFonts/Cmap/CodespaceRange.cs @@ -50,7 +50,7 @@ public CodespaceRange(IReadOnlyList start, IReadOnlyList end) /// public bool Matches(byte[] code) { - if (code == null) + if (code is null) { throw new ArgumentNullException(nameof(code)); } @@ -63,7 +63,7 @@ public bool Matches(byte[] code) /// public bool IsFullMatch(byte[] code, int codeLength) { - if (code == null) + if (code is null) { throw new ArgumentNullException(nameof(code)); } diff --git a/src/UglyToad.PdfPig/PdfFonts/Parser/CMapParser.cs b/src/UglyToad.PdfPig/PdfFonts/Parser/CMapParser.cs index 35f97dfe3..190f7b41e 100644 --- a/src/UglyToad.PdfPig/PdfFonts/Parser/CMapParser.cs +++ b/src/UglyToad.PdfPig/PdfFonts/Parser/CMapParser.cs @@ -133,7 +133,7 @@ public bool TryParseExternal(string name, out CMap result) var resource = resources.FirstOrDefault(x => x.EndsWith("CMap." + name, StringComparison.InvariantCultureIgnoreCase)); - if (resource == null) + if (resource is null) { return false; } @@ -141,7 +141,7 @@ public bool TryParseExternal(string name, out CMap result) byte[] bytes; using (var stream = typeof(CMapParser).Assembly.GetManifestResourceStream(resource)) { - if (stream == null) + if (stream is null) { return false; } diff --git a/src/UglyToad.PdfPig/PdfFonts/Parser/EncodingReader.cs b/src/UglyToad.PdfPig/PdfFonts/Parser/EncodingReader.cs index 2a7c21bde..edcfc61d8 100644 --- a/src/UglyToad.PdfPig/PdfFonts/Parser/EncodingReader.cs +++ b/src/UglyToad.PdfPig/PdfFonts/Parser/EncodingReader.cs @@ -57,7 +57,7 @@ public Encoding Read(DictionaryToken fontDictionary, FontDescriptor descriptor = private Encoding ReadEncodingDictionary(DictionaryToken encodingDictionary, Encoding fontEncoding) { - if (encodingDictionary == null) + if (encodingDictionary is null) { return null; } diff --git a/src/UglyToad.PdfPig/PdfFonts/Parser/Handlers/TrueTypeFontHandler.cs b/src/UglyToad.PdfPig/PdfFonts/Parser/Handlers/TrueTypeFontHandler.cs index aff2d251b..a10cb8141 100644 --- a/src/UglyToad.PdfPig/PdfFonts/Parser/Handlers/TrueTypeFontHandler.cs +++ b/src/UglyToad.PdfPig/PdfFonts/Parser/Handlers/TrueTypeFontHandler.cs @@ -57,7 +57,7 @@ public IFont Generate(DictionaryToken dictionary) // 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 @@ public IFont Generate(DictionaryToken dictionary) var thisEncoding = encodingReader.Read(dictionary); - if (thisEncoding == null) + if (thisEncoding is null) { thisEncoding = new AdobeFontMetricsEncoding(standard14Font); } @@ -97,7 +97,7 @@ public IFont Generate(DictionaryToken dictionary) 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 @@ public IFont Generate(DictionaryToken dictionary) 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 @@ private TrueTypeFont ParseTrueTypeFont(FontDescriptor descriptor, out IFontHandl { actualHandler = null; - if (descriptor.FontFile == null) + if (descriptor.FontFile is null) { try { diff --git a/src/UglyToad.PdfPig/PdfFonts/Parser/Handlers/Type0FontHandler.cs b/src/UglyToad.PdfPig/PdfFonts/Parser/Handlers/Type0FontHandler.cs index fe29aa794..becd354b3 100644 --- a/src/UglyToad.PdfPig/PdfFonts/Parser/Handlers/Type0FontHandler.cs +++ b/src/UglyToad.PdfPig/PdfFonts/Parser/Handlers/Type0FontHandler.cs @@ -193,7 +193,7 @@ private static (CMap, bool isChineseJapaneseOrKorean) GetUcs2CMap(DictionaryToke var encodingName = dictionary.GetNameOrDefault(NameToken.Encoding); - if (encodingName == null) + if (encodingName is null) { return (null, false); } diff --git a/src/UglyToad.PdfPig/PdfFonts/Parser/Handlers/Type1FontHandler.cs b/src/UglyToad.PdfPig/PdfFonts/Parser/Handlers/Type1FontHandler.cs index b329452f8..94d01304e 100644 --- a/src/UglyToad.PdfPig/PdfFonts/Parser/Handlers/Type1FontHandler.cs +++ b/src/UglyToad.PdfPig/PdfFonts/Parser/Handlers/Type1FontHandler.cs @@ -116,7 +116,7 @@ public IFont Generate(DictionaryToken dictionary) 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 @@ public IFont Generate(DictionaryToken dictionary) private Union ParseFontProgram(FontDescriptor descriptor) { - if (descriptor?.FontFile == null) + if (descriptor?.FontFile is null) { return null; } diff --git a/src/UglyToad.PdfPig/PdfFonts/Parser/Parts/CidFontFactory.cs b/src/UglyToad.PdfPig/PdfFonts/Parser/Parts/CidFontFactory.cs index 8e48bd11b..be50f79b0 100644 --- a/src/UglyToad.PdfPig/PdfFonts/Parser/Parts/CidFontFactory.cs +++ b/src/UglyToad.PdfPig/PdfFonts/Parser/Parts/CidFontFactory.cs @@ -90,14 +90,14 @@ private bool TryGetFontDescriptor(DictionaryToken dictionary, out DictionaryToke private ICidFontProgram ReadDescriptorFile(FontDescriptor descriptor) { - if (descriptor?.FontFile == null) + if (descriptor?.FontFile is null) { return null; } var fontFileStream = DirectObjectFinder.Get(descriptor.FontFile.ObjectKey, pdfScanner); - if (fontFileStream == null) + if (fontFileStream is null) { return null; } diff --git a/src/UglyToad.PdfPig/PdfFonts/Parser/Parts/FontDescriptorFactory.cs b/src/UglyToad.PdfPig/PdfFonts/Parser/Parts/FontDescriptorFactory.cs index 17cb461f7..5d4d458be 100644 --- a/src/UglyToad.PdfPig/PdfFonts/Parser/Parts/FontDescriptorFactory.cs +++ b/src/UglyToad.PdfPig/PdfFonts/Parser/Parts/FontDescriptorFactory.cs @@ -11,7 +11,7 @@ internal static class FontDescriptorFactory { public static FontDescriptor Generate(DictionaryToken dictionary, IPdfTokenScanner pdfScanner) { - if (dictionary == null) + if (dictionary is null) { throw new ArgumentNullException(nameof(dictionary)); } diff --git a/src/UglyToad.PdfPig/PdfFonts/Simple/TrueTypeSimpleFont.cs b/src/UglyToad.PdfPig/PdfFonts/Simple/TrueTypeSimpleFont.cs index 16512fa2d..490b9d586 100644 --- a/src/UglyToad.PdfPig/PdfFonts/Simple/TrueTypeSimpleFont.cs +++ b/src/UglyToad.PdfPig/PdfFonts/Simple/TrueTypeSimpleFont.cs @@ -87,7 +87,7 @@ public bool TryGetUnicode(int characterCode, out string value) return true; } - if (encoding == null) + if (encoding is null) { return false; } @@ -194,7 +194,7 @@ private PdfRectangle GetBoundingBoxInGlyphSpace(int characterCode, out bool from { fromFont = true; - if (font == null) + if (font is null) { return descriptor.BoundingBox; } @@ -221,11 +221,11 @@ bool HasFlag(FontDescriptorFlags value, FontDescriptorFlags target) 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 @@ private double GetWidth(int characterCode) /// public bool TryGetPath(int characterCode, out IReadOnlyList path) { - if (font == null) + if (font is null) { path = null; return false; diff --git a/src/UglyToad.PdfPig/PdfFonts/Simple/TrueTypeStandard14FallbackSimpleFont.cs b/src/UglyToad.PdfPig/PdfFonts/Simple/TrueTypeStandard14FallbackSimpleFont.cs index 95563bb4f..64e741b98 100644 --- a/src/UglyToad.PdfPig/PdfFonts/Simple/TrueTypeStandard14FallbackSimpleFont.cs +++ b/src/UglyToad.PdfPig/PdfFonts/Simple/TrueTypeStandard14FallbackSimpleFont.cs @@ -37,7 +37,7 @@ public TrueTypeStandard14FallbackSimpleFont(NameToken name, AdobeFontMetrics fon 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 TransformationMatrix GetFontMatrix() public bool TryGetPath(int characterCode, out IReadOnlyList path) { path = null; - if (font == null) + if (font is null) { return false; } diff --git a/src/UglyToad.PdfPig/Tokenization/Scanner/ObjectLocationProvider.cs b/src/UglyToad.PdfPig/Tokenization/Scanner/ObjectLocationProvider.cs index e4c855509..e5a707d4d 100644 --- a/src/UglyToad.PdfPig/Tokenization/Scanner/ObjectLocationProvider.cs +++ b/src/UglyToad.PdfPig/Tokenization/Scanner/ObjectLocationProvider.cs @@ -55,7 +55,7 @@ public bool TryGetOffset(IndirectReference reference, out long offset) return true; } - if (bruteForcedOffsets == null) + if (bruteForcedOffsets is null) { bruteForcedOffsets = BruteForceSearcher.GetObjectLocations(bytes); } @@ -75,7 +75,7 @@ public bool TryGetCached(IndirectReference reference, out ObjectToken objectToke public void Cache(ObjectToken objectToken, bool force = false) { - if (objectToken == null) + if (objectToken is null) { throw new ArgumentNullException(); } diff --git a/src/UglyToad.PdfPig/Util/Annotations.cs b/src/UglyToad.PdfPig/Util/Annotations.cs index 88383a550..6b0c8d334 100644 --- a/src/UglyToad.PdfPig/Util/Annotations.cs +++ b/src/UglyToad.PdfPig/Util/Annotations.cs @@ -138,7 +138,7 @@ public ValueProviderAttribute([NotNull] string name) /// /// /// void Foo(string param) { - /// if (param == null) + /// if (param is null) /// throw new ArgumentNullException("par"); // Warning: Cannot resolve symbol /// } /// diff --git a/src/UglyToad.PdfPig/Util/ArrayHelper.cs b/src/UglyToad.PdfPig/Util/ArrayHelper.cs index fc72157ab..323e4de0e 100644 --- a/src/UglyToad.PdfPig/Util/ArrayHelper.cs +++ b/src/UglyToad.PdfPig/Util/ArrayHelper.cs @@ -6,7 +6,7 @@ internal static class ArrayHelper { public static void Fill(T[] array, int start, int end, T value) { - if (array == null) + if (array is null) { throw new ArgumentNullException(nameof(array)); } diff --git a/src/UglyToad.PdfPig/Util/ColorSpaceDetailsParser.cs b/src/UglyToad.PdfPig/Util/ColorSpaceDetailsParser.cs index 2c7514d00..ce5ff245e 100644 --- a/src/UglyToad.PdfPig/Util/ColorSpaceDetailsParser.cs +++ b/src/UglyToad.PdfPig/Util/ColorSpaceDetailsParser.cs @@ -85,7 +85,7 @@ public static ColorSpaceDetails GetColorSpaceDetails(ColorSpace? colorSpace, 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 @@ public static ColorSpaceDetails GetColorSpaceDetails(ColorSpace? colorSpace, 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 @@ public static ColorSpaceDetails GetColorSpaceDetails(ColorSpace? colorSpace, 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 @@ public static ColorSpaceDetails GetColorSpaceDetails(ColorSpace? colorSpace, 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 @@ public static ColorSpaceDetails GetColorSpaceDetails(ColorSpace? colorSpace, 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; diff --git a/src/UglyToad.PdfPig/Util/DateFormatHelper.cs b/src/UglyToad.PdfPig/Util/DateFormatHelper.cs index 14d7d4b31..24a8349d2 100644 --- a/src/UglyToad.PdfPig/Util/DateFormatHelper.cs +++ b/src/UglyToad.PdfPig/Util/DateFormatHelper.cs @@ -35,7 +35,7 @@ bool IsWithinRange(int val, int min, int max) return val >= min && val <= max; } - if (s == null || s.Length < 4) + if (s is null || s.Length < 4) { return false; } diff --git a/src/UglyToad.PdfPig/Util/DefaultWordExtractor.cs b/src/UglyToad.PdfPig/Util/DefaultWordExtractor.cs index 25692d518..44a90996c 100644 --- a/src/UglyToad.PdfPig/Util/DefaultWordExtractor.cs +++ b/src/UglyToad.PdfPig/Util/DefaultWordExtractor.cs @@ -38,7 +38,7 @@ public IEnumerable GetWords(IReadOnlyList letters) lastX = letter.Location.X; } - if (lastLetter == null) + if (lastLetter is null) { if (string.IsNullOrWhiteSpace(letter.Value)) { diff --git a/src/UglyToad.PdfPig/Util/Diacritics.cs b/src/UglyToad.PdfPig/Util/Diacritics.cs index becaa5fb6..95251ced4 100644 --- a/src/UglyToad.PdfPig/Util/Diacritics.cs +++ b/src/UglyToad.PdfPig/Util/Diacritics.cs @@ -43,7 +43,7 @@ public static bool TryCombineDiacriticWithPreviousLetter(string diacritic, strin { result = null; - if (previous == null) + if (previous is null) { return false; } diff --git a/src/UglyToad.PdfPig/Util/DictionaryTokenExtensions.cs b/src/UglyToad.PdfPig/Util/DictionaryTokenExtensions.cs index 99247343a..cc1799a5c 100644 --- a/src/UglyToad.PdfPig/Util/DictionaryTokenExtensions.cs +++ b/src/UglyToad.PdfPig/Util/DictionaryTokenExtensions.cs @@ -38,7 +38,7 @@ public static IToken GetObjectOrDefault(this DictionaryToken token, NameToken fi 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 GetInt(this DictionaryToken token, NameToken name) 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 name, in 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 int GetIntOrDefault(this DictionaryToken token, NameToken first, N 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 int GetIntOrDefault(this DictionaryToken token, NameToken first, N 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 @@ public static bool GetBooleanOrDefault(this DictionaryToken token, NameToken nam [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 @@ internal static class ArrayTokenExtensions { 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 NumericToken GetNumeric(this ArrayToken array, int index) 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 ToRectangle(this ArrayToken array, IPdfTokenScanner t public static PdfRectangle ToIntRectangle(this ArrayToken array, IPdfTokenScanner tokenScanner) { - if (array == null) + if (array is null) { throw new ArgumentNullException(nameof(array)); } diff --git a/src/UglyToad.PdfPig/Util/Hex.cs b/src/UglyToad.PdfPig/Util/Hex.cs index 75aae868a..c9f2c003c 100644 --- a/src/UglyToad.PdfPig/Util/Hex.cs +++ b/src/UglyToad.PdfPig/Util/Hex.cs @@ -23,11 +23,6 @@ internal static class Hex /// public static string GetString(ReadOnlySpan bytes) { - if (bytes == null) - { - throw new ArgumentNullException(nameof(bytes)); - } - var stringBuilder = new StringBuilder(bytes.Length * 2); foreach (var b in bytes) diff --git a/src/UglyToad.PdfPig/Util/InternalStringExtensions.cs b/src/UglyToad.PdfPig/Util/InternalStringExtensions.cs index 6ba0dae76..e9a0758f8 100644 --- a/src/UglyToad.PdfPig/Util/InternalStringExtensions.cs +++ b/src/UglyToad.PdfPig/Util/InternalStringExtensions.cs @@ -11,9 +11,9 @@ public static bool StartsWithOffset(this string value, string start, int offset) 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; } diff --git a/src/UglyToad.PdfPig/Util/Matrix3x3.cs b/src/UglyToad.PdfPig/Util/Matrix3x3.cs index 6b588bcf0..a3f8e968f 100644 --- a/src/UglyToad.PdfPig/Util/Matrix3x3.cs +++ b/src/UglyToad.PdfPig/Util/Matrix3x3.cs @@ -162,7 +162,7 @@ public override bool Equals(object obj) public bool Equals(Matrix3x3 other) { - if (other == null) + if (other is null) { return false; } diff --git a/src/UglyToad.PdfPig/Util/PdfFunctionParser.cs b/src/UglyToad.PdfPig/Util/PdfFunctionParser.cs index 4468969b0..1b8a5bc55 100644 --- a/src/UglyToad.PdfPig/Util/PdfFunctionParser.cs +++ b/src/UglyToad.PdfPig/Util/PdfFunctionParser.cs @@ -42,7 +42,7 @@ public static PdfFunction Create(IToken function, IPdfTokenScanner scanner, ILoo switch (functionType) { case 0: - if (functionStream == null) + if (functionStream is null) { throw new NotImplementedException("PdfFunctionType0 not stream"); } @@ -55,7 +55,7 @@ public static PdfFunction Create(IToken function, IPdfTokenScanner scanner, ILoo 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 @@ public static PdfFunction Create(IToken function, IPdfTokenScanner scanner, ILoo 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 @@ private static PdfFunctionType0 CreatePdfFunctionType0(StreamToken functionStrea order = orderToken.Int; } - if (!functionStream.StreamDictionary.TryGet(NameToken.Encode, scanner, out var encode) || encode == null) + if (!functionStream.StreamDictionary.TryGet(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(); @@ -102,7 +102,7 @@ private static PdfFunctionType0 CreatePdfFunctionType0(StreamToken functionStrea encode = new ArrayToken(values); } - if (!functionStream.StreamDictionary.TryGet(NameToken.Decode, scanner, out var decode) || decode == null) + if (!functionStream.StreamDictionary.TryGet(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 PdfFunctionType3 CreatePdfFunctionType3(DictionaryToken functionD 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."); } diff --git a/src/UglyToad.PdfPig/Util/ShadingParser.cs b/src/UglyToad.PdfPig/Util/ShadingParser.cs index 14803c7d4..d0c249fed 100644 --- a/src/UglyToad.PdfPig/Util/ShadingParser.cs +++ b/src/UglyToad.PdfPig/Util/ShadingParser.cs @@ -28,11 +28,12 @@ public static Shading Create(IToken shading, IPdfTokenScanner scanner, IResource shadingDictionary = fd; } - if (shadingDictionary.TryGet(NameToken.ShadingType, scanner, out ShadingType shadingTypeToken)) + ShadingType shadingType; + if (shadingDictionary.TryGet(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."); } diff --git a/src/UglyToad.PdfPig/Writer/Colors/ProfileStreamReader.cs b/src/UglyToad.PdfPig/Writer/Colors/ProfileStreamReader.cs index 433891645..489f78ede 100644 --- a/src/UglyToad.PdfPig/Writer/Colors/ProfileStreamReader.cs +++ b/src/UglyToad.PdfPig/Writer/Colors/ProfileStreamReader.cs @@ -14,7 +14,7 @@ public static byte[] GetSRgb2014() 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."); } diff --git a/src/UglyToad.PdfPig/Writer/Fonts/Standard14WritingFont.cs b/src/UglyToad.PdfPig/Writer/Fonts/Standard14WritingFont.cs index 398d0d3d2..9d44f5a68 100644 --- a/src/UglyToad.PdfPig/Writer/Fonts/Standard14WritingFont.cs +++ b/src/UglyToad.PdfPig/Writer/Fonts/Standard14WritingFont.cs @@ -38,7 +38,7 @@ public bool TryGetBoundingBox(char character, out PdfRectangle boundingBox) .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 @@ public byte GetValueForCharacter(char character) .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})."); } diff --git a/src/UglyToad.PdfPig/Writer/Fonts/TrueTypeWritingFont.cs b/src/UglyToad.PdfPig/Writer/Fonts/TrueTypeWritingFont.cs index c60ec9498..727bd4579 100644 --- a/src/UglyToad.PdfPig/Writer/Fonts/TrueTypeWritingFont.cs +++ b/src/UglyToad.PdfPig/Writer/Fonts/TrueTypeWritingFont.cs @@ -80,7 +80,7 @@ public IndirectReferenceToken WriteFont(IPdfStreamWriter writer, IndirectRefere }; var os2 = font.TableRegister.Os2Table; - if (os2 == null) + if (os2 is null) { throw new InvalidFontFormatException("Embedding TrueType font requires OS/2 table."); } diff --git a/src/UglyToad.PdfPig/Writer/PdfDocumentBuilder.cs b/src/UglyToad.PdfPig/Writer/PdfDocumentBuilder.cs index 095591efe..8f2ffb678 100644 --- a/src/UglyToad.PdfPig/Writer/PdfDocumentBuilder.cs +++ b/src/UglyToad.PdfPig/Writer/PdfDocumentBuilder.cs @@ -133,7 +133,7 @@ public bool CanUseTrueTypeFont(IReadOnlyList fontFileBytes, out IReadOnlyL reasons = reasonsMutable; try { - if (fontFileBytes == null) + if (fontFileBytes is null) { reasonsMutable.Add("Provided bytes were null."); return false; @@ -147,19 +147,19 @@ public bool CanUseTrueTypeFont(IReadOnlyList fontFileBytes, out IReadOnlyL 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 @@ public PdfPageBuilder AddPage(double width, double height) } } - if (builder == null) + if (builder is null) { builder = new PdfPageBuilder(pages.Count + 1, this); } @@ -436,7 +436,7 @@ public PdfPageBuilder AddPage(PdfDocument document, int pageNumber, Func destinationDict) { DictionaryToken dict = GetRemoteDict(token); - if (dict == null) + if (dict is null) { return; } @@ -545,7 +545,7 @@ void CopyResourceDict(IToken token, Dictionary destinationDic 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 @@ internal Dictionary ToDictionary() foreach (var pair in CustomMetadata) { - if (pair.Key == null || pair.Value == null) + if (pair.Key is null || pair.Value is null) { continue; } diff --git a/src/UglyToad.PdfPig/Writer/PdfMerger.cs b/src/UglyToad.PdfPig/Writer/PdfMerger.cs index 33e24423b..ba1b8043f 100644 --- a/src/UglyToad.PdfPig/Writer/PdfMerger.cs +++ b/src/UglyToad.PdfPig/Writer/PdfMerger.cs @@ -155,7 +155,7 @@ private static void Merge(IReadOnlyList files, Stream output, IRead var basePageNumber = document.Pages.Count; - if (pages == null) + if (pages is null) { for (var i = 1; i <= existing.NumberOfPages; i++) { @@ -182,14 +182,14 @@ private static void Merge(IReadOnlyList files, Stream output, IRead PdfAction CopyLink(PdfAction action, Func 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; diff --git a/src/UglyToad.PdfPig/Writer/PdfPageBuilder.cs b/src/UglyToad.PdfPig/Writer/PdfPageBuilder.cs index 0e86e9c06..da61813ed 100644 --- a/src/UglyToad.PdfPig/Writer/PdfPageBuilder.cs +++ b/src/UglyToad.PdfPig/Writer/PdfPageBuilder.cs @@ -36,7 +36,7 @@ public NameConflictSolver(string prefix) 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 @@ public PdfPageBuilder ResetColor() /// The letters from the input text with their corresponding size and position. public IReadOnlyList 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 @@ public IReadOnlyList MeasureText(string text, double fontSize, PdfPoint /// The letters from the input text with their corresponding size and position. public IReadOnlyList 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)); } diff --git a/src/UglyToad.PdfPig/Writer/PdfTextRemover.cs b/src/UglyToad.PdfPig/Writer/PdfTextRemover.cs index ed407fe1f..f8f7b6797 100644 --- a/src/UglyToad.PdfPig/Writer/PdfTextRemover.cs +++ b/src/UglyToad.PdfPig/Writer/PdfTextRemover.cs @@ -86,7 +86,7 @@ public static void RemoveText(PdfDocument file, Stream output, IReadOnlyListThe stream to write the token to. public void WriteToken(IToken token, Stream outputStream) { - if (token == null) + if (token is null) { WriteNullToken(outputStream); return; @@ -378,7 +378,7 @@ protected void WriteDictionary(DictionaryToken dictionary, Stream outputStream) 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); } diff --git a/src/UglyToad.PdfPig/Writer/WriterUtil.cs b/src/UglyToad.PdfPig/Writer/WriterUtil.cs index ef13d2092..38ce82711 100644 --- a/src/UglyToad.PdfPig/Writer/WriterUtil.cs +++ b/src/UglyToad.PdfPig/Writer/WriterUtil.cs @@ -74,7 +74,7 @@ public static Dictionary GetOrCreateDict(this Dictionary referencesFromDocument, Dictionary callstack=null) { - if (callstack == null) + if (callstack is null) { callstack = new Dictionary(); } @@ -111,7 +111,7 @@ public static IToken CopyToken(IPdfStreamWriter writer, IToken tokenToCopy, IPdf 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 @@ public static IToken CopyToken(IPdfStreamWriter writer, IToken tokenToCopy, IPdf internal static IEnumerable<(DictionaryToken, IReadOnlyList)> WalkTree(PageTreeNode node, List parents=null) { - if (parents == null) + if (parents is null) { parents = new List(); } diff --git a/src/UglyToad.PdfPig/Writer/Xmp/XmpWriter.cs b/src/UglyToad.PdfPig/Writer/Xmp/XmpWriter.cs index fc5835606..1d3bf1b26 100644 --- a/src/UglyToad.PdfPig/Writer/Xmp/XmpWriter.cs +++ b/src/UglyToad.PdfPig/Writer/Xmp/XmpWriter.cs @@ -111,7 +111,7 @@ private static void AddElementsForSchema(XElement parent, string prefix, string { var value = mapper.ValueFunc(builder); - if (value == null) + if (value is null) { continue; } diff --git a/src/UglyToad.PdfPig/XObjects/XObjectFactory.cs b/src/UglyToad.PdfPig/XObjects/XObjectFactory.cs index e20c2f9c7..ccdd8ae04 100644 --- a/src/UglyToad.PdfPig/XObjects/XObjectFactory.cs +++ b/src/UglyToad.PdfPig/XObjects/XObjectFactory.cs @@ -25,7 +25,7 @@ public static XObjectImage ReadImage(XObjectContentRecord xObject, IPdfTokenScan ILookupFilterProvider filterProvider, IResourceStore resourceStore) { - if (xObject == null) + if (xObject is null) { throw new ArgumentNullException(nameof(xObject)); } diff --git a/src/UglyToad.PdfPig/XObjects/XObjectImage.cs b/src/UglyToad.PdfPig/XObjects/XObjectImage.cs index 12029438d..c2fff8e77 100644 --- a/src/UglyToad.PdfPig/XObjects/XObjectImage.cs +++ b/src/UglyToad.PdfPig/XObjects/XObjectImage.cs @@ -99,7 +99,7 @@ internal XObjectImage(PdfRectangle bounds, public bool TryGetBytes(out IReadOnlyList bytes) { bytes = null; - if (bytesFactory == null) + if (bytesFactory is null) { return false; }