Skip to content

Commit 80a24e0

Browse files
committed
搭建基础的项目
1 parent d20638a commit 80a24e0

20 files changed

Lines changed: 1894 additions & 2 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ DLL Pakcage:
9494

9595
### Usage
9696

97-
See [DocumentFormat.OpenXml.Flatten README.md](src/DocumentFormat.OpenXml.Flatten/README.md)
97+
See [DocumentFormat.OpenXml.Flatten README.md](src/DocumentFormat.OpenXml.Flatten/README.md) and the [Demo](demo).
9898

9999

100100
# Thanks

README.zh-cn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ DLL 包:
103103

104104
### 使用方法
105105

106-
具体使用方法请参阅 [DocumentFormat.OpenXml.Flatten 使用文档](src/DocumentFormat.OpenXml.Flatten/README.md)
106+
具体使用方法请参阅 [DocumentFormat.OpenXml.Flatten 使用文档](src/DocumentFormat.OpenXml.Flatten/README.md)[示例代码](demo)
107107

108108
# 感谢
109109

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
<ItemGroup>
9+
<PackageReference Include="Microsoft.Maui.Graphics" Version="6.0.501" />
10+
</ItemGroup>
11+
<ItemGroup>
12+
<ProjectReference Include="..\..\..\..\src\DocumentFormat.OpenXml.Flatten\DocumentFormat.OpenXml.Flatten\dotnetCampus.DocumentFormat.OpenXml.Flatten.csproj" />
13+
</ItemGroup>
14+
</Project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Windows;
3+
4+
namespace Microsoft.Maui.Graphics.Xaml
5+
{
6+
static class Fonts
7+
{
8+
public readonly static FontService CurrentService = new FontService();
9+
}
10+
11+
class FontService
12+
{
13+
internal FakeFontStyle? GetFontStyleById(string fontName)
14+
{
15+
return null;
16+
}
17+
}
18+
19+
class FakeFontStyle
20+
{
21+
public FontStyleType StyleType { get; internal set; }
22+
23+
public Font FontFamily { get; internal set; }
24+
public int Weight { get; internal set; }
25+
}
26+
}
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Numerics;
4+
using System.Text;
5+
6+
//[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Microsoft.Maui.Graphics.Tests")]
7+
8+
namespace Microsoft.Maui.Graphics
9+
{
10+
static class Matrix3x2Extensions
11+
{
12+
public static bool IsZero(this in Matrix3x2 matrix)
13+
{
14+
if (matrix.M11 != 0) return false;
15+
if (matrix.M12 != 0) return false;
16+
if (matrix.M21 != 0) return false;
17+
if (matrix.M22 != 0) return false;
18+
if (matrix.M31 != 0) return false;
19+
if (matrix.M32 != 0) return false;
20+
return true;
21+
}
22+
23+
public static bool IsFinite(this in Matrix3x2 matrix)
24+
{
25+
bool result = true;
26+
27+
#if NETSTANDARD2_0 || TIZEN40
28+
result &= !(float.IsNaN(matrix.M11) || float.IsInfinity(matrix.M11));
29+
result &= !(float.IsNaN(matrix.M12) || float.IsInfinity(matrix.M12));
30+
result &= !(float.IsNaN(matrix.M21) || float.IsInfinity(matrix.M21));
31+
result &= !(float.IsNaN(matrix.M22) || float.IsInfinity(matrix.M22));
32+
result &= !(float.IsNaN(matrix.M31) || float.IsInfinity(matrix.M31));
33+
result &= !(float.IsNaN(matrix.M32) || float.IsInfinity(matrix.M32));
34+
#else
35+
result &= float.IsFinite(matrix.M11);
36+
result &= float.IsFinite(matrix.M12);
37+
result &= float.IsFinite(matrix.M21);
38+
result &= float.IsFinite(matrix.M22);
39+
result &= float.IsFinite(matrix.M31);
40+
result &= float.IsFinite(matrix.M32);
41+
#endif
42+
return result;
43+
}
44+
45+
public static Vector2 GetScale(this in Matrix3x2 matrix)
46+
{
47+
var sx = matrix.M12 == 0 ? Math.Abs(matrix.M11) : new Vector2(matrix.M11, matrix.M12).Length();
48+
var sy = matrix.M21 == 0 ? Math.Abs(matrix.M22) : new Vector2(matrix.M21, matrix.M22).Length();
49+
if (matrix.GetDeterminant() < 0) sy = -sy;
50+
return new Vector2(sx, sy);
51+
}
52+
53+
public static float GetRotation(this in Matrix3x2 matrix)
54+
{
55+
return (float) Math.Atan2(matrix.M12, matrix.M11);
56+
}
57+
58+
public static Vector2 GetTranslation(this in Matrix3x2 matrix)
59+
{
60+
return matrix.Translation;
61+
}
62+
63+
public static Matrix3x2 WithScale(this Matrix3x2 matrix, Vector2 scale)
64+
{
65+
var sx = matrix.M12 == 0 ? Math.Abs(matrix.M11) : new Vector2(matrix.M11, matrix.M12).Length();
66+
var sy = matrix.M21 == 0 ? Math.Abs(matrix.M22) : new Vector2(matrix.M21, matrix.M22).Length();
67+
// if (matrix.GetDeterminant() < 0) sy = -sy;
68+
69+
scale /= new Vector2(sx, sy);
70+
71+
matrix.M11 *= scale.X;
72+
matrix.M12 *= scale.X;
73+
matrix.M21 *= scale.Y;
74+
matrix.M22 *= scale.Y;
75+
return matrix;
76+
77+
// var t = matrix.Translation;
78+
// var r = matrix.GetRotation();
79+
// return CreateMatrix3x2(scale, r, t);
80+
}
81+
82+
public static Matrix3x2 WithoutScale(this in Matrix3x2 matrix)
83+
{
84+
return matrix.WithScale(Vector2.One);
85+
}
86+
87+
public static Matrix3x2 WithRotation(this in Matrix3x2 matrix, float radians)
88+
{
89+
var t = matrix.Translation;
90+
var s = matrix.GetScale();
91+
return CreateMatrix3x2(s, radians, t);
92+
}
93+
94+
public static Matrix3x2 WithoutRotation(this in Matrix3x2 matrix)
95+
{
96+
var t = matrix.Translation;
97+
var s = matrix.GetScale();
98+
return CreateMatrix3x2(s, 0, t);
99+
}
100+
101+
public static Matrix3x2 WithTranslation(this Matrix3x2 matrix, Vector2 translation)
102+
{
103+
matrix.Translation = translation;
104+
return matrix;
105+
}
106+
107+
/// <summary>
108+
/// Creates a matrix from an SRT.
109+
/// </summary>
110+
/// <param name="scale">The scale</param>
111+
/// <param name="rotation">The rotation, in radians</param>
112+
/// <param name="translation">the translation</param>
113+
/// <returns>A Matrix3x2</returns>
114+
/// <remarks>
115+
/// This is equivalent to:<br/>
116+
/// <c>
117+
/// m = Matrix3x2.CreateScale(scale)<br/>
118+
/// m *= Matri3x2.CreateRotation(rotation)<br/>
119+
/// m *= Matri3x2.CreateTranslation(translation)<br/>
120+
/// </c>
121+
/// </remarks>
122+
internal static Matrix3x2 CreateMatrix3x2(Vector2 scale, float rotation, Vector2 translation)
123+
{
124+
var m = Matrix3x2.CreateRotation(rotation);
125+
m.M11 *= scale.X;
126+
m.M12 *= scale.X;
127+
m.M21 *= scale.Y;
128+
m.M22 *= scale.Y;
129+
m.M31 = translation.X;
130+
m.M32 = translation.Y;
131+
return m;
132+
}
133+
134+
public static float GetLengthScale(this in Matrix3x2 matrix)
135+
{
136+
var determinant = matrix.GetDeterminant();
137+
var areaScale = Math.Abs(determinant);
138+
return (float) Math.Sqrt(areaScale);
139+
}
140+
141+
public static void CopyTo(this in Matrix3x2 matrix, float[] dst, int offset = 0, int count = 6)
142+
{
143+
count = Math.Min(dst.Length, count);
144+
145+
dst[offset + 0] = matrix.M11;
146+
dst[offset + 1] = matrix.M12;
147+
dst[offset + 2] = matrix.M21;
148+
dst[offset + 3] = matrix.M22;
149+
if (count > 4)
150+
{
151+
dst[offset + 4] = matrix.M31;
152+
dst[offset + 5] = matrix.M32;
153+
}
154+
}
155+
156+
public static Vector2 Transform(this Matrix3x2 target, float x, float y)
157+
{
158+
Vector2 vector2 = new Vector2(x, y);
159+
return Vector2.Transform(vector2, target);
160+
}
161+
162+
163+
public static void DeconstructScales(this in Matrix3x2 value, out float scale, out float scalex, out float scaley)
164+
{
165+
var det = value.GetDeterminant();
166+
scale = (float) Math.Sqrt(Math.Abs(det));
167+
scalex = value.M12 == 0 ? Math.Abs(value.M11) : new Vector2(value.M11, value.M12).Length();
168+
scaley = value.M21 == 0 ? Math.Abs(value.M22) : new Vector2(value.M21, value.M22).Length();
169+
if (det < 0) scaley = -scaley;
170+
}
171+
}
172+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0-windows</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<UseWPF>true</UseWPF>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.Maui.Graphics" Version="6.0.501" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Microsoft.Maui.Graphics.Xaml
2+
3+
Copy from: https://github.com/dotnet/Microsoft.Maui.Graphics
4+
5+
I can not wait for Microsoft.Maui.Graphics.Xaml to be released

0 commit comments

Comments
 (0)