From 0512bb1e4f3645b74a4c6974ac9314660f6d6f38 Mon Sep 17 00:00:00 2001 From: Eliot Jones Date: Sun, 10 May 2020 15:46:38 +0100 Subject: [PATCH 1/4] handle indirect references appearing in cid font widths array #174 --- .../PdfFonts/Parser/Parts/CidFontFactory.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/UglyToad.PdfPig/PdfFonts/Parser/Parts/CidFontFactory.cs b/src/UglyToad.PdfPig/PdfFonts/Parser/Parts/CidFontFactory.cs index e5241086..b3e3b9e4 100644 --- a/src/UglyToad.PdfPig/PdfFonts/Parser/Parts/CidFontFactory.cs +++ b/src/UglyToad.PdfPig/PdfFonts/Parser/Parts/CidFontFactory.cs @@ -166,7 +166,7 @@ var counter = 0; while (counter < size) { - var firstCode = (NumericToken)widthArray.Data[counter++]; + var firstCode = DirectObjectFinder.Get(widthArray.Data[counter++], pdfScanner); var next = widthArray.Data[counter++]; if (DirectObjectFinder.TryGet(next, pdfScanner, out ArrayToken array)) { @@ -175,14 +175,14 @@ for (var i = 0; i < arraySize; i++) { - var width = (NumericToken)array.Data[i]; + var width = DirectObjectFinder.Get(array.Data[i], pdfScanner); widths[startRange + i] = width.Double; } } else { - var secondCode = (NumericToken)next; - var rangeWidth = (NumericToken)widthArray.Data[counter++]; + var secondCode = DirectObjectFinder.Get(next, pdfScanner); + var rangeWidth = DirectObjectFinder.Get(widthArray.Data[counter++], pdfScanner); var startRange = firstCode.Int; var endRange = secondCode.Int; var width = rangeWidth.Double; From bb337415522291573c72cf92d5460865e766b4fb Mon Sep 17 00:00:00 2001 From: BobLd Date: Tue, 28 Apr 2020 22:01:50 +0100 Subject: [PATCH 2/4] Fix KdTree.FindNearestNeighbours(k) returning the pivot itself --- src/UglyToad.PdfPig.Core/PdfRectangle.cs | 4 ++++ .../Distances.cs | 9 +++++---- .../KdTree.cs | 2 +- src/UglyToad.PdfPig/Content/Word.cs | 14 +++++++------- src/UglyToad.PdfPig/Geometry/GeometryExtensions.cs | 2 +- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/UglyToad.PdfPig.Core/PdfRectangle.cs b/src/UglyToad.PdfPig.Core/PdfRectangle.cs index 4a57c5b0..808b1d48 100644 --- a/src/UglyToad.PdfPig.Core/PdfRectangle.cs +++ b/src/UglyToad.PdfPig.Core/PdfRectangle.cs @@ -81,6 +81,7 @@ /// /// Rotation angle of the rectangle. Counterclockwise, in degrees. + /// -180 ≤ θ ≤ 180 /// public double Rotation { @@ -173,6 +174,9 @@ BottomLeft.Translate(dx, dy), BottomRight.Translate(dx, dy)); } + /// + /// -π ≤ θ ≤ π + /// private double GetT() { if (!BottomRight.Equals(BottomLeft)) diff --git a/src/UglyToad.PdfPig.DocumentLayoutAnalysis/Distances.cs b/src/UglyToad.PdfPig.DocumentLayoutAnalysis/Distances.cs index bb13f97a..3dc8688e 100644 --- a/src/UglyToad.PdfPig.DocumentLayoutAnalysis/Distances.cs +++ b/src/UglyToad.PdfPig.DocumentLayoutAnalysis/Distances.cs @@ -49,12 +49,13 @@ /// /// The angle in degrees between the horizontal axis and the line between two points. + /// -180 ≤ θ ≤ 180 /// - /// The first point. - /// The second point. - public static double Angle(PdfPoint point1, PdfPoint point2) + /// The first point. + /// The second point. + public static double Angle(PdfPoint startPoint, PdfPoint endPoint) { - return Math.Atan2(point2.Y - point1.Y, point2.X - point1.X) * 57.29577951; + return Math.Atan2(endPoint.Y - startPoint.Y, endPoint.X - startPoint.X) * 180 / Math.PI; } /// diff --git a/src/UglyToad.PdfPig.DocumentLayoutAnalysis/KdTree.cs b/src/UglyToad.PdfPig.DocumentLayoutAnalysis/KdTree.cs index 7fedbac2..648fed75 100644 --- a/src/UglyToad.PdfPig.DocumentLayoutAnalysis/KdTree.cs +++ b/src/UglyToad.PdfPig.DocumentLayoutAnalysis/KdTree.cs @@ -250,7 +250,7 @@ var point = pivotPointFunc(pivot); var currentNearestNode = node; var currentDistance = distance(node.Value, point); - if (!queue.IsFull || currentDistance <= queue.LastDistance) + if ((!queue.IsFull || currentDistance <= queue.LastDistance) && !node.Element.Equals(pivot)) { queue.Add(currentDistance, currentNearestNode); currentDistance = queue.LastDistance; diff --git a/src/UglyToad.PdfPig/Content/Word.cs b/src/UglyToad.PdfPig/Content/Word.cs index d1b731b4..3c89c758 100644 --- a/src/UglyToad.PdfPig/Content/Word.cs +++ b/src/UglyToad.PdfPig/Content/Word.cs @@ -333,33 +333,33 @@ // Find the orientation of the OBB, using the baseline angle var firstLetter = letters[0]; var lastLetter = letters[letters.Count - 1]; + var baseLineAngle = Math.Atan2( lastLetter.EndBaseLine.Y - firstLetter.StartBaseLine.Y, lastLetter.EndBaseLine.X - firstLetter.StartBaseLine.X) * 180 / Math.PI; - var bbox = obb; - var deltaAngle = Math.Abs(baseLineAngle - angleRad * 180 / Math.PI); - + double deltaAngle = Math.Abs(baseLineAngle - obb.Rotation); double deltaAngle1 = Math.Abs(baseLineAngle - obb1.Rotation); if (deltaAngle1 < deltaAngle) { deltaAngle = deltaAngle1; - bbox = obb1; + obb = obb1; } double deltaAngle2 = Math.Abs(baseLineAngle - obb2.Rotation); if (deltaAngle2 < deltaAngle) { deltaAngle = deltaAngle2; - bbox = obb2; + obb = obb2; } double deltaAngle3 = Math.Abs(baseLineAngle - obb3.Rotation); if (deltaAngle3 < deltaAngle) { - bbox = obb3; + obb = obb3; } - return new Tuple(builder.ToString(), bbox); + + return new Tuple(builder.ToString(), obb); } #endregion diff --git a/src/UglyToad.PdfPig/Geometry/GeometryExtensions.cs b/src/UglyToad.PdfPig/Geometry/GeometryExtensions.cs index 6c09b1f4..1538d9f6 100644 --- a/src/UglyToad.PdfPig/Geometry/GeometryExtensions.cs +++ b/src/UglyToad.PdfPig/Geometry/GeometryExtensions.cs @@ -230,7 +230,7 @@ var slope = sumProduct / sumDiffSquaredX; // Rotate the points to build the axis-aligned bounding box (AABB) - var angleRad = Math.Atan(slope); + var angleRad = Math.Atan(slope); // -π/2 ≤ θ ≤ π/2 var cos = Math.Cos(angleRad); var sin = Math.Sin(angleRad); From 256c2833ab9e2fcac3ba9e58184e77c4714d3f63 Mon Sep 17 00:00:00 2001 From: Eliot Jones Date: Sun, 10 May 2020 16:36:14 +0100 Subject: [PATCH 3/4] 0.1.2-alpha002 --- src/UglyToad.PdfPig.Core/UglyToad.PdfPig.Core.csproj | 2 +- .../UglyToad.PdfPig.DocumentLayoutAnalysis.csproj | 2 +- src/UglyToad.PdfPig.Fonts/UglyToad.PdfPig.Fonts.csproj | 2 +- .../UglyToad.PdfPig.Tokenization.csproj | 2 +- src/UglyToad.PdfPig.Tokens/UglyToad.PdfPig.Tokens.csproj | 2 +- src/UglyToad.PdfPig/UglyToad.PdfPig.csproj | 2 +- tools/UglyToad.PdfPig.Package/UglyToad.PdfPig.Package.csproj | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/UglyToad.PdfPig.Core/UglyToad.PdfPig.Core.csproj b/src/UglyToad.PdfPig.Core/UglyToad.PdfPig.Core.csproj index ff398177..00a13bb4 100644 --- a/src/UglyToad.PdfPig.Core/UglyToad.PdfPig.Core.csproj +++ b/src/UglyToad.PdfPig.Core/UglyToad.PdfPig.Core.csproj @@ -2,7 +2,7 @@ netstandard2.0;net45;net451;net452;net46;net461;net462;net47 latest - 0.1.2-alpha001 + 0.1.2-alpha002 False true true diff --git a/src/UglyToad.PdfPig.DocumentLayoutAnalysis/UglyToad.PdfPig.DocumentLayoutAnalysis.csproj b/src/UglyToad.PdfPig.DocumentLayoutAnalysis/UglyToad.PdfPig.DocumentLayoutAnalysis.csproj index 92d1311b..e331fdda 100644 --- a/src/UglyToad.PdfPig.DocumentLayoutAnalysis/UglyToad.PdfPig.DocumentLayoutAnalysis.csproj +++ b/src/UglyToad.PdfPig.DocumentLayoutAnalysis/UglyToad.PdfPig.DocumentLayoutAnalysis.csproj @@ -2,7 +2,7 @@ netstandard2.0;net45;net451;net452;net46;net461;net462;net47 latest - 0.1.2-alpha001 + 0.1.2-alpha002 False true true diff --git a/src/UglyToad.PdfPig.Fonts/UglyToad.PdfPig.Fonts.csproj b/src/UglyToad.PdfPig.Fonts/UglyToad.PdfPig.Fonts.csproj index 0449c08b..15fd446a 100644 --- a/src/UglyToad.PdfPig.Fonts/UglyToad.PdfPig.Fonts.csproj +++ b/src/UglyToad.PdfPig.Fonts/UglyToad.PdfPig.Fonts.csproj @@ -2,7 +2,7 @@ netstandard2.0;net45;net451;net452;net46;net461;net462;net47 latest - 0.1.2-alpha001 + 0.1.2-alpha002 False true true diff --git a/src/UglyToad.PdfPig.Tokenization/UglyToad.PdfPig.Tokenization.csproj b/src/UglyToad.PdfPig.Tokenization/UglyToad.PdfPig.Tokenization.csproj index e7834b57..7faa683d 100644 --- a/src/UglyToad.PdfPig.Tokenization/UglyToad.PdfPig.Tokenization.csproj +++ b/src/UglyToad.PdfPig.Tokenization/UglyToad.PdfPig.Tokenization.csproj @@ -2,7 +2,7 @@ netstandard2.0;net45;net451;net452;net46;net461;net462;net47 latest - 0.1.2-alpha001 + 0.1.2-alpha002 False true true diff --git a/src/UglyToad.PdfPig.Tokens/UglyToad.PdfPig.Tokens.csproj b/src/UglyToad.PdfPig.Tokens/UglyToad.PdfPig.Tokens.csproj index c3322988..400156a5 100644 --- a/src/UglyToad.PdfPig.Tokens/UglyToad.PdfPig.Tokens.csproj +++ b/src/UglyToad.PdfPig.Tokens/UglyToad.PdfPig.Tokens.csproj @@ -2,7 +2,7 @@ netstandard2.0;net45;net451;net452;net46;net461;net462;net47 latest - 0.1.2-alpha001 + 0.1.2-alpha002 False true true diff --git a/src/UglyToad.PdfPig/UglyToad.PdfPig.csproj b/src/UglyToad.PdfPig/UglyToad.PdfPig.csproj index 6e90b9b7..d0279e83 100644 --- a/src/UglyToad.PdfPig/UglyToad.PdfPig.csproj +++ b/src/UglyToad.PdfPig/UglyToad.PdfPig.csproj @@ -2,7 +2,7 @@ netstandard2.0;net45;net451;net452;net46;net461;net462;net47 latest - 0.1.2-alpha001 + 0.1.2-alpha002 False true true diff --git a/tools/UglyToad.PdfPig.Package/UglyToad.PdfPig.Package.csproj b/tools/UglyToad.PdfPig.Package/UglyToad.PdfPig.Package.csproj index 369bc708..c690b864 100644 --- a/tools/UglyToad.PdfPig.Package/UglyToad.PdfPig.Package.csproj +++ b/tools/UglyToad.PdfPig.Package/UglyToad.PdfPig.Package.csproj @@ -12,7 +12,7 @@ PDF;Reader;Document;Adobe;PDFBox;PdfPig;pdf-extract https://github.com/UglyToad/PdfPig true - 0.1.2-alpha001 + 0.1.2-alpha002 0.1.1.0 0.1.1.0 https://raw.githubusercontent.com/UglyToad/PdfPig/master/documentation/pdfpig.png From a7a2ef0630b78aac522744aca7d7f8a0796b46aa Mon Sep 17 00:00:00 2001 From: Eliot Jones Date: Sun, 10 May 2020 16:40:05 +0100 Subject: [PATCH 4/4] remove old text from the readme --- README.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/README.md b/README.md index 96fcf805..d10d5516 100644 --- a/README.md +++ b/README.md @@ -305,10 +305,6 @@ Please do file an issue if you encounter a bug. However in order for us to assist you, you **must** provide the file which causes your issue. Please host this in a publically available place. -## Status - -_Why is class or property X internal?_ Internal properties and classes are not stable enough for the end user yet. If you want to access them feel free to use reflection but be aware they may change or disappear between versions. - ## Credit -This project wouldn't be possible without the work done by the [PDFBox](https://pdfbox.apache.org/) team and the Apache Foundation. Any bugs in the code are entirely my fault. +This project wouldn't be possible without the work done by the [PDFBox](https://pdfbox.apache.org/) team and the Apache Foundation.