Skip to content

Commit 6f5d96c

Browse files
committed
More XML comments
1 parent 0017f73 commit 6f5d96c

File tree

10 files changed

+467
-18
lines changed

10 files changed

+467
-18
lines changed

src/Synercoding.FileFormats.Pdf/Extensions/IPageContentContextExtensions.cs

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,21 @@
88
using System.Threading.Tasks;
99

1010
namespace Synercoding.FileFormats.Pdf.Extensions;
11+
12+
/// <summary>
13+
/// Extension methods for <see cref="IPageContentContext"/>
14+
/// </summary>
1115
public static class IPageContentContextExtensions
1216
{
17+
/// <summary>
18+
/// Add a JPG stream directly to the page
19+
/// </summary>
20+
/// <param name="context">The context to add the image to.</param>
21+
/// <param name="jpgStream">The stream containing a JPG image</param>
22+
/// <param name="originalWidth">The width of the JPG in the <paramref name="jpgStream"/>.</param>
23+
/// <param name="originalHeight">The height of the JPG in the <paramref name="jpgStream"/>.</param>
24+
/// <param name="colorSpace">The colorspace of the JPG in the <paramref name="jpgStream"/>.</param>
25+
/// <returns>The same <paramref name="context"/> to enable chaining operations.</returns>
1326
public static IPageContentContext AddJpgUnsafe(this IPageContentContext context, System.IO.Stream jpgStream, int originalWidth, int originalHeight, ColorSpace colorSpace)
1427
{
1528
var name = context.RawContentStream.Resources.AddJpgUnsafe(jpgStream, originalWidth, originalHeight, colorSpace);
@@ -19,6 +32,13 @@ public static IPageContentContext AddJpgUnsafe(this IPageContentContext context,
1932
return context;
2033
}
2134

35+
/// <summary>
36+
/// Add an image to the page
37+
/// </summary>
38+
/// <param name="context">The context to add the image to.</param>
39+
/// <param name="stream">The stream containing the image</param>
40+
/// <param name="matrix">The placement matrix to use</param>
41+
/// <returns>The same <paramref name="context"/> to enable chaining operations.</returns>
2242
public static IPageContentContext AddImage(this IPageContentContext context, System.IO.Stream stream, Matrix matrix)
2343
{
2444
return context.WrapInState((stream, matrix), static (tuple, context) =>
@@ -28,16 +48,36 @@ public static IPageContentContext AddImage(this IPageContentContext context, Sys
2848
});
2949
}
3050

51+
/// <summary>
52+
/// Add an image to the page
53+
/// </summary>
54+
/// <param name="context">The context to add the image to.</param>
55+
/// <param name="stream">The stream containing the image</param>
56+
/// <param name="rectangle">The rectangle of where to place the image.</param>
57+
/// <returns>The same <paramref name="context"/> to enable chaining operations.</returns>
3158
public static IPageContentContext AddImage(this IPageContentContext context, System.IO.Stream stream, Rectangle rectangle)
3259
=> context.AddImage(stream, rectangle.AsPlacementMatrix());
3360

61+
/// <summary>
62+
/// Add an image to the page
63+
/// </summary>
64+
/// <param name="context">The context to add the image to.</param>
65+
/// <param name="stream">The stream containing the image</param>
66+
/// <returns>The same <paramref name="context"/> to enable chaining operations.</returns>
3467
public static IPageContentContext AddImage(this IPageContentContext context, System.IO.Stream stream)
3568
{
3669
using var image = SixLabors.ImageSharp.Image.Load(stream);
3770

3871
return context.AddImage(image);
3972
}
4073

74+
/// <summary>
75+
/// Add an image to the page
76+
/// </summary>
77+
/// <param name="context">The context to add the image to.</param>
78+
/// <param name="image">The image to place</param>
79+
/// <param name="matrix">The placement matrix to use</param>
80+
/// <returns>The same <paramref name="context"/> to enable chaining operations.</returns>
4181
public static IPageContentContext AddImage(this IPageContentContext context, SixLabors.ImageSharp.Image image, Matrix matrix)
4282
{
4383
return context.WrapInState((image, matrix), static (tuple, context) =>
@@ -47,9 +87,22 @@ public static IPageContentContext AddImage(this IPageContentContext context, Six
4787
});
4888
}
4989

90+
/// <summary>
91+
/// Add an image to the page
92+
/// </summary>
93+
/// <param name="context">The context to add the image to.</param>
94+
/// <param name="image">The image to place</param>
95+
/// <param name="rectangle">The rectangle of where to place the image.</param>
96+
/// <returns>The same <paramref name="context"/> to enable chaining operations.</returns>
5097
public static IPageContentContext AddImage(this IPageContentContext context, SixLabors.ImageSharp.Image image, Rectangle rectangle)
5198
=> context.AddImage(image, rectangle.AsPlacementMatrix());
5299

100+
/// <summary>
101+
/// Add an image to the page
102+
/// </summary>
103+
/// <param name="context">The context to add the image to.</param>
104+
/// <param name="image">The image to place</param>
105+
/// <returns>The same <paramref name="context"/> to enable chaining operations.</returns>
53106
public static IPageContentContext AddImage(this IPageContentContext context, SixLabors.ImageSharp.Image image)
54107
{
55108
var name = context.RawContentStream.Resources.AddImage(image);
@@ -59,9 +112,23 @@ public static IPageContentContext AddImage(this IPageContentContext context, Six
59112
return context;
60113
}
61114

115+
/// <summary>
116+
/// Add an image to the page
117+
/// </summary>
118+
/// <param name="context">The context to add the image to.</param>
119+
/// <param name="image">The image to place</param>
120+
/// <param name="rectangle">The rectangle of where to place the image.</param>
121+
/// <returns>The same <paramref name="context"/> to enable chaining operations.</returns>
62122
public static IPageContentContext AddImage(this IPageContentContext context, Image image, Rectangle rectangle)
63123
=> context.AddImage(image, rectangle.AsPlacementMatrix());
64124

125+
/// <summary>
126+
/// Add an image to the page
127+
/// </summary>
128+
/// <param name="context">The context to add the image to.</param>
129+
/// <param name="image">The image to place</param>
130+
/// <param name="matrix">The placement matrix to use</param>
131+
/// <returns>The same <paramref name="context"/> to enable chaining operations.</returns>
65132
public static IPageContentContext AddImage(this IPageContentContext context, Image image, Matrix matrix)
66133
{
67134
return context.WrapInState((image, matrix), static (tuple, context) =>
@@ -71,27 +138,88 @@ public static IPageContentContext AddImage(this IPageContentContext context, Ima
71138
});
72139
}
73140

141+
/// <summary>
142+
/// Start a shape operation on the page
143+
/// </summary>
144+
/// <param name="context">The context to add the shape to.</param>
145+
/// <param name="shapeOperations">The shape operations to execute</param>
146+
/// <returns>The same <paramref name="context"/> to enable chaining operations.</returns>
74147
public static IPageContentContext AddShapes(this IPageContentContext context, Action<IShapeContentContext> shapeOperations)
75148
=> context.AddShapes(shapeOperations, static (operations, context) => operations(context));
76149

150+
/// <summary>
151+
/// Start a shape operation on the page
152+
/// </summary>
153+
/// <param name="context">The context to add the shape to.</param>
154+
/// <param name="shapeOperations">The shape operations to execute</param>
155+
/// <returns>A task that resolves to <paramref name="context"/> to enable chaining operations</returns>
77156
public static Task<IPageContentContext> AddShapesAsync(this IPageContentContext context, Func<IShapeContentContext, Task> shapeOperations)
78157
=> context.AddShapesAsync(shapeOperations, static (operations, context) => operations(context));
79158

159+
/// <summary>
160+
/// Start a text operation on the page
161+
/// </summary>
162+
/// <param name="context">The context to add the text to.</param>
163+
/// <param name="textOperations">The text operations to execute</param>
164+
/// <returns>The same <paramref name="context"/> to enable chaining operations.</returns>
80165
public static IPageContentContext AddText(this IPageContentContext context, Action<ITextContentContext> textOperations)
81166
=> context.AddText(textOperations, static (operations, context) => operations(context));
82167

168+
/// <summary>
169+
/// Start a text operation on the page
170+
/// </summary>
171+
/// <param name="context">The context to add the text to.</param>
172+
/// <param name="textOperations">The text operations to execute</param>
173+
/// <returns>A task that resolves to <paramref name="context"/> to enable chaining operations</returns>
83174
public static Task<IPageContentContext> AddTextAsync(this IPageContentContext context, Func<ITextContentContext, Task> textOperations)
84175
=> context.AddTextAsync(textOperations, static (operations, context) => operations(context));
85176

177+
/// <summary>
178+
/// Show text on the page using the parameters provided
179+
/// </summary>
180+
/// <param name="context">The context to add the text to.</param>
181+
/// <param name="text">The text to show</param>
182+
/// <param name="font">The font to use</param>
183+
/// <param name="size">The font size to use</param>
184+
/// <returns>The same <paramref name="context"/> to enable chaining operations.</returns>
86185
public static IPageContentContext AddText(this IPageContentContext context, string text, Font font, double size)
87186
=> context.AddText(text, font, size, ops => { });
88187

188+
/// <summary>
189+
/// Show text on the page using the parameters provided
190+
/// </summary>
191+
/// <param name="context">The context to add the text to.</param>
192+
/// <param name="text">The text to show</param>
193+
/// <param name="font">The font to use</param>
194+
/// <param name="size">The font size to use</param>
195+
/// <param name="location">The location to place the text</param>
196+
/// <returns>The same <paramref name="context"/> to enable chaining operations.</returns>
89197
public static IPageContentContext AddText(this IPageContentContext context, string text, Font font, double size, Point location)
90198
=> context.AddText(text, font, size, location, static (location, ops) => ops.MoveToStartNextLine(location.X.AsRaw(Unit.Points), location.Y.AsRaw(Unit.Points)));
91199

200+
/// <summary>
201+
/// Show text on the page using the parameters provided
202+
/// </summary>
203+
/// <param name="context">The context to add the text to.</param>
204+
/// <param name="text">The text to show</param>
205+
/// <param name="font">The font to use</param>
206+
/// <param name="size">The font size to use</param>
207+
/// <param name="extraOperations">The extra text operations to execute</param>
208+
/// <returns>The same <paramref name="context"/> to enable chaining operations.</returns>
92209
public static IPageContentContext AddText(this IPageContentContext context, string text, Font font, double size, Action<ITextContentContext> extraOperations)
93210
=> context.AddText(text, font, size, extraOperations, static (extraOperations, context) => extraOperations(context));
94211

212+
/// <summary>
213+
/// Show text on the page using the parameters provided
214+
/// </summary>
215+
/// <typeparam name="T">The type of the data to provide to the <paramref name="extraOperations"/></typeparam>
216+
/// <param name="context">The context to add the text to.</param>
217+
/// <param name="text">The text to show</param>
218+
/// <param name="font">The font to use</param>
219+
/// <param name="size">The font size to use</param>
220+
/// <param name="data">the data to provide to <paramref name="extraOperations"/></param>
221+
/// <param name="extraOperations">The extra text operations to execute</param>
222+
/// <returns>The same <paramref name="context"/> to enable chaining operations.</returns>
95223
public static IPageContentContext AddText<T>(this IPageContentContext context, string text, Font font, double size, T data, Action<T, ITextContentContext> extraOperations)
96224
{
97225
return context.AddText((text, font, size, data, extraOperations), static (quintuple, context) =>

src/Synercoding.FileFormats.Pdf/Extensions/IShapeContextExtensions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,18 @@
22
using Synercoding.Primitives.Extensions;
33

44
namespace Synercoding.FileFormats.Pdf.Extensions;
5+
6+
/// <summary>
7+
/// Extensions for <see cref="IShapeContentContext"/>
8+
/// </summary>
59
public static class IShapeContextExtensions
610
{
11+
/// <summary>
12+
/// Add a rectangle to the current path
13+
/// </summary>
14+
/// <param name="context">The context to execute this path on.</param>
15+
/// <param name="rectangle">The <see cref="Synercoding.Primitives.Rectangle"/> to add.</param>
16+
/// <returns>The same <paramref name="context"/> to enable chaining operations.</returns>
717
public static IShapeContentContext Rectangle(this IShapeContentContext context, Rectangle rectangle)
818
=> context.Rectangle(rectangle.LLX.AsRaw(Unit.Points), rectangle.LLY.AsRaw(Unit.Points), rectangle.Width.AsRaw(Unit.Points), rectangle.Height.AsRaw(Unit.Points));
919
}

src/Synercoding.FileFormats.Pdf/GraphicState.cs

Lines changed: 80 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55

66
namespace Synercoding.FileFormats.Pdf;
77

8+
/// <summary>
9+
/// Class representing the grahpic state of a PDF at a certain moment in time.
10+
/// </summary>
811
public sealed class GraphicState
912
{
1013
internal GraphicState()
1114
{
1215
CTM = Matrix.Identity;
13-
FillColor = PredefinedColors.Black;
14-
StrokeColor = PredefinedColors.Black;
16+
Fill = PredefinedColors.Black;
17+
Stroke = PredefinedColors.Black;
1518
LineWidth = 1.0;
1619
LineCap = LineCapStyle.ButtCap;
1720
LineJoin = LineJoinStyle.MiterJoin;
@@ -27,30 +30,95 @@ internal GraphicState()
2730
TextRise = 0.0;
2831
}
2932

30-
public Matrix CTM { get; internal set; }
31-
public Color FillColor { get; internal set; }
32-
public Color StrokeColor { get; internal set; }
33-
public double LineWidth { get; internal set; }
34-
public LineCapStyle LineCap { get; internal set; }
33+
/// <summary>
34+
/// The current transformation matrix, which maps positions from user coordinates to device coordinates.
35+
/// This matrix is modified by each application of the coordinate transformation operator, cm
36+
/// </summary>
37+
public Matrix CTM { get; internal set; }
38+
39+
/// <summary>
40+
/// The color used for filling operations
41+
/// </summary>
42+
public Color Fill { get; internal set; }
43+
44+
/// <summary>
45+
/// The color used for stroking operations
46+
/// </summary>
47+
public Color Stroke { get; internal set; }
48+
49+
/// <summary>
50+
/// The thickness, in user space units, of paths to be stroked.
51+
/// </summary>
52+
public double LineWidth { get; internal set; }
53+
54+
/// <summary>
55+
/// A code specifying the shape of the endpoints for any open path that is stroked.
56+
/// </summary>
57+
public LineCapStyle LineCap { get; internal set; }
58+
59+
/// <summary>
60+
/// A code specifying the shape of joints between connected segments of a stroked path.
61+
/// </summary>
3562
public LineJoinStyle LineJoin { get; internal set; }
63+
64+
/// <summary>
65+
/// The maximum length of mitered line joins for stroked paths.
66+
/// This parameter limits the length of “spikes” produced when line segments join at sharp angles.
67+
/// </summary>
3668
public double MiterLimit { get; internal set; }
37-
public Dash DashPattern { get; internal set; }
38-
public double CharacterSpacing { get; internal set; }
39-
public double WordSpacing { get; internal set; }
69+
70+
/// <summary>
71+
/// A description of the dash pattern to be used when paths are stroked.
72+
/// </summary>
73+
public Dash DashPattern { get; internal set; }
74+
75+
/// <summary>
76+
/// The spacing between characters
77+
/// </summary>
78+
public double CharacterSpacing { get; internal set; }
79+
80+
/// <summary>
81+
/// The spacing between words
82+
/// </summary>
83+
public double WordSpacing { get; internal set; }
84+
85+
/// <summary>
86+
/// The horizontal scaling is a number specifying the percentage of the normal width.
87+
/// </summary>
4088
public double HorizontalScaling { get; internal set; }
89+
90+
/// <summary>
91+
/// The text leading is a number expressed in unscaled text space units.
92+
/// </summary>
4193
public double TextLeading { get; internal set; }
94+
95+
/// <summary>
96+
/// The font used when placing text on the page
97+
/// </summary>
4298
public Font? Font { get; internal set; }
99+
100+
/// <summary>
101+
/// The font size used when placing text on the page
102+
/// </summary>
43103
public double? FontSize { get; internal set; }
104+
105+
/// <summary>
106+
/// The text rendering mode, determines whether showing text causes glyph outlines to be stroked, filled, used as a clipping boundary, or some combination of the three.
107+
/// </summary>
44108
public TextRenderingMode TextRenderingMode { get; internal set; }
109+
110+
/// <summary>
111+
/// Text rise, specifies the distance, in unscaled text space units, to move the baseline up or down from its default location.
112+
/// </summary>
45113
public double TextRise { get; internal set; }
46114

47115
internal GraphicState Clone()
48116
{
49117
return new GraphicState()
50118
{
51119
CTM = CTM,
52-
FillColor = FillColor,
53-
StrokeColor = StrokeColor,
120+
Fill = Fill,
121+
Stroke = Stroke,
54122
LineWidth = LineWidth,
55123
LineCap = LineCap,
56124
LineJoin = LineJoin,

0 commit comments

Comments
 (0)