improve performance of the truetype name table parsing

This commit is contained in:
Eliot Jones
2019-12-25 10:52:00 +00:00
parent 815705494a
commit a4805ce97d
3 changed files with 22 additions and 27 deletions

View File

@@ -4,26 +4,24 @@
{
public TrueTypePlatformIdentifier PlatformId { get; }
public int PlatformEncodingId { get; }
public ushort PlatformEncodingId { get; }
public int LanguageId { get; }
public ushort LanguageId { get; }
public int NameId { get; }
public int Length { get; }
public int Offset { get; }
public ushort NameId { get; }
public string Value { get; }
public TrueTypeNameRecord(TrueTypePlatformIdentifier platformId, int platformEncodingId, int languageId, int nameId, int length, int offset, string value)
public TrueTypeNameRecord(TrueTypePlatformIdentifier platformId,
ushort platformEncodingId,
ushort languageId,
ushort nameId,
string value)
{
PlatformId = platformId;
PlatformEncodingId = platformEncodingId;
LanguageId = languageId;
NameId = nameId;
Length = length;
Offset = offset;
Value = value;
}

View File

@@ -111,17 +111,20 @@
{
public TrueTypePlatformIdentifier PlatformId { get; }
public int PlatformEncodingId { get; }
public ushort PlatformEncodingId { get; }
private int LanguageId { get; }
private ushort LanguageId { get; }
private int NameId { get; }
private ushort NameId { get; }
public int Length { get; }
public ushort Length { get; }
public int Offset { get; }
public ushort Offset { get; }
private NameRecordBuilder(int platformId, int platformEncodingId, int languageId, int nameId, int length, int offset)
private NameRecordBuilder(ushort platformId, ushort platformEncodingId, ushort languageId,
ushort nameId,
ushort length,
ushort offset)
{
PlatformId = (TrueTypePlatformIdentifier)platformId;
PlatformEncodingId = platformEncodingId;
@@ -134,7 +137,7 @@
public TrueTypeNameRecord ToNameRecord(string s)
{
return new TrueTypeNameRecord(PlatformId, PlatformEncodingId,
LanguageId, NameId, Length, Offset, s);
LanguageId, NameId, s);
}
public static NameRecordBuilder Read(TrueTypeDataBytes data)

View File

@@ -41,17 +41,11 @@
private void ReadBuffered(byte[] buffer, int length)
{
var numberRead = 0;
while (numberRead < length)
{
if (!inputBytes.MoveNext())
var read = inputBytes.Read(buffer, length);
if (read < length)
{
throw new EndOfStreamException($"Could not read a buffer of {length} bytes.");
}
buffer[numberRead] = inputBytes.CurrentByte;
numberRead++;
}
}
public byte ReadByte()