Skip to content

Commit 90eb7db

Browse files
Fix compilation VS2019, undo bogus null-check-removal in XGraphcs
1 parent 8ed0880 commit 90eb7db

File tree

4 files changed

+80
-26
lines changed

4 files changed

+80
-26
lines changed

PdfSharpCore/Drawing/XGraphics.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ public sealed class XGraphics : IDisposable
123123
}
124124
XGraphics(XSize size, XGraphicsUnit pageUnit, XPageDirection pageDirection)
125125
{
126+
if (size == null)
127+
throw new ArgumentNullException("size");
128+
126129
_gsStack = new GraphicsStateStack(this);
127130
_pageSizePoints = new XSize(size.Width, size.Height);
128131
switch (pageUnit)

PdfSharpCore/Pdf.AcroForms/PdfAcroField.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,11 @@ public sealed class PdfAcroFieldCollection : PdfArray
300300
: base(array)
301301
{ }
302302

303+
PdfAcroFieldCollection(PdfDocument document)
304+
: base(document)
305+
{ }
306+
307+
303308
/// <summary>
304309
/// Gets the names of all fields in the collection.
305310
/// </summary>
@@ -553,6 +558,30 @@ public class Keys : KeysBase
553558
[KeyInfo(KeyType.Integer | KeyType.Optional)]
554559
public const string Q = "/Q";
555560

561+
/// <summary>
562+
/// (Optional) The type of PDF object that this dictionary describes; if present,
563+
/// must be Sig for a signature dictionary.
564+
/// </summary>
565+
[KeyInfo(KeyType.Name | KeyType.Optional)]
566+
public const string Type = "/Type";
567+
568+
/// <summary>
569+
///
570+
/// </summary>
571+
[KeyInfo(KeyType.Name | KeyType.Required)]
572+
public const string Subtype = "/Subtype";
573+
574+
575+
/// <summary>
576+
///
577+
/// </summary>
578+
[KeyInfo(KeyType.Rectangle | KeyType.Required)]
579+
public const string Rect = "/Rect";
580+
581+
582+
[KeyInfo(KeyType.Rectangle | KeyType.Required)]
583+
public const string P = "/P";
584+
556585
// ReSharper restore InconsistentNaming
557586
}
558587
}

SampleApp/Program.cs

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,58 @@
1-
using PdfSharpCore.Drawing;
2-
using PdfSharpCore.Pdf;
3-
4-
string GetOutFilePath(string name)
1+

2+
namespace SampleApp
53
{
6-
var OutputDirName = @".";
7-
return Path.Combine(OutputDirName, name);
8-
}
94

10-
void SaveDocument(PdfDocument document, string name)
11-
{
12-
var outFilePath = GetOutFilePath(name);
13-
var dir = Path.GetDirectoryName(outFilePath);
14-
if (dir is not null && !Directory.Exists(dir))
5+
6+
public class Program
157
{
16-
Directory.CreateDirectory(dir);
17-
}
8+
9+
10+
private static string GetOutFilePath(string name)
11+
{
12+
string OutputDirName = @".";
13+
return System.IO.Path.Combine(OutputDirName, name);
14+
}
15+
16+
17+
private static void SaveDocument(PdfSharpCore.Pdf.PdfDocument document, string name)
18+
{
19+
string outFilePath = GetOutFilePath(name);
20+
string? dir = System.IO.Path.GetDirectoryName(outFilePath);
21+
if (dir != null && !System.IO.Directory.Exists(dir))
22+
{
23+
System.IO.Directory.CreateDirectory(dir);
24+
}
25+
26+
document.Save(outFilePath);
27+
}
28+
29+
30+
public static void Main(string[] args)
31+
{
32+
System.Console.WriteLine("Starting...");
33+
34+
const string outName = "test1.pdf";
35+
36+
PdfSharpCore.Pdf.PdfDocument? document = new PdfSharpCore.Pdf.PdfDocument();
1837

19-
document.Save(outFilePath);
20-
}
38+
PdfSharpCore.Pdf.PdfPage? pageNewRenderer = document.AddPage();
2139

22-
Console.WriteLine("Starting...");
40+
PdfSharpCore.Drawing.XGraphics? renderer = PdfSharpCore.Drawing.XGraphics.FromPdfPage(pageNewRenderer);
2341

24-
const string outName = "test1.pdf";
42+
renderer.DrawString(
43+
"Testy Test Test"
44+
, new PdfSharpCore.Drawing.XFont("Arial", 12)
45+
, PdfSharpCore.Drawing.XBrushes.Black
46+
, new PdfSharpCore.Drawing.XPoint(12, 12)
47+
);
2548

26-
var document = new PdfDocument();
49+
SaveDocument(document, outName);
2750

28-
var pageNewRenderer = document.AddPage();
51+
System.Console.WriteLine("Done!");
52+
} // End Sub Main
2953

30-
var renderer = XGraphics.FromPdfPage(pageNewRenderer);
3154

32-
renderer.DrawString("Testy Test Test", new XFont("Arial", 12), XBrushes.Black, new XPoint(12, 12));
55+
} // End Class Program
3356

34-
SaveDocument(document, outName);
3557

36-
Console.WriteLine("Done!");
58+
} // End Namespace SampleApp

SampleApp/SampleApp.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
@@ -7,7 +7,7 @@
77
<Nullable>enable</Nullable>
88
<IsTrimmable>true</IsTrimmable>
99
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
10-
<LangVersion>10</LangVersion>
10+
<ImplicitUsings>disable</ImplicitUsings>
1111
</PropertyGroup>
1212

1313
<ItemGroup>

0 commit comments

Comments
 (0)