Skip to content

Commit 9abdd1b

Browse files
committed
Added new metric values
1 parent 8295892 commit 9abdd1b

17 files changed

+517
-54
lines changed

src/AngleSharp.Css/Constants/InitialValues.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,11 @@ static class InitialValues
151151
public static readonly ICssValue ColumnGapDecl = new Constant<Length>(CssKeywords.Normal, Length.Normal);
152152
public static readonly ICssValue RowGapDecl = new Constant<Length>(CssKeywords.Normal, Length.Normal);
153153
public static readonly ICssValue PerspectiveDecl = new Constant<Object>(CssKeywords.None, null);
154-
public static readonly ICssValue PerspectiveOriginDecl = Point.Center;
154+
public static readonly ICssValue PerspectiveOriginDecl = CssPoint2D.Center;
155155
public static readonly ICssValue PositionDecl = new Constant<PositionMode>(CssKeywords.Inline, PositionMode.Static);
156156
public static readonly ICssValue TransformDecl = new Constant<Object>(CssKeywords.None, null);
157157
public static readonly ICssValue TransformStyleDecl = new Constant<Boolean>(CssKeywords.Flat, true);
158-
public static readonly ICssValue TransformOriginDecl = Point.Center;
158+
public static readonly ICssValue TransformOriginDecl = CssPoint2D.Center;
159159
public static readonly ICssValue TableLayoutDecl = new Constant<Boolean>(CssKeywords.Auto, false);
160160
public static readonly ICssValue ClearDecl = new Constant<ClearMode>(CssKeywords.None, ClearMode.None);
161161
public static readonly ICssValue ClipDecl = new Constant<Length>(CssKeywords.Auto, Length.Auto);
@@ -199,7 +199,7 @@ static class InitialValues
199199
public static readonly ICssValue OrphansDecl = new Length(2, Length.Unit.None);
200200
public static readonly ICssValue OrderDecl = new Length(0, Length.Unit.None);
201201
public static readonly ICssValue ObjectFitDecl = new Constant<ObjectFitting>(CssKeywords.Fill, ObjectFitting.Fill);
202-
public static readonly ICssValue ObjectPositionDecl = Point.Center;
202+
public static readonly ICssValue ObjectPositionDecl = CssPoint2D.Center;
203203
public static readonly ICssValue WhiteSpaceDecl = new Constant<Whitespace>(CssKeywords.Normal, Whitespace.Normal);
204204
public static readonly ICssValue ZIndexDecl = new Constant<Length>(CssKeywords.Auto, Length.Auto);
205205
public static readonly ICssValue WidthDecl = Length.Auto;

src/AngleSharp.Css/Declarations/BackgroundDeclaration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public ICssValue Convert(StringSource source)
102102
}
103103

104104
var image = default(ICssImageValue);
105-
var position = default(Point?);
105+
var position = default(CssPoint2D?);
106106
var size = default(CssBackgroundSizeValue);
107107
var repeat = default(CssImageRepeatsValue);
108108
var attachment = default(ICssValue);

src/AngleSharp.Css/Declarations/BackgroundPositionDeclaration.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public ICssValue Merge(ICssValue[] values)
4747

4848
for (var i = 0; i < points.Length; i++)
4949
{
50-
points[i] = new Point(x.Items[i], y.Items[i]);
50+
points[i] = new CssPoint2D(x.Items[i], y.Items[i]);
5151
}
5252

