Skip to content

Commit a6bef8d

Browse files
authored
Merge pull request #35 from synercoder/develop
Develop
2 parents 20b09ee + 8f65e79 commit a6bef8d

File tree

13 files changed

+784
-42
lines changed

13 files changed

+784
-42
lines changed

.github/workflows/dotnet-core.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- name: Setup .NET Core
3434
uses: actions/setup-dotnet@v1
3535
with:
36-
dotnet-version: 3.1.x
36+
dotnet-version: 5.0.x
3737
- name: Restore
3838
run: dotnet restore
3939
- name: Build
@@ -42,7 +42,7 @@ jobs:
4242
run: dotnet test -c Release
4343
- name: Pack
4444
if: matrix.os == 'ubuntu-latest'
45-
run: dotnet pack -v normal -c Release --no-restore --include-symbols --include-source -p:SymbolPackageFormat=snupkg -p:PackageVersion=$GITHUB_RUN_ID src/$PROJECT_NAME/$PROJECT_NAME.*proj
45+
run: dotnet pack -v normal -c Release --no-restore --include-symbols --include-source -p:SymbolPackageFormat=snupkg -p:PackageVersion=$GITHUB_RUN_ID-pre src/$PROJECT_NAME/$PROJECT_NAME.*proj
4646
- name: Upload Artifact
4747
if: matrix.os == 'ubuntu-latest'
4848
uses: actions/upload-artifact@v2
@@ -73,7 +73,7 @@ jobs:
7373
- name: Setup .NET Core
7474
uses: actions/setup-dotnet@v1
7575
with:
76-
dotnet-version: 3.1.x
76+
dotnet-version: 5.0.x
7777
- name: Create Release NuGet package
7878
run: |
7979
arrTag=(${GITHUB_REF//\// })

Directory.Build.props

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,62 @@
4141
</PropertyGroup>
4242

4343
<PropertyGroup>
44-
<LangVersion>8.0</LangVersion>
44+
<LangVersion>9.0</LangVersion>
4545
<Nullable>enable</Nullable>
4646
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
4747
<Features>strict</Features>
4848
</PropertyGroup>
4949

50-
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
51-
<DefineConstants>$(DefineConstants);SUPPORTS_HASHCODE</DefineConstants>
52-
</PropertyGroup>
53-
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
54-
<DefineConstants>$(DefineConstants);SUPPORTS_HASHCODE</DefineConstants>
55-
</PropertyGroup>
56-
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
57-
<DefineConstants>$(DefineConstants);SUPPORTS_HASHCODE</DefineConstants>
58-
</PropertyGroup>
50+
<Choose>
51+
<When Condition="'$(TargetFramework)' == 'net472'">
52+
<PropertyGroup>
53+
<DefineConstants>$(DefineConstants);SUPPORTS_CODECOVERAGE</DefineConstants>
54+
</PropertyGroup>
55+
</When>
56+
<When Condition="'$(TargetFramework)' == 'netstandard2.0'">
57+
<PropertyGroup>
58+
<DefineConstants>$(DefineConstants);SUPPORTS_CODECOVERAGE</DefineConstants>
59+
</PropertyGroup>
60+
</When>
61+
<When Condition="'$(TargetFramework)' == 'netstandard2.1'">
62+
<PropertyGroup>
63+
<DefineConstants>$(DefineConstants);SUPPORTS_MATHF</DefineConstants>
64+
<DefineConstants>$(DefineConstants);SUPPORTS_HASHCODE</DefineConstants>
65+
<DefineConstants>$(DefineConstants);SUPPORTS_CODECOVERAGE</DefineConstants>
66+
<DefineConstants>$(DefineConstants);SUPPORTS_NULLABLEREFATTRIBUTES</DefineConstants>
67+
</PropertyGroup>
68+
</When>
69+
<When Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
70+
<PropertyGroup>
71+
<DefineConstants>$(DefineConstants);SUPPORTS_MATHF</DefineConstants>
72+
<DefineConstants>$(DefineConstants);SUPPORTS_CODECOVERAGE</DefineConstants>
73+
</PropertyGroup>
74+
</When>
75+
<When Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
76+
<PropertyGroup>
77+
<DefineConstants>$(DefineConstants);SUPPORTS_MATHF</DefineConstants>
78+
<DefineConstants>$(DefineConstants);SUPPORTS_HASHCODE</DefineConstants>
79+
<DefineConstants>$(DefineConstants);SUPPORTS_CODECOVERAGE</DefineConstants>
80+
</PropertyGroup>
81+
</When>
82+
<When Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
83+
<PropertyGroup>
84+
<DefineConstants>$(DefineConstants);SUPPORTS_MATHF</DefineConstants>
85+
<DefineConstants>$(DefineConstants);SUPPORTS_HASHCODE</DefineConstants>
86+
<DefineConstants>$(DefineConstants);SUPPORTS_CODECOVERAGE</DefineConstants>
87+
<DefineConstants>$(DefineConstants);SUPPORTS_NULLABLEREFATTRIBUTES</DefineConstants>
88+
</PropertyGroup>
89+
</When>
90+
<When Condition="'$(TargetFramework)' == 'net5.0'">
91+
<PropertyGroup>
92+
<DefineConstants>$(DefineConstants);SUPPORTS_MATHF</DefineConstants>
93+
<DefineConstants>$(DefineConstants);SUPPORTS_HASHCODE</DefineConstants>
94+
<DefineConstants>$(DefineConstants);SUPPORTS_CODECOVERAGE</DefineConstants>
95+
<DefineConstants>$(DefineConstants);SUPPORTS_NULLABLEREFATTRIBUTES</DefineConstants>
96+
<DefineConstants>$(DefineConstants);SUPPORTS_MEMBERNOTNULL</DefineConstants>
97+
<DefineConstants>$(DefineConstants);SUPPORTS_INIT</DefineConstants>
98+
</PropertyGroup>
99+
</When>
100+
</Choose>
59101

60102
</Project>

samples/Synercoding.FileFormats.Pdf.ConsoleTester/Synercoding.FileFormats.Pdf.ConsoleTester.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<TargetFramework>net5.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project>
33

44
<PropertyGroup>
5-
<TargetFrameworks>netcoreapp3.1;netcoreapp2.1;netstandard2.1;netstandard2.0;netstandard1.6</TargetFrameworks>
5+
<TargetFrameworks>net5.0;netcoreapp3.1;netcoreapp2.1;netstandard2.1;netstandard2.0;netstandard1.6</TargetFrameworks>
66
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileDirectory)..\Directory.Build.props</MSBuildAllProjects>
77
<SynercodingProjectCategory>src</SynercodingProjectCategory>
88
</PropertyGroup>

src/Synercoding.FileFormats.Pdf/PackageDetails.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<Product>Synercoding.FileFormats.Pdf</Product>
1111
<Title>Synercoding.FileFormats.Pdf</Title>
1212
<Description>Contains classes which makes it easy to quickly create a pdf file.</Description>
13-
<PackageReleaseNotes>Fixed AddImage bug on PdfWriter.</PackageReleaseNotes>
13+
<PackageReleaseNotes>Improved Matrix and added support for C# 9.</PackageReleaseNotes>
1414
</PropertyGroup>
1515

1616
</Project>

src/Synercoding.FileFormats.Pdf/PdfPage.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace Synercoding.FileFormats.Pdf
1515
/// </summary>
1616
public class PdfPage
1717
{
18-
private int _pageCounter = 0;
18+
private int _imageCounter = 0;
1919
private readonly Dictionary<string, Image> _images = new Dictionary<string, Image>();
2020
private readonly TableBuilder _tableBuilder;
2121

@@ -194,7 +194,7 @@ private string _addImageToResources(ImageSharp.Image image, bool clone)
194194

195195
private string _addImageToResources(Image image)
196196
{
197-
var key = "Im" + System.Threading.Interlocked.Increment(ref _pageCounter).ToString().PadLeft(6, '0');
197+
var key = "Im" + System.Threading.Interlocked.Increment(ref _imageCounter).ToString().PadLeft(6, '0');
198198

199199
_images.Add(key, image);
200200

src/Synercoding.FileFormats.Pdf/Primitives/Matrix.cs

Lines changed: 67 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Synercoding.Primitives;
22
using System;
3+
using System.Runtime.CompilerServices;
34

45
namespace Synercoding.FileFormats.Pdf.Primitives
56
{
@@ -14,8 +15,21 @@ namespace Synercoding.FileFormats.Pdf.Primitives
1415
/// E F 1
1516
/// </code>
1617
/// </remarks>
17-
public readonly struct Matrix
18+
public readonly struct Matrix : IEquatable<Matrix>
1819
{
20+
/// <summary>
21+
/// The identity matrix
22+
/// </summary>
23+
/// <remarks>
24+
/// This matrix can be interpreted as:
25+
/// <list type="bullet">
26+
/// <item>translation with (0,0)</item>
27+
/// <item>rotation with 0 degrees</item>
28+
/// <item>scaling with (1,1)</item>
29+
/// </list>
30+
/// </remarks>
31+
public static Matrix Identity { get; } = new Matrix(1, 0, 0, 1, 0, 0);
32+
1933
/// <summary>
2034
/// Copy constructor for the <see cref="Matrix"/>
2135
/// </summary>
@@ -52,32 +66,54 @@ public Matrix(double a, double b, double c, double d, double e, double f)
5266
/// <summary>
5367
/// The A value
5468
/// </summary>
55-
public double A { get; }
69+
public double A { get; init; }
5670

5771
/// <summary>
5872
/// The B value
5973
/// </summary>
60-
public double B { get; }
74+
public double B { get; init; }
6175

6276
/// <summary>
6377
/// The C value
6478
/// </summary>
65-
public double C { get; }
79+
public double C { get; init; }
6680

6781
/// <summary>
6882
/// The D value
6983
/// </summary>
70-
public double D { get; }
84+
public double D { get; init; }
7185

7286
/// <summary>
7387
/// The E value
7488
/// </summary>
75-
public double E { get; }
89+
public double E { get; init; }
7690

7791
/// <summary>
7892
/// The F value
7993
/// </summary>
80-
public double F { get; }
94+
public double F { get; init; }
95+
96+
/// <inheritdoc/>
97+
public override bool Equals(object? obj)
98+
=> obj is Rectangle other && Equals(other);
99+
100+
/// <inheritdoc/>
101+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
102+
public bool Equals(Matrix other)
103+
=> A.Equals(other.A)
104+
&& B.Equals(other.B)
105+
&& C.Equals(other.C)
106+
&& D.Equals(other.D)
107+
&& E.Equals(other.E)
108+
&& F.Equals(other.F);
109+
110+
/// <inheritdoc/>
111+
public override int GetHashCode()
112+
=> HashCode.Combine(A, B, C, D, E, F);
113+
114+
/// <inheritdoc/>
115+
public override string ToString()
116+
=> $"Matrix [ {A}, {B}, {C}, {D}, {E}, {F} ]";
81117

82118
/// <summary>
83119
/// Apply a rotation operation on the matrix
@@ -87,6 +123,20 @@ public Matrix(double a, double b, double c, double d, double e, double f)
87123
public Matrix Rotate(double degrees)
88124
=> Multiply(CreateRotationMatrix(degrees));
89125

126+
/// <summary>
127+
/// Apply a horizontal flip operation on the matrix
128+
/// </summary>
129+
/// <returns>The new <see cref="Matrix"/></returns>
130+
public Matrix FlipHorizontal()
131+
=> Multiply(CreateScaleMatrix(-1, 1));
132+
133+
/// <summary>
134+
/// Apply a vertical flip operation on the matrix
135+
/// </summary>
136+
/// <returns>The new <see cref="Matrix"/></returns>
137+
public Matrix FlipVertical()
138+
=> Multiply(CreateScaleMatrix(1, -1));
139+
90140
/// <summary>
91141
/// Apply a scale operation on the matrix
92142
/// </summary>
@@ -146,19 +196,15 @@ public Matrix Translate(Value x, Value y)
146196
/// </summary>
147197
/// <param name="other">The matrix to multiply with</param>
148198
/// <returns>The new <see cref="Matrix"/></returns>
199+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
149200
public Matrix Multiply(in Matrix other)
150-
{
151-
double a, b, c, d, e, f;
152-
153-
a = (A * other.A) + (B * other.C);
154-
b = (A * other.B) + (B * other.D);
155-
c = (C * other.A) + (D * other.C);
156-
d = (C * other.B) + (D * other.D);
157-
e = (E * other.A) + (F * other.C) + other.E;
158-
f = (E * other.B) + (F * other.D) + other.F;
159-
160-
return new Matrix(a, b, c, d, e, f);
161-
}
201+
=> new Matrix(
202+
a: ( A * other.A ) + ( B * other.C ),
203+
b: ( A * other.B ) + ( B * other.D ),
204+
c: ( C * other.A ) + ( D * other.C ),
205+
d: ( C * other.B ) + ( D * other.D ),
206+
e: ( E * other.A ) + ( F * other.C ) + other.E,
207+
f: ( E * other.B ) + ( F * other.D ) + other.F);
162208

163209
/// <summary>
164210
/// Create a matrix used for rotation
@@ -234,9 +280,8 @@ public static Matrix CreateTranslationMatrix(Value x, Value y)
234280
0, 1,
235281
x.ConvertTo(Unit.Points).Raw, y.ConvertTo(Unit.Points).Raw);
236282

283+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
237284
private static double _degreeToRad(double degree)
238-
{
239-
return degree * Math.PI / 180;
240-
}
285+
=> degree * Math.PI / 180;
241286
}
242287
}

src/Synercoding.FileFormats.Pdf/Synercoding.FileFormats.Pdf.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
</ItemGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-rc0003" />
11-
<PackageReference Include="Synercoding.Primitives" Version="1.0.0-rc02" />
10+
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.2" />
11+
<PackageReference Include="Synercoding.Primitives" Version="1.0.0-rc03" />
1212
</ItemGroup>
1313

1414
</Project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#if SUPPORTS_CODECOVERAGE
2+
using System.Runtime.CompilerServices;
3+
4+
[assembly: TypeForwardedTo(typeof(System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute))]
5+
#else
6+
namespace System.Diagnostics.CodeAnalysis
7+
{
8+
/// <summary>
9+
/// Specifies that the attributed code should be excluded from code coverage information.
10+
/// </summary>
11+
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Event, Inherited = false, AllowMultiple = false)]
12+
internal sealed class ExcludeFromCodeCoverageAttribute : Attribute
13+
{
14+
}
15+
}
16+
#endif

0 commit comments

Comments
 (0)