Skip to content

Commit b56645c

Browse files
committed
Initial Interfaces added
1 parent a453a3b commit b56645c

16 files changed

+46
-28
lines changed

src/AngleSharp.Css/DefaultRenderDevice.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,10 @@ public Int32 ViewPortWidth
9090
get;
9191
set;
9292
} = 0;
93+
94+
//todo
95+
public int RenderWidth { get; set; }
96+
public int RenderHeight { get; set; }
97+
public double FontSize { get; set; }
9398
}
9499
}

src/AngleSharp.Css/Extensions/CssValueExtensions.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ public static Double AsDouble(this ICssValue value)
4141
/// </summary>
4242
/// <param name="value">The value to convert.</param>
4343
/// <returns>The resulting number.</returns>
44-
public static Double AsPx(this ICssValue value)
44+
public static Double AsPx(this ICssValue value, IRenderDimensions renderDimensions)
4545
{
4646
if (value is Length length && length.Type != Length.Unit.None)
4747
{
48-
return length.ToPixel();
48+
return length.ToPixel(renderDimensions);
4949
}
5050
else if (value is ICssMultipleValue multiple && multiple.Count == 1)
5151
{
52-
return multiple[0].AsPx();
52+
return multiple[0].AsPx(renderDimensions);
5353
}
5454
else if (value is ICssSpecialValue special && special.Value != null)
5555
{
56-
return special.Value.AsPx();
56+
return special.Value.AsPx(renderDimensions);
5757
}
5858

5959
return 0.0;
@@ -202,19 +202,19 @@ public static String AsUrl(this ICssValue value)
202202
/// </summary>
203203
/// <param name="value">The value to convert.</param>
204204
/// <returns>The resulting matrix.</returns>
205-
public static TransformMatrix AsMatrix(this ICssValue value)
205+
public static TransformMatrix AsMatrix(this ICssValue value, IRenderDimensions dimensions)
206206
{
207207
if (value is ICssTransformFunctionValue res)
208208
{
209-
return res.ComputeMatrix();
209+
return res.ComputeMatrix(dimensions);
210210
}
211211
else if (value is ICssMultipleValue multiple && multiple.Count == 1)
212212
{
213-
return multiple[0].AsMatrix();
213+
return multiple[0].AsMatrix(dimensions);
214214
}
215215
else if (value is ICssSpecialValue special && special.Value != null)
216216
{
217-
return special.Value.AsMatrix();
217+
return special.Value.AsMatrix(dimensions);
218218
}
219219

220220
return null;

src/AngleSharp.Css/FeatureValidators/DeviceHeightFeatureValidator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public Boolean Validate(IMediaFeature feature, IRenderDevice device)
1313

1414
if (length != null)
1515
{
16-
var desired = length.AsPx();
16+
var desired = length.AsPx(device);
1717
var available = (Double)device.DeviceHeight;
1818

1919
if (feature.IsMaximum)

src/AngleSharp.Css/FeatureValidators/DeviceWidthFeatureValidator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public Boolean Validate(IMediaFeature feature, IRenderDevice device)
1313

1414
if (length != null)
1515
{
16-
var desired = length.AsPx();
16+
var desired = length.AsPx(device);
1717
var available = (Double)device.DeviceWidth;
1818

1919
if (feature.IsMaximum)

src/AngleSharp.Css/FeatureValidators/HeightFeatureValidator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public Boolean Validate(IMediaFeature feature, IRenderDevice device)
1313

1414
if (length != null)
1515
{
16-
var desired = length.AsPx();
16+
var desired = length.AsPx(device);
1717
var available = (Double)device.ViewPortHeight;
1818

1919
if (feature.IsMaximum)

src/AngleSharp.Css/FeatureValidators/WidthFeatureValidator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public Boolean Validate(IMediaFeature feature, IRenderDevice device)
1313

1414
if (length != null)
1515
{
16-
var desired = length.AsPx();
16+
var desired = length.AsPx(device);
1717
var available = (Double)device.ViewPortWidth;
1818

1919
if (feature.IsMaximum)

src/AngleSharp.Css/IRenderDevice.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace AngleSharp.Css
55
/// <summary>
66
/// Represents the renderers setting.
77
/// </summary>
8-
public interface IRenderDevice
8+
public interface IRenderDevice : IRenderDimensions
99
{
1010
/// <summary>
1111
/// Gets the width of the viewport in pixels.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace AngleSharp.Css
4+
{
5+
public interface IRenderDimensions
6+
{
7+
Int32 RenderWidth { get; set; }
8+
Int32 RenderHeight { get; set; }
9+
double FontSize { get; set; }
10+
}
11+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public ICssValue[] Arguments
7070
/// Returns the stored matrix.
7171
/// </summary>
7272
/// <returns>The current transformation.</returns>
73-
public TransformMatrix ComputeMatrix()
73+
public TransformMatrix ComputeMatrix(IRenderDimensions dimensions)
7474
{
7575
var values = _values;
7676

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ internal CssPerspectiveValue(ICssValue distance)
5454
/// Computes the matrix for the given transformation.
5555
/// </summary>
5656
/// <returns>The transformation matrix representation.</returns>
57-
public TransformMatrix ComputeMatrix()
57+
public TransformMatrix ComputeMatrix(IRenderDimensions renderDimensions)
5858
{
5959
var distance = _distance as Length? ?? Length.Zero;
60-
return new TransformMatrix(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0 / distance.ToPixel());
60+
return new TransformMatrix(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0 / distance.ToPixel(renderDimensions));
6161
}
6262

6363
#endregion

0 commit comments

Comments
 (0)