5353
return new CssListValue(points);
@@ -60,7 +60,7 @@ public ICssValue[] Split(ICssValue value)
6060
{
6161
if (value is CssListValue list)
6262
{
63-
var points = list.Items.OfType<Point>();
63+
var points = list.Items.OfType<CssPoint2D>();
6464
var x = points.Select(m => m.X).ToArray();
6565
var y = points.Select(m => m.Y).ToArray();
6666
return new ICssValue[]

src/AngleSharp.Css/Declarations/CursorDeclaration.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ public ICssValue Convert(StringSource source)
4040
break;
4141

4242
source.SkipCurrentAndSpaces();
43-
var position = default(Point?);
43+
var position = default(CssPoint2D?);
4444

4545
if (x.HasValue)
4646
{
4747
var xp = new Length(x.Value, Length.Unit.None);
4848
var yp = new Length(y.Value, Length.Unit.None);
49-
position = new Point(xp, yp);
49+
position = new CssPoint2D(xp, yp);
5050
}
5151

5252
definitions.Add(new CssCustomCursorValue(imageSource, position));

src/AngleSharp.Css/Extensions/StringExtensions.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,36 @@ public static class StringExtensions
1818
/// <returns>The CSS color representation.</returns>
1919
public static String CssColor(this String value)
2020
{
21-
var color = default(Color);
22-
23-
if (Color.TryFromHex(value, out color))
21+
if (Color.TryFromHex(value, out var color))
2422
{
2523
return color.CssText;
2624
}
2725

2826
return value;
2927
}
3028

29+
/// <summary>
30+
/// Parses the integer according to the rules.
31+
/// </summary>
32+
/// <param name="value">The string to parse.</param>
33+
/// <param name="result">The result of parsing the string.</param>
34+
/// <returns>The indicator if the string was indeed an integer.</returns>
35+
public static Boolean CssInteger(this String value, out Int32 result)
36+
{
37+
return Int32.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out result);
38+
}
39+
40+
/// <summary>
41+
/// Parses the number according to the rules.
42+
/// </summary>
43+
/// <param name="value">The string to parse.</param>
44+
/// <param name="result">The result of parsing the string.</param>
45+
/// <returns>The indicator if the string was indeed a number.</returns>
46+
public static Boolean CssNumber(this String value, out Double result)
47+
{
48+
return Double.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out result);
49+
}
50+
3151
/// <summary>
3252
/// Splits the string in a numeric value (result) and a unit. Returns
3353
/// null if the provided string is ill-formatted.
@@ -46,7 +66,7 @@ public static String CssUnit(this String value, out Double result)
4666
// Intentional empty.
4767
}
4868

49-
if (firstLetter > 0 && Double.TryParse(value.Substring(0, firstLetter), NumberStyles.Any, CultureInfo.InvariantCulture, out result))
69+
if (firstLetter > 0 && value.Substring(0, firstLetter).CssNumber(out result))
5070
{
5171
return value.Substring(firstLetter);
5272
}

src/AngleSharp.Css/Parser/Micro/GradientParser.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ private static ICssGradientFunctionValue ParseRadialGradient(StringSource source
125125
if (stops != null && source.Current == Symbols.RoundBracketClose)
126126
{
127127
var circle = options?.Circle ?? false;
128-
var center = options?.Center ?? Point.Center;
128+
var center = options?.Center ?? CssPoint2D.Center;
129129
var width = options?.Width;
130130
var height = options?.Height;
131131
var sizeMode = options?.Size ?? CssRadialGradientValue.SizeMode.None;
@@ -302,7 +302,7 @@ private static ICssValue ParseLinearAngleKeywords(StringSource source)
302302
private static RadialOptions? ParseRadialOptions(StringSource source)
303303
{
304304
var circle = false;
305-
var center = Point.Center;
305+
var center = CssPoint2D.Center;
306306
var width = default(ICssValue);
307307
var height = default(ICssValue);
308308
var size = CssRadialGradientValue.SizeMode.None;
@@ -445,7 +445,7 @@ public struct RadialOptions
445445
/// <summary>
446446
/// Gets or sets the center of the gradient.
447447
/// </summary>
448-
public Point Center;
448+
public CssPoint2D Center;
449449

450450
/// <summary>
451451
/// Gets or sets the width of the gradient.

src/AngleSharp.Css/Parser/Micro/PointParser.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static CssOriginValue ParseOrigin(this StringSource source)
6969
/// <summary>
7070
/// Parses a point value.
7171
/// </summary>
72-
public static Point? ParsePoint(this StringSource source)
72+
public static CssPoint2D? ParsePoint(this StringSource source)
7373
{
7474
var pos = source.Index;
7575
var x = new Length(50f, Length.Unit.Percent);
@@ -91,7 +91,7 @@ public static CssOriginValue ParseOrigin(this StringSource source)
9191
{
9292
x = KeywordToLength(l).Value;
9393
y = KeywordToLength(r).Value;
94-
return new Point(x, y);
94+
return new CssPoint2D(x, y);
9595
}
9696
}
9797
else if (l != null)
@@ -101,12 +101,12 @@ public static CssOriginValue ParseOrigin(this StringSource source)
101101
if (IsHorizontal(l))
102102
{
103103
x = KeywordToLength(l).Value;
104-
return new Point(x, s ?? y);
104+
return new CssPoint2D(x, s ?? y);
105105
}
106106
else if (IsVertical(l))
107107
{
108108
y = KeywordToLength(l).Value;
109-
return new Point(s ?? x, y);
109+
return new CssPoint2D(s ?? x, y);
110110
}
111111
}
112112
else
@@ -117,7 +117,7 @@ public static CssOriginValue ParseOrigin(this StringSource source)
117117

118118
if (s != null)
119119
{
120-
return new Point(f ?? x, s ?? y);
120+
return new CssPoint2D(f ?? x, s ?? y);
121121
}
122122
else if (f != null)
123123
{
@@ -126,22 +126,22 @@ public static CssOriginValue ParseOrigin(this StringSource source)
126126

127127
if (r == null)
128128
{
129-
return new Point(f, y);
129+
return new CssPoint2D(f, y);
130130
}
131131
else if (IsVertical(r))
132132
{
133133
y = KeywordToLength(r).Value;
134-
return new Point(f ?? x, y);
134+
return new CssPoint2D(f ?? x, y);
135135
}
136136
else if (IsHorizontal(r))
137137
{
138138
x = KeywordToLength(r).Value;
139-
return new Point(x, f ?? y);
139+
return new CssPoint2D(x, f ?? y);
140140
}
141141
else
142142
{
143143
source.BackTo(pos);
144-
return new Point(f ?? x, y);
144+
return new CssPoint2D(f ?? x, y);
145145
}
146146
}
147147
}

src/AngleSharp.Css/ValueConverters.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ static class ValueConverters
214214
/// Represents a position object.
215215
/// http://www.w3.org/TR/css3-background/#ltpositiongt
216216
/// </summary>
217-
public static readonly IValueConverter PointConverter = new StructValueConverter<Point>(PointParser.ParsePoint);
217+
public static readonly IValueConverter PointConverter = new StructValueConverter<CssPoint2D>(PointParser.ParsePoint);
218218

219219
/// <summary>
220220
/// Represents an origin (Point3D) object.

src/AngleSharp.Css/Values/Composites/CssCustomCursorValue.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ sealed class CssCustomCursorValue : ICssCompositeValue
99
#region Fields
1010

1111
private readonly ICssImageValue _source;
12-
private readonly Point? _position;
12+
private readonly CssPoint2D? _position;
1313

1414
#endregion
1515

@@ -20,7 +20,7 @@ sealed class CssCustomCursorValue : ICssCompositeValue
2020
/// </summary>
2121
/// <param name="source">The image source to display.</param>
2222
/// <param name="position">The position offset, if any.</param>
23-
public CssCustomCursorValue(ICssImageValue source, Point? position)
23+
public CssCustomCursorValue(ICssImageValue source, CssPoint2D? position)
2424
{
2525
_source = source;
2626
_position = position;
@@ -38,7 +38,7 @@ public CssCustomCursorValue(ICssImageValue source, Point? position)
3838
/// <summary>
3939
/// Gets the positional offset, if any.
4040
/// </summary>
41-
public Point? Position => _position;
41+
public CssPoint2D? Position => _position;
4242

4343
/// <summary>
4444
/// Gets the CSS text representation.
@@ -68,7 +68,7 @@ public String CssText
6868
ICssValue ICssValue.Compute(ICssComputeContext context)
6969
{
7070
var source = (ICssImageValue)_source.Compute(context);
71-
var position = _position.HasValue ? (Point?)((ICssValue)_position.Value).Compute(context) : null;
71+
var position = _position.HasValue ? (CssPoint2D?)((ICssValue)_position.Value).Compute(context) : null;
7272
return new CssCustomCursorValue(source, position);
7373
}
7474

src/AngleSharp.Css/Values/Composites/CssOriginValue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public String CssText
4242
{
4343
get
4444
{
45-
var pt = new Point(_x, _y).CssText;
45+
var pt = new CssPoint2D(_x, _y).CssText;
4646
return _z != null ? String.Concat(pt, " ", _z.CssText) : pt;
4747
}
4848
}

src/AngleSharp.Css/Values/Functions/CssConicGradientValue.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public String CssText
7777
get
7878
{
7979
var defaultAngle = _angle as Angle?;
80-
var defaultPosition = _center as Point?;
80+
var defaultPosition = _center as CssPoint2D?;
8181
var offset = (defaultAngle.HasValue ? 1 : 0) + (defaultPosition.HasValue ? 1 : 0);
8282
var args = new String[_stops.Length + offset];
8383

@@ -108,7 +108,7 @@ public String CssText
108108
/// <summary>
109109
/// Gets the position of the conic gradient.
110110
/// </summary>
111-
public ICssValue Center => _center ?? Point.Center;
111+
public ICssValue Center => _center ?? CssPoint2D.Center;
112112

113113
/// <summary>
114114
/// Gets all stops.

src/AngleSharp.Css/Values/Functions/CssRadialGradientValue.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public sealed class CssRadialGradientValue : ICssGradientFunctionValue
1616
#region Fields
1717

1818
private readonly CssGradientStopValue[] _stops;
19-
private readonly Point _center;
19+
private readonly CssPoint2D _center;
2020
private readonly ICssValue _width;
2121
private readonly ICssValue _height;
2222
private readonly Boolean _repeating;
@@ -37,7 +37,7 @@ public sealed class CssRadialGradientValue : ICssGradientFunctionValue
3737
/// <param name="sizeMode">The size mode of the ellipsoid.</param>
3838
/// <param name="stops">A collection of stops to use.</param>
3939
/// <param name="repeating">The repeating setting.</param>
40-
public CssRadialGradientValue(Boolean circle, Point center, ICssValue width, ICssValue height, SizeMode sizeMode, CssGradientStopValue[] stops, Boolean repeating = false)
40+
public CssRadialGradientValue(Boolean circle, CssPoint2D center, ICssValue width, ICssValue height, SizeMode sizeMode, CssGradientStopValue[] stops, Boolean repeating = false)
4141
{
4242
_stops = stops;
4343
_center = center;
@@ -64,7 +64,7 @@ public ICssValue[] Arguments
6464
{
6565
get
6666
{
67-
var isDefault = _center == Point.Center && !_circle && _height == null && _width == null && _sizeMode == SizeMode.None;
67+
var isDefault = _center == CssPoint2D.Center && !_circle && _height == null && _width == null && _sizeMode == SizeMode.None;
6868
var args = new List<ICssValue>();
6969

7070
if (!isDefault)
@@ -130,7 +130,7 @@ public ICssValue[] Arguments
130130
/// <summary>
131131
/// Gets the position of the radial gradient.
132132
/// </summary>
133-
public Point Position => _center;
133+
public CssPoint2D Position => _center;
134134

135135
/// <summary>
136136
/// Gets the horizontal radius.
@@ -158,7 +158,7 @@ public ICssValue[] Arguments
158158

159159
ICssValue ICssValue.Compute(ICssComputeContext context)
160160
{
161-
var center = (Point)((ICssValue)_center).Compute(context);
161+
var center = (CssPoint2D)((ICssValue)_center).Compute(context);
162162
var width = _width.Compute(context);
163163
var height = _height.Compute(context);
164164
var stops = _stops.Select(m => (CssGradientStopValue)((ICssValue)m).Compute(context)).ToArray();

0 commit comments

Comments
 (0)