mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-10-15 19:54:52 +08:00
remove inefficient approach to checking if content stream path has been added #99
This commit is contained in:
@@ -50,6 +50,7 @@
|
|||||||
private Stack<CurrentGraphicsState> graphicsStack = new Stack<CurrentGraphicsState>();
|
private Stack<CurrentGraphicsState> graphicsStack = new Stack<CurrentGraphicsState>();
|
||||||
private IFont activeExtendedGraphicsStateFont;
|
private IFont activeExtendedGraphicsStateFont;
|
||||||
private InlineImageBuilder inlineImageBuilder;
|
private InlineImageBuilder inlineImageBuilder;
|
||||||
|
private bool currentPathAdded;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A counter to track individual calls to <see cref="ShowText"/> operations used to determine if letters are likely to be
|
/// A counter to track individual calls to <see cref="ShowText"/> operations used to determine if letters are likely to be
|
||||||
@@ -215,20 +216,22 @@
|
|||||||
? currentState.CurrentNonStrokingColor
|
? currentState.CurrentNonStrokingColor
|
||||||
: currentState.CurrentStrokingColor;
|
: currentState.CurrentStrokingColor;
|
||||||
|
|
||||||
ShowGlyph(font, transformedGlyphBounds,
|
var letter = new Letter(unicode, transformedGlyphBounds,
|
||||||
transformedPdfBounds.BottomLeft,
|
transformedPdfBounds.BottomLeft,
|
||||||
transformedPdfBounds.BottomRight,
|
transformedPdfBounds.BottomRight,
|
||||||
transformedPdfBounds.Width,
|
transformedPdfBounds.Width,
|
||||||
unicode,
|
|
||||||
fontSize,
|
fontSize,
|
||||||
|
font.Name.Data,
|
||||||
color,
|
color,
|
||||||
pointSize,
|
pointSize,
|
||||||
textSequence);
|
textSequence);
|
||||||
|
|
||||||
|
letters.Add(letter);
|
||||||
|
|
||||||
decimal tx, ty;
|
decimal tx, ty;
|
||||||
if (font.IsVertical)
|
if (font.IsVertical)
|
||||||
{
|
{
|
||||||
var verticalFont = (IVerticalWritingSupported) font;
|
var verticalFont = (IVerticalWritingSupported)font;
|
||||||
var displacement = verticalFont.GetDisplacementVector(code);
|
var displacement = verticalFont.GetDisplacementVector(code);
|
||||||
tx = 0;
|
tx = 0;
|
||||||
ty = (displacement.Y * fontSize) + characterSpacing + wordSpacing;
|
ty = (displacement.Y * fontSize) + characterSpacing + wordSpacing;
|
||||||
@@ -352,7 +355,7 @@
|
|||||||
{
|
{
|
||||||
formMatrix = TransformationMatrix.FromArray(formMatrixToken.Data.OfType<NumericToken>().Select(x => x.Data).ToArray());
|
formMatrix = TransformationMatrix.FromArray(formMatrixToken.Data.OfType<NumericToken>().Select(x => x.Data).ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Update current transformation matrix.
|
// 2. Update current transformation matrix.
|
||||||
var resultingTransformationMatrix = startState.CurrentTransformationMatrix.Multiply(formMatrix);
|
var resultingTransformationMatrix = startState.CurrentTransformationMatrix.Multiply(formMatrix);
|
||||||
|
|
||||||
@@ -378,12 +381,13 @@
|
|||||||
|
|
||||||
public void BeginSubpath()
|
public void BeginSubpath()
|
||||||
{
|
{
|
||||||
if (CurrentPath != null && CurrentPath.Commands.Count > 0 && !paths.Contains(CurrentPath))
|
if (CurrentPath != null && CurrentPath.Commands.Count > 0 && !currentPathAdded)
|
||||||
{
|
{
|
||||||
paths.Add(CurrentPath);
|
paths.Add(CurrentPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
CurrentPath = new PdfPath();
|
CurrentPath = new PdfPath();
|
||||||
|
currentPathAdded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StrokePath(bool close)
|
public void StrokePath(bool close)
|
||||||
@@ -395,6 +399,7 @@
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
paths.Add(CurrentPath);
|
paths.Add(CurrentPath);
|
||||||
|
currentPathAdded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -407,6 +412,7 @@
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
paths.Add(CurrentPath);
|
paths.Add(CurrentPath);
|
||||||
|
currentPathAdded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -415,6 +421,7 @@
|
|||||||
CurrentPath.ClosePath();
|
CurrentPath.ClosePath();
|
||||||
paths.Add(CurrentPath);
|
paths.Add(CurrentPath);
|
||||||
CurrentPath = null;
|
CurrentPath = null;
|
||||||
|
currentPathAdded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetNamedGraphicsState(NameToken stateName)
|
public void SetNamedGraphicsState(NameToken stateName)
|
||||||
@@ -501,28 +508,5 @@
|
|||||||
|
|
||||||
TextMatrices.TextMatrix = newMatrix;
|
TextMatrices.TextMatrix = newMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ShowGlyph(IFont font, PdfRectangle glyphRectangle,
|
|
||||||
PdfPoint startBaseLine,
|
|
||||||
PdfPoint endBaseLine,
|
|
||||||
decimal width,
|
|
||||||
string unicode,
|
|
||||||
decimal fontSize,
|
|
||||||
IColor color,
|
|
||||||
decimal pointSize,
|
|
||||||
int textSequence)
|
|
||||||
{
|
|
||||||
var letter = new Letter(unicode, glyphRectangle,
|
|
||||||
startBaseLine,
|
|
||||||
endBaseLine,
|
|
||||||
width,
|
|
||||||
fontSize,
|
|
||||||
font.Name.Data,
|
|
||||||
color,
|
|
||||||
pointSize,
|
|
||||||
textSequence);
|
|
||||||
|
|
||||||
letters.Add(letter);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user