mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-04-05 20:55:01 +08:00
Use Array.Empty
This commit is contained in:
parent
87e36165ce
commit
834fb350a3
@ -1,13 +0,0 @@
|
||||
namespace UglyToad.PdfPig.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// NET 4.5 compatible Array.Empty.
|
||||
/// </summary>
|
||||
public static class EmptyArray<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// An empty array.
|
||||
/// </summary>
|
||||
public static T[] Instance { get; } = new T[0];
|
||||
}
|
||||
}
|
@ -44,7 +44,7 @@
|
||||
{
|
||||
if (words?.Any() != true)
|
||||
{
|
||||
return EmptyArray<TextBlock>.Instance;
|
||||
return Array.Empty<TextBlock>();
|
||||
}
|
||||
|
||||
return new List<TextBlock>() { new TextBlock(new XYLeaf(words).GetLines(options.WordSeparator), options.LineSeparator) };
|
||||
|
@ -50,7 +50,7 @@
|
||||
{
|
||||
if (words?.Any() != true)
|
||||
{
|
||||
return EmptyArray<TextBlock>.Instance;
|
||||
return Array.Empty<TextBlock>();
|
||||
}
|
||||
|
||||
return GetBlocks(words.ToList(),
|
||||
@ -95,7 +95,7 @@
|
||||
words = words.Where(w => !string.IsNullOrWhiteSpace(w.Text)).ToList();
|
||||
if (words.Count == 0)
|
||||
{
|
||||
return EmptyArray<TextBlock>.Instance;
|
||||
return Array.Empty<TextBlock>();
|
||||
}
|
||||
|
||||
// 1. Estimate within line and between line spacing
|
||||
|
@ -48,7 +48,7 @@
|
||||
{
|
||||
if (words?.Any() != true)
|
||||
{
|
||||
return EmptyArray<TextBlock>.Instance;
|
||||
return Array.Empty<TextBlock>();
|
||||
}
|
||||
|
||||
return GetBlocks(words,
|
||||
@ -77,7 +77,7 @@
|
||||
words = words.Where(w => !string.IsNullOrWhiteSpace(w.Text));
|
||||
if (!words.Any())
|
||||
{
|
||||
return EmptyArray<TextBlock>.Instance;
|
||||
return Array.Empty<TextBlock>();
|
||||
}
|
||||
|
||||
XYLeaf root = new XYLeaf(words); // Create a root node.
|
||||
|
@ -49,7 +49,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
Children = EmptyArray<XYNode>.Instance;
|
||||
Children = [];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@
|
||||
public static IReadOnlyList<PdfRectangle> GetWhitespaces(IEnumerable<PdfRectangle> boundingboxes,
|
||||
double minWidth, double minHeight, int maxRectangleCount = 40, double whitespaceFuzziness = 0.15, int maxBoundQueueSize = 0)
|
||||
{
|
||||
if (!boundingboxes.Any()) return EmptyArray<PdfRectangle>.Instance;
|
||||
if (!boundingboxes.Any()) return Array.Empty<PdfRectangle>();
|
||||
|
||||
var obstacles = new HashSet<PdfRectangle>(boundingboxes);
|
||||
var pageBound = GetBound(obstacles);
|
||||
|
@ -46,7 +46,7 @@
|
||||
{
|
||||
if (letters == null || letters.Count == 0)
|
||||
{
|
||||
return EmptyArray<Word>.Instance;
|
||||
return Array.Empty<Word>();
|
||||
}
|
||||
|
||||
if (options.GroupByOrientation)
|
||||
|
@ -326,9 +326,9 @@ namespace UglyToad.PdfPig.Fonts.AdobeFontMetrics
|
||||
/// </summary>
|
||||
public const string KernPairKpy = "KPY";
|
||||
|
||||
private static readonly char[] IndividualCharmetricsSplit = {';'};
|
||||
private static readonly char[] IndividualCharmetricsSplit = [';'];
|
||||
|
||||
private static readonly char[] CharmetricsKeySplit = {' '};
|
||||
private static readonly char[] CharmetricsKeySplit = [' '];
|
||||
|
||||
/// <summary>
|
||||
/// Parse the font metrics from the input bytes.
|
||||
|
@ -2,7 +2,6 @@
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Core;
|
||||
|
||||
/// <summary>
|
||||
/// Holds common properties between Adobe Type 1 and Compact Font Format private dictionaries.
|
||||
@ -144,17 +143,17 @@
|
||||
throw new ArgumentNullException(nameof(builder));
|
||||
}
|
||||
|
||||
BlueValues = builder.BlueValues ?? EmptyArray<int>.Instance;
|
||||
OtherBlues = builder.OtherBlues ?? EmptyArray<int>.Instance;
|
||||
FamilyBlues = builder.FamilyBlues ?? EmptyArray<int>.Instance;
|
||||
FamilyOtherBlues = builder.FamilyOtherBlues ?? EmptyArray<int>.Instance;
|
||||
BlueValues = builder.BlueValues ?? Array.Empty<int>();
|
||||
OtherBlues = builder.OtherBlues ?? Array.Empty<int>();
|
||||
FamilyBlues = builder.FamilyBlues ?? Array.Empty<int>();
|
||||
FamilyOtherBlues = builder.FamilyOtherBlues ?? Array.Empty<int>();
|
||||
BlueScale = builder.BlueScale ?? DefaultBlueScale;
|
||||
BlueFuzz = builder.BlueFuzz ?? DefaultBlueFuzz;
|
||||
BlueShift = builder.BlueShift ?? DefaultBlueShift;
|
||||
StandardHorizontalWidth = builder.StandardHorizontalWidth;
|
||||
StandardVerticalWidth = builder.StandardVerticalWidth;
|
||||
StemSnapHorizontalWidths = builder.StemSnapHorizontalWidths ?? EmptyArray<double>.Instance;
|
||||
StemSnapVerticalWidths = builder.StemSnapVerticalWidths ?? EmptyArray<double>.Instance;
|
||||
StemSnapHorizontalWidths = builder.StemSnapHorizontalWidths ?? Array.Empty<double>();
|
||||
StemSnapVerticalWidths = builder.StemSnapVerticalWidths ?? Array.Empty<double>();
|
||||
ForceBold = builder.ForceBold ?? false;
|
||||
LanguageGroup = builder.LanguageGroup ?? DefaultLanguageGroup;
|
||||
ExpansionFactor = builder.ExpansionFactor ?? DefaultExpansionFactor;
|
||||
|
@ -163,7 +163,7 @@
|
||||
{
|
||||
if (length == 0)
|
||||
{
|
||||
return new CompactFontFormatData(EmptyArray<byte>.Instance);
|
||||
return new CompactFontFormatData(Array.Empty<byte>());
|
||||
}
|
||||
|
||||
if (startLocation > dataBytes.Count - 1 || startLocation + length > dataBytes.Count)
|
||||
|
@ -1,8 +1,8 @@
|
||||
namespace UglyToad.PdfPig.Fonts.CompactFontFormat
|
||||
{
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Core;
|
||||
|
||||
internal class CompactFontFormatIndex : IReadOnlyList<IReadOnlyList<byte>>
|
||||
{
|
||||
@ -16,7 +16,7 @@
|
||||
|
||||
public CompactFontFormatIndex(byte[][] bytes)
|
||||
{
|
||||
this.bytes = bytes ?? EmptyArray<IReadOnlyList<byte>>.Instance;
|
||||
this.bytes = bytes ?? Array.Empty<IReadOnlyList<byte>>();
|
||||
}
|
||||
|
||||
public IEnumerator<IReadOnlyList<byte>> GetEnumerator()
|
||||
|
@ -44,7 +44,7 @@
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
return EmptyArray<int>.Instance;
|
||||
return [];
|
||||
}
|
||||
|
||||
var offsetSize = data.ReadOffsize();
|
||||
|
@ -85,7 +85,7 @@
|
||||
|
||||
if (index.Length == 0)
|
||||
{
|
||||
return EmptyArray<string>.Instance;
|
||||
return [];
|
||||
}
|
||||
|
||||
var count = index.Length - 1;
|
||||
|
@ -166,7 +166,7 @@ namespace UglyToad.PdfPig.Fonts.SystemFonts
|
||||
return values;
|
||||
}
|
||||
|
||||
return EmptyArray<string>.Instance;
|
||||
return Array.Empty<string>();
|
||||
}
|
||||
|
||||
private TrueTypeFont GetTrueTypeFontNamed(string name)
|
||||
|
@ -121,7 +121,7 @@
|
||||
#region Subpaths
|
||||
public bool TryGetGlyphPath(out IReadOnlyList<PdfSubpath> subpaths)
|
||||
{
|
||||
subpaths = EmptyArray<PdfSubpath>.Instance;
|
||||
subpaths = Array.Empty<PdfSubpath>();
|
||||
if (Points == null)
|
||||
{
|
||||
return false;
|
||||
|
@ -396,7 +396,7 @@
|
||||
Offset = offset;
|
||||
Type = type;
|
||||
DataLength = dataLength;
|
||||
DependencyIndices = dependentIndices ?? EmptyArray<CompositeGlyphIndexReference>.Instance;
|
||||
DependencyIndices = dependentIndices ?? Array.Empty<CompositeGlyphIndexReference>();
|
||||
}
|
||||
|
||||
public GlyphRecord(int offset)
|
||||
@ -404,7 +404,7 @@
|
||||
Offset = offset;
|
||||
Type = GlyphType.Empty;
|
||||
DataLength = 0;
|
||||
DependencyIndices = EmptyArray<CompositeGlyphIndexReference>.Instance;
|
||||
DependencyIndices = Array.Empty<CompositeGlyphIndexReference>();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -263,7 +263,7 @@
|
||||
|
||||
private static HorizontalMetricsTable GetHorizontalMetricsTable(DirectoryEntry entry, TrueTypeSubsetGlyphTable glyphTable)
|
||||
{
|
||||
return new HorizontalMetricsTable(entry.DummyHeader, glyphTable.HorizontalMetrics, EmptyArray<short>.Instance);
|
||||
return new HorizontalMetricsTable(entry.DummyHeader, glyphTable.HorizontalMetrics, Array.Empty<short>());
|
||||
}
|
||||
|
||||
private static byte[] GetRawInputTableBytes(byte[] font, DirectoryEntry entry)
|
||||
|
@ -36,7 +36,7 @@
|
||||
|
||||
if (length == 0)
|
||||
{
|
||||
return new ByteEncodingCMapTable(platformId, encodingId, language, EmptyArray<byte>.Instance);
|
||||
return new ByteEncodingCMapTable(platformId, encodingId, language, []);
|
||||
}
|
||||
|
||||
var glyphMapping = data.ReadByteArray(length - (SizeOfShort * 3));
|
||||
|
@ -165,9 +165,7 @@
|
||||
{
|
||||
if (contourCount == 0)
|
||||
{
|
||||
return new Glyph(true, EmptyArray<byte>.Instance, EmptyArray<ushort>.Instance,
|
||||
EmptyArray<GlyphPoint>.Instance,
|
||||
new PdfRectangle(0, 0, 0, 0));
|
||||
return new Glyph(true, [], [], [], new PdfRectangle(0, 0, 0, 0));
|
||||
}
|
||||
|
||||
var endPointsOfContours = data.ReadUnsignedShortArray(contourCount);
|
||||
|
@ -160,11 +160,11 @@
|
||||
}
|
||||
else if (Math.Abs(formatType - 3) < float.Epsilon)
|
||||
{
|
||||
glyphNames = EmptyArray<string>.Instance;
|
||||
glyphNames = [];
|
||||
}
|
||||
else
|
||||
{
|
||||
glyphNames = EmptyArray<string>.Instance;
|
||||
glyphNames = [];
|
||||
}
|
||||
|
||||
return glyphNames;
|
||||
|
@ -19,14 +19,14 @@
|
||||
/// </summary>
|
||||
internal class AcroFormFactory
|
||||
{
|
||||
private static readonly HashSet<NameToken> InheritableFields = new HashSet<NameToken>
|
||||
{
|
||||
private static readonly HashSet<NameToken> InheritableFields =
|
||||
[
|
||||
NameToken.Ft,
|
||||
NameToken.Ff,
|
||||
NameToken.V,
|
||||
NameToken.Dv,
|
||||
NameToken.Aa
|
||||
};
|
||||
];
|
||||
|
||||
private readonly IPdfTokenScanner tokenScanner;
|
||||
private readonly ILookupFilterProvider filterProvider;
|
||||
@ -338,16 +338,16 @@
|
||||
int? pageNumber,
|
||||
PdfRectangle? bounds)
|
||||
{
|
||||
var selectedOptions = EmptyArray<string>.Instance;
|
||||
var selectedOptions = Array.Empty<string>();
|
||||
if (fieldDictionary.TryGet(NameToken.V, out var valueToken))
|
||||
{
|
||||
if (DirectObjectFinder.TryGet(valueToken, tokenScanner, out StringToken valueString))
|
||||
{
|
||||
selectedOptions = new[] {valueString.Data};
|
||||
selectedOptions = [valueString.Data];
|
||||
}
|
||||
else if (DirectObjectFinder.TryGet(valueToken, tokenScanner, out HexToken valueHex))
|
||||
{
|
||||
selectedOptions = new[] {valueHex.Data};
|
||||
selectedOptions = [valueHex.Data];
|
||||
|
||||
}
|
||||
else if (DirectObjectFinder.TryGet(valueToken, tokenScanner, out ArrayToken valueArray))
|
||||
|
@ -121,7 +121,7 @@
|
||||
ModifiedDate = modifiedDate;
|
||||
Flags = flags;
|
||||
Border = border;
|
||||
QuadPoints = quadPoints ?? EmptyArray<QuadPointsQuadrilateral>.Instance;
|
||||
QuadPoints = quadPoints ?? Array.Empty<QuadPointsQuadrilateral>();
|
||||
Action = action;
|
||||
this.normalAppearanceStream = normalAppearanceStream;
|
||||
this.rollOverAppearanceStream = rollOverAppearanceStream;
|
||||
|
@ -1,6 +1,7 @@
|
||||
namespace UglyToad.PdfPig.Content
|
||||
{
|
||||
using Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Tokens;
|
||||
using UglyToad.PdfPig.Graphics;
|
||||
@ -92,7 +93,7 @@
|
||||
SubType = subType;
|
||||
AttributeOwners = attributeOwners;
|
||||
BoundingBox = boundingBox;
|
||||
Attached = attached ?? EmptyArray<NameToken>.Instance;
|
||||
Attached = attached ?? Array.Empty<NameToken>();
|
||||
}
|
||||
|
||||
private bool IsAttached(NameToken edge)
|
||||
|
@ -183,7 +183,7 @@
|
||||
|
||||
if (contentBytes == null || contentBytes.Count == 0)
|
||||
{
|
||||
operations = EmptyArray<IGraphicsStateOperation>.Instance;
|
||||
operations = Array.Empty<IGraphicsStateOperation>();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -59,7 +59,7 @@
|
||||
{
|
||||
pageNumber.Increment();
|
||||
|
||||
return new PageTreeNode(nodeDictionaryInput, referenceInput, true, pageNumber.PageCount).WithChildren(EmptyArray<PageTreeNode>.Instance);
|
||||
return new PageTreeNode(nodeDictionaryInput, referenceInput, true, pageNumber.PageCount).WithChildren(Array.Empty<PageTreeNode>());
|
||||
}
|
||||
|
||||
//If we got here, we have to iterate till we manage to exit
|
||||
@ -138,7 +138,7 @@
|
||||
throw new PdfDocumentFormatException($"Pages node in the document pages tree did not define a kids array: {current.nodeDictionary}.");
|
||||
}
|
||||
|
||||
kids = new ArrayToken(EmptyArray<IToken>.Instance);
|
||||
kids = new ArrayToken(Array.Empty<IToken>());
|
||||
}
|
||||
|
||||
foreach (var kid in kids.Data)
|
||||
@ -158,7 +158,7 @@
|
||||
if (isChildPage)
|
||||
{
|
||||
var kidPageNode =
|
||||
new PageTreeNode(kidDictionaryToken, kidRef.Data, true, pageNumber.PageCount).WithChildren(EmptyArray<PageTreeNode>.Instance);
|
||||
new PageTreeNode(kidDictionaryToken, kidRef.Data, true, pageNumber.PageCount).WithChildren(Array.Empty<PageTreeNode>());
|
||||
current.nodeChildren.Add(kidPageNode);
|
||||
}
|
||||
else
|
||||
|
@ -96,7 +96,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
Identifier = EmptyArray<IDataToken<string>>.Instance;
|
||||
Identifier = Array.Empty<IDataToken<string>>();
|
||||
}
|
||||
|
||||
if (dictionary.TryGet(NameToken.Encrypt, out var encryptionToken))
|
||||
|
@ -13,10 +13,10 @@
|
||||
using Util;
|
||||
using Util.JetBrains.Annotations;
|
||||
|
||||
internal class EncryptionHandler : IEncryptionHandler
|
||||
internal sealed class EncryptionHandler : IEncryptionHandler
|
||||
{
|
||||
private static readonly byte[] PaddingBytes =
|
||||
{
|
||||
[
|
||||
0x28, 0xBF, 0x4E, 0x5E,
|
||||
0x4E, 0x75, 0x8A, 0x41,
|
||||
0x64, 0x00, 0x4E, 0x56,
|
||||
@ -25,7 +25,7 @@
|
||||
0xD0, 0x68, 0x3E, 0x80,
|
||||
0x2F, 0x0C, 0xA9, 0xFE,
|
||||
0x64, 0x53, 0x69, 0x7A
|
||||
};
|
||||
];
|
||||
|
||||
private readonly HashSet<IndirectReference> previouslyDecrypted = new HashSet<IndirectReference>();
|
||||
|
||||
@ -43,7 +43,7 @@
|
||||
{
|
||||
this.encryptionDictionary = encryptionDictionary;
|
||||
|
||||
passwords = passwords ?? new[] { string.Empty };
|
||||
passwords ??= new[] { string.Empty };
|
||||
|
||||
if (!passwords.Contains(string.Empty))
|
||||
{
|
||||
@ -75,7 +75,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
documentIdBytes = EmptyArray<byte>.Instance;
|
||||
documentIdBytes = [];
|
||||
}
|
||||
|
||||
if (encryptionDictionary == null)
|
||||
@ -179,7 +179,7 @@
|
||||
|
||||
// 3. Pass the first element of the file identifier array to the hash function and finish the hash.
|
||||
UpdateMd5(md5, documentIdBytes);
|
||||
md5.TransformFinalBlock(EmptyArray<byte>.Instance, 0, 0);
|
||||
md5.TransformFinalBlock([], 0, 0);
|
||||
|
||||
var result = md5.Hash;
|
||||
|
||||
@ -597,18 +597,18 @@
|
||||
// with the value 0xFFFFFFFF to the MD5 hash function.
|
||||
if (revision >= 4 && !encryptionDictionary.EncryptMetadata)
|
||||
{
|
||||
UpdateMd5(md5, new byte[] { 0xFF, 0xFF, 0xFF, 0xFF });
|
||||
UpdateMd5(md5, [0xFF, 0xFF, 0xFF, 0xFF]);
|
||||
}
|
||||
|
||||
// 7. Do the following 50 times: Take the output from the previous MD5 hash and
|
||||
// pass the first n bytes of the output as input into a new MD5 hash,
|
||||
// where n is the number of bytes of the encryption key as defined by the value
|
||||
// of the encryption dictionary's Length entry.
|
||||
if (revision == 3 || revision == 4)
|
||||
if (revision is 3 or 4)
|
||||
{
|
||||
var n = length;
|
||||
|
||||
md5.TransformFinalBlock(EmptyArray<byte>.Instance, 0, 0);
|
||||
md5.TransformFinalBlock([], 0, 0);
|
||||
|
||||
var input = md5.Hash;
|
||||
using (var newMd5 = MD5.Create())
|
||||
@ -627,7 +627,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
md5.TransformFinalBlock(EmptyArray<byte>.Instance, 0, 0);
|
||||
md5.TransformFinalBlock([], 0, 0);
|
||||
|
||||
var result = new byte[length];
|
||||
|
||||
@ -722,7 +722,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
sha.TransformFinalBlock(EmptyArray<byte>.Instance, 0, 0);
|
||||
sha.TransformFinalBlock([], 0, 0);
|
||||
}
|
||||
|
||||
return sha.Hash;
|
||||
@ -781,7 +781,7 @@
|
||||
// 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)
|
||||
{
|
||||
vector = EmptyArray<byte>.Instance;
|
||||
vector = [];
|
||||
}
|
||||
else if (vector.Length > 0 && vector.Length < 48)
|
||||
{
|
||||
@ -802,7 +802,7 @@
|
||||
sha256.TransformBlock(password, 0, password.Length, null, 0);
|
||||
sha256.TransformBlock(salt, 0, salt.Length, null, 0);
|
||||
sha256.TransformBlock(vector, 0, vector.Length, null, 0);
|
||||
sha256.TransformFinalBlock(EmptyArray<byte>.Instance, 0, 0);
|
||||
sha256.TransformFinalBlock([], 0, 0);
|
||||
input = sha256.Hash;
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
internal class AsciiHexDecodeFilter : IFilter
|
||||
{
|
||||
private static readonly short[] ReverseHex =
|
||||
{
|
||||
[
|
||||
/* 0 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
/* 10 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
/* 20 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
@ -24,7 +24,7 @@
|
||||
/* 80 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
/* 90 */ -1, -1, -1, -1, -1, -1, -1, 10, 11, 12,
|
||||
/* 100 */ 13, 14, 15
|
||||
};
|
||||
];
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsSupported { get; } = true;
|
||||
|
@ -64,7 +64,7 @@
|
||||
var token = dictionary.GetObjectOrDefault(NameToken.Filter, NameToken.F);
|
||||
if (token == null)
|
||||
{
|
||||
return EmptyArray<IFilter>.Instance;
|
||||
return Array.Empty<IFilter>();
|
||||
}
|
||||
|
||||
switch (token)
|
||||
|
@ -37,7 +37,7 @@
|
||||
var token = dictionary.GetObjectOrDefault(NameToken.Filter, NameToken.F);
|
||||
if (token == null)
|
||||
{
|
||||
return EmptyArray<IFilter>.Instance;
|
||||
return Array.Empty<IFilter>();
|
||||
}
|
||||
|
||||
switch (token)
|
||||
|
@ -267,7 +267,7 @@
|
||||
|
||||
if (points.Count() < 3) return points;
|
||||
|
||||
double polarAngle(PdfPoint point1, PdfPoint point2)
|
||||
static double polarAngle(in PdfPoint point1, in PdfPoint point2)
|
||||
{
|
||||
// This is used for grouping, we could use Math.Round()
|
||||
return Math.Atan2(point2.Y - point1.Y, point2.X - point1.X) % Math.PI;
|
||||
@ -347,7 +347,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
double area(PdfPoint p1, PdfPoint p2, PdfPoint p3)
|
||||
static double area(in PdfPoint p1, PdfPoint p2, PdfPoint p3)
|
||||
{
|
||||
return Math.Abs((p2.X * p1.Y - p1.X * p2.Y) + (p3.X * p2.Y - p2.X * p3.Y) + (p1.X * p3.Y - p3.X * p1.Y)) / 2.0;
|
||||
}
|
||||
@ -881,12 +881,12 @@
|
||||
private static PdfPoint[] Intersect(BezierCurve bezierCurve, PdfPoint p1, PdfPoint p2)
|
||||
{
|
||||
var ts = IntersectT(bezierCurve, p1, p2);
|
||||
if (ts == null || ts.Length == 0) return EmptyArray<PdfPoint>.Instance;
|
||||
if (ts == null || ts.Length == 0) return [];
|
||||
|
||||
List<PdfPoint> points = new List<PdfPoint>();
|
||||
foreach (var t in ts)
|
||||
{
|
||||
PdfPoint point = new PdfPoint(
|
||||
var point = new PdfPoint(
|
||||
BezierCurve.ValueWithT(bezierCurve.StartPoint.X,
|
||||
bezierCurve.FirstControlPoint.X,
|
||||
bezierCurve.SecondControlPoint.X,
|
||||
@ -1247,9 +1247,9 @@
|
||||
double OneOverTwiceB = 1 / (2.0 * b);
|
||||
double x = (-c + sqrtDetQ) * OneOverTwiceB;
|
||||
double x0 = (-c - sqrtDetQ) * OneOverTwiceB;
|
||||
return new double[] { x, x0 };
|
||||
return [x, x0];
|
||||
}
|
||||
return EmptyArray<double>.Instance; // no real roots
|
||||
return []; // no real roots
|
||||
}
|
||||
|
||||
double aSquared = a * a;
|
||||
@ -1298,7 +1298,7 @@
|
||||
x3 = vietTrigonometricSolution(p, q, 2) - bOver3a;
|
||||
}
|
||||
|
||||
return new[] {x1, x2, x3};
|
||||
return [x1, x2, x3];
|
||||
}
|
||||
|
||||
internal static string ToSvg(this PdfSubpath p, double height)
|
||||
|
@ -973,7 +973,7 @@
|
||||
internal override double[] Process(params double[] values)
|
||||
{
|
||||
var (R, G, B) = colorSpaceTransformer.TransformToRGB((values[0], values[1], values[2]));
|
||||
return new double[] { R, G, B };
|
||||
return [R, G, B];
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
@ -98,7 +98,7 @@
|
||||
|
||||
var filters = filterProvider.GetNamedFilters(filterNames);
|
||||
|
||||
var decodeRaw = GetByKeys<ArrayToken>(NameToken.Decode, NameToken.D, false) ?? new ArrayToken(EmptyArray<IToken>.Instance);
|
||||
var decodeRaw = GetByKeys<ArrayToken>(NameToken.Decode, NameToken.D, false) ?? new ArrayToken(Array.Empty<IToken>());
|
||||
|
||||
var decode = decodeRaw.Data.OfType<NumericToken>().Select(x => x.Double).ToArray();
|
||||
|
||||
|
@ -1,11 +1,10 @@
|
||||
namespace UglyToad.PdfPig.Images
|
||||
{
|
||||
using Content;
|
||||
using Graphics.Colors;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content;
|
||||
using Core;
|
||||
using Graphics.Colors;
|
||||
|
||||
/// <summary>
|
||||
/// Utility for working with the bytes in <see cref="IPdfImage"/>s and converting according to their <see cref="ColorSpaceDetails"/>.s
|
||||
@ -22,7 +21,7 @@
|
||||
{
|
||||
if (decoded == null)
|
||||
{
|
||||
return EmptyArray<byte>.Instance;
|
||||
return [];
|
||||
}
|
||||
|
||||
if (details == null)
|
||||
|
@ -1,5 +1,6 @@
|
||||
namespace UglyToad.PdfPig.Parser
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Annotations;
|
||||
using Content;
|
||||
@ -42,11 +43,12 @@
|
||||
|
||||
if (operations == null || operations.Count == 0)
|
||||
{
|
||||
PageContent emptyContent = new PageContent(EmptyArray<IGraphicsStateOperation>.Instance,
|
||||
EmptyArray<Letter>.Instance,
|
||||
EmptyArray<PdfPath>.Instance,
|
||||
EmptyArray<Union<XObjectContentRecord, InlineImage>>.Instance,
|
||||
EmptyArray<MarkedContentElement>.Instance,
|
||||
PageContent emptyContent = new PageContent(
|
||||
Array.Empty<IGraphicsStateOperation>(),
|
||||
Array.Empty<Letter>(),
|
||||
Array.Empty<PdfPath>(),
|
||||
Array.Empty<Union<XObjectContentRecord, InlineImage>>(),
|
||||
Array.Empty<MarkedContentElement>(),
|
||||
PdfScanner,
|
||||
FilterProvider,
|
||||
ResourceStore);
|
||||
|
@ -65,7 +65,7 @@
|
||||
{
|
||||
firstCharacter = 0;
|
||||
lastCharacter = 0;
|
||||
widths = EmptyArray<double>.Instance;
|
||||
widths = [];
|
||||
}
|
||||
|
||||
if (!dictionary.TryGet(NameToken.FontDescriptor, out var _))
|
||||
|
@ -14,10 +14,7 @@
|
||||
|
||||
internal class PdfTokenScanner : IPdfTokenScanner
|
||||
{
|
||||
private static readonly byte[] EndstreamBytes =
|
||||
{
|
||||
(byte)'e', (byte)'n', (byte)'d', (byte)'s', (byte)'t', (byte)'r', (byte)'e', (byte)'a', (byte)'m'
|
||||
};
|
||||
private static ReadOnlySpan<byte> EndstreamBytes => "endstream"u8;
|
||||
|
||||
private static readonly Regex EndsWithNumberRegex = new Regex(@"(?<=^[^\s\d]+)\d+$");
|
||||
|
||||
@ -38,7 +35,7 @@
|
||||
/// Stores tokens encountered between obj - endobj markers for each <see cref="MoveNext"/> call.
|
||||
/// Cleared after each operation.
|
||||
/// </summary>
|
||||
private readonly List<IToken> readTokens = new List<IToken>();
|
||||
private readonly List<IToken> readTokens = [];
|
||||
|
||||
// Store the previous 3 tokens and their positions so we can backtrack to find object numbers and stream dictionaries.
|
||||
private readonly long[] previousTokenPositions = new long[3];
|
||||
|
@ -4,7 +4,8 @@
|
||||
using Core;
|
||||
using Filters;
|
||||
using Graphics.Colors;
|
||||
using Parser.Parts;
|
||||
using Parser.Parts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Tokenization.Scanner;
|
||||
@ -55,7 +56,7 @@
|
||||
var colorSpaceDetails = GetColorSpaceDetails(colorSpace, imageDictionary.Without(NameToken.Filter).Without(NameToken.F), scanner, resourceStore, filterProvider, true);
|
||||
|
||||
var decodeRaw = imageDictionary.GetObjectOrDefault(NameToken.Decode, NameToken.D) as ArrayToken
|
||||
?? new ArrayToken(EmptyArray<IToken>.Instance);
|
||||
?? new ArrayToken(Array.Empty<IToken>());
|
||||
var decode = decodeRaw.Data.OfType<NumericToken>().Select(x => x.Double).ToArray();
|
||||
|
||||
return IndexedColorSpaceDetails.Stencil(colorSpaceDetails, decode);
|
||||
|
@ -1,13 +1,12 @@
|
||||
namespace UglyToad.PdfPig.Util
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
|
||||
internal static class Diacritics
|
||||
{
|
||||
private static readonly HashSet<string> NonCombiningDiacritics = new HashSet<string>
|
||||
{
|
||||
private static readonly HashSet<string> NonCombiningDiacritics =
|
||||
[
|
||||
"´",
|
||||
"^",
|
||||
"ˆ",
|
||||
@ -19,7 +18,7 @@
|
||||
"˜",
|
||||
"∼",
|
||||
"¸"
|
||||
};
|
||||
];
|
||||
|
||||
public static bool IsPotentialStandaloneDiacritic(string value) => NonCombiningDiacritics.Contains(value);
|
||||
|
||||
|
@ -835,13 +835,13 @@ namespace UglyToad.PdfPig.Writer
|
||||
|
||||
private static ArrayToken RectangleToArray(PdfRectangle rectangle)
|
||||
{
|
||||
return new ArrayToken(new[]
|
||||
{
|
||||
return new ArrayToken(
|
||||
[
|
||||
new NumericToken(rectangle.BottomLeft.X),
|
||||
new NumericToken(rectangle.BottomLeft.Y),
|
||||
new NumericToken(rectangle.TopRight.X),
|
||||
new NumericToken(rectangle.TopRight.Y)
|
||||
});
|
||||
]);
|
||||
}
|
||||
|
||||
private IndirectReferenceToken[] CreateBookmarkTree(IReadOnlyList<BookmarkNode> nodes, Dictionary<int, IndirectReferenceToken> pageReferences, IndirectReferenceToken parent)
|
||||
@ -960,27 +960,27 @@ namespace UglyToad.PdfPig.Writer
|
||||
});
|
||||
|
||||
case ExplicitDestinationType.FitBoundingBox:
|
||||
return new ArrayToken(new IToken[]
|
||||
{
|
||||
return new ArrayToken(
|
||||
[
|
||||
page,
|
||||
NameToken.FitB,
|
||||
});
|
||||
]);
|
||||
|
||||
case ExplicitDestinationType.FitBoundingBoxHorizontally:
|
||||
return new ArrayToken(new IToken[]
|
||||
{
|
||||
return new ArrayToken(
|
||||
[
|
||||
page,
|
||||
NameToken.FitBH,
|
||||
new NumericToken(destination.Coordinates.Left ?? 0)
|
||||
});
|
||||
]);
|
||||
|
||||
case ExplicitDestinationType.FitBoundingBoxVertically:
|
||||
return new ArrayToken(new IToken[]
|
||||
{
|
||||
return new ArrayToken(
|
||||
[
|
||||
page,
|
||||
NameToken.FitBV,
|
||||
new NumericToken(destination.Coordinates.Left ?? 0)
|
||||
});
|
||||
]);
|
||||
|
||||
default:
|
||||
throw new NotSupportedException($"{destination.Type} is not a supported bookmark destination type.");
|
||||
|
@ -516,15 +516,15 @@
|
||||
outputStream.Write(StreamEnd, 0, StreamEnd.Length);
|
||||
}
|
||||
|
||||
private static readonly int[] EscapeNeeded = new int[]
|
||||
{
|
||||
private static readonly int[] EscapeNeeded =
|
||||
[
|
||||
'\r', '\n', '\t', '\b', '\f', '\\'
|
||||
};
|
||||
];
|
||||
|
||||
private static readonly int[] Escaped = new int[]
|
||||
{
|
||||
private static readonly int[] Escaped =
|
||||
[
|
||||
'r', 'n', 't', 'b', 'f', '\\'
|
||||
};
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Write string to the stream, with whitespace at the end
|
||||
|
@ -116,7 +116,7 @@
|
||||
var decodedBytes = supportsFilters ? new Lazy<IReadOnlyList<byte>>(() => streamToken.Decode(filterProvider, pdfScanner))
|
||||
: null;
|
||||
|
||||
var decode = EmptyArray<double>.Instance;
|
||||
var decode = Array.Empty<double>();
|
||||
|
||||
if (dictionary.TryGet(NameToken.Decode, pdfScanner, out ArrayToken decodeArrayToken))
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user