Skip to content

Commit 3b60235

Browse files
committed
Fix build on .NET Framework due to Math.Clamp
1 parent d721927 commit 3b60235

File tree

3 files changed

+102
-3
lines changed

3 files changed

+102
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
## 0.16.0 - not released yet
1+
## 0.16.0 - 2025.10.26
22

33
- Support shape type and outline color/width for pictures in DOCX to RTF converter
44
(some issues remaining with inline pictures: line color might not be correct and line dash style is not preserved)
55
- Support custom dash styles for shape outlines in DOCX to RTF converter
6+
- Fix table grid iteration and bounds checks in DOC converter (PR [#14](https://github.com/manfromarce/DocSharp/pull/14))
67

78
## 0.15.0 - 2025.09.12
89

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
using System;
2+
using System.Globalization;
3+
4+
namespace DocSharp.Binary.Tools
5+
{
6+
public static class MathHelper
7+
{
8+
/// <summary>
9+
/// Alternative to Math.Clamp for .NET Framework / .NET Standard compatibility
10+
/// </summary>
11+
/// <param name="val"></param>
12+
/// <param name="min"></param>
13+
/// <param name="max"></param>
14+
/// <returns></returns>
15+
public static int Clamp(int val, int min, int max)
16+
{
17+
return (val < min) ? min : (val > max) ? max : val;
18+
}
19+
20+
/// <summary>
21+
/// Alternative to Math.Clamp for .NET Framework / .NET Standard compatibility
22+
/// </summary>
23+
/// <param name="val"></param>
24+
/// <param name="min"></param>
25+
/// <param name="max"></param>
26+
/// <returns></returns>
27+
/// <remarks>Overload for double values</remarks>
28+
public static double Clamp(double val, double min, double max)
29+
{
30+
return (val < min) ? min : (val > max) ? max : val;
31+
}
32+
33+
/// <summary>
34+
/// Alternative to Math.Clamp for .NET Framework / .NET Standard compatibility
35+
/// </summary>
36+
/// <param name="val"></param>
37+
/// <param name="min"></param>
38+
/// <param name="max"></param>
39+
/// <returns></returns>
40+
/// <remarks>Overload for float values</remarks>
41+
public static float Clamp(float val, float min, float max)
42+
{
43+
return (val < min) ? min : (val > max) ? max : val;
44+
}
45+
46+
/// <summary>
47+
/// Alternative to Math.Clamp for .NET Framework / .NET Standard compatibility
48+
/// </summary>
49+
/// <param name="val"></param>
50+
/// <param name="min"></param>
51+
/// <param name="max"></param>
52+
/// <returns></returns>
53+
/// <remarks>Overload for decimal values</remarks>
54+
public static decimal Clamp(decimal val, decimal min, decimal max)
55+
{
56+
return (val < min) ? min : (val > max) ? max : val;
57+
}
58+
59+
/// <summary>
60+
/// Alternative to Math.Clamp for .NET Framework / .NET Standard compatibility
61+
/// </summary>
62+
/// <param name="val"></param>
63+
/// <param name="min"></param>
64+
/// <param name="max"></param>
65+
/// <returns></returns>
66+
/// <remarks>Overload for uint values</remarks>
67+
public static uint Clamp(uint val, uint min, uint max)
68+
{
69+
return (val < min) ? min : (val > max) ? max : val;
70+
}
71+
72+
/// <summary>
73+
/// Alternative to Math.Clamp for .NET Framework / .NET Standard compatibility
74+
/// </summary>
75+
/// <param name="val"></param>
76+
/// <param name="min"></param>
77+
/// <param name="max"></param>
78+
/// <returns></returns>
79+
/// <remarks>Overload for long values</remarks>
80+
public static long Clamp(long val, long min, long max)
81+
{
82+
return (val < min) ? min : (val > max) ? max : val;
83+
}
84+
85+
/// <summary>
86+
/// Alternative to Math.Clamp for .NET Framework / .NET Standard compatibility
87+
/// </summary>
88+
/// <param name="val"></param>
89+
/// <param name="min"></param>
90+
/// <param name="max"></param>
91+
/// <returns></returns>
92+
/// <remarks>Overload for ulong values</remarks>
93+
public static ulong Clamp(ulong val, ulong min, ulong max)
94+
{
95+
return (val < min) ? min : (val > max) ? max : val;
96+
}
97+
}
98+
}

src/DocSharp.Binary/DocSharp.Binary.Doc/WordprocessingMLMapping/TableCellPropertiesMapping.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void Apply(TablePropertyExceptions tapx)
7070
this._tGrid = tdef.rgdxaCenter;
7171

7272
// Bounds check to prevent array out of range exceptions
73-
int cellDefIndex = Math.Clamp(this._cellIndex, 0, Math.Max(0, tdef.rgTc80.Length - 1));
73+
int cellDefIndex = MathHelper.Clamp(this._cellIndex, 0, Math.Max(0, tdef.rgTc80.Length - 1));
7474
this._tcDef = tdef.rgTc80.Length > 0 ? tdef.rgTc80[cellDefIndex] : new TC80();
7575

7676
appendValueElement(this._tcPr, "textDirection", this._tcDef.textFlow.ToString(), false);
@@ -94,7 +94,7 @@ public void Apply(TablePropertyExceptions tapx)
9494
// Bounds check to prevent array out of range exceptions
9595
if (tdef.rgdxaCenter.Length >= 2)
9696
{
97-
int widthIndex = Math.Clamp(this._cellIndex, 0, tdef.rgdxaCenter.Length - 2);
97+
int widthIndex = MathHelper.Clamp(this._cellIndex, 0, tdef.rgdxaCenter.Length - 2);
9898
this._width = (short)(tdef.rgdxaCenter[widthIndex + 1] - tdef.rgdxaCenter[widthIndex]);
9999
}
100100
else

0 commit comments

Comments
 (0)