From 03af28ed6d69c32b84baeffc5307e85b928c063f Mon Sep 17 00:00:00 2001 From: Eliot Jones Date: Fri, 10 May 2019 20:02:29 +0100 Subject: [PATCH] fix bug with compact font format font matrix reading and where endstream token is missed if immediately following 'e' --- src/UglyToad.PdfPig.Tests/Integration/LocalTests.cs | 2 +- .../CompactFontFormatTopLevelDictionaryReader.cs | 12 +++++++++--- .../Tokenization/Scanner/PdfTokenScanner.cs | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/UglyToad.PdfPig.Tests/Integration/LocalTests.cs b/src/UglyToad.PdfPig.Tests/Integration/LocalTests.cs index 39a61e21..f8894828 100644 --- a/src/UglyToad.PdfPig.Tests/Integration/LocalTests.cs +++ b/src/UglyToad.PdfPig.Tests/Integration/LocalTests.cs @@ -13,7 +13,7 @@ //[Fact] //public void Tests() //{ - // var files = new[] { @"C:\Users\eliot\Downloads\Encrypted1.pdf" }; + // var files = Directory.GetFiles(@"C:\temp\pdfs"); // foreach (var file in files) // { diff --git a/src/UglyToad.PdfPig/Fonts/CompactFontFormat/Dictionaries/CompactFontFormatTopLevelDictionaryReader.cs b/src/UglyToad.PdfPig/Fonts/CompactFontFormat/Dictionaries/CompactFontFormatTopLevelDictionaryReader.cs index 25cf18d6..41cb323c 100644 --- a/src/UglyToad.PdfPig/Fonts/CompactFontFormat/Dictionaries/CompactFontFormatTopLevelDictionaryReader.cs +++ b/src/UglyToad.PdfPig/Fonts/CompactFontFormat/Dictionaries/CompactFontFormatTopLevelDictionaryReader.cs @@ -71,12 +71,18 @@ { var array = ToArray(operands); - if (array.Length != 4) + if (array.Length == 4) + { + dictionary.FontMatrix = TransformationMatrix.FromArray(array); + } + else if (array.Length == 6) + { + dictionary.FontMatrix = TransformationMatrix.FromArray(array); + } + else { throw new InvalidOperationException($"Expected four values for the font matrix, instead got: {array}."); } - - dictionary.FontMatrix = TransformationMatrix.FromArray(array); } break; case 8: diff --git a/src/UglyToad.PdfPig/Tokenization/Scanner/PdfTokenScanner.cs b/src/UglyToad.PdfPig/Tokenization/Scanner/PdfTokenScanner.cs index c0fcfb19..73f45b00 100644 --- a/src/UglyToad.PdfPig/Tokenization/Scanner/PdfTokenScanner.cs +++ b/src/UglyToad.PdfPig/Tokenization/Scanner/PdfTokenScanner.cs @@ -304,7 +304,7 @@ endStreamPosition = 0; endObjPosition = 0; - commonPartPosition = 0; + commonPartPosition = (inputBytes.CurrentByte == commonPart[0]) ? 1 : 0; } binaryWrite.Write(inputBytes.CurrentByte);