mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-08-20 09:21:57 +08:00
Make all structs readonly when possible
This commit is contained in:
parent
f5b4b84dea
commit
c6e2de1b0c
@ -5,7 +5,7 @@
|
||||
/// <summary>
|
||||
/// Used to uniquely identify and refer to objects in the PDF file.
|
||||
/// </summary>
|
||||
public struct IndirectReference
|
||||
public readonly struct IndirectReference
|
||||
{
|
||||
/// <summary>
|
||||
/// A positive integer object number.
|
||||
|
||||
@ -3,14 +3,14 @@
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// A line in a PDF file.
|
||||
/// A line in a PDF file.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// PDF coordinates are defined with the origin at the lower left (0, 0).
|
||||
/// The Y-axis extends vertically upwards and the X-axis horizontally to the right.
|
||||
/// Unless otherwise specified on a per-page basis, units in PDF space are equivalent to a typographic point (1/72 inch).
|
||||
/// </remarks>
|
||||
public struct PdfLine
|
||||
public readonly struct PdfLine
|
||||
{
|
||||
/// <summary>
|
||||
/// Length of the line.
|
||||
@ -71,7 +71,6 @@
|
||||
/// Returns a value indicating whether this <see cref="PdfLine"/> is equal to a specified <see cref="PdfLine"/> .
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is PdfLine line)
|
||||
@ -84,7 +83,6 @@
|
||||
/// <summary>
|
||||
/// Returns the hash code for this <see cref="PdfLine"/>.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return (Point1, Point2).GetHashCode();
|
||||
|
||||
@ -4,14 +4,14 @@
|
||||
using System.Globalization;
|
||||
|
||||
/// <summary>
|
||||
/// A point in a PDF file.
|
||||
/// A point in a PDF file.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// PDF coordinates are defined with the origin at the lower left (0, 0).
|
||||
/// The Y-axis extends vertically upwards and the X-axis horizontally to the right.
|
||||
/// Unless otherwise specified on a per-page basis, units in PDF space are equivalent to a typographic point (1/72 inch).
|
||||
/// </remarks>
|
||||
public struct PdfPoint
|
||||
public readonly struct PdfPoint
|
||||
{
|
||||
/// <summary>
|
||||
/// The origin of the coordinates system.
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/// <summary>
|
||||
/// This class will be used to signify a range. a(min) <= a* <= a(max)
|
||||
/// </summary>
|
||||
public struct PdfRange
|
||||
public readonly struct PdfRange
|
||||
{
|
||||
private readonly IReadOnlyList<double> rangeArray;
|
||||
private readonly int startingIndex;
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
using System.Globalization;
|
||||
|
||||
/// <summary>
|
||||
/// A rectangle in a PDF file.
|
||||
/// A rectangle in a PDF file.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// PDF coordinates are defined with the origin at the lower left (0, 0).
|
||||
@ -36,7 +36,7 @@
|
||||
/// <summary>
|
||||
/// Centroid point of the rectangle.
|
||||
/// </summary>
|
||||
public PdfPoint Centroid
|
||||
public readonly PdfPoint Centroid
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -86,13 +86,7 @@
|
||||
/// Rotation angle of the rectangle. Counterclockwise, in degrees.
|
||||
/// <para>-180 ≤ θ ≤ 180</para>
|
||||
/// </summary>
|
||||
public double Rotation
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetT() * 180 / Math.PI;
|
||||
}
|
||||
}
|
||||
public readonly double Rotation => GetT() * 180 / Math.PI;
|
||||
|
||||
/// <summary>
|
||||
/// Area of the rectangle.
|
||||
@ -102,22 +96,22 @@
|
||||
/// <summary>
|
||||
/// Left. This value is only valid if the rectangle is not rotated, check <see cref="Rotation"/>.
|
||||
/// </summary>
|
||||
public double Left => TopLeft.X < TopRight.X ? TopLeft.X : TopRight.X;
|
||||
public readonly double Left => TopLeft.X < TopRight.X ? TopLeft.X : TopRight.X;
|
||||
|
||||
/// <summary>
|
||||
/// Top. This value is only valid if the rectangle is not rotated, check <see cref="Rotation"/>.
|
||||
/// </summary>
|
||||
public double Top => TopLeft.Y > BottomLeft.Y ? TopLeft.Y : BottomLeft.Y;
|
||||
public readonly double Top => TopLeft.Y > BottomLeft.Y ? TopLeft.Y : BottomLeft.Y;
|
||||
|
||||
/// <summary>
|
||||
/// Right. This value is only valid if the rectangle is not rotated, check <see cref="Rotation"/>.
|
||||
/// </summary>
|
||||
public double Right => BottomRight.X > BottomLeft.X ? BottomRight.X : BottomLeft.X;
|
||||
public readonly double Right => BottomRight.X > BottomLeft.X ? BottomRight.X : BottomLeft.X;
|
||||
|
||||
/// <summary>
|
||||
/// Bottom. This value is only valid if the rectangle is not rotated, check <see cref="Rotation"/>.
|
||||
/// </summary>
|
||||
public double Bottom => BottomRight.Y < TopRight.Y ? BottomRight.Y : TopRight.Y;
|
||||
public readonly double Bottom => BottomRight.Y < TopRight.Y ? BottomRight.Y : TopRight.Y;
|
||||
|
||||
/// <summary>
|
||||
/// Create a new <see cref="PdfRectangle"/>.
|
||||
@ -171,7 +165,7 @@
|
||||
/// <param name="dx">The distance to move the rectangle in the x direction relative to its current location.</param>
|
||||
/// <param name="dy">The distance to move the rectangle in the y direction relative to its current location.</param>
|
||||
/// <returns>A new rectangle shifted on the y axis by the given delta value.</returns>
|
||||
public PdfRectangle Translate(double dx, double dy)
|
||||
public readonly PdfRectangle Translate(double dx, double dy)
|
||||
{
|
||||
return new PdfRectangle(TopLeft.Translate(dx, dy), TopRight.Translate(dx, dy),
|
||||
BottomLeft.Translate(dx, dy), BottomRight.Translate(dx, dy));
|
||||
@ -180,17 +174,15 @@
|
||||
/// <summary>
|
||||
/// -π ≤ θ ≤ π
|
||||
/// </summary>
|
||||
private double GetT()
|
||||
private readonly double GetT()
|
||||
{
|
||||
if (!BottomRight.Equals(BottomLeft))
|
||||
{
|
||||
return Math.Atan2(BottomRight.Y - BottomLeft.Y, BottomRight.X - BottomLeft.X);
|
||||
}
|
||||
else
|
||||
{
|
||||
// handle the case where both bottom points are identical
|
||||
return Math.Atan2(TopLeft.Y - BottomLeft.Y, TopLeft.X - BottomLeft.X) - Math.PI / 2;
|
||||
}
|
||||
|
||||
// handle the case where both bottom points are identical
|
||||
return Math.Atan2(TopLeft.Y - BottomLeft.Y, TopLeft.X - BottomLeft.X) - Math.PI / 2;
|
||||
}
|
||||
|
||||
private void GetWidthHeight()
|
||||
|
||||
@ -135,47 +135,47 @@
|
||||
switch (row)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
switch (col)
|
||||
{
|
||||
switch (col)
|
||||
{
|
||||
case 0:
|
||||
return A;
|
||||
case 1:
|
||||
return B;
|
||||
case 2:
|
||||
return row1;
|
||||
default:
|
||||
case 0:
|
||||
return A;
|
||||
case 1:
|
||||
return B;
|
||||
case 2:
|
||||
return row1;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException($"Trying to access {row}, {col} which was not in the value array.");
|
||||
}
|
||||
}
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
switch (col)
|
||||
{
|
||||
switch (col)
|
||||
{
|
||||
case 0:
|
||||
return C;
|
||||
case 1:
|
||||
return D;
|
||||
case 2:
|
||||
return row2;
|
||||
default:
|
||||
case 0:
|
||||
return C;
|
||||
case 1:
|
||||
return D;
|
||||
case 2:
|
||||
return row2;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException($"Trying to access {row}, {col} which was not in the value array.");
|
||||
}
|
||||
}
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
switch (col)
|
||||
{
|
||||
switch (col)
|
||||
{
|
||||
case 0:
|
||||
return E;
|
||||
case 1:
|
||||
return F;
|
||||
case 2:
|
||||
return row3;
|
||||
default:
|
||||
case 0:
|
||||
return E;
|
||||
case 1:
|
||||
return F;
|
||||
case 2:
|
||||
return row3;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException($"Trying to access {row}, {col} which was not in the value array.");
|
||||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException($"Trying to access {row}, {col} which was not in the value array.");
|
||||
}
|
||||
@ -404,7 +404,7 @@
|
||||
var r3 = (E * matrix.row1) + (F * matrix.row2) + (row3 * matrix.row3);
|
||||
|
||||
return new TransformationMatrix(a, b, r1,
|
||||
c, d, r2,
|
||||
c, d, r2,
|
||||
e, f, r3);
|
||||
}
|
||||
|
||||
|
||||
@ -575,7 +575,7 @@
|
||||
/// <summary>
|
||||
/// The bounds for the angle between two words for them to have a certain type of relationship.
|
||||
/// </summary>
|
||||
public struct AngleBounds
|
||||
public readonly struct AngleBounds
|
||||
{
|
||||
/// <summary>
|
||||
/// The lower bound in degrees.
|
||||
@ -646,7 +646,7 @@
|
||||
public AngleBounds WithinLineBounds { get; set; } = new AngleBounds(-30, 30);
|
||||
|
||||
/// <summary>
|
||||
/// Multiplier that gives the maximum euclidian distance between
|
||||
/// Multiplier that gives the maximum euclidean distance between
|
||||
/// words for building lines. Maximum distance will be this number times the within-line
|
||||
/// distance found by the analysis.
|
||||
/// <para>Default value is 3.</para>
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
/// <summary>
|
||||
/// A vector in the Adobe Font Metrics.
|
||||
/// </summary>
|
||||
public struct AdobeFontMetricsVector
|
||||
public readonly struct AdobeFontMetricsVector
|
||||
{
|
||||
/// <summary>
|
||||
/// The x component of the vector.
|
||||
|
||||
@ -196,7 +196,7 @@
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
public struct CommandIdentifier
|
||||
public readonly struct CommandIdentifier
|
||||
{
|
||||
public int CommandIndex { get; }
|
||||
|
||||
|
||||
@ -3,13 +3,13 @@
|
||||
/// <summary>
|
||||
/// The header table for the binary data of a Compact Font Format file.
|
||||
/// </summary>
|
||||
public struct CompactFontFormatHeader
|
||||
public readonly struct CompactFontFormatHeader
|
||||
{
|
||||
/// <summary>
|
||||
/// The major version of this font format. Starting at 1.
|
||||
/// </summary>
|
||||
public byte MajorVersion { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The minor version of this font format. Starting at 0. Indicates extensions to the format which
|
||||
/// are undetectable by readers which do not support them.
|
||||
|
||||
@ -397,7 +397,7 @@
|
||||
return 0;
|
||||
}
|
||||
|
||||
internal struct Range3
|
||||
internal readonly struct Range3
|
||||
{
|
||||
public int First { get; }
|
||||
|
||||
@ -415,7 +415,4 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -290,7 +290,7 @@
|
||||
return results;
|
||||
}
|
||||
|
||||
protected struct Operand
|
||||
protected readonly struct Operand
|
||||
{
|
||||
public int? Int { get; }
|
||||
|
||||
@ -309,13 +309,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
protected struct OperandKey
|
||||
protected readonly struct OperandKey
|
||||
{
|
||||
public byte Byte0 { get; }
|
||||
|
||||
public byte? Byte1 { get; }
|
||||
|
||||
public OperandKey(Byte byte0)
|
||||
public OperandKey(byte byte0)
|
||||
{
|
||||
Byte0 = byte0;
|
||||
Byte1 = null;
|
||||
|
||||
@ -60,7 +60,7 @@
|
||||
|
||||
public CidFontOperators CidFontOperators { get; set; } = new CidFontOperators();
|
||||
|
||||
public struct SizeAndOffset
|
||||
public readonly struct SizeAndOffset
|
||||
{
|
||||
public int Size { get; }
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
{
|
||||
using System;
|
||||
|
||||
internal struct SystemFontRecord
|
||||
internal readonly struct SystemFontRecord
|
||||
{
|
||||
public string Path { get; }
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ namespace UglyToad.PdfPig.Fonts.TrueType.Glyphs
|
||||
{
|
||||
using Core;
|
||||
|
||||
internal struct CompositeTransformMatrix3By2
|
||||
internal readonly struct CompositeTransformMatrix3By2
|
||||
{
|
||||
private readonly double r0c0;
|
||||
private readonly double r0c1;
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
{
|
||||
using UglyToad.PdfPig.Core;
|
||||
|
||||
internal struct GlyphPoint
|
||||
internal readonly struct GlyphPoint
|
||||
{
|
||||
public short X { get; }
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
/// <summary>
|
||||
/// The pair of horizontal metrics for an individual glyph.
|
||||
/// </summary>
|
||||
public struct HorizontalMetric
|
||||
public readonly struct HorizontalMetric
|
||||
{
|
||||
/// <summary>
|
||||
/// The advance width.
|
||||
|
||||
@ -125,7 +125,7 @@
|
||||
return windows ?? any;
|
||||
}
|
||||
|
||||
private struct NameRecordBuilder
|
||||
private readonly struct NameRecordBuilder
|
||||
{
|
||||
public TrueTypePlatformIdentifier PlatformId { get; }
|
||||
|
||||
|
||||
@ -418,7 +418,7 @@
|
||||
/// <summary>
|
||||
/// Marks a glyph index referenced by a composite glyph.
|
||||
/// </summary>
|
||||
private struct CompositeGlyphIndexReference
|
||||
private readonly struct CompositeGlyphIndexReference
|
||||
{
|
||||
/// <summary>
|
||||
/// The index of the glyph reference by this composite glyph.
|
||||
|
||||
@ -305,7 +305,7 @@
|
||||
/// <summary>
|
||||
/// Mapping from a glyph index in the old file to the new (subset) glyph index.
|
||||
/// </summary>
|
||||
public struct OldToNewGlyphIndex
|
||||
public readonly struct OldToNewGlyphIndex
|
||||
{
|
||||
/// <summary>
|
||||
/// Glyph index in the old input file.
|
||||
|
||||
@ -116,7 +116,7 @@ namespace UglyToad.PdfPig.Fonts.TrueType.Tables.CMapSubTables
|
||||
/// <summary>
|
||||
/// A contiguous segment which maps character to glyph codes in a Format 4 CMap sub-table.
|
||||
/// </summary>
|
||||
public struct Segment
|
||||
public readonly struct Segment
|
||||
{
|
||||
/// <summary>
|
||||
/// The start character code in the range.
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
public TrueTypeCMapPlatform PlatformId { get; }
|
||||
|
||||
public ushort EncodingId { get; }
|
||||
|
||||
|
||||
private HighByteMappingCMapTable(TrueTypeCMapPlatform platformId, ushort encodingId, IReadOnlyDictionary<int, int> characterCodesToGlyphIndices)
|
||||
{
|
||||
this.characterCodesToGlyphIndices = characterCodesToGlyphIndices ?? throw new ArgumentNullException(nameof(characterCodesToGlyphIndices));
|
||||
@ -47,7 +47,6 @@
|
||||
var value = data.ReadUnsignedShort();
|
||||
maximumSubHeaderIndex = Math.Max(maximumSubHeaderIndex, value / 8);
|
||||
subHeaderKeys[i] = value;
|
||||
|
||||
}
|
||||
|
||||
var subHeaderCount = maximumSubHeaderIndex + 1;
|
||||
@ -96,7 +95,7 @@
|
||||
return new HighByteMappingCMapTable(platformId, encodingId, characterCodeToGlyphId);
|
||||
}
|
||||
|
||||
public struct SubHeader
|
||||
public readonly struct SubHeader
|
||||
{
|
||||
/// <summary>
|
||||
/// First valid low byte for the sub header.
|
||||
|
||||
@ -390,7 +390,7 @@
|
||||
/// Stores the composite glyph information we read when initially scanning the glyph table.
|
||||
/// Once we have all composite glyphs we can start building them from simple glyphs.
|
||||
/// </summary>
|
||||
private struct TemporaryCompositeLocation
|
||||
private readonly struct TemporaryCompositeLocation
|
||||
{
|
||||
/// <summary>
|
||||
/// Stores the position after reading the contour count and bounds.
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
/// <summary>
|
||||
/// A kerning value for a pair of glyphs.
|
||||
/// </summary>
|
||||
public struct KernPair
|
||||
public readonly struct KernPair
|
||||
{
|
||||
/// <summary>
|
||||
/// The index of the left-hand glyph.
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
/// A table directory entry from the TrueType font file. Indicates the position of the corresponding table
|
||||
/// data in the TrueType font.
|
||||
/// </summary>
|
||||
public struct TrueTypeHeaderTable : IWriteable
|
||||
public readonly struct TrueTypeHeaderTable : IWriteable
|
||||
{
|
||||
#region RequiredTableTags
|
||||
/// <summary>
|
||||
|
||||
@ -135,7 +135,7 @@
|
||||
return match.Key.Width > 0;
|
||||
}
|
||||
|
||||
private struct WidthHeight
|
||||
private readonly struct WidthHeight
|
||||
{
|
||||
public double Width { get; }
|
||||
|
||||
|
||||
@ -61,11 +61,11 @@
|
||||
|
||||
this.objectOffsets = result;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The offset of a cross-reference table or stream in the document.
|
||||
/// </summary>
|
||||
public struct CrossReferenceOffset
|
||||
public readonly struct CrossReferenceOffset
|
||||
{
|
||||
/// <summary>
|
||||
/// The offset in bytes from the start of the document where the stream or table starts.
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
using System;
|
||||
using Core;
|
||||
|
||||
internal struct PdfVector
|
||||
internal readonly struct PdfVector
|
||||
{
|
||||
public double X { get; }
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/// <summary>
|
||||
/// A color space definition from a resource dictionary.
|
||||
/// </summary>
|
||||
internal struct ResourceColorSpace
|
||||
internal readonly struct ResourceColorSpace
|
||||
{
|
||||
public NameToken Name { get; }
|
||||
|
||||
|
||||
@ -7,9 +7,9 @@
|
||||
|
||||
/// <summary>
|
||||
/// The line dash pattern controls the pattern of dashes and gaps used to stroke paths.
|
||||
/// It is specified by a dash array and a dash phase.
|
||||
/// It is specified by a dash array and a dash phase.
|
||||
/// </summary>
|
||||
public struct LineDashPattern
|
||||
public readonly struct LineDashPattern
|
||||
{
|
||||
/// <summary>
|
||||
/// The distance into the dash pattern at which to start the dash.
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
///
|
||||
/// Defines a table subsection that starts with object 12 and has 16 entries (12-27).
|
||||
/// </example>
|
||||
internal struct TableSubsectionDefinition
|
||||
internal readonly struct TableSubsectionDefinition
|
||||
{
|
||||
private static readonly char[] Splitters = { ' ' };
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/// Defines the default position and displacement vector vertical components
|
||||
/// for fonts which have vertical writing modes.
|
||||
/// </summary>
|
||||
internal struct VerticalVectorComponents
|
||||
internal readonly struct VerticalVectorComponents
|
||||
{
|
||||
/// <summary>
|
||||
/// The default value of <see cref="VerticalVectorComponents"/> if not defined by a font.
|
||||
@ -22,7 +22,7 @@
|
||||
/// Where w0 is the width of the given glyph.
|
||||
/// </remarks>
|
||||
public double Position { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The vertical component of the displacement vector.
|
||||
/// </summary>
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
/// <summary>
|
||||
/// Maps from a single character code to its CID.
|
||||
/// </summary>
|
||||
internal struct CidCharacterMapping
|
||||
internal readonly struct CidCharacterMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// The character code.
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/// <summary>
|
||||
/// Associates the beginning and end of a range of character codes with the starting CID for the range.
|
||||
/// </summary>
|
||||
internal struct CidRange
|
||||
internal readonly struct CidRange
|
||||
{
|
||||
/// <summary>
|
||||
/// The beginning of the range of character codes.
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/// <summary>
|
||||
/// Used internally by the <see cref="PdfTokenScanner"/> when reading streams to store any occurrences of 'endobj' or 'endstream' observed.
|
||||
/// </summary>
|
||||
internal struct PossibleStreamEndLocation
|
||||
internal readonly struct PossibleStreamEndLocation
|
||||
{
|
||||
/// <summary>
|
||||
/// The offset at which the token started in the file.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user