示例#1
0
        public void VersionFormatInvalidLenientDefaults1Point4()
        {
            var scanner = StringBytesTestConverter.Scanner("%Pdeef-1.69");

            var result = FileHeaderParser.Parse(scanner, true, log);

            Assert.Equal(1.4m, result.Version);
        }
示例#2
0
        public void ParsingResetsPosition()
        {
            var scanner = StringBytesTestConverter.Scanner(@"%FDF-1.6");

            FileHeaderParser.Parse(scanner, false, log);

            Assert.Equal(0, scanner.CurrentPosition);
        }
示例#3
0
        public void VersionFormatInvalidNotLenientThrows()
        {
            var scanner = StringBytesTestConverter.Scanner("%Pdeef-1.69");

            Action action = () => FileHeaderParser.Parse(scanner, false, log);

            Assert.Throws <PdfDocumentFormatException>(action);
        }
示例#4
0
        public void EmptyInputThrows()
        {
            var scanner = StringBytesTestConverter.Scanner(string.Empty);

            Action action = () => FileHeaderParser.Parse(scanner, false, log);

            Assert.Throws <PdfDocumentFormatException>(action);
        }
示例#5
0
        public void JunkThenEndThrows()
        {
            var scanner = StringBytesTestConverter.Scanner(@"one two");

            Action action = () => FileHeaderParser.Parse(scanner, true, log);

            Assert.Throws <PdfDocumentFormatException>(action);
        }
示例#6
0
        public void ParsingResetsPosition()
        {
            var scanner = StringBytesTestConverter.Scanner(@"%FDF-1.6");

            var result = FileHeaderParser.Parse(scanner.scanner, scanner.bytes, false, log);

            Assert.Equal(0, scanner.scanner.CurrentPosition);
            Assert.Equal(0, result.OffsetInFile);
        }
示例#7
0
        public void HeaderPrecededByTooMuchJunkThrows()
        {
            var scanner = StringBytesTestConverter.Scanner(@"one two
three %PDF-1.6");

            Action action = () => FileHeaderParser.Parse(scanner, true, log);

            Assert.Throws <PdfDocumentFormatException>(action);
        }
示例#8
0
        public void HeaderPrecededByJunkNonLenientThrows()
        {
            var scanner = StringBytesTestConverter.Scanner(@"one    
    %PDF-1.2");

            Action action = () => FileHeaderParser.Parse(scanner, false, log);

            Assert.Throws <PdfDocumentFormatException>(action);
        }
示例#9
0
        public void HeaderPrecededByJunkLenientReads()
        {
            var scanner = StringBytesTestConverter.Scanner(@"one    
    %PDF-1.7");

            var result = FileHeaderParser.Parse(scanner, true, log);

            Assert.Equal(1.7m, result.Version);
        }
示例#10
0
        public void HeaderPrecededByJunkDoesNotThrow()
        {
            var scanner = StringBytesTestConverter.Scanner(@"one two
three %PDF-1.6");

            var result = FileHeaderParser.Parse(scanner, true, log);

            Assert.Equal(1.6m, result.Version);
            Assert.Equal(15, result.OffsetInFile);
        }
示例#11
0
        public void HeaderPrecededByJunkLenientReads()
        {
            var scanner = StringBytesTestConverter.Scanner(@"one    
    %PDF-1.7");

            var result = FileHeaderParser.Parse(scanner.scanner, scanner.bytes, true, log);

            Assert.Equal(1.7m, result.Version);
            Assert.Equal(TestEnvironment.IsUnixPlatform ? 12 : 13, result.OffsetInFile);
        }
示例#12
0
        public void ReadsConformingHeader(string format)
        {
            var input = $"%{format}\nany garbage";

            var scanner = StringBytesTestConverter.Scanner(input);

            var result = FileHeaderParser.Parse(scanner, false, log);

            Assert.Equal(format, result.VersionString);
        }
示例#13
0
        public void HeaderPrecededByJunkNonLenientDoesNotThrow()
        {
            var scanner = StringBytesTestConverter.Scanner(@"one    
    %PDF-1.2");

            var result = FileHeaderParser.Parse(scanner, false, log);

            Assert.Equal(1.2m, result.Version);
            Assert.Equal(13, result.OffsetInFile);
        }
示例#14
0
        public void ReadsHeaderWithBlankSpaceBefore()
        {
            const string input = @"     

%PDF-1.2";

            var scanner = StringBytesTestConverter.Scanner(input);

            var result = FileHeaderParser.Parse(scanner, false, log);

            Assert.Equal(1.2m, result.Version);
        }
示例#15
0
        public void ReadsHeaderWithBlankSpaceBefore()
        {
            const string input = @"     

%PDF-1.2";

            var scanner = StringBytesTestConverter.Scanner(input);

            var result = FileHeaderParser.Parse(scanner.scanner, scanner.bytes, false, log);

            Assert.Equal(1.2m, result.Version);
            Assert.Equal(TestEnvironment.IsUnixPlatform ? 7 : 9, result.OffsetInFile);
        }
示例#16
0
        public void CanParseWithHex()
        {
            var input = StringBytesTestConverter.Scanner("<8141> <8147> <8141>");

            var builder = new CharacterMapBuilder();

            parser.Parse(new NumericToken(1), input, builder, false);

            Assert.Equal(7, builder.BaseFontCharacterMap.Count);

            Assert.Equal("腁", builder.BaseFontCharacterMap[33089]);
            Assert.Equal(char.ConvertFromUtf32(33090), builder.BaseFontCharacterMap[33090]);
        }
示例#17
0
        public void CanParseWithArray()
        {
            var input = StringBytesTestConverter.Scanner("<0003> <0004> [<0020> <0041>]");

            var builder = new CharacterMapBuilder();

            parser.Parse(new NumericToken(1), input, builder, false);

            Assert.Equal(2, builder.BaseFontCharacterMap.Count);

            Assert.Equal(" ", builder.BaseFontCharacterMap[3]);
            Assert.Equal("A", builder.BaseFontCharacterMap[4]);
        }
示例#18
0
        public void CanParseTwoRowsWithDifferentFormat()
        {
            var input = StringBytesTestConverter.Scanner(@"<0019> <001B> <3C>
<0001> <0003> [/happy /feet /penguin]");

            var builder = new CharacterMapBuilder();

            parser.Parse(new NumericToken(2), input, builder, false);

            Assert.Equal(6, builder.BaseFontCharacterMap.Count);

            Assert.Equal("happy", builder.BaseFontCharacterMap[1]);
            Assert.Equal("feet", builder.BaseFontCharacterMap[2]);
            Assert.Equal("penguin", builder.BaseFontCharacterMap[3]);

            Assert.Equal("<", builder.BaseFontCharacterMap[25]);
        }
        public void ParseNewDefaultTable()
        {
            var input = StringBytesTestConverter.Scanner(@"one xref
0 6
0000000003 65535 f
0000000090 00000 n
0000000081 00000 n
0000000000 00007 f
0000000331 00000 n
0000000409 00000 n

trailer
<< >>");

            var result = parser.Parse(input, 4, false);

            Assert.Equal(4, result.ObjectOffsets.Count);
        }
示例#20
0
        public void Issue443()
        {
            const string hex =
                @"00 0F 4A 43 42 31 33 36 36 31 32 32 37 2E 70 64 66 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 50 44 46 20 43 41 52 4F 01 00 FF FF FF FF 00 00 00 00 00 04 DF 28 00 00 00 00 AF 51 7E 82 AF 52 D7 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 81 81 03 0D 00 00 25 50 44 46 2D 31 2E 31 0A 25 E2 E3 CF D3 0D 0A 31 20 30 20 6F 62 6A";

            var bytes = hex.Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(x => HexToken.Convert(x[0], x[1]));

            var str = OtherEncodings.BytesAsLatin1String(bytes.ToArray());

            var scanner = StringBytesTestConverter.Scanner(str);

            var result = FileHeaderParser.Parse(scanner.scanner, scanner.bytes, false, log);

            Assert.Equal(0, scanner.scanner.CurrentPosition);
            Assert.Equal(128, result.OffsetInFile);
            Assert.Equal(1.1m, result.Version);
            Assert.Equal("PDF-1.1", result.VersionString);
        }
 private static CoreTokenScanner GetReader(string input)
 {
     return(StringBytesTestConverter.Scanner(input));
 }