Skip to content

Commit 22a98a1

Browse files
authored
Merge pull request #29 from dotnet-campus/t/lindexi/Update
从私有项目更新2月版本更改
2 parents 83bb28b + eb1c346 commit 22a98a1

23 files changed

Lines changed: 4784 additions & 27 deletions
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using DocumentFormat.OpenXml.Drawing;
2+
3+
namespace DocumentFormat.OpenXml.Flatten.Contexts
4+
{
5+
/// <summary>
6+
/// 记录自定义形状信息
7+
/// </summary>
8+
public readonly struct CustomGeometryInfo
9+
{
10+
/// <summary>
11+
/// 创建记录自定义形状信息
12+
/// </summary>
13+
/// <param name="shapeGuideList">形状导航集合</param>
14+
/// <param name="adjustValueList">调整点集合</param>
15+
/// <param name="pathList">路径集合</param>
16+
/// <param name="rectangle">文本框范围</param>
17+
public CustomGeometryInfo(ShapeGuideList? shapeGuideList, AdjustValueList? adjustValueList, PathList? pathList, Rectangle? rectangle)
18+
{
19+
ShapeGuideList = shapeGuideList;
20+
AdjustValueList = adjustValueList;
21+
PathList = pathList;
22+
Rectangle = rectangle;
23+
}
24+
25+
/// <summary>
26+
/// 形状导航集合
27+
/// </summary>
28+
public ShapeGuideList? ShapeGuideList { get; }
29+
30+
/// <summary>
31+
/// 调整点集合
32+
/// </summary>
33+
public AdjustValueList? AdjustValueList { get; }
34+
35+
/// <summary>
36+
/// 路径集合
37+
/// </summary>
38+
public PathList? PathList { get; }
39+
40+
/// <summary>
41+
/// 文本框范围
42+
/// </summary>
43+
public Rectangle? Rectangle { get; }
44+
}
45+
}

src/DocumentFormat.OpenXml.Flatten/DocumentFormat.OpenXml.Flatten/Contexts/GeometryPath.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ public readonly struct ShapePath
1818
/// <param name="isExtrusionOk">指定使用 3D 拉伸可能在此路径</param>
1919
/// <param name="emuWidth">指定的宽度或在路径坐标系统中应在使用的最大的 x 坐标</param>
2020
/// <param name="emuHeight">指定框架的高度或在路径坐标系统中应在使用的最大的 y 坐标</param>
21-
public ShapePath(string path, PathFillModeValues fillMode = PathFillModeValues.Norm, bool isStroke = true, bool isExtrusionOk = false, double emuWidth = 0, double emuHeight = 0)
21+
public ShapePath(string path, PathFillModeValues fillMode = PathFillModeValues.Norm, bool isStroke = true, bool isExtrusionOk = false, double? emuWidth = null, double? emuHeight = null)
2222
{
2323
Path = path;
2424
IsStroke = isStroke;
2525
FillMode = fillMode;
2626
IsFilled = fillMode is not PathFillModeValues.None;
2727
IsExtrusionOk = isExtrusionOk;
28-
Width = new Emu(emuWidth);
29-
Height = new Emu(emuHeight);
28+
Width = emuWidth.HasValue ? new Emu(emuWidth.Value) : null;
29+
Height = emuHeight.HasValue ? new Emu(emuHeight.Value) : null;
3030
}
3131

3232
/// <summary>
@@ -68,11 +68,11 @@ public ShapePath(string path, double eumWidth, double eumHeight) : this(path, Pa
6868
/// <summary>
6969
/// 指定的宽度或在路径坐标系统中应在使用的最大的 x 坐标。默认是 0 的值
7070
/// </summary>
71-
public Emu Width { get; }
71+
public Emu? Width { get; }
7272

7373
/// <summary>
7474
/// 指定框架的高度或在路径坐标系统中应在使用的最大的 y 坐标。默认是 0 的值
7575
/// </summary>
76-
public Emu Height { get; }
76+
public Emu? Height { get; }
7777
}
7878
}

