99namespace SixLabors . Fonts ;
1010
1111/// <summary>
12- /// BinaryReader using big-endian encoding .
12+ /// A binary reader that reads in big-endian format .
1313/// </summary>
1414[ DebuggerDisplay ( "Start: {StartOfStream}, Position: {BaseStream.Position}" ) ]
1515internal sealed class BigEndianBinaryReader : IDisposable
@@ -19,6 +19,7 @@ internal sealed class BigEndianBinaryReader : IDisposable
1919 /// </summary>
2020 private readonly byte [ ] buffer = new byte [ 16 ] ;
2121
22+ private readonly long startOfStream ;
2223 private readonly bool leaveOpen ;
2324
2425 /// <summary>
@@ -31,12 +32,10 @@ internal sealed class BigEndianBinaryReader : IDisposable
3132 public BigEndianBinaryReader ( Stream stream , bool leaveOpen )
3233 {
3334 this . BaseStream = stream ;
34- this . StartOfStream = stream . Position ;
35+ this . startOfStream = stream . Position ;
3536 this . leaveOpen = leaveOpen ;
3637 }
3738
38- private long StartOfStream { get ; }
39-
4039 /// <summary>
4140 /// Gets the underlying stream of the EndianBinaryReader.
4241 /// </summary>
@@ -52,7 +51,7 @@ public void Seek(long offset, SeekOrigin origin)
5251 // If SeekOrigin.Begin, the offset will be set to the start of stream position.
5352 if ( origin == SeekOrigin . Begin )
5453 {
55- offset += this . StartOfStream ;
54+ offset += this . startOfStream ;
5655 }
5756
5857 this . BaseStream . Seek ( offset , origin ) ;
@@ -68,6 +67,13 @@ public byte ReadByte()
6867 return this . buffer [ 0 ] ;
6968 }
7069
70+ public TEnum ReadByte < TEnum > ( )
71+ where TEnum : struct , Enum
72+ {
73+ TryConvert ( this . ReadByte ( ) , out TEnum value ) ;
74+ return value ;
75+ }
76+
7177 /// <summary>
7278 /// Reads a single signed byte from the stream.
7379 /// </summary>
@@ -78,9 +84,9 @@ public sbyte ReadSByte()
7884 return unchecked ( ( sbyte ) this . buffer [ 0 ] ) ;
7985 }
8086
81- public float ReadF2dot14 ( )
87+ public float ReadF2Dot14 ( )
8288 {
83- const float f2Dot14ToFloat = 16384.0f ;
89+ const float f2Dot14ToFloat = 16384F ;
8490 return this . ReadInt16 ( ) / f2Dot14ToFloat ;
8591 }
8692
@@ -103,28 +109,35 @@ public TEnum ReadInt16<TEnum>()
103109 return value ;
104110 }
105111
112+ /// <summary>
113+ /// Reads a signed 16-bit integer in big-endian order, representing an FWORD value from the current stream position.
114+ /// </summary>
115+ /// <returns>A 16-bit signed integer read from the stream, interpreted as an FWORD value.</returns>
106116 public short ReadFWORD ( ) => this . ReadInt16 ( ) ;
107117
108118 public short [ ] ReadFWORDArray ( int length ) => this . ReadInt16Array ( length ) ;
109119
120+ /// <summary>
121+ /// Reads an unsigned 16-bit integer (UFWORD) from the current stream and advances the position by two bytes.
122+ /// </summary>
123+ /// <returns>An unsigned 16-bit integer read from the current stream.</returns>
110124 public ushort ReadUFWORD ( ) => this . ReadUInt16 ( ) ;
111125
112126 /// <summary>
113- /// Reads a fixed 32-bit value from the stream.
114- /// 4 bytes are read .
127+ /// Reads a 32-bit fixed-point number from the underlying data source and returns it as a single-precision
128+ /// floating-point value .
115129 /// </summary>
116- /// <returns>The 32-bit value read.</returns>
130+ /// <returns>A <see cref="float"/> representing the fixed-point value read from the data source .</returns>
117131 public float ReadFixed ( )
118132 {
119133 this . ReadInternal ( this . buffer , 4 ) ;
120134 return BinaryPrimitives . ReadInt32BigEndian ( this . buffer ) / 65536F ;
121135 }
122136
123137 /// <summary>
124- /// Reads a 32-bit signed integer from the stream, using the bit converter
125- /// for this reader. 4 bytes are read.
138+ /// Reads a 4-byte signed integer from the current stream.
126139 /// </summary>
127- /// <returns>The 32-bit integer read</returns>
140+ /// <returns>The 32-bit signed integer read from the stream. </returns>
128141 public int ReadInt32 ( )
129142 {
130143 this . ReadInternal ( this . buffer , 4 ) ;
@@ -273,12 +286,14 @@ public byte ReadUInt8()
273286 /// for this reader. 3 bytes are read.
274287 /// </summary>
275288 /// <returns>The 24-bit unsigned integer read.</returns>
276- public int ReadUInt24 ( )
289+ public uint ReadUInt24 ( )
277290 {
278291 byte highByte = this . ReadByte ( ) ;
279- return ( highByte << 16 ) | this . ReadUInt16 ( ) ;
292+ return ( uint ) ( ( highByte << 16 ) | this . ReadUInt16 ( ) ) ;
280293 }
281294
295+ public uint ReadOffset24 ( ) => this . ReadUInt24 ( ) ;
296+
282297 /// <summary>
283298 /// Reads a 32-bit unsigned integer from the stream, using the bit converter
284299 /// for this reader. 4 bytes are read.
0 commit comments