Skip to content

Commit bcea187

Browse files
Merge pull request #438 from SixLabors/js/fix-line-break
Rewrite Line Breaker.
2 parents e8d71d4 + 62920ee commit bcea187

File tree

70 files changed

+1508
-336
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1508
-336
lines changed

.github/workflows/build-and-test.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ jobs:
155155
if: failure()
156156
with:
157157
name: actual_output_${{ runner.os }}_${{ matrix.options.framework }}${{ matrix.options.runtime }}.zip
158-
path: tests/Images/ActualOutput/
158+
path: |
159+
tests/Images/ActualOutput/
160+
**/msbuild.binlog
159161
160162
- name: Codecov Update
161163
uses: codecov/codecov-action@v4

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ paket-files/
254254
*.sln.iml
255255
/samples/DrawWithImageSharp/Output
256256

257+
# Tests
258+
**/Images/ActualOutput
257259
/tests/CodeCoverage/OpenCover.*
258260
SixLabors.Shapes.Coverage.xml
259261
/SixLabors.Fonts.Coverage.xml

ci-build.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ dotnet clean -c Release
88
$repositoryUrl = "https://github.com/$env:GITHUB_REPOSITORY"
99

1010
# Building for a specific framework.
11-
dotnet build -c Release -f $targetFramework /p:RepositoryUrl=$repositoryUrl
11+
dotnet build -c Release -f $targetFramework /p:RepositoryUrl=$repositoryUrl -bl

src/SixLabors.Fonts/SixLabors.Fonts.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
<PropertyGroup>
2020
<Nullable>enable</Nullable>
2121
<WarningsAsErrors>Nullable</WarningsAsErrors>
22+
23+
<!--Temporarily disable the COM analyzer to work around build issue.-->
24+
<NoWarn>$(NoWarn);IL2050;</NoWarn>
2225
</PropertyGroup>
2326

2427
<PropertyGroup>

src/SixLabors.Fonts/TextLayout.cs

+224-212
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Six Labors Split License.
3+
4+
using SixLabors.ImageSharp;
5+
using SixLabors.ImageSharp.Memory;
6+
using SixLabors.ImageSharp.PixelFormats;
7+
8+
namespace SixLabors.Fonts.Tests.ImageComparison;
9+
10+
public class ExactImageComparer : ImageComparer
11+
{
12+
public static ExactImageComparer Instance { get; } = new ExactImageComparer();
13+
14+
public override ImageSimilarityReport<TPixelA, TPixelB> CompareImagesOrFrames<TPixelA, TPixelB>(
15+
int index,
16+
ImageFrame<TPixelA> expected,
17+
ImageFrame<TPixelB> actual)
18+
{
19+
if (expected.Size != actual.Size)
20+
{
21+
throw new InvalidOperationException("Calling ImageComparer is invalid when dimensions mismatch!");
22+
}
23+
24+
int width = actual.Width;
25+
26+
// TODO: Comparing through Rgba64 may not be robust enough because of the existence of super high precision pixel types.
27+
Rgba64[] aBuffer = new Rgba64[width];
28+
Rgba64[] bBuffer = new Rgba64[width];
29+
30+
List<PixelDifference> differences = new();
31+
Configuration configuration = expected.Configuration;
32+
Buffer2D<TPixelA> expectedBuffer = expected.PixelBuffer;
33+
Buffer2D<TPixelB> actualBuffer = actual.PixelBuffer;
34+
35+
for (int y = 0; y < actual.Height; y++)
36+
{
37+
Span<TPixelA> aSpan = expectedBuffer.DangerousGetRowSpan(y);
38+
Span<TPixelB> bSpan = actualBuffer.DangerousGetRowSpan(y);
39+
40+
PixelOperations<TPixelA>.Instance.ToRgba64(configuration, aSpan, aBuffer);
41+
PixelOperations<TPixelB>.Instance.ToRgba64(configuration, bSpan, bBuffer);
42+
43+
for (int x = 0; x < width; x++)
44+
{
45+
Rgba64 aPixel = aBuffer[x];
46+
Rgba64 bPixel = bBuffer[x];
47+
48+
if (aPixel != bPixel)
49+
{
50+
PixelDifference diff = new(new Point(x, y), aPixel, bPixel);
51+
differences.Add(diff);
52+
}
53+
}
54+
}
55+
56+
return new ImageSimilarityReport<TPixelA, TPixelB>(index, expected, actual, differences);
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Six Labors Split License.
3+
4+
using System.Globalization;
5+
using System.Text;
6+
7+
namespace SixLabors.Fonts.Tests.ImageComparison;
8+
9+
public class ImageDifferenceIsOverThresholdException : ImagesSimilarityException
10+
{
11+
public ImageSimilarityReport[] Reports { get; }
12+
13+
public ImageDifferenceIsOverThresholdException(params ImageSimilarityReport[] reports)
14+
: base("Image difference is over threshold!" + FormatReports(reports))
15+
=> this.Reports = reports.ToArray();
16+
17+
private static string FormatReports(IEnumerable<ImageSimilarityReport> reports)
18+
{
19+
StringBuilder sb = new();
20+
21+
sb.Append(Environment.NewLine);
22+
sb.AppendFormat(CultureInfo.InvariantCulture, "Test Environment OS : {0}", GetEnvironmentName());
23+
sb.Append(Environment.NewLine);
24+
25+
sb.AppendFormat(CultureInfo.InvariantCulture, "Test Environment is CI : {0}", TestEnvironment.RunsOnCI);
26+
sb.Append(Environment.NewLine);
27+
28+
sb.AppendFormat(CultureInfo.InvariantCulture, "Test Environment OS Architecture : {0}", TestEnvironment.OSArchitecture);
29+
sb.Append(Environment.NewLine);
30+
31+
sb.AppendFormat(CultureInfo.InvariantCulture, "Test Environment Process Architecture : {0}", TestEnvironment.ProcessArchitecture);
32+
sb.Append(Environment.NewLine);
33+
34+
foreach (ImageSimilarityReport r in reports)
35+
{
36+
sb.AppendFormat(CultureInfo.InvariantCulture, "Report ImageFrame {0}: ", r.Index)
37+
.Append(r)
38+
.Append(Environment.NewLine);
39+
}
40+
41+
return sb.ToString();
42+
}
43+
44+
private static string GetEnvironmentName()
45+
{
46+
if (TestEnvironment.IsMacOS)
47+
{
48+
return "MacOS";
49+
}
50+
51+
if (TestEnvironment.IsLinux)
52+
{
53+
return "Linux";
54+
}
55+
56+
if (TestEnvironment.IsWindows)
57+
{
58+
return "Windows";
59+
}
60+
61+
return "Unknown";
62+
}
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Six Labors Split License.
3+
4+
using SixLabors.ImageSharp;
5+
6+
namespace SixLabors.Fonts.Tests.ImageComparison;
7+
8+
public class ImageDimensionsMismatchException : ImagesSimilarityException
9+
{
10+
public ImageDimensionsMismatchException(Size expectedSize, Size actualSize)
11+
: base($"The image dimensions {actualSize} do not match the expected {expectedSize}!")
12+
{
13+
this.ExpectedSize = expectedSize;
14+
this.ActualSize = actualSize;
15+
}
16+
17+
public Size ExpectedSize { get; }
18+
19+
public Size ActualSize { get; }
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Six Labors Split License.
3+
4+
namespace SixLabors.Fonts.Tests.ImageComparison;
5+
6+
using System;
7+
8+
public class ImagesSimilarityException : Exception
9+
{
10+
public ImagesSimilarityException(string message)
11+
: base(message)
12+
{
13+
}
14+
}

0 commit comments

Comments
 (0)