Skip to content

Commit cee2f62

Browse files
authored
Merge pull request #4 from albyoo/features/border-radius
Rename corner-radius to border-radius & Implement Skia border-radius.
2 parents 2d92052 + e11379e commit cee2f62

File tree

12 files changed

+180
-170
lines changed

12 files changed

+180
-170
lines changed

Source/Demos/HtmlRenderer.Demo.Common/DemoUtils.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public static string GetStylesheet(string src)
7474
a:link { text-decoration: none; }
7575
a:hover { text-decoration: underline; }
7676
.gray { color:gray; }
77-
.example { background-color:#efefef; corner-radius:5px; padding:0.5em; }
78-
.whitehole { background-color:white; corner-radius:10px; padding:15px; }
77+
.example { background-color:#efefef; border-radius:5px; padding:0.5em; }
78+
.whitehole { background-color:white; border-radius:10px; padding:15px; }
7979
.caption { font-size: 1.1em }
8080
.comment { color: green; margin-bottom: 5px; margin-left: 3px; }
8181
.comment2 { color: green; }";

Source/Demos/HtmlRenderer.Demo.Common/Samples/07.Additional features.htm

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@
2727
vertical-align: middle;
2828
}
2929

30-
.c1 { corner-radius: 0px; }
30+
.c1 { border-radius: 0px; }
3131

32-
.c2 { corner-radius: 10px; }
32+
.c2 { border-radius: 10px; }
3333

34-
.c3 { corner-radius: 0px 10px 10px 0px; }
34+
.c3 { border-radius: 0px 10px 10px 0px; }
3535

36-
.c4 { corner-radius: 18px; }
36+
.c4 { border-radius: 18px; }
3737

3838
.c5 {
39-
corner-radius: 10px;
39+
border-radius: 10px;
4040
border: outset #BBBB00 2px;
4141
}
4242

@@ -121,15 +121,15 @@ <h3>
121121
<p>
122122
In this renderer, the rounded corners are achieved by adding this CSS properties:</p>
123123
<ul>
124-
<li><code>corner-ne-radius: (length)</code> Indicates the radius of the north-east corner.
124+
<li><code>border-top-right-radius: (length)</code> Indicates the radius of the top-right corner.
125125
Not ineritted</li>
126-
<li><code>corner-se-radius: (length)</code> Indicates the radius of the south-east corner.
126+
<li><code>border-bottom-right-radius: (length)</code> Indicates the radius of the bottom-right corner.
127127
Not ineritted</li>
128-
<li><code>corner-sw-radius: (length)</code> Indicates the radius of the south-west corner.
128+
<li><code>border-bottom-left-radius: (length)</code> Indicates the radius of the bottom-left corner.
129129
Not ineritted</li>
130-
<li><code>corner-nw-radius: (length)</code> Indicates the radius of the north-west corner.
130+
<li><code>border-top-left-radius: (length)</code> Indicates the radius of the top-left corner.
131131
Not ineritted</li>
132-
<li><code>corner-radius: (length){1,4}</code> Shorthand for the other corner properties.
132+
<li><code>border-radius: (length){1,4}</code> Shorthand for the other corner properties.
133133
Not ineritted</li>
134134
</ul>
135135
<!-- Corners table -->
@@ -160,11 +160,11 @@ <h3>
160160
</tr>
161161
</table>
162162
<pre>.c1, .c2, .c3, .c4, .c5 { background-color:olive; border:0px; color:white; vertical-align:middle; }
163-
.c1 { corner-radius: 0px }
164-
.c2 { corner-radius: 10px }
165-
.c3 { corner-radius: 0px 10px 10px 0px }
166-
.c4 { corner-radius: 18px }
167-
.c5 { corner-radius: 10px; border: outset #bb0 2px; }</pre>
163+
.c1 { border-radius: 0px }
164+
.c2 { border-radius: 10px }
165+
.c3 { border-radius: 0px 10px 10px 0px }
166+
.c4 { border-radius: 18px }
167+
.c5 { border-radius: 10px; border: outset #bb0 2px; }</pre>
168168
</blockquote>
169169
</body>
170170
</html>

Source/Demos/HtmlRenderer.Demo.Common/TestSamples/16.Borders.htm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
</div>
1313
</p>
1414
<p>
15-
<div style="padding: 5px; border: 1px solid black; corner-radius: 5px;">
16-
border 1px with corner-radius 5px
15+
<div style="padding: 5px; border: 1px solid black; border-radius: 5px;">
16+
border 1px with border-radius 5px
1717
</div>
1818
</p>
1919
<p>
20-
<div style="padding: 5px; border: 2px solid black; corner-radius: 10px;">
21-
border 2px with corner-radius 10px
20+
<div style="padding: 5px; border: 2px solid black; border-radius: 10px;">
21+
border 2px with border-radius 10px
2222
</div>
2323
</p>
2424
<p>
@@ -37,8 +37,8 @@
3737
</div>
3838
</p>
3939
<p>
40-
<div style="padding: 5px; border: 2px dashed darkred; corner-radius: 10px;">
41-
dashed border 2px with corner-radius 10px
40+
<div style="padding: 5px; border: 2px dashed darkred; border-radius: 10px;">
41+
dashed border 2px with border-radius 10px
4242
</div>
4343
</p>
4444
</div>

Source/Demos/HtmlRenderer.Demo.Console/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
}
1212

1313
//Probably won't be running a suite of tests more than once a second, so this will do.
14-
string runIdentifier = DateTime.Now.ToString("ddMMyyyy-hhmmss");
14+
string runIdentifier = DateTime.Now.ToString("yyyyMMdd-hhmmss");
1515

1616
var skia = new SkiaConverter(runIdentifier, basePath);
1717
var pdfSharp = new PdfSharpCoreConverter(runIdentifier, basePath);

Source/HtmlRenderer.SkiaSharp/Adapters/GraphicsAdapter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
namespace TheArtOfDev.HtmlRenderer.SkiaSharp.Adapters
2121
{
2222
/// <summary>
23-
/// Adapter for WinForms Graphics for core.
23+
/// Adapter for Skia Graphics for core.
2424
/// </summary>
2525
internal sealed class GraphicsAdapter : RGraphics
2626
{

Source/HtmlRenderer.SkiaSharp/Adapters/GraphicsPathAdapter.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@
1919
namespace TheArtOfDev.HtmlRenderer.SkiaSharp.Adapters
2020
{
2121
/// <summary>
22-
/// Adapter for WinForms graphics path object for core.
22+
/// Adapter for Skia graphics path object for core.
2323
/// </summary>
2424
internal sealed class GraphicsPathAdapter : RGraphicsPath
2525
{
2626
/// <summary>
27-
/// The actual PdfSharp graphics path instance.
27+
/// The actual SKPath graphics path instance.
2828
/// </summary>
29-
private readonly SKPath _graphicsPath = new SKPath();
29+
private readonly SKPath _graphicsPath = new();
3030

3131
/// <summary>
3232
/// the last point added to the path to begin next segment from
3333
/// </summary>
3434
private RPoint _lastPoint;
3535

3636
/// <summary>
37-
/// The actual PdfSharp graphics path instance.
37+
/// The actual SKPath graphics path instance.
3838
/// </summary>
3939
public SKPath GraphicsPath
4040
{
@@ -44,6 +44,7 @@ public SKPath GraphicsPath
4444
public override void Start(double x, double y)
4545
{
4646
_lastPoint = new RPoint(x, y);
47+
_graphicsPath.MoveTo((float)x, (float)y);
4748
}
4849

4950
public override void LineTo(double x, double y)
@@ -56,12 +57,16 @@ public override void ArcTo(double x, double y, double size, Corner corner)
5657
{
5758
float left = (float)(Math.Min(x, _lastPoint.X) - (corner == Corner.TopRight || corner == Corner.BottomRight ? size : 0));
5859
float top = (float)(Math.Min(y, _lastPoint.Y) - (corner == Corner.BottomLeft || corner == Corner.BottomRight ? size : 0));
59-
_graphicsPath.ArcTo(left, top, (float)size * 2, (float)size * 2, GetStartAngle(corner));
60+
61+
var rect = SKRect.Create(left, top, (float)size * 2, (float)size * 2);
62+
_graphicsPath.ArcTo(rect, GetStartAngle(corner), 90f, false);
6063
_lastPoint = new RPoint(x, y);
6164
}
6265

6366
public override void Dispose()
64-
{ }
67+
{
68+
_graphicsPath.Dispose();
69+
}
6570

6671
/// <summary>
6772
/// Get arc start angle for the given corner.

Source/HtmlRenderer.SkiaSharp/Adapters/SkiaSharpAdapter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ protected override RColor GetColorInt(string colorName)
7575

7676
protected override RPen CreatePen(RColor color)
7777
{
78-
return new PenAdapter(new SKPaint { Color = Utils.Convert(color) });
78+
return new PenAdapter(new SKPaint { Color = Utils.Convert(color), IsStroke = true });
7979
}
8080

8181
protected override RBrush CreateSolidBrush(RColor color)

Source/HtmlRenderer/Core/Dom/CssBox.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ protected void PaintBackground(RGraphics g, RRect rect, bool isFirst, bool isLas
13461346
RGraphicsPath roundrect = null;
13471347
if (IsRounded)
13481348
{
1349-
roundrect = RenderUtils.GetRoundRect(g, rect, ActualCornerNw, ActualCornerNe, ActualCornerSe, ActualCornerSw);
1349+
roundrect = RenderUtils.GetRoundRect(g, rect, ActualBorderRadiusTopLeft, ActualBorderRadiusTopRight, ActualBorderRadiusBottomRight, ActualBorderRadiusBottomLeft);
13501350
}
13511351

13521352
Object prevMode = null;

0 commit comments

Comments
 (0)