Skip to content

Commit

Permalink
Move Paths, GetAnnotations() and GetOptionalContents() outside of Exp…
Browse files Browse the repository at this point in the history
…erimentalAccess and mark Experimental class and reference as obsolete
  • Loading branch information
BobLd committed Oct 30, 2024
1 parent 40af401 commit d3bf63f
Show file tree
Hide file tree
Showing 18 changed files with 99 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private AltoDocument.AltoPage ToAltoPage(Page page, bool includePaths)

if (includePaths)
{
altoPage.PrintSpace.GraphicalElements = page.ExperimentalAccess.Paths
altoPage.PrintSpace.GraphicalElements = page.Paths
.Select(p => ToAltoGraphicalElement(p, page.Height))
.ToArray();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ private string GetCode(Page page, bool includePaths, string imageName = "unknown

if (includePaths)
{
foreach (var path in page.ExperimentalAccess.Paths)
foreach (var path in page.Paths)
{
hocr += "\n" + GetCode(path, page.Height, true, level + 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ private PageXmlDocument.PageXmlPage ToPageXmlPage(Page page, PageXmlData data, b

if (includePaths)
{
foreach (var path in page.ExperimentalAccess.Paths)
foreach (var path in page.Paths)
{
var graphicalElement = ToPageXmlLineDrawingRegion(path, data, page.Width, page.Height);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public string Get(Page page)
{
var builder = new StringBuilder($"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width='{Math.Round(page.Width, Rounding)}' height='{Math.Round(page.Height, Rounding)}'>\n<g transform=\"scale(1, 1) translate(0, 0)\">\n");

foreach (var path in page.ExperimentalAccess.Paths)
foreach (var path in page.Paths)
{
if (!path.IsClipping)
{
Expand Down
2 changes: 1 addition & 1 deletion src/UglyToad.PdfPig.Tests/Geometry/ClippingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public void ContainsRectangleEvenOdd()
new ParsingOptions { ClipPaths = true }))
{
var page = document.GetPage(45);
Assert.Equal(28, page.ExperimentalAccess.Paths.Count);
Assert.Equal(28, page.Paths.Count);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void ContainsRectangleEvenOdd()
var page = document.GetPage(1);
var words = page.GetWords().ToList();

foreach (var path in page.ExperimentalAccess.Paths)
foreach (var path in page.Paths)
{
Assert.NotEqual(FillingRule.NonZeroWinding, path.FillingRule); // allow none and even-odd

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public void HasCorrectNumberOfAnnotations()

var page = document.GetPage(1);

var annotations = page.ExperimentalAccess.GetAnnotations().ToList();
var annotations = page.GetAnnotations().ToArray();

Assert.Equal(4, annotations.Count);
Assert.Equal(4, annotations.Length);

Assert.Equal(AnnotationType.Text, annotations[0].Type);
Assert.Equal(AnnotationType.Popup, annotations[1].Type);
Expand All @@ -33,7 +33,7 @@ public void SecondTextReplyToFirst()

var page = document.GetPage(1);

var annotations = page.ExperimentalAccess.GetAnnotations().ToList();
var annotations = page.GetAnnotations().ToArray();

Assert.Equal(annotations[0], annotations[2].InReplyTo);
}
Expand Down
4 changes: 2 additions & 2 deletions src/UglyToad.PdfPig.Tests/Integration/AnnotationsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public void AnnotationsHaveActions()

using (var doc = PdfDocument.Open(pdf))
{
var annots = doc.GetPage(1).ExperimentalAccess.GetAnnotations().ToArray();
var annots = doc.GetPage(1).GetAnnotations().ToArray();
Assert.Equal(5, annots.Length);
Assert.All(annots, a => Assert.NotNull(a.Action));
Assert.All(annots, a => Assert.IsType<GoToAction>(a.Action));
Expand All @@ -25,7 +25,7 @@ public void CheckAnnotationAppearanceStreams()
var pdf = IntegrationHelpers.GetSpecificTestDocumentPath("appearances");
using (var doc = PdfDocument.Open(pdf))
{
var annotations = doc.GetPage(1).ExperimentalAccess.GetAnnotations().ToArray();
var annotations = doc.GetPage(1).GetAnnotations().ToArray();
var annotation = Assert.Single(annotations);

Assert.True(annotation.HasDownAppearance);
Expand Down
2 changes: 1 addition & 1 deletion src/UglyToad.PdfPig.Tests/Integration/CatGeneticsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void CanGetAnnotations()
{
var page = document.GetPage(1);

var annotations = page.ExperimentalAccess.GetAnnotations().ToList();
var annotations = page.GetAnnotations().ToArray();

Assert.NotEmpty(annotations);

Expand Down
6 changes: 3 additions & 3 deletions src/UglyToad.PdfPig.Tests/Integration/ColorSpaceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public void SeparationLabColorSpace()
{
var page1 = document.GetPage(1);

var background = page1.ExperimentalAccess.Paths[0];
var background = page1.Paths[0];
Assert.True(background.IsFilled);

var (r, g, b) = background.FillColor.ToRGBValues();
Expand Down Expand Up @@ -327,7 +327,7 @@ public void SeparationIccColorSpacesWithForm()
using (var document = PdfDocument.Open(path))
{
Page page1 = document.GetPage(1);
var paths1 = page1.ExperimentalAccess.Paths.Where(p => p.IsFilled).ToArray();
var paths1 = page1.Paths.Where(p => p.IsFilled).ToArray();
var reflexRed = paths1[0].FillColor.ToRGBValues(); // 'Reflex Red' Separation color space
Assert.Equal(0.930496, reflexRed.r, 6);
Assert.Equal(0.111542, reflexRed.g, 6);
Expand All @@ -341,7 +341,7 @@ public void SeparationIccColorSpacesWithForm()
Assert.Equal("w", firstLetter.Value);
Assert.Equal((0, 0, 1), firstLetter.Color.ToRGBValues()); // Blue

var paths2 = page2.ExperimentalAccess.Paths;
var paths2 = page2.Paths;
var filledPath = paths2.Where(p => p.IsFilled).ToArray();
var filledRects = filledPath.Where(p => p.Count == 1 && p[0].IsDrawnAsRectangle).ToArray();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void CanReadAllPages(string documentName)
{
var page = document.GetPage(i + 1);

Assert.NotNull(page.ExperimentalAccess.GetAnnotations().ToList());
Assert.NotNull(page.GetAnnotations().ToArray());
}
}
}
Expand All @@ -45,7 +45,7 @@ public void CanUseStreamForFirstPage(string documentName)
{
var page = document.GetPage(i + 1);

Assert.NotNull(page.ExperimentalAccess.GetAnnotations().ToList());
Assert.NotNull(page.GetAnnotations().ToArray());
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/UglyToad.PdfPig.Tests/Integration/OptionalContentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public void NoMarkedOptionalContent()
using (var document = PdfDocument.Open(IntegrationHelpers.GetDocumentPath("AcroFormsBasicFields.pdf")))
{
var page = document.GetPage(1);
var oc = page.ExperimentalAccess.GetOptionalContents();
var oc = page.GetOptionalContents();

Assert.Empty(oc);
}
Expand All @@ -20,7 +20,7 @@ public void MarkedOptionalContent()
using (var document = PdfDocument.Open(IntegrationHelpers.GetDocumentPath("odwriteex.pdf")))
{
var page = document.GetPage(1);
var oc = page.ExperimentalAccess.GetOptionalContents();
var oc = page.GetOptionalContents();

Assert.Equal(3, oc.Count);

Expand All @@ -40,19 +40,19 @@ public void MarkedOptionalContentRecursion()
using (var document = PdfDocument.Open(IntegrationHelpers.GetDocumentPath("Layer pdf - 322_High_Holborn_building_Brochure.pdf")))
{
var page1 = document.GetPage(1);
var oc1 = page1.ExperimentalAccess.GetOptionalContents();
var oc1 = page1.GetOptionalContents();
Assert.Equal(16, oc1.Count);
Assert.Contains("NEW ARRANGEMENT", oc1);

var page2 = document.GetPage(2);
var oc2 = page2.ExperimentalAccess.GetOptionalContents();
var oc2 = page2.GetOptionalContents();
Assert.Equal(15, oc2.Count);
Assert.DoesNotContain("NEW ARRANGEMENT", oc2);
Assert.Contains("WDL Shell text", oc2);
Assert.Equal(2, oc2["WDL Shell text"].Count);

var page3 = document.GetPage(3);
var oc3 = page3.ExperimentalAccess.GetOptionalContents();
var oc3 = page3.GetOptionalContents();
Assert.Equal(15, oc3.Count);
Assert.Contains("WDL Shell text", oc3);
Assert.Equal(2, oc3["WDL Shell text"].Count);
Expand Down
10 changes: 5 additions & 5 deletions src/UglyToad.PdfPig.Tests/Integration/PatternColorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public void ShadingPattern1()
{
var page = document.GetPage(1);

var annotationStamp = page.ExperimentalAccess.GetAnnotations().ElementAt(14);
var annotationStamp = page.GetAnnotations().ElementAt(14);
Assert.Equal(Annotations.AnnotationType.Stamp, annotationStamp.Type);
Assert.True(annotationStamp.HasNormalAppearance);

Expand All @@ -28,7 +28,7 @@ public void ShadingPattern2()
using (var document = PdfDocument.Open(IntegrationHelpers.GetDocumentPath("output_w3c_csswg_drafts_issues2023.pdf")))
{
var page = document.GetPage(1);
var path = page.ExperimentalAccess.Paths.Single();
var path = page.Paths.Single();
var color = path.FillColor;
Assert.Equal(ColorSpace.Pattern, color.ColorSpace);

Expand All @@ -55,7 +55,7 @@ public void TillingPattern1()
using (var document = PdfDocument.Open(IntegrationHelpers.GetDocumentPath("22060_A1_01_Plans-1.pdf")))
{
var page = document.GetPage(1);
var filledPath = page.ExperimentalAccess.Paths.Where(p => p.IsFilled).ToArray();
var filledPath = page.Paths.Where(p => p.IsFilled).ToArray();
var pattern = filledPath[0].FillColor;
Assert.Equal(ColorSpace.Pattern, pattern.ColorSpace);

Expand Down Expand Up @@ -100,7 +100,7 @@ public void TillingPattern2()
{
// page 53
var page = document.GetPage(53);
var strokedPath = page.ExperimentalAccess.Paths.Where(p => p.StrokeColor?.ColorSpace == ColorSpace.Pattern).ToArray();
var strokedPath = page.Paths.Where(p => p.StrokeColor?.ColorSpace == ColorSpace.Pattern).ToArray();
Assert.Equal(5, strokedPath.Length);
foreach (var p in strokedPath)
{
Expand All @@ -114,7 +114,7 @@ public void TillingPattern2()

// page 307
page = document.GetPage(307);
strokedPath = page.ExperimentalAccess.Paths.Where(p => p.StrokeColor?.ColorSpace == ColorSpace.Pattern).ToArray();
strokedPath = page.Paths.Where(p => p.StrokeColor?.ColorSpace == ColorSpace.Pattern).ToArray();
Assert.Equal(2, strokedPath.Length);
foreach (var p in strokedPath)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void WrongPathCount()
{
var page = document.GetPage(1);
Assert.Equal(612, page.Height);
Assert.Equal(224, page.ExperimentalAccess.Paths.Count);
Assert.Equal(224, page.Paths.Count);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private static void Run(string file, int imageHeight = 792, int pageNo = 1)
DrawRectangle(letter.GlyphRectangle, graphics, violetPen, imageHeight, scale);
}

foreach (var annotation in page.ExperimentalAccess.GetAnnotations())
foreach (var annotation in page.GetAnnotations())
{
DrawRectangle(annotation.Rectangle, graphics, bluePen, imageHeight, scale);
}
Expand Down
8 changes: 4 additions & 4 deletions src/UglyToad.PdfPig.Tests/Writer/PdfDocumentBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,16 @@ public void CanFastAddPageAndStripLinkAnnots()
output.AddPage(existing, 1);
results = output.Build();
var pg = existing.GetPage(1);
var annots = pg.ExperimentalAccess.GetAnnotations().ToList();
annotCount = annots.Count;
var annots = pg.GetAnnotations().ToArray();
annotCount = annots.Length;
Assert.Contains(annots, x => x.Type == Annotations.AnnotationType.Link);
}

using (var rewritten = PdfDocument.Open(results, ParsingOptions.LenientParsingOff))
{
var pg = rewritten.GetPage(1);
var annots = pg.ExperimentalAccess.GetAnnotations().ToList();
Assert.Equal(annotCount - 1, annots.Count);
var annots = pg.GetAnnotations().ToArray();
Assert.Equal(annotCount - 1, annots.Length);
Assert.DoesNotContain(annots, x => x.Type == Annotations.AnnotationType.Link);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/UglyToad.PdfPig.Tests/Writer/PdfMergerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public void CanMergeWithLinks()
using (var document = PdfDocument.Open(result, ParsingOptions.LenientParsingOff))
{
Assert.Equal(2, document.GetPages().Sum(
page => page.ExperimentalAccess.GetAnnotations().Count(x => x.Type == Annotations.AnnotationType.Link)));
page => page.GetAnnotations().Count(x => x.Type == Annotations.AnnotationType.Link)));
}
}

Expand All @@ -209,7 +209,7 @@ public void CanMergeWithLinksWithSelection()
using (var document = PdfDocument.Open(result, ParsingOptions.LenientParsingOff))
{
Assert.Equal(1, document.GetPages().Sum(
page => page.ExperimentalAccess.GetAnnotations().Count(x => x.Type == Annotations.AnnotationType.Link)));
page => page.GetAnnotations().Count(x => x.Type == Annotations.AnnotationType.Link)));
}
}

Expand Down
Loading

0 comments on commit d3bf63f

Please sign in to comment.