Merge pull request #61 from vadik299/master

Adding TextSequence number to each letter to determine if letters belong to the same Tj operation
This commit is contained in:
Eliot Jones
2019-08-17 12:59:46 +01:00
committed by GitHub
3 changed files with 28 additions and 5 deletions

View File

@@ -65,6 +65,11 @@
/// </summary>
internal decimal PointSize { get; }
/// <summary>
/// Sequence number of the ShowText operation that printed this letter.
/// </summary>
public int TextSequence { get; }
/// <summary>
/// Create a new letter to represent some text drawn by the Tj operator.
/// </summary>
@@ -75,7 +80,8 @@
decimal fontSize,
string fontName,
IColor color,
decimal pointSize)
decimal pointSize,
int textSequence)
{
Value = value;
GlyphRectangle = glyphRectangle;
@@ -86,6 +92,7 @@
FontName = fontName;
Color = color ?? GrayColor.Black;
PointSize = pointSize;
TextSequence = textSequence;
TextDirection = GetTextDirection();
}

View File

@@ -31,6 +31,9 @@
private Stack<CurrentGraphicsState> graphicsStack = new Stack<CurrentGraphicsState>();
private IFont activeExtendedGraphicsStateFont = null;
//a sequence number of ShowText operation to determine whether letters belong to same operation or not (letters that belong to different operations have less changes to belong to same word)
private int textSequence = 0;
public TextMatrices TextMatrices { get; } = new TextMatrices();
public TransformationMatrix CurrentTransformationMatrix
@@ -187,7 +190,8 @@
unicode,
fontSize,
color,
pointSize);
pointSize,
textSequence);
decimal tx, ty;
if (font.IsVertical)
@@ -209,6 +213,8 @@
public void ShowPositionedText(IReadOnlyList<IToken> tokens)
{
textSequence++;
var currentState = GetCurrentState();
var textState = currentState.FontState;
@@ -361,7 +367,8 @@
string unicode,
decimal fontSize,
IColor color,
decimal pointSize)
decimal pointSize,
int textSequence)
{
var letter = new Letter(unicode, glyphRectangle,
startBaseLine,
@@ -370,7 +377,8 @@
fontSize,
font.Name.Data,
color,
pointSize);
pointSize,
textSequence);
Letters.Add(letter);
}

View File

@@ -22,6 +22,10 @@
{
private readonly PdfDocumentBuilder documentBuilder;
private readonly List<IGraphicsStateOperation> operations = new List<IGraphicsStateOperation>();
//a sequence number of ShowText operation to determine whether letters belong to same operation or not (letters that belong to different operations have less changes to belong to same word)
private static int textSequence = 0;
internal IReadOnlyList<IGraphicsStateOperation> Operations => operations;
/// <summary>
@@ -240,6 +244,8 @@
var width = 0m;
textSequence++;
for (var i = 0; i < text.Length; i++)
{
var c = text[i];
@@ -261,7 +267,9 @@
var letter = new Letter(c.ToString(), documentSpace, advanceRect.BottomLeft, advanceRect.BottomRight, width, fontSize, font.Name,
GrayColor.Black,
fontSize);
fontSize,
textSequence);
letters.Add(letter);
var tx = advanceRect.Width * horizontalScaling;