mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-11-28 17:47:12 +08:00
performance tweak and test case for #334
This commit is contained in:
@@ -860,8 +860,8 @@ namespace UglyToad.PdfPig.Fonts.CompactFontFormat.CharStrings
|
||||
return new Type2CharStrings.CommandSequence.CommandIdentifier(precedingValues.Count, false, 255);
|
||||
}
|
||||
|
||||
private static int CalculatePrecedingHintBytes(IReadOnlyList<float> precedingValues,
|
||||
IReadOnlyList<Type2CharStrings.CommandSequence.CommandIdentifier> precedingCommands)
|
||||
private static int CalculatePrecedingHintBytes(List<float> precedingValues,
|
||||
List<Type2CharStrings.CommandSequence.CommandIdentifier> precedingCommands)
|
||||
{
|
||||
int SafeStemCount(int counts)
|
||||
{
|
||||
@@ -873,7 +873,7 @@ namespace UglyToad.PdfPig.Fonts.CompactFontFormat.CharStrings
|
||||
|
||||
return (counts - 1) / 2;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* The hintmask operator is followed by one or more data bytes that specify the stem hints which are to be active for the
|
||||
* subsequent path construction. The number of data bytes must be exactly the number needed to represent the number of
|
||||
@@ -891,8 +891,14 @@ namespace UglyToad.PdfPig.Fonts.CompactFontFormat.CharStrings
|
||||
precedingNumbers++;
|
||||
}
|
||||
|
||||
foreach (var identifier in precedingCommands.Where(x => x.CommandIndex == i + 1))
|
||||
for (var j = 0; j < precedingCommands.Count; j++)
|
||||
{
|
||||
var identifier = precedingCommands[j];
|
||||
if (identifier.CommandIndex != i + 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!identifier.IsMultiByteCommand
|
||||
&& (identifier.CommandId == HintmaskByte || identifier.CommandId == CntrmaskByte)
|
||||
&& !hasEncounteredInitialHintMask)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
using Logging;
|
||||
using PdfPig.Core;
|
||||
using PdfPig.Parser.FileStructure;
|
||||
using PdfPig.Tokenization.Scanner;
|
||||
using Xunit;
|
||||
|
||||
public class FileHeaderParserTests
|
||||
@@ -137,5 +138,17 @@ three %PDF-1.6");
|
||||
Assert.Equal(0, scanner.CurrentPosition);
|
||||
Assert.Equal(0, result.OffsetInFile);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Issue334()
|
||||
{
|
||||
var input = OtherEncodings.StringAsLatin1Bytes("%PDF-1.7\r\n%âãÏÓ\r\n1 0 obj\r\n<</Lang(en-US)>>\r\nendobj");
|
||||
|
||||
var scanner = new CoreTokenScanner(new ByteArrayInputBytes(input), ScannerScope.None);
|
||||
|
||||
var result = FileHeaderParser.Parse(scanner, false, log);
|
||||
|
||||
Assert.Equal(1.7m, result.Version);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user