Change Subpath to path where necessary

This commit is contained in:
BobLd
2020-04-02 16:39:48 +01:00
committed by Eliot Jones
parent 002d8dc06d
commit 43b40da5d5
15 changed files with 37 additions and 63 deletions

View File

@@ -10,6 +10,7 @@
using System.Xml;
using System.Xml.Serialization;
using UglyToad.PdfPig.DocumentLayoutAnalysis.PageSegmenter;
using UglyToad.PdfPig.Graphics;
using Util;
/// <inheritdoc />
@@ -159,7 +160,7 @@
return altoPage;
}
private AltoDocument.AltoGraphicalElement ToAltoGraphicalElement(PdfSubpath pdfPath, double height)
private AltoDocument.AltoGraphicalElement ToAltoGraphicalElement(PdfPath pdfPath, double height)
{
graphicalElementCount++;

View File

@@ -6,6 +6,7 @@
using System;
using System.Linq;
using UglyToad.PdfPig.DocumentLayoutAnalysis.PageSegmenter;
using UglyToad.PdfPig.Graphics;
using Util;
/// <summary>
@@ -176,7 +177,7 @@
/// <param name="pageHeight"></param>
/// <param name="subPaths"></param>
/// <param name="level">The indent level.</param>
private string GetCode(PdfSubpath path, double pageHeight, bool subPaths, int level)
private string GetCode(PdfPath path, double pageHeight, bool subPaths, int level)
{
if (path == null) return string.Empty;
@@ -190,7 +191,7 @@
areaCount++;
hocr += GetIndent(level) + @"<div class='ocr_carea' id='block_" + pageCount + "_"
+ areaCount + "' title='" + GetCode(bbox.Value, pageHeight) + "'>\n";
foreach (var subPath in path.Commands)
foreach (var subPath in path)
{
var subBbox = subPath.GetBoundingRectangle();
if (subBbox.HasValue)

View File

@@ -12,6 +12,7 @@
using System.Xml.Serialization;
using UglyToad.PdfPig.DocumentLayoutAnalysis.PageSegmenter;
using UglyToad.PdfPig.DocumentLayoutAnalysis.ReadingOrderDetector;
using UglyToad.PdfPig.Graphics;
using Util;
/// <summary>
@@ -199,7 +200,7 @@
return pageXmlPage;
}
private PageXmlDocument.PageXmlLineDrawingRegion ToPageXmlLineDrawingRegion(PdfSubpath pdfPath, double height)
private PageXmlDocument.PageXmlLineDrawingRegion ToPageXmlLineDrawingRegion(PdfPath pdfPath, double height)
{
var bbox = pdfPath.GetBoundingRectangle();
if (bbox.HasValue)

View File

@@ -20,7 +20,9 @@
public TransformationMatrix CurrentTransformationMatrix => GetCurrentState().CurrentTransformationMatrix;
public PdfSubpath CurrentPath { get; set; }
public PdfSubpath CurrentSubpath { get; set; }
public PdfPath CurrentPath { get; set; }
public IColorSpaceContext ColorSpaceContext { get; }
@@ -29,7 +31,7 @@
public TestOperationContext()
{
StateStack.Push(new CurrentGraphicsState());
CurrentPath = new PdfSubpath();
CurrentSubpath = new PdfSubpath();
ColorSpaceContext = new ColorSpaceContext(GetCurrentState, new ResourceStore(new TestPdfTokenScanner(), new TestFontFactory()));
}

View File

@@ -10,6 +10,7 @@
using Util;
using Util.JetBrains.Annotations;
using Tokenization.Scanner;
using UglyToad.PdfPig.Graphics;
/// <summary>
/// Contains the content and provides access to methods of a single page in the <see cref="PdfDocument"/>.
@@ -172,9 +173,9 @@
private readonly AnnotationProvider annotationProvider;
/// <summary>
/// The set of <see cref="PdfSubpath"/>s drawn by the PDF content.
/// The set of <see cref="PdfPath"/>s drawn by the PDF content.
/// </summary>
public IReadOnlyList<PdfSubpath> Paths => page.Content?.Paths ?? new List<PdfSubpath>();
public IReadOnlyList<PdfPath> Paths => page.Content?.Paths ?? new List<PdfPath>();
internal Experimental(Page page, AnnotationProvider annotationProvider)
{

View File

@@ -28,12 +28,12 @@
public IReadOnlyList<Letter> Letters { get; }
public IReadOnlyList<PdfSubpath> Paths { get; }
public IReadOnlyList<PdfPath> Paths { get; }
public int NumberOfImages => images.Count;
internal PageContent(IReadOnlyList<IGraphicsStateOperation> graphicsStateOperations, IReadOnlyList<Letter> letters,
IReadOnlyList<PdfSubpath> paths,
IReadOnlyList<PdfPath> paths,
IReadOnlyList<Union<XObjectContentRecord, InlineImage>> images,
IReadOnlyList<MarkedContentElement> markedContents,
IPdfTokenScanner pdfScanner,

View File

@@ -28,7 +28,7 @@
/// <summary>
/// Stores each path as it is encountered in the content stream.
/// </summary>
private readonly List<PdfSubpath> paths = new List<PdfSubpath>();
private readonly List<PdfPath> paths = new List<PdfPath>();
/// <summary>
/// Stores a link to each image (either inline or XObject) as it is encountered in the content stream.
@@ -52,7 +52,6 @@
private Stack<CurrentGraphicsState> graphicsStack = new Stack<CurrentGraphicsState>();
private IFont activeExtendedGraphicsStateFont;
private InlineImageBuilder inlineImageBuilder;
private bool currentPathAdded;
private int pageNumber;
/// <summary>
@@ -66,7 +65,9 @@
public TransformationMatrix CurrentTransformationMatrix => GetCurrentState().CurrentTransformationMatrix;
public PdfSubpath CurrentPath { get; private set; }
public PdfSubpath CurrentSubpath { get; private set; }
public PdfPath CurrentPath { get; private set; }
public IColorSpaceContext ColorSpaceContext { get; }
@@ -398,61 +399,22 @@
public void BeginSubpath()
{
if (CurrentPath != null && CurrentPath.Commands.Count > 0 && !currentPathAdded)
{
paths.Add(CurrentPath);
markedContentStack.AddPath(CurrentPath);
}
CurrentPath = new PdfSubpath();
currentPathAdded = false;
}
public void StrokePath(bool close)
{
if (CurrentPath == null)
{
return;
}
if (close)
{
ClosePath();
}
else
{
paths.Add(CurrentPath);
markedContentStack.AddPath(CurrentPath);
currentPathAdded = true;
}
}
public void FillPath(bool close)
{
if (CurrentPath == null)
{
return;
}
if (close)
{
ClosePath();
}
else
{
paths.Add(CurrentPath);
markedContentStack.AddPath(CurrentPath);
currentPathAdded = true;
}
}
public void ClosePath()
{
CurrentPath.ClosePath();
paths.Add(CurrentPath);
markedContentStack.AddPath(CurrentPath);
CurrentPath = null;
currentPathAdded = false;
}
public void SetNamedGraphicsState(NameToken stateName)
@@ -557,7 +519,7 @@
public void ModifyClippingIntersect(FillingRule clippingRule)
{
if (CurrentPath == null)
if (CurrentSubpath == null)
{
return;
}

View File

@@ -10,11 +10,17 @@
/// </summary>
public interface IOperationContext
{
/// <summary>
/// The current subpath being drawn if applicable.
/// </summary>
[CanBeNull]
PdfSubpath CurrentSubpath { get; }
/// <summary>
/// The current path being drawn if applicable.
/// </summary>
[CanBeNull]
PdfSubpath CurrentPath { get; }
PdfPath CurrentPath { get; }
/// <summary>
/// The active colorspaces for this content stream.

View File

@@ -78,7 +78,7 @@
var controlPoint1Transform = operationContext.CurrentTransformationMatrix.Transform(controlPoint1);
var controlPoint2Transform = operationContext.CurrentTransformationMatrix.Transform(controlPoint2);
var endTransform = operationContext.CurrentTransformationMatrix.Transform(end);
operationContext.CurrentPath.BezierCurveTo(controlPoint1Transform.X, controlPoint1Transform.Y,
operationContext.CurrentSubpath.BezierCurveTo(controlPoint1Transform.X, controlPoint1Transform.Y,
controlPoint2Transform.X, controlPoint2Transform.Y,
endTransform.X, endTransform.Y);
operationContext.CurrentPosition = endTransform;

View File

@@ -60,7 +60,7 @@
var end = new PdfPoint(X3, Y3);
var controlPoint1Transform = operationContext.CurrentTransformationMatrix.Transform(controlPoint1);
var endTransform = operationContext.CurrentTransformationMatrix.Transform(end);
operationContext.CurrentPath.BezierCurveTo(controlPoint1Transform.X, controlPoint1Transform.Y,
operationContext.CurrentSubpath.BezierCurveTo(controlPoint1Transform.X, controlPoint1Transform.Y,
endTransform.X,
endTransform.Y,
endTransform.X,

View File

@@ -63,7 +63,7 @@
var lowerLeftTransform = operationContext.CurrentTransformationMatrix.Transform(lowerLeft);
var upperRightTransform = operationContext.CurrentTransformationMatrix.Transform(upperRight);
operationContext.CurrentPath.Rectangle(lowerLeftTransform.X, lowerLeftTransform.Y, upperRightTransform.X - lowerLeftTransform.X, upperRightTransform.Y - lowerLeftTransform.Y);
operationContext.CurrentSubpath.Rectangle(lowerLeftTransform.X, lowerLeftTransform.Y, upperRightTransform.X - lowerLeftTransform.X, upperRightTransform.Y - lowerLeftTransform.Y);
}
/// <inheritdoc />

View File

@@ -60,7 +60,7 @@
var end = new PdfPoint(X3, Y3);
var controlPoint2Transform = operationContext.CurrentTransformationMatrix.Transform(controlPoint2);
var endTransform = operationContext.CurrentTransformationMatrix.Transform(end);
operationContext.CurrentPath.BezierCurveTo(operationContext.CurrentPosition.X,
operationContext.CurrentSubpath.BezierCurveTo(operationContext.CurrentPosition.X,
operationContext.CurrentPosition.Y,
controlPoint2Transform.X,
controlPoint2Transform.Y,

View File

@@ -42,7 +42,7 @@
public void Run(IOperationContext operationContext)
{
var endPoint = operationContext.CurrentTransformationMatrix.Transform(new PdfPoint(X, Y));
operationContext.CurrentPath.LineTo(endPoint.X, endPoint.Y);
operationContext.CurrentSubpath.LineTo(endPoint.X, endPoint.Y);
operationContext.CurrentPosition = endPoint;
}

View File

@@ -45,7 +45,7 @@
operationContext.BeginSubpath();
var pointTransform = operationContext.CurrentTransformationMatrix.Transform(point);
operationContext.CurrentPosition = pointTransform;
operationContext.CurrentPath.MoveTo(pointTransform.X, pointTransform.Y);
operationContext.CurrentSubpath.MoveTo(pointTransform.X, pointTransform.Y);
}
/// <inheritdoc />

View File

@@ -29,7 +29,7 @@
/// <inheritdoc />
public void Run(IOperationContext operationContext)
{
operationContext.CurrentPath?.ClosePath();
operationContext.CurrentSubpath?.ClosePath();
}
/// <inheritdoc />