mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-10-15 19:54:52 +08:00
revert change to public api of letter. update readme
This commit is contained in:
@@ -47,7 +47,7 @@
|
||||
{
|
||||
Assert.Equal(Text, letter.Value);
|
||||
Assert.Equal(FontName, letter.FontName);
|
||||
Assert.Equal(X, letter.Origin.X, 1);
|
||||
Assert.Equal(X, letter.Location.X, 1);
|
||||
Assert.Equal(Width, letter.Width, 1);
|
||||
if (includeHeight)
|
||||
{
|
||||
|
@@ -68,7 +68,7 @@
|
||||
break;
|
||||
}
|
||||
|
||||
var myX = pageLetter.Origin.X;
|
||||
var myX = pageLetter.Location.X;
|
||||
var theirX = pdfBoxData[index].X;
|
||||
|
||||
var myLetter = pageLetter.Value;
|
||||
@@ -111,7 +111,7 @@
|
||||
break;
|
||||
}
|
||||
|
||||
var myX = pageLetter.Origin.X;
|
||||
var myX = pageLetter.Location.X;
|
||||
var theirX = positions[index].X;
|
||||
|
||||
var myLetter = pageLetter.Value;
|
||||
|
@@ -132,9 +132,9 @@ namespace UglyToad.PdfPig.Tests.Integration
|
||||
}
|
||||
|
||||
Assert.Equal(datum.Text, letter.Value);
|
||||
Assert.Equal(datum.X, letter.Origin.X, 2);
|
||||
Assert.Equal(datum.X, letter.Location.X, 2);
|
||||
|
||||
var transformed = page.Height - letter.Origin.Y;
|
||||
var transformed = page.Height - letter.Location.Y;
|
||||
Assert.Equal(datum.Y, transformed, 2);
|
||||
|
||||
Assert.Equal(datum.Width, letter.Width, 2);
|
||||
@@ -177,9 +177,9 @@ namespace UglyToad.PdfPig.Tests.Integration
|
||||
}
|
||||
|
||||
Assert.Equal(datum.Text, letter.Value);
|
||||
Assert.Equal(datum.X, letter.Origin.X, 2);
|
||||
Assert.Equal(datum.X, letter.Location.X, 2);
|
||||
|
||||
var transformed = page.Height - letter.Origin.Y;
|
||||
var transformed = page.Height - letter.Location.Y;
|
||||
Assert.Equal(datum.Y, transformed, 2);
|
||||
|
||||
// Until we get width from glyphs we're a bit out.
|
||||
|
@@ -15,7 +15,7 @@
|
||||
/// <summary>
|
||||
/// The placement position of the character in PDF space.
|
||||
/// </summary>
|
||||
public PdfPoint Origin { get; }
|
||||
public PdfPoint Location { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The width occupied by the character within the PDF content.
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
/// <summary>
|
||||
/// Position of the bounding box for the glyph, this is the box surrounding the visible glyph as it appears on the page.
|
||||
/// For example letters with descenders, p, j, etc., will have a box extending below the <see cref="Origin"/> they are placed at.
|
||||
/// For example letters with descenders, p, j, etc., will have a box extending below the <see cref="Location"/> they are placed at.
|
||||
/// The width of the glyph may also be more or less than the <see cref="Width"/> allocated for the character in the PDF content.
|
||||
/// </summary>
|
||||
public PdfRectangle GlyphRectangle { get; }
|
||||
@@ -47,14 +47,14 @@
|
||||
/// <summary>
|
||||
/// Create a new letter to represent some text drawn by the Tj operator.
|
||||
/// </summary>
|
||||
internal Letter(string value, PdfRectangle glyphRectangle, PdfPoint origin, decimal width, decimal fontSize, string fontName, decimal pointSize)
|
||||
internal Letter(string value, PdfRectangle glyphRectangle, PdfPoint location, decimal width, decimal fontSize, string fontName, decimal pointSize)
|
||||
{
|
||||
Value = value;
|
||||
GlyphRectangle = glyphRectangle;
|
||||
FontSize = fontSize;
|
||||
FontName = fontName;
|
||||
PointSize = pointSize;
|
||||
Origin = origin;
|
||||
Location = location;
|
||||
Width = width;
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@
|
||||
/// </summary>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{Value} {Origin} {FontName} {PointSize}";
|
||||
return $"{Value} {Location} {FontName} {PointSize}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -43,9 +43,9 @@
|
||||
|
||||
Text = string.Join(string.Empty, letters.Select(x => x.Value));
|
||||
|
||||
var minX = letters.Min(x => x.Origin.X);
|
||||
var minY = letters.Min(x => x.Origin.Y);
|
||||
var maxX = letters.Max(x => x.Origin.X + x.Width);
|
||||
var minX = letters.Min(x => x.Location.X);
|
||||
var minY = letters.Min(x => x.Location.Y);
|
||||
var maxX = letters.Max(x => x.Location.X + x.Width);
|
||||
var maxY = letters.Max(x => x.GlyphRectangle.Top);
|
||||
|
||||
BoundingBox = new PdfRectangle(minX, minY, maxX, maxY);
|
||||
|
@@ -9,8 +9,8 @@
|
||||
{
|
||||
public IEnumerable<Word> GetWords(IReadOnlyList<Letter> letters)
|
||||
{
|
||||
var lettersOrder = letters.OrderByDescending(x => x.Origin.Y)
|
||||
.ThenBy(x => x.Origin.X);
|
||||
var lettersOrder = letters.OrderByDescending(x => x.Location.Y)
|
||||
.ThenBy(x => x.Location.X);
|
||||
|
||||
var lettersSoFar = new List<Letter>(10);
|
||||
|
||||
@@ -21,12 +21,12 @@
|
||||
{
|
||||
if (!y.HasValue)
|
||||
{
|
||||
y = letter.Origin.Y;
|
||||
y = letter.Location.Y;
|
||||
}
|
||||
|
||||
if (!lastX.HasValue)
|
||||
{
|
||||
lastX = letter.Origin.X;
|
||||
lastX = letter.Location.X;
|
||||
}
|
||||
|
||||
if (lastLetter == null)
|
||||
@@ -41,7 +41,7 @@
|
||||
continue;
|
||||
}
|
||||
|
||||
if (letter.Origin.Y > y.Value + 0.5m)
|
||||
if (letter.Location.Y > y.Value + 0.5m)
|
||||
{
|
||||
if (lettersSoFar.Count > 0)
|
||||
{
|
||||
@@ -54,15 +54,15 @@
|
||||
lettersSoFar.Add(letter);
|
||||
}
|
||||
|
||||
y = letter.Origin.Y;
|
||||
lastX = letter.Origin.X;
|
||||
y = letter.Location.Y;
|
||||
lastX = letter.Location.X;
|
||||
lastLetter = letter;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
var gap = letter.Origin.X - (lastLetter.Origin.X + lastLetter.Width);
|
||||
var nextToLeft = letter.Origin.X < lastX.Value - 1;
|
||||
var gap = letter.Location.X - (lastLetter.Location.X + lastLetter.Width);
|
||||
var nextToLeft = letter.Location.X < lastX.Value - 1;
|
||||
var nextBigSpace = gap > Math.Max(lastLetter.GlyphRectangle.Height, letter.GlyphRectangle.Height) * 0.39m;
|
||||
var nextIsWhiteSpace = string.IsNullOrWhiteSpace(letter.Value);
|
||||
var nextFontDiffers = !string.Equals(letter.FontName, lastLetter.FontName, StringComparison.OrdinalIgnoreCase) && gap > letter.Width * 0.1m;
|
||||
@@ -84,7 +84,7 @@
|
||||
|
||||
lastLetter = letter;
|
||||
|
||||
lastX = letter.Origin.X;
|
||||
lastX = letter.Location.X;
|
||||
}
|
||||
|
||||
if (lettersSoFar.Count > 0)
|
||||
|
Reference in New Issue
Block a user