From 7ab3a6a2cdbb80c613e5e80df56adce440220fdf Mon Sep 17 00:00:00 2001 From: BobLd <38405645+BobLd@users.noreply.github.com> Date: Sun, 22 Oct 2023 17:34:47 +0100 Subject: [PATCH] Add more classes to the Public API (#717) * Made interfaces and classes public * Made NamedDestinations public and fixed namespace * Fixed NamedDestinationsProvider namespace * Expose more internal classes as public * Update PublicApiScannerTests * Make setters internal --- .../PublicApiScannerTests.cs | 9 +++++++++ src/UglyToad.PdfPig/Content/Catalog.cs | 6 +++--- src/UglyToad.PdfPig/Content/IPageFactory.cs | 2 +- .../Content/PageTreeMembers.cs | 17 +++++++++++++---- src/UglyToad.PdfPig/Content/Pages.cs | 2 +- .../Filters/IFilterProvider.cs | 8 +++++++- src/UglyToad.PdfPig/Geometry/UserSpaceUnit.cs | 8 ++++++-- .../Graphics/Colors/ResourceColorSpace.cs | 12 +++++++++--- .../Graphics/InlineImageBuilder.cs | 19 +++++++++++++------ .../PerformantRectangleTransformer.cs | 8 +++++++- .../Outline/Destinations/NamedDestinations.cs | 9 ++++----- .../Destinations/NamedDestinationsProvider.cs | 6 ++---- src/UglyToad.PdfPig/Parser/CatalogFactory.cs | 2 +- .../Parser/IPageContentParser.cs | 8 +++++++- src/UglyToad.PdfPig/Parser/PageFactory.cs | 1 + src/UglyToad.PdfPig/PdfDocument.cs | 1 + src/UglyToad.PdfPig/PdfExtensions.cs | 16 +++++++++++----- .../Tokenization/Scanner/IPdfTokenScanner.cs | 2 +- 18 files changed, 97 insertions(+), 39 deletions(-) diff --git a/src/UglyToad.PdfPig.Tests/PublicApiScannerTests.cs b/src/UglyToad.PdfPig.Tests/PublicApiScannerTests.cs index b8716073..d11a0662 100644 --- a/src/UglyToad.PdfPig.Tests/PublicApiScannerTests.cs +++ b/src/UglyToad.PdfPig.Tests/PublicApiScannerTests.cs @@ -88,6 +88,7 @@ "UglyToad.PdfPig.Content.Page", "UglyToad.PdfPig.Content.PageRotationDegrees", "UglyToad.PdfPig.Content.PageSize", + "UglyToad.PdfPig.Content.PageTreeMembers", "UglyToad.PdfPig.Content.PageTreeNode", "UglyToad.PdfPig.Content.Word", "UglyToad.PdfPig.Content.TextOrientation", @@ -99,6 +100,7 @@ "UglyToad.PdfPig.Filters.DefaultFilterProvider", "UglyToad.PdfPig.Filters.IFilter", "UglyToad.PdfPig.Filters.IFilterProvider", + "UglyToad.PdfPig.Filters.ILookupFilterProvider", "UglyToad.PdfPig.Functions.FunctionTypes", "UglyToad.PdfPig.Functions.PdfFunction", "UglyToad.PdfPig.PdfFonts.CharacterBoundingBox", @@ -109,9 +111,11 @@ "UglyToad.PdfPig.PdfFonts.FontStretch", "UglyToad.PdfPig.PdfFonts.IFont", "UglyToad.PdfPig.Geometry.GeometryExtensions", + "UglyToad.PdfPig.Geometry.UserSpaceUnit", "UglyToad.PdfPig.Graphics.Colors.CMYKColor", "UglyToad.PdfPig.Graphics.Colors.ColorSpace", "UglyToad.PdfPig.Graphics.PdfPath", + "UglyToad.PdfPig.Graphics.Colors.ResourceColorSpace", "UglyToad.PdfPig.Graphics.Colors.ColorSpaceExtensions", "UglyToad.PdfPig.Graphics.Colors.ColorSpaceFamily", "UglyToad.PdfPig.Graphics.Colors.GrayColor", @@ -152,6 +156,7 @@ "UglyToad.PdfPig.Graphics.CurrentFontState", "UglyToad.PdfPig.Graphics.CurrentGraphicsState", "UglyToad.PdfPig.Graphics.IColorSpaceContext", + "UglyToad.PdfPig.Graphics.InlineImageBuilder", "UglyToad.PdfPig.Graphics.IOperationContext", "UglyToad.PdfPig.Graphics.Operations.ClippingPaths.ModifyClippingByEvenOddIntersect", "UglyToad.PdfPig.Graphics.Operations.ClippingPaths.ModifyClippingByNonZeroWindingIntersect", @@ -227,6 +232,7 @@ "UglyToad.PdfPig.Graphics.Operations.TextState.SetWordSpacing", "UglyToad.PdfPig.Graphics.Operations.TextState.Type3SetGlyphWidth", "UglyToad.PdfPig.Graphics.Operations.TextState.Type3SetGlyphWidthAndBoundingBox", + "UglyToad.PdfPig.Graphics.PerformantRectangleTransformer", "UglyToad.PdfPig.Graphics.TextMatrices", "UglyToad.PdfPig.Graphics.XObjectContentRecord", "UglyToad.PdfPig.Images.ColorSpaceDetailsByteConverter", @@ -240,12 +246,15 @@ "UglyToad.PdfPig.Outline.Destinations.ExplicitDestination", "UglyToad.PdfPig.Outline.Destinations.ExplicitDestinationCoordinates", "UglyToad.PdfPig.Outline.Destinations.ExplicitDestinationType", + "UglyToad.PdfPig.Outline.Destinations.NamedDestinations", "UglyToad.PdfPig.ParsingOptions", + "UglyToad.PdfPig.Parser.IPageContentParser", "UglyToad.PdfPig.PdfDocument", "UglyToad.PdfPig.PdfExtensions", "UglyToad.PdfPig.Rendering.IPageImageRenderer", "UglyToad.PdfPig.Rendering.PdfRendererImageFormat", "UglyToad.PdfPig.Structure", + "UglyToad.PdfPig.Tokenization.Scanner.IPdfTokenScanner", "UglyToad.PdfPig.Util.Adler32Checksum", "UglyToad.PdfPig.Util.IWordExtractor", "UglyToad.PdfPig.Util.DefaultWordExtractor", diff --git a/src/UglyToad.PdfPig/Content/Catalog.cs b/src/UglyToad.PdfPig/Content/Catalog.cs index 4153f259..582c1bed 100644 --- a/src/UglyToad.PdfPig/Content/Catalog.cs +++ b/src/UglyToad.PdfPig/Content/Catalog.cs @@ -1,7 +1,7 @@ namespace UglyToad.PdfPig.Content -{ +{ using System; - using Outline; + using Outline.Destinations; using Tokens; using Util.JetBrains.Annotations; @@ -9,7 +9,7 @@ /// The root of the document's object hierarchy. Contains references to objects defining the contents, /// outline, named destinations and more. /// - public class Catalog + public sealed class Catalog { /// /// The catalog dictionary containing assorted information. diff --git a/src/UglyToad.PdfPig/Content/IPageFactory.cs b/src/UglyToad.PdfPig/Content/IPageFactory.cs index c0380cad..93e1d8f4 100644 --- a/src/UglyToad.PdfPig/Content/IPageFactory.cs +++ b/src/UglyToad.PdfPig/Content/IPageFactory.cs @@ -1,6 +1,6 @@ namespace UglyToad.PdfPig.Content { - using Outline; + using Outline.Destinations; using Tokens; internal interface IPageFactory diff --git a/src/UglyToad.PdfPig/Content/PageTreeMembers.cs b/src/UglyToad.PdfPig/Content/PageTreeMembers.cs index 20ae0744..8e3f15b0 100644 --- a/src/UglyToad.PdfPig/Content/PageTreeMembers.cs +++ b/src/UglyToad.PdfPig/Content/PageTreeMembers.cs @@ -6,17 +6,26 @@ /// /// Contains the values inherited from the Page Tree for this page. /// - internal class PageTreeMembers + public sealed class PageTreeMembers { - public CropBox GetCropBox() + internal CropBox GetCropBox() { return null; } - public MediaBox MediaBox { get; set; } + /// + /// The page media box. + /// + public MediaBox MediaBox { get; internal set; } - public int Rotation { get; set; } + /// + /// The page rotation. + /// + public int Rotation { get; internal set; } + /// + /// The page parent resources. + /// public Queue ParentResources { get; } = new Queue(); } } \ No newline at end of file diff --git a/src/UglyToad.PdfPig/Content/Pages.cs b/src/UglyToad.PdfPig/Content/Pages.cs index e25d0137..f459e308 100644 --- a/src/UglyToad.PdfPig/Content/Pages.cs +++ b/src/UglyToad.PdfPig/Content/Pages.cs @@ -1,7 +1,7 @@ namespace UglyToad.PdfPig.Content { using Core; - using Outline; + using Outline.Destinations; using System; using System.Collections.Generic; using Tokenization.Scanner; diff --git a/src/UglyToad.PdfPig/Filters/IFilterProvider.cs b/src/UglyToad.PdfPig/Filters/IFilterProvider.cs index 51bcfecc..39b87fa2 100644 --- a/src/UglyToad.PdfPig/Filters/IFilterProvider.cs +++ b/src/UglyToad.PdfPig/Filters/IFilterProvider.cs @@ -25,8 +25,14 @@ IReadOnlyList GetAllFilters(); } - internal interface ILookupFilterProvider : IFilterProvider + /// + /// Gets filter implementations () for decoding PDF data. + /// + public interface ILookupFilterProvider : IFilterProvider { + /// + /// Get the filters specified in this dictionary, using the . + /// IReadOnlyList GetFilters(DictionaryToken dictionary, IPdfTokenScanner scanner); } } \ No newline at end of file diff --git a/src/UglyToad.PdfPig/Geometry/UserSpaceUnit.cs b/src/UglyToad.PdfPig/Geometry/UserSpaceUnit.cs index 65f15a22..15a0c292 100644 --- a/src/UglyToad.PdfPig/Geometry/UserSpaceUnit.cs +++ b/src/UglyToad.PdfPig/Geometry/UserSpaceUnit.cs @@ -7,8 +7,11 @@ /// By default user space units correspond to 1/72nd of an inch (a typographic point). /// The UserUnit entry in a page dictionary can define the space units as a different multiple of 1/72 (1 point). /// - internal readonly struct UserSpaceUnit + public readonly struct UserSpaceUnit { + /// + /// Default user space units with set to 1. + /// public static readonly UserSpaceUnit Default = new UserSpaceUnit(1); /// @@ -19,7 +22,7 @@ /// /// Create a new unit specification for a page. /// - public UserSpaceUnit(int pointMultiples) + internal UserSpaceUnit(int pointMultiples) { if (pointMultiples <= 0) { @@ -29,6 +32,7 @@ PointMultiples = pointMultiples; } + /// public override string ToString() { return PointMultiples.ToString(CultureInfo.InvariantCulture); diff --git a/src/UglyToad.PdfPig/Graphics/Colors/ResourceColorSpace.cs b/src/UglyToad.PdfPig/Graphics/Colors/ResourceColorSpace.cs index 748dd2b5..8d0cafe8 100644 --- a/src/UglyToad.PdfPig/Graphics/Colors/ResourceColorSpace.cs +++ b/src/UglyToad.PdfPig/Graphics/Colors/ResourceColorSpace.cs @@ -5,18 +5,24 @@ /// /// A color space definition from a resource dictionary. /// - internal readonly struct ResourceColorSpace + public readonly struct ResourceColorSpace { + /// + /// The color space name. + /// public NameToken Name { get; } + /// + /// The color space data. + /// public IToken Data { get; } - public ResourceColorSpace(NameToken name, IToken data) + internal ResourceColorSpace(NameToken name, IToken data) { Name = name; Data = data; } - public ResourceColorSpace(NameToken name) : this(name, null) { } + internal ResourceColorSpace(NameToken name) : this(name, null) { } } } diff --git a/src/UglyToad.PdfPig/Graphics/InlineImageBuilder.cs b/src/UglyToad.PdfPig/Graphics/InlineImageBuilder.cs index 213fa4e4..536554ba 100644 --- a/src/UglyToad.PdfPig/Graphics/InlineImageBuilder.cs +++ b/src/UglyToad.PdfPig/Graphics/InlineImageBuilder.cs @@ -3,22 +3,29 @@ using System; using System.Collections.Generic; using System.Linq; - using Colors; using Content; using Core; using Filters; using PdfPig.Core; using Tokenization.Scanner; using Tokens; - using Util; - internal class InlineImageBuilder + /// + /// Inline Image Builder. + /// + public sealed class InlineImageBuilder { - public IReadOnlyDictionary Properties { get; set; } + /// + /// Inline image properties. + /// + public IReadOnlyDictionary Properties { get; internal set; } - public IReadOnlyList Bytes { get; set; } + /// + /// Inline image bytes. + /// + public IReadOnlyList Bytes { get; internal set; } - public InlineImage CreateInlineImage(TransformationMatrix transformationMatrix, ILookupFilterProvider filterProvider, + internal InlineImage CreateInlineImage(TransformationMatrix transformationMatrix, ILookupFilterProvider filterProvider, IPdfTokenScanner tokenScanner, RenderingIntent defaultRenderingIntent, IResourceStore resourceStore) diff --git a/src/UglyToad.PdfPig/Graphics/PerformantRectangleTransformer.cs b/src/UglyToad.PdfPig/Graphics/PerformantRectangleTransformer.cs index 9dd10433..1e2ac4b0 100644 --- a/src/UglyToad.PdfPig/Graphics/PerformantRectangleTransformer.cs +++ b/src/UglyToad.PdfPig/Graphics/PerformantRectangleTransformer.cs @@ -2,8 +2,14 @@ { using PdfPig.Core; - internal static class PerformantRectangleTransformer + /// + /// Performant rectangle transformer. + /// + public static class PerformantRectangleTransformer { + /// + /// Transform the rectangle using the matrices. + /// public static PdfRectangle Transform(TransformationMatrix first, TransformationMatrix second, TransformationMatrix third, PdfRectangle rectangle) { var tl = rectangle.TopLeft; diff --git a/src/UglyToad.PdfPig/Outline/Destinations/NamedDestinations.cs b/src/UglyToad.PdfPig/Outline/Destinations/NamedDestinations.cs index 016a3f2b..1ce88378 100644 --- a/src/UglyToad.PdfPig/Outline/Destinations/NamedDestinations.cs +++ b/src/UglyToad.PdfPig/Outline/Destinations/NamedDestinations.cs @@ -1,15 +1,14 @@ -namespace UglyToad.PdfPig.Outline +namespace UglyToad.PdfPig.Outline.Destinations { - using Content; - using Destinations; - using Logging; using System.Collections.Generic; + using Content; + using Logging; using Tokens; /// /// Named destinations in a PDF document /// - internal class NamedDestinations + public class NamedDestinations { /// /// Dictionary containing explicit destinations, keyed by name diff --git a/src/UglyToad.PdfPig/Outline/Destinations/NamedDestinationsProvider.cs b/src/UglyToad.PdfPig/Outline/Destinations/NamedDestinationsProvider.cs index 52cc1f86..ac28331d 100644 --- a/src/UglyToad.PdfPig/Outline/Destinations/NamedDestinationsProvider.cs +++ b/src/UglyToad.PdfPig/Outline/Destinations/NamedDestinationsProvider.cs @@ -1,11 +1,9 @@ -namespace UglyToad.PdfPig.Outline +namespace UglyToad.PdfPig.Outline.Destinations { + using System.Collections.Generic; using Content; - using Destinations; using Logging; using Parser.Parts; - using System.Collections.Generic; - using System.Diagnostics; using Tokenization.Scanner; using Tokens; diff --git a/src/UglyToad.PdfPig/Parser/CatalogFactory.cs b/src/UglyToad.PdfPig/Parser/CatalogFactory.cs index 83c88449..4d8ce673 100644 --- a/src/UglyToad.PdfPig/Parser/CatalogFactory.cs +++ b/src/UglyToad.PdfPig/Parser/CatalogFactory.cs @@ -4,7 +4,7 @@ using Content; using Core; using Logging; - using Outline; + using Outline.Destinations; using Parts; using Tokenization.Scanner; using Tokens; diff --git a/src/UglyToad.PdfPig/Parser/IPageContentParser.cs b/src/UglyToad.PdfPig/Parser/IPageContentParser.cs index c7817b2f..51db0f61 100644 --- a/src/UglyToad.PdfPig/Parser/IPageContentParser.cs +++ b/src/UglyToad.PdfPig/Parser/IPageContentParser.cs @@ -5,8 +5,14 @@ using Graphics.Operations; using Logging; - internal interface IPageContentParser + /// + /// Page content parser interface. + /// + public interface IPageContentParser { + /// + /// Parse the into s. + /// IReadOnlyList Parse(int pageNumber, IInputBytes inputBytes, ILog log); } diff --git a/src/UglyToad.PdfPig/Parser/PageFactory.cs b/src/UglyToad.PdfPig/Parser/PageFactory.cs index aae5884e..74890e40 100644 --- a/src/UglyToad.PdfPig/Parser/PageFactory.cs +++ b/src/UglyToad.PdfPig/Parser/PageFactory.cs @@ -11,6 +11,7 @@ using Graphics.Operations; using Logging; using Outline; + using Outline.Destinations; using Parts; using Tokenization.Scanner; using Tokens; diff --git a/src/UglyToad.PdfPig/PdfDocument.cs b/src/UglyToad.PdfPig/PdfDocument.cs index fb27420c..50829f5f 100644 --- a/src/UglyToad.PdfPig/PdfDocument.cs +++ b/src/UglyToad.PdfPig/PdfDocument.cs @@ -14,6 +14,7 @@ using Tokenization.Scanner; using Tokens; using Outline; + using Outline.Destinations; using Util.JetBrains.Annotations; /// diff --git a/src/UglyToad.PdfPig/PdfExtensions.cs b/src/UglyToad.PdfPig/PdfExtensions.cs index 9d415455..4bbcc997 100644 --- a/src/UglyToad.PdfPig/PdfExtensions.cs +++ b/src/UglyToad.PdfPig/PdfExtensions.cs @@ -15,7 +15,7 @@ /// /// Try and get the entry with a given name and type or look-up the object if it's an indirect reference. /// - internal static bool TryGet(this DictionaryToken dictionary, NameToken name, IPdfTokenScanner tokenScanner, out T token) where T : IToken + public static bool TryGet(this DictionaryToken dictionary, NameToken name, IPdfTokenScanner tokenScanner, out T token) where T : IToken { token = default(T); if (!dictionary.TryGet(name, out var t) || !(t is T typedToken)) @@ -31,8 +31,11 @@ token = typedToken; return true; } - - internal static T Get(this DictionaryToken dictionary, NameToken name, IPdfTokenScanner scanner) where T : class, IToken + + /// + /// Get the entry with a given name and type or look-up the object if it's an indirect reference. + /// + public static T Get(this DictionaryToken dictionary, NameToken name, IPdfTokenScanner scanner) where T : class, IToken { if (!dictionary.TryGet(name, out var token) || !(token is T typedToken)) { @@ -61,9 +64,12 @@ } return transform; - } + } - internal static IReadOnlyList Decode(this StreamToken stream, ILookupFilterProvider filterProvider, IPdfTokenScanner scanner) + /// + /// Get the decoded data from this stream. + /// + public static IReadOnlyList Decode(this StreamToken stream, ILookupFilterProvider filterProvider, IPdfTokenScanner scanner) { var filters = filterProvider.GetFilters(stream.StreamDictionary, scanner); diff --git a/src/UglyToad.PdfPig/Tokenization/Scanner/IPdfTokenScanner.cs b/src/UglyToad.PdfPig/Tokenization/Scanner/IPdfTokenScanner.cs index 31171cc4..5ba7269c 100644 --- a/src/UglyToad.PdfPig/Tokenization/Scanner/IPdfTokenScanner.cs +++ b/src/UglyToad.PdfPig/Tokenization/Scanner/IPdfTokenScanner.cs @@ -7,7 +7,7 @@ /// /// Tokenizes objects from bytes in a PDF file. /// - internal interface IPdfTokenScanner : ISeekableTokenScanner, IDisposable + public interface IPdfTokenScanner : ISeekableTokenScanner, IDisposable { /// /// Tokenize the object with a given object number.