5 Commits
1_5 ... 1_5_2

5 changed files with 35 additions and 17 deletions

2
.gitignore vendored
View File

@@ -27,3 +27,5 @@ obj/
_ReSharper*/
*.userprefs
*.nupkg
.vs

View File

@@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2016-2017 Valeriano Alfonso Rodriguez
Copyright (c) 2016-2019 Valeriano Alfonso Rodriguez
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -11,4 +11,4 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("a5825d8e-9f81-49e0-b610-8ae5e46d02ea")]
[assembly: AssemblyVersion("1.5.0.*")]
[assembly: AssemblyVersion("1.5.1.*")]

View File

@@ -85,6 +85,11 @@ namespace VAR.PdfTools
return blockElem;
}
public double MaxWidth()
{
return Characters.Average(c => c.Width) / 2;
}
#endregion
}
@@ -622,13 +627,22 @@ namespace VAR.PdfTools
while (i < _textElements.Count)
{
PdfTextElement neighbour = _textElements[i];
if (neighbour.Font != elem.Font || neighbour.FontSize != elem.FontSize)
{
i++;
continue;
}
double neighbourY = neighbour.GetY();
if (Math.Abs(neighbourY - blockY) > 0.001) { i++; continue; }
double maxWidth = neighbour.MaxWidth();
double neighbourXMin = neighbour.GetX();
double neighbourXMax = neighbourXMin + neighbour.VisibleWidth;
double auxBlockXMin = blockXMin - (elem.FontSize * elem.Font.GetCharWidth('m'));
double auxBlockXMax = blockXMax + (elem.FontSize * elem.Font.GetCharWidth('m'));
double auxBlockXMin = blockXMin - maxWidth;
double auxBlockXMax = blockXMax + maxWidth;
if (auxBlockXMax >= neighbourXMin && neighbourXMax >= auxBlockXMin)
{
_textElements.Remove(neighbour);
@@ -641,7 +655,7 @@ namespace VAR.PdfTools
i++;
}
if(textElementNeighbours.Count == 0)
if (textElementNeighbours.Count == 1)
{
textElementsCondensed.Add(elem);
continue;
@@ -694,12 +708,14 @@ namespace VAR.PdfTools
PdfTextElement elem = _textElements[0];
_textElements.Remove(elem);
double maxWidth = elem.MaxWidth();
int prevBreak = 0;
for (int i = 1; i < elem.Characters.Count; i++)
{
double prevCharEnd = elem.Characters[i - 1].Displacement + elem.Characters[i - 1].Width;
double charSeparation = elem.Characters[i].Displacement - prevCharEnd;
if (charSeparation > (elem.Characters[i - 1].Width * 2))
if (charSeparation > maxWidth)
{
PdfTextElement partElem = elem.SubPart(prevBreak, i);
textElementsSplitted.Add(partElem);

View File

@@ -6,9 +6,9 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("VAR")]
[assembly: AssemblyProduct("VAR.PdfTools")]
[assembly: AssemblyCopyright("Copyright © VAR 2016-2017")]
[assembly: AssemblyCopyright("Copyright © VAR 2016-2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("eb7e003a-6a95-4002-809f-926c7c8a11e9")]
[assembly: AssemblyVersion("1.5.0.*")]
[assembly: AssemblyVersion("1.5.2.*")]