src/DocumentFormat.OpenXml.Flatten/DocumentFormat.OpenXml.Flatten/Contexts/SvgPath.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ public class SvgPath
1414
/// <param name="svgPathString">Svg Path字符串</param>
1515
/// <param name="shapeTextRectangle">形状文本框</param>
1616
/// <param name="multiShapePaths">Svg 多路径</param>
17-
public SvgPath(ShapeTypeValues? geometryShapeType, string? svgPathString, EmuShapeTextRectangle shapeTextRectangle, ShapePath[]? multiShapePaths)
17+
/// <param name="customGeometryInfo">自定义形状上下文信息</param>
18+
public SvgPath(ShapeTypeValues? geometryShapeType, string? svgPathString, EmuShapeTextRectangle shapeTextRectangle, ShapePath[]? multiShapePaths, CustomGeometryInfo? customGeometryInfo = null)
1819
{
1920
ShapeType = geometryShapeType;
2021
SvgPathString = svgPathString;
2122
ShapeTextRectangle = shapeTextRectangle;
2223
MultiShapePaths = multiShapePaths;
24+
CustomGeometryInfo = customGeometryInfo;
2325
}
2426

2527
/// <summary>
@@ -41,5 +43,10 @@ public SvgPath(ShapeTypeValues? geometryShapeType, string? svgPathString, EmuSha
4143
///Shape Path 多路径
4244
/// </summary>
4345
public ShapePath[]? MultiShapePaths { get; }
46+
47+
/// <summary>
48+
/// 自定义形状上下文信息
49+
/// </summary>
50+
public CustomGeometryInfo? CustomGeometryInfo { get; }
4451
}
4552
}

src/DocumentFormat.OpenXml.Flatten/DocumentFormat.OpenXml.Flatten/ElementConverters/Shape/CustomGeometryConverters/CustomGeometryConverter.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,14 @@ void TryClosePath()
138138
stringPath.Clear();
139139
}
140140

141+
var customGeometryInfo = new CustomGeometryInfo(_customGeometry.ShapeGuideList, _customGeometry.AdjustValueList, _customGeometry.PathList, _customGeometry.Rectangle);
141142
if (svgPathList.Count == 1)
142143
{
143-
return new SvgPath(null, svgPathList.First().Path, ShapeTextRectangle, default);
144+
return new SvgPath(null, svgPathList.First().Path, ShapeTextRectangle, default, customGeometryInfo);
144145
}
145146
else if (svgPathList.Count > 1)
146147
{
147-
return new SvgPath(null, svgPathList.First().Path, ShapeTextRectangle, svgPathList.ToArray());
148+
return new SvgPath(null, svgPathList.First().Path, ShapeTextRectangle, svgPathList.ToArray(), customGeometryInfo);
148149
}
149150
else
150151
{

src/DocumentFormat.OpenXml.Flatten/DocumentFormat.OpenXml.Flatten/ElementConverters/Shape/ShapeFlattenConverter.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ protected override Shape Convert(Shape element, ElementContext context)
6565
masterPlaceholderShape?.NonVisualShapeProperties?.NonVisualShapeDrawingProperties!);
6666

6767
FlattenTransformData(shapeProperties, layoutPlaceholderShape, masterPlaceholderShape, context);
68+
69+
70+
FlattenPresetGeometryFormData(shapeProperties, layoutPlaceholderShape, masterPlaceholderShape, context);
71+
6872
}
6973
}
7074

@@ -74,6 +78,33 @@ protected override Shape Convert(Shape element, ElementContext context)
7478
return element;
7579
}
7680

81+
private void FlattenPresetGeometryFormData(ShapeProperties shapeProperties, Shape? layoutPlaceholderShape, Shape? masterPlaceholderShape, ElementContext context)
82+
{
83+
var layoutPresetGeometry = layoutPlaceholderShape?.ShapeProperties?.GetFirstChild<PresetGeometry>();
84+
var masterPresetGeometry = masterPlaceholderShape?.ShapeProperties?.GetFirstChild<PresetGeometry>();
85+
var geometry = shapeProperties.GetFirstChild<PresetGeometry>();
86+
if (geometry is null && layoutPresetGeometry is null && masterPresetGeometry is null)
87+
{
88+
// 对于草绘的形状,尽管也是逻辑上也是 PresetGeometry 对象
89+
// 但是在 XML 里面,使用 CustomGeometry 存放
90+
// 不能在拍平加上 PresetGeometry 的值,否则将会丢失
91+
return;
92+
}
93+
94+
var provider = new OpenXmlCompositeElementFlattenProvider<PresetGeometry>
95+
(
96+
shapeProperties.GetOrCreateElement<PresetGeometry>(),
97+
layoutPresetGeometry,
98+
masterPresetGeometry
99+
);
100+
101+
provider.FlattenMainElementProperty(presetGeometry => presetGeometry.AdjustValueList!);
102+
103+
var elementPresetGeometry = provider.Main;
104+
elementPresetGeometry.Preset = provider.GetFlattenProperty(presetGeometry => presetGeometry.Preset);
105+
elementPresetGeometry.AdjustValueList = provider.GetFlattenProperty(presetGeometry => presetGeometry.AdjustValueList);
106+
}
107+
77108
private void FlattenTransformData(ShapeProperties shapeProperties, Shape? layoutPlaceholderShape, Shape? masterPlaceholderShape, ElementContext context)
78109
{
79110
var layoutTransform2D = layoutPlaceholderShape?.ShapeProperties?.Transform2D;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
using System.Text;
2+
3+
using DocumentFormat.OpenXml.Drawing;
4+
using DocumentFormat.OpenXml.Flatten.Contexts;
5+
6+
using dotnetCampus.OpenXmlUnitConverter;
7+
8+
using static DocumentFormat.OpenXml.Flatten.ElementConverters.ShapeGeometryConverters.ShapeGeometryFormulaHelper;
9+
10+
using ElementEmuSize = dotnetCampus.OpenXmlUnitConverter.EmuSize;
11+
12+
namespace DocumentFormat.OpenXml.Flatten.ElementConverters.ShapeGeometryConverters
13+
{
14+
/// <summary>
15+
/// 动作按钮: 后退或前一项
16+
/// </summary>
17+
public class ActionButtonBackPreviousGeometry : ShapeGeometryBase
18+
{
19+
/// <inheritdoc />
20+
public override string? ToGeometryPathString(EmuSize emuSize, AdjustValueList? adjusts = null)
21+
{
22+
return null;
23+
}
24+
25+
/// <inheritdoc />
26+
public override ShapePath[]? GetMultiShapePaths(EmuSize emuSize, AdjustValueList? adjusts = null)
27+
{
28+
var (h, w, l, r, t, b, hd2, hd4, hd5, hd6, hd8, ss, hc, vc, ls, ss2, ss4, ss6, ss8, wd2, wd4, wd5, wd6, wd8, wd10, cd2, cd4, cd6, cd8) = GetFormulaProperties(emuSize);
29+
30+
//<gdLst xmlns="http://schemas.openxmlformats.org/drawingml/2006/main">
31+
// <gd name="dx2" fmla="*/ ss 3 8" />
32+
// <gd name="g9" fmla="+- vc 0 dx2" />
33+
// <gd name="g10" fmla="+- vc dx2 0" />
34+
// <gd name="g11" fmla="+- hc 0 dx2" />
35+
// <gd name="g12" fmla="+- hc dx2 0" />
36+
//</gdLst>
37+
38+
//<gd name="dx2" fmla="*/ ss 3 8" xmlns="http://schemas.openxmlformats.org/drawingml/2006/main" />
39+
var dx2 = ss * 3 / 8;
40+
//<gd name="g9" fmla="+- vc 0 dx2" xmlns="http://schemas.openxmlformats.org/drawingml/2006/main" />
41+
var g9 = vc + 0 - dx2;
42+
//<gd name="g10" fmla="+- vc dx2 0" xmlns="http://schemas.openxmlformats.org/drawingml/2006/main" />
43+
var g10 = vc + dx2 - 0;
44+
//<gd name="g11" fmla="+- hc 0 dx2" xmlns="http://schemas.openxmlformats.org/drawingml/2006/main" />
45+
var g11 = hc + 0 - dx2;
46+
//<gd name="g12" fmla="+- hc dx2 0" xmlns="http://schemas.openxmlformats.org/drawingml/2006/main" />
47+
var g12 = hc + dx2 - 0;
48+
49+
//<pathLst xmlns="http://schemas.openxmlformats.org/drawingml/2006/main">
50+
// <path stroke="false" extrusionOk="false">
51+
// <moveTo>
52+
// <pt x="l" y="t" />
53+
// </moveTo>
54+
// <lnTo>
55+
// <pt x="r" y="t" />
56+
// </lnTo>
57+
// <lnTo>
58+
// <pt x="r" y="b" />
59+
// </lnTo>
60+
// <lnTo>
61+
// <pt x="l" y="b" />
62+
// </lnTo>
63+
// <close />
64+
// <moveTo>
65+
// <pt x="g11" y="vc" />
66+
// </moveTo>
67+
// <lnTo>
68+
// <pt x="g12" y="g9" />
69+
// </lnTo>
70+
// <lnTo>
71+
// <pt x="g12" y="g10" />
72+
// </lnTo>
73+
// <close />
74+
// </path>
75+
// <path stroke="false" fill="darken" extrusionOk="false">
76+
// <moveTo>
77+
// <pt x="g11" y="vc" />
78+
// </moveTo>
79+
// <lnTo>
80+
// <pt x="g12" y="g9" />
81+
// </lnTo>
82+
// <lnTo>
83+
// <pt x="g12" y="g10" />
84+
// </lnTo>
85+
// <close />
86+
// </path>
87+
// <path fill="none" extrusionOk="false">
88+
// <moveTo>
89+
// <pt x="g11" y="vc" />
90+
// </moveTo>
91+
// <lnTo>
92+
// <pt x="g12" y="g9" />
93+
// </lnTo>
94+
// <lnTo>
95+
// <pt x="g12" y="g10" />
96+
// </lnTo>
97+
// <close />
98+
// </path>
99+
// <path fill="none">
100+
// <moveTo>
101+
// <pt x="l" y="t" />
102+
// </moveTo>
103+
// <lnTo>
104+
// <pt x="r" y="t" />
105+
// </lnTo>
106+
// <lnTo>
107+
// <pt x="r" y="b" />
108+
// </lnTo>
109+
// <lnTo>
110+
// <pt x="l" y="b" />
111+
// </lnTo>
112+
// <close />
113+
// </path>
114+
//</pathLst>
115+
116+
var shapePaths = new ShapePath[4];
117+
118+
// <path stroke="false"extrusionOk="false">
119+
//<moveTo xmlns="http://schemas.openxmlformats.org/drawingml/2006/main">
120+
// <pt x="l" y="t" />
121+
//</moveTo>
122+
var currentPoint = new EmuPoint(l, t);
123+
var stringPath = new StringBuilder();
124+
stringPath.Append($"M {EmuToPixelString(currentPoint.X)},{EmuToPixelString(currentPoint.Y)} ");
125+
//<lnTo xmlns="http://schemas.openxmlformats.org/drawingml/2006/main">
126+
// <pt x="r" y="t" />
127+
//</lnTo>
128+
currentPoint = LineToToString(stringPath, r, t);
129+
//<lnTo xmlns="http://schemas.openxmlformats.org/drawingml/2006/main">
130+
// <pt x="r" y="b" />
131+
//</lnTo>
132+
currentPoint = LineToToString(stringPath, r, b);
133+
//<lnTo xmlns="http://schemas.openxmlformats.org/drawingml/2006/main">
134+
// <pt x="l" y="b" />
135+
//</lnTo>
136+
currentPoint = LineToToString(stringPath, l, b);
137+
//<close xmlns="http://schemas.openxmlformats.org/drawingml/2006/main" />
138+
stringPath.Append("z ");
139+
//<moveTo xmlns="http://schemas.openxmlformats.org/drawingml/2006/main">
140+
// <pt x="g11" y="vc" />
141+
//</moveTo>
142+
currentPoint = new EmuPoint(g11, vc);
143+
stringPath.Append($"M {EmuToPixelString(currentPoint.X)},{EmuToPixelString(currentPoint.Y)} ");
144+
//<lnTo xmlns="http://schemas.openxmlformats.org/drawingml/2006/main">
145+
// <pt x="g12" y="g9" />
146+
//</lnTo>
147+
currentPoint = LineToToString(stringPath, g12, g9);
148+
//<lnTo xmlns="http://schemas.openxmlformats.org/drawingml/2006/main">
149+
// <pt x="g12" y="g10" />
150+
//</lnTo>
151+
currentPoint = LineToToString(stringPath, g12, g10);
152+
//<close xmlns="http://schemas.openxmlformats.org/drawingml/2006/main" />
153+
stringPath.Append("z ");
154+
shapePaths[0] = new ShapePath(stringPath.ToString(), isStroke: false);
155+
156+
157+
// <path stroke="false"fill="darken"extrusionOk="false">
158+
//<moveTo xmlns="http://schemas.openxmlformats.org/drawingml/2006/main">
159+
// <pt x="g11" y="vc" />
160+
//</moveTo>
161+
currentPoint = new EmuPoint(g11, vc);
162+
stringPath.Clear();
163+
stringPath.Append($"M {EmuToPixelString(currentPoint.X)},{EmuToPixelString(currentPoint.Y)} ");
164+
//<lnTo xmlns="http://schemas.openxmlformats.org/drawingml/2006/main">
165+
// <pt x="g12" y="g9" />
166+
//</lnTo>
167+
currentPoint = LineToToString(stringPath, g12, g9);
168+
//<lnTo xmlns="http://schemas.openxmlformats.org/drawingml/2006/main">
169+
// <pt x="g12" y="g10" />
170+
//</lnTo>
171+
currentPoint = LineToToString(stringPath, g12, g10);
172+
//<close xmlns="http://schemas.openxmlformats.org/drawingml/2006/main" />
173+
stringPath.Append("z ");
174+
shapePaths[1] = new ShapePath(stringPath.ToString(), PathFillModeValues.Darken, isStroke: false);
175+
176+
177+
// <path fill="none"extrusionOk="false">
178+
//<moveTo xmlns="http://schemas.openxmlformats.org/drawingml/2006/main">
179+
// <pt x="g11" y="vc" />
180+
//</moveTo>
181+
currentPoint = new EmuPoint(g11, vc);
182+
stringPath.Clear();
183+
stringPath.Append($"M {EmuToPixelString(currentPoint.X)},{EmuToPixelString(currentPoint.Y)} ");
184+
//<lnTo xmlns="http://schemas.openxmlformats.org/drawingml/2006/main">
185+
// <pt x="g12" y="g9" />
186+
//</lnTo>
187+
currentPoint = LineToToString(stringPath, g12, g9);
188+
//<lnTo xmlns="http://schemas.openxmlformats.org/drawingml/2006/main">
189+
// <pt x="g12" y="g10" />
190+
//</lnTo>
191+
currentPoint = LineToToString(stringPath, g12, g10);
192+
//<close xmlns="http://schemas.openxmlformats.org/drawingml/2006/main" />
193+
stringPath.Append("z ");
194+
shapePaths[2] = new ShapePath(stringPath.ToString(), PathFillModeValues.None);
195+
196+
197+
// <path fill="none">
198+
//<moveTo xmlns="http://schemas.openxmlformats.org/drawingml/2006/main">
199+
// <pt x="l" y="t" />
200+
//</moveTo>
201+
currentPoint = new EmuPoint(l, t);
202+
stringPath.Clear();
203+
stringPath.Append($"M {EmuToPixelString(currentPoint.X)},{EmuToPixelString(currentPoint.Y)} ");
204+
//<lnTo xmlns="http://schemas.openxmlformats.org/drawingml/2006/main">
205+
// <pt x="r" y="t" />
206+
//</lnTo>
207+
currentPoint = LineToToString(stringPath, r, t);
208+
//<lnTo xmlns="http://schemas.openxmlformats.org/drawingml/2006/main">
209+
// <pt x="r" y="b" />
210+
//</lnTo>
211+
currentPoint = LineToToString(stringPath, r, b);
212+
//<lnTo xmlns="http://schemas.openxmlformats.org/drawingml/2006/main">
213+
// <pt x="l" y="b" />
214+
//</lnTo>
215+
currentPoint = LineToToString(stringPath, l, b);
216+
//<close xmlns="http://schemas.openxmlformats.org/drawingml/2006/main" />
217+
stringPath.Append("z ");
218+
shapePaths[3] = new ShapePath(stringPath.ToString(), PathFillModeValues.None);
219+
220+
221+
//<rect l="l" t="t" r="r" b="b" xmlns="http://schemas.openxmlformats.org/drawingml/2006/main" />
222+
InitializeShapeTextRectangle(l, t, r, b);
223+
224+
return shapePaths;
225+
}
226+
}
227+
228+
229+
}
230+

0 commit comments

Comments
 (0)