mirror of
https://github.com/UglyToad/PdfPig.git
synced 2026-03-10 00:23:29 +08:00
Compare commits
6 Commits
v0.1.6
...
xref-strea
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b5d90d1725 | ||
|
|
559f3af5f3 | ||
|
|
5eed9fd1bc | ||
|
|
ddab53e456 | ||
|
|
4e490d63be | ||
|
|
03692cf42f |
@@ -67,7 +67,7 @@
|
||||
{
|
||||
return new PdfPoint(X + dx, Y);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="PdfPoint"/> which is the current point moved in the y direction relative to its current position by a value.
|
||||
/// </summary>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net45;net451;net452;net46;net461;net462;net47;net6.0</TargetFrameworks>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Version>0.1.6</Version>
|
||||
<Version>0.1.7-alpha-001</Version>
|
||||
<IsTestProject>False</IsTestProject>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net45;net451;net452;net46;net461;net462;net47;net6.0</TargetFrameworks>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Version>0.1.6</Version>
|
||||
<Version>0.1.7-alpha-001</Version>
|
||||
<IsTestProject>False</IsTestProject>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net45;net451;net452;net46;net461;net462;net47;net6.0</TargetFrameworks>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Version>0.1.6</Version>
|
||||
<Version>0.1.7-alpha-001</Version>
|
||||
<IsTestProject>False</IsTestProject>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
|
||||
@@ -528,6 +528,52 @@
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public static IEnumerable<object[]> Issue458Data => new[]
|
||||
{
|
||||
new object[]
|
||||
{
|
||||
new PdfPoint[]
|
||||
{
|
||||
new PdfPoint(134.74199999999985, 1611.657),
|
||||
new PdfPoint(277.58043749999985, 1611.657),
|
||||
new PdfPoint(314.74199999999985, 1611.657),
|
||||
new PdfPoint(507.0248828124999, 1611.657),
|
||||
new PdfPoint(545.1419999999998, 1611.657),
|
||||
new PdfPoint(632.9658281249997, 1611.657),
|
||||
new PdfPoint(668.5709999999998, 1611.657),
|
||||
new PdfPoint(831.3395078125002, 1611.657),
|
||||
new PdfPoint(868.1139999999998, 1611.657),
|
||||
new PdfPoint(892.8907187499999, 1611.657),
|
||||
new PdfPoint(1010.0569999999999, 1611.6569999999997),
|
||||
new PdfPoint(1046.2174003906248, 1611.7654812011715),
|
||||
new PdfPoint(1010.0569999999999, 1611.657),
|
||||
new PdfPoint(1046.2174003906248, 1611.7654812011717),
|
||||
new PdfPoint(1085.145, 1611.8822639999996),
|
||||
new PdfPoint(1255.484941406251, 1612.3932838242179),
|
||||
new PdfPoint(1301.144, 1612.5302609999994),
|
||||
new PdfPoint(1359.0006406250002, 1612.7038309218747),
|
||||
new PdfPoint(1301.144, 1612.5302609999997),
|
||||
new PdfPoint(1359.0006406250002, 1612.703830921875),
|
||||
new PdfPoint(1400.915, 1612.8295739999996),
|
||||
new PdfPoint(1505.379062499999, 1613.1429661874993),
|
||||
new PdfPoint(1400.915, 1612.8295739999999),
|
||||
new PdfPoint(1505.379062499999, 1613.1429661874995),
|
||||
new PdfPoint(1543.886, 1613.2584869999996),
|
||||
new PdfPoint(1600.9401015625003, 1613.4296493046872),
|
||||
new PdfPoint(1641.597, 1613.5516199999997),
|
||||
new PdfPoint(1764.5577421874998, 1613.9205022265612),
|
||||
new PdfPoint(1641.597, 1613.55162),
|
||||
new PdfPoint(1764.5577421874998, 1613.9205022265614)
|
||||
},
|
||||
new PdfPoint[]
|
||||
{
|
||||
new PdfPoint(134.74199999999985, 1611.657),
|
||||
new PdfPoint(1010.0569999999999, 1611.6569999999997),
|
||||
new PdfPoint(1764.5577421874998, 1613.9205022265614),
|
||||
}
|
||||
}
|
||||
};
|
||||
#endregion
|
||||
|
||||
[Fact]
|
||||
@@ -570,7 +616,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(MinimumAreaRectangleData))]
|
||||
public void MinimumAreaRectangle(PdfPoint[] points, PdfPoint[] expected)
|
||||
@@ -585,5 +630,51 @@
|
||||
Assert.Equal(expected[i], mar[i], PointComparer);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Issue458Data))]
|
||||
public void Issue458(PdfPoint[] points, PdfPoint[] expected)
|
||||
{
|
||||
/*
|
||||
* https://github.com/UglyToad/PdfPig/issues/458
|
||||
* An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in System.Linq.dll: 'Specified argument was out of the range of valid values.'
|
||||
* at System.Linq.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument)
|
||||
* at System.Linq.Enumerable.ElementAt[TSource](IEnumerable`1 source, Int32 index)
|
||||
*/
|
||||
|
||||
var result = GeometryExtensions.GrahamScan(points);
|
||||
|
||||
// Data is noisy so we just check it does not throw an exception
|
||||
// and that key points are present (other points might be present,
|
||||
// e.g. 'not enough equal dupplicates' or 'not collinear enough' points)
|
||||
foreach (var point in expected)
|
||||
{
|
||||
Assert.Contains(point, result);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Issue458Data))]
|
||||
public void Issue458_Inv(PdfPoint[] points, PdfPoint[] expected)
|
||||
{
|
||||
/*
|
||||
* https://github.com/UglyToad/PdfPig/issues/458
|
||||
* An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in System.Linq.dll: 'Specified argument was out of the range of valid values.'
|
||||
* at System.Linq.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument)
|
||||
* at System.Linq.Enumerable.ElementAt[TSource](IEnumerable`1 source, Int32 index)
|
||||
*/
|
||||
var pointsInv = points.Select(p => new PdfPoint(p.Y, p.X)).ToArray();
|
||||
var expectedInv = expected.Select(p => new PdfPoint(p.Y, p.X)).ToArray();
|
||||
|
||||
var result = GeometryExtensions.GrahamScan(pointsInv);
|
||||
|
||||
// Data is noisy so we just check it does not throw an exception
|
||||
// and that key points are present (other points might be present,
|
||||
// e.g. 'not enough equal dupplicates' or 'not collinear enough' points)
|
||||
foreach (var point in expectedInv)
|
||||
{
|
||||
Assert.Contains(point, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net45;net451;net452;net46;net461;net462;net47;net6.0</TargetFrameworks>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Version>0.1.6</Version>
|
||||
<Version>0.1.7-alpha-001</Version>
|
||||
<IsTestProject>False</IsTestProject>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net45;net451;net452;net46;net461;net462;net47;net6.0</TargetFrameworks>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Version>0.1.6</Version>
|
||||
<Version>0.1.7-alpha-001</Version>
|
||||
<IsTestProject>False</IsTestProject>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
namespace UglyToad.PdfPig.Encryption
|
||||
{
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
@@ -29,11 +28,6 @@
|
||||
|
||||
var buffer = new byte[256];
|
||||
|
||||
if (data.Length > 256)
|
||||
{
|
||||
Debugger.Break();
|
||||
}
|
||||
|
||||
using (var decryptor = rijndael.CreateDecryptor(rijndael.Key, rijndael.IV))
|
||||
using (var input = new MemoryStream(data))
|
||||
using (var output = new MemoryStream())
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
namespace UglyToad.PdfPig.Filters
|
||||
{
|
||||
using Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Core;
|
||||
using Tokens;
|
||||
using UglyToad.PdfPig.Util;
|
||||
using Util;
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
|
||||
@@ -269,11 +269,12 @@
|
||||
|
||||
double polarAngle(PdfPoint point1, PdfPoint point2)
|
||||
{
|
||||
// This is used for grouping, we could use Math.Round()
|
||||
return Math.Atan2(point2.Y - point1.Y, point2.X - point1.X) % Math.PI;
|
||||
}
|
||||
|
||||
Stack<PdfPoint> stack = new Stack<PdfPoint>();
|
||||
var sortedPoints = points.OrderBy(p => p.Y).ThenBy(p => p.X).ToList();
|
||||
var stack = new Stack<PdfPoint>();
|
||||
var sortedPoints = points.OrderBy(p => p.X).ThenBy(p => p.Y).ToList();
|
||||
var P0 = sortedPoints[0];
|
||||
var groups = sortedPoints.Skip(1).GroupBy(p => polarAngle(P0, p)).OrderBy(g => g.Key);
|
||||
|
||||
@@ -309,7 +310,7 @@
|
||||
for (int i = 2; i < sortedPoints.Count; i++)
|
||||
{
|
||||
var point = sortedPoints[i];
|
||||
while (!ccw(stack.ElementAt(1), stack.Peek(), point))
|
||||
while (stack.Count > 1 && !ccw(stack.ElementAt(1), stack.Peek(), point))
|
||||
{
|
||||
stack.Pop();
|
||||
}
|
||||
|
||||
@@ -269,7 +269,7 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
xrefTablePart = crossReferenceStreamParser.Parse(objByteOffset, fromTableAtOffset, objectStream);
|
||||
xrefTablePart = crossReferenceStreamParser.Parse(objByteOffset, fromTableAtOffset, objectStream, pdfScanner);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
using Core;
|
||||
using Filters;
|
||||
using PdfPig.CrossReference;
|
||||
using Tokenization.Scanner;
|
||||
using Tokens;
|
||||
using Util;
|
||||
|
||||
@@ -19,9 +20,9 @@
|
||||
/// <summary>
|
||||
/// Parses through the unfiltered stream and populates the xrefTable HashMap.
|
||||
/// </summary>
|
||||
public CrossReferenceTablePart Parse(long streamOffset, long? fromTableAtOffset, StreamToken stream)
|
||||
public CrossReferenceTablePart Parse(long streamOffset, long? fromTableAtOffset, StreamToken stream, IPdfTokenScanner pdfTokenScanner)
|
||||
{
|
||||
var decoded = stream.Decode(filterProvider);
|
||||
var decoded = stream.DecodeWithLookup(filterProvider, pdfTokenScanner);
|
||||
|
||||
var fieldSizes = new CrossReferenceStreamFieldSize(stream.StreamDictionary);
|
||||
|
||||
|
||||
@@ -45,14 +45,18 @@
|
||||
}
|
||||
|
||||
return typedToken;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the decoded data from this stream.
|
||||
/// </summary>
|
||||
public static IReadOnlyList<byte> Decode(this StreamToken stream, IFilterProvider filterProvider)
|
||||
=> DecodeWithLookup(stream, filterProvider, null);
|
||||
internal static IReadOnlyList<byte> DecodeWithLookup(this StreamToken stream, IFilterProvider filterProvider, IPdfTokenScanner pdfTokenScanner)
|
||||
{
|
||||
var filters = filterProvider.GetFilters(stream.StreamDictionary);
|
||||
var filters = pdfTokenScanner != null
|
||||
? new FilterProviderWithLookup(filterProvider).GetFilters(stream.StreamDictionary, pdfTokenScanner)
|
||||
: filterProvider.GetFilters(stream.StreamDictionary);
|
||||
|
||||
var transform = stream.Data;
|
||||
for (var i = 0; i < filters.Count; i++)
|
||||
|
||||
@@ -107,18 +107,25 @@
|
||||
CMap toUnicodeCMap = null;
|
||||
if (dictionary.TryGet(NameToken.ToUnicode, out var toUnicodeObj))
|
||||
{
|
||||
var toUnicode = DirectObjectFinder.Get<StreamToken>(toUnicodeObj, pdfScanner);
|
||||
|
||||
var decodedUnicodeCMap = toUnicode.Decode(filterProvider, pdfScanner);
|
||||
|
||||
if (decodedUnicodeCMap != null)
|
||||
try
|
||||
{
|
||||
toUnicodeCMap = CMapCache.Parse(new ByteArrayInputBytes(decodedUnicodeCMap));
|
||||
var toUnicode = DirectObjectFinder.Get<StreamToken>(toUnicodeObj, pdfScanner);
|
||||
|
||||
var decodedUnicodeCMap = toUnicode.Decode(filterProvider, pdfScanner);
|
||||
|
||||
if (decodedUnicodeCMap != null)
|
||||
{
|
||||
toUnicodeCMap = CMapCache.Parse(new ByteArrayInputBytes(decodedUnicodeCMap));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.Error("Failed to decode ToUnicode CMap for a TrueType font in file due to an exception.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
Encoding encoding = encodingReader.Read(dictionary, descriptor);
|
||||
|
||||
|
||||
if (encoding == null && font?.TableRegister?.CMapTable != null
|
||||
&& font.TableRegister.PostScriptTable?.GlyphNames != null)
|
||||
{
|
||||
@@ -199,7 +206,7 @@
|
||||
$"Expected a TrueType font in the TrueType font descriptor, instead it was {descriptor.FontFile.FileType}.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var font = TrueTypeFontParser.Parse(new TrueTypeDataBytes(new ByteArrayInputBytes(fontFile)));
|
||||
|
||||
return font;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net45;net451;net452;net46;net461;net462;net47;net6.0</TargetFrameworks>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Version>0.1.6</Version>
|
||||
<Version>0.1.7-alpha-001</Version>
|
||||
<IsTestProject>False</IsTestProject>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<PackageTags>PDF;Reader;Document;Adobe;PDFBox;PdfPig;pdf-extract;pdf-to-text;pdf;file;text;C#;dotnet;.NET</PackageTags>
|
||||
<RepositoryUrl>https://github.com/UglyToad/PdfPig</RepositoryUrl>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<Version>0.1.6</Version>
|
||||
<Version>0.1.7-alpha-001</Version>
|
||||
<AssemblyVersion>0.1.5.0</AssemblyVersion>
|
||||
<FileVersion>0.1.5.0</FileVersion>
|
||||
<PackageIconUrl>https://raw.githubusercontent.com/UglyToad/PdfPig/master/documentation/pdfpig.png</PackageIconUrl>
|
||||
|
||||
Reference in New Issue
Block a user