Added TextSequence

This commit is contained in:
Vasya
2019-08-11 14:55:59 -04:00
parent dadcccfa82
commit 22278f64c4
3 changed files with 22 additions and 5 deletions

View File

@@ -59,10 +59,15 @@
/// </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>
internal Letter(string value, PdfRectangle glyphRectangle, PdfPoint startBaseLine, PdfPoint endBaseLine, decimal width, decimal fontSize, string fontName, decimal pointSize)
internal Letter(string value, PdfRectangle glyphRectangle, PdfPoint startBaseLine, PdfPoint endBaseLine, decimal width, decimal fontSize, string fontName, decimal pointSize, int textSequence)
{
Value = value;
GlyphRectangle = glyphRectangle;
@@ -71,6 +76,7 @@
PointSize = pointSize;
Width = width;
StartBaseLine = startBaseLine;
TextSequence = textSequence;
EndBaseLine = endBaseLine;
TextDirection = GetTextDirection();
}

View File

@@ -30,6 +30,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
@@ -169,7 +172,7 @@
.Transform(TextMatrices.TextMatrix
.Transform(renderingMatrix.Transform(new PdfRectangle(0, 0, boundingBox.Width, 0))));
ShowGlyph(font, transformedGlyphBounds, transformedPdfBounds.BottomLeft, transformedPdfBounds.BottomRight, transformedPdfBounds.Width, unicode, fontSize, pointSize);
ShowGlyph(font, transformedGlyphBounds, transformedPdfBounds.BottomLeft, transformedPdfBounds.BottomRight, transformedPdfBounds.Width, unicode, fontSize, pointSize, textSequence);
decimal tx, ty;
if (font.IsVertical)
@@ -191,6 +194,8 @@
public void ShowPositionedText(IReadOnlyList<IToken> tokens)
{
textSequence++;
var currentState = GetCurrentState();
var textState = currentState.FontState;
@@ -336,9 +341,9 @@
TextMatrices.TextMatrix = newMatrix;
}
private void ShowGlyph(IFont font, PdfRectangle glyphRectangle, PdfPoint startBaseLine, PdfPoint endBaseLine, decimal width, string unicode, decimal fontSize, decimal pointSize)
private void ShowGlyph(IFont font, PdfRectangle glyphRectangle, PdfPoint startBaseLine, PdfPoint endBaseLine, decimal width, string unicode, decimal fontSize, decimal pointSize, int textSequence)
{
var letter = new Letter(unicode, glyphRectangle, startBaseLine, endBaseLine, width, fontSize, font.Name.Data, pointSize);
var letter = new Letter(unicode, glyphRectangle, startBaseLine, endBaseLine, width, fontSize, font.Name.Data, pointSize, textSequence);
Letters.Add(letter);
}

View File

@@ -21,6 +21,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>
@@ -239,6 +243,8 @@
var width = 0m;
textSequence++;
for (var i = 0; i < text.Length; i++)
{
var c = text[i];
@@ -258,7 +264,7 @@
var documentSpace = textMatrix.Transform(renderingMatrix.Transform(fontMatrix.Transform(rect)));
var letter = new Letter(c.ToString(), documentSpace, advanceRect.BottomLeft, advanceRect.BottomRight, width, fontSize, font.Name, fontSize);
var letter = new Letter(c.ToString(), documentSpace, advanceRect.BottomLeft, advanceRect.BottomRight, width, fontSize, font.Name, fontSize, textSequence);
letters.Add(letter);
var tx = advanceRect.Width * horizontalScaling;