Use Rect class for size definition of TextElements and pages.

This commit is contained in:
2019-10-27 13:11:40 +01:00
parent 9bc7854b48
commit 53d07db9c0
4 changed files with 51 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VAR.PdfTools.Maths
{
public class Rect
{
public double XMin { get; set; }
public double XMax { get; set; }
public double YMin { get; set; }
public double YMax { get; set; }
public void Add(Rect rect)
{
if (rect.XMax > XMax) { XMax = rect.XMax; }
if (rect.YMax > YMax) { YMax = rect.YMax; }
if (rect.XMin < XMin) { XMin = rect.XMin; }
if (rect.YMin < YMin) { YMin = rect.YMin; }
}
}
}

View File

@@ -87,6 +87,19 @@ namespace VAR.PdfTools
return Characters.Average(c => c.Width);
}
public Rect GetRect()
{
double x = GetX();
double y = GetY();
return new Rect
{
XMin = x,
YMax = y,
XMax = x + VisibleWidth,
YMin = y - VisibleHeight,
};
}
#endregion
}

View File

@@ -652,6 +652,18 @@ namespace VAR.PdfTools
#region Public methods
public Rect GetRect()
{
Rect rect = null;
foreach (PdfTextElement textElement in _textElements)
{
Rect elementRect = textElement.GetRect();
if (rect == null) { rect = elementRect; }
rect.Add(elementRect);
}
return rect;
}
public List<string> GetColumnAsStrings(string column, bool fuzzy =true)
{
PdfTextElement columnHead = FindElementByText(column, fuzzy);

View File

@@ -63,6 +63,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Maths\Matrix3x3.cs" />
<Compile Include="Maths\Rect.cs" />
<Compile Include="PdfContentAction.cs" />
<Compile Include="PdfDocument.cs" />
<Compile Include="PdfDocumentPage.cs" />