mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-09-18 18:27:55 +08:00
Change Subpath to path where necessary
This commit is contained in:
@@ -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++;
|
||||
|
||||
|
@@ -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)
|
||||
|
@@ -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)
|
||||
|
@@ -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()));
|
||||
}
|
||||
|
||||
|
@@ -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)
|
||||
{
|
||||
|
@@ -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,
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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.
|
||||
|
@@ -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;
|
||||
|
@@ -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,
|
||||
|
@@ -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 />
|
||||
|
@@ -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,
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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 />
|
||||
|
@@ -29,7 +29,7 @@
|
||||
/// <inheritdoc />
|
||||
public void Run(IOperationContext operationContext)
|
||||
{
|
||||
operationContext.CurrentPath?.ClosePath();
|
||||
operationContext.CurrentSubpath?.ClosePath();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
Reference in New Issue
Block a user