Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite Line Breaker. #438

Merged
merged 11 commits into from
Jan 8, 2025
4 changes: 3 additions & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ jobs:
if: failure()
with:
name: actual_output_${{ runner.os }}_${{ matrix.options.framework }}${{ matrix.options.runtime }}.zip
path: tests/Images/ActualOutput/
path: |
tests/Images/ActualOutput/
**/msbuild.binlog

- name: Codecov Update
uses: codecov/codecov-action@v4
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ paket-files/
*.sln.iml
/samples/DrawWithImageSharp/Output

# Tests
**/Images/ActualOutput
/tests/CodeCoverage/OpenCover.*
SixLabors.Shapes.Coverage.xml
/SixLabors.Fonts.Coverage.xml
Expand Down
2 changes: 1 addition & 1 deletion ci-build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ dotnet clean -c Release
$repositoryUrl = "https://github.com/$env:GITHUB_REPOSITORY"

# Building for a specific framework.
dotnet build -c Release -f $targetFramework /p:RepositoryUrl=$repositoryUrl
dotnet build -c Release -f $targetFramework /p:RepositoryUrl=$repositoryUrl -bl
3 changes: 3 additions & 0 deletions src/SixLabors.Fonts/SixLabors.Fonts.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<PropertyGroup>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>

<!--Temporarily disable the COM analyzer to work around build issue.-->
<NoWarn>$(NoWarn);IL2050;</NoWarn>
</PropertyGroup>

<PropertyGroup>
Expand Down
436 changes: 224 additions & 212 deletions src/SixLabors.Fonts/TextLayout.cs

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions tests/SixLabors.Fonts.Tests/ImageComparison/ExactImageComparer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.

using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;

namespace SixLabors.Fonts.Tests.ImageComparison;

public class ExactImageComparer : ImageComparer
{
public static ExactImageComparer Instance { get; } = new ExactImageComparer();

public override ImageSimilarityReport<TPixelA, TPixelB> CompareImagesOrFrames<TPixelA, TPixelB>(
int index,
ImageFrame<TPixelA> expected,
ImageFrame<TPixelB> actual)
{
if (expected.Size != actual.Size)
{
throw new InvalidOperationException("Calling ImageComparer is invalid when dimensions mismatch!");
}

int width = actual.Width;

// TODO: Comparing through Rgba64 may not be robust enough because of the existence of super high precision pixel types.
Rgba64[] aBuffer = new Rgba64[width];
Rgba64[] bBuffer = new Rgba64[width];

List<PixelDifference> differences = new();
Configuration configuration = expected.Configuration;
Buffer2D<TPixelA> expectedBuffer = expected.PixelBuffer;
Buffer2D<TPixelB> actualBuffer = actual.PixelBuffer;

for (int y = 0; y < actual.Height; y++)
{
Span<TPixelA> aSpan = expectedBuffer.DangerousGetRowSpan(y);
Span<TPixelB> bSpan = actualBuffer.DangerousGetRowSpan(y);

PixelOperations<TPixelA>.Instance.ToRgba64(configuration, aSpan, aBuffer);
PixelOperations<TPixelB>.Instance.ToRgba64(configuration, bSpan, bBuffer);

for (int x = 0; x < width; x++)
{
Rgba64 aPixel = aBuffer[x];
Rgba64 bPixel = bBuffer[x];

if (aPixel != bPixel)
{
PixelDifference diff = new(new Point(x, y), aPixel, bPixel);
differences.Add(diff);
}
}
}

return new ImageSimilarityReport<TPixelA, TPixelB>(index, expected, actual, differences);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.

using System.Globalization;
using System.Text;

namespace SixLabors.Fonts.Tests.ImageComparison;

public class ImageDifferenceIsOverThresholdException : ImagesSimilarityException
{
public ImageSimilarityReport[] Reports { get; }

public ImageDifferenceIsOverThresholdException(params ImageSimilarityReport[] reports)
: base("Image difference is over threshold!" + FormatReports(reports))
=> this.Reports = reports.ToArray();

private static string FormatReports(IEnumerable<ImageSimilarityReport> reports)
{
StringBuilder sb = new();

sb.Append(Environment.NewLine);
sb.AppendFormat(CultureInfo.InvariantCulture, "Test Environment OS : {0}", GetEnvironmentName());
sb.Append(Environment.NewLine);

sb.AppendFormat(CultureInfo.InvariantCulture, "Test Environment is CI : {0}", TestEnvironment.RunsOnCI);
sb.Append(Environment.NewLine);

sb.AppendFormat(CultureInfo.InvariantCulture, "Test Environment OS Architecture : {0}", TestEnvironment.OSArchitecture);
sb.Append(Environment.NewLine);

sb.AppendFormat(CultureInfo.InvariantCulture, "Test Environment Process Architecture : {0}", TestEnvironment.ProcessArchitecture);
sb.Append(Environment.NewLine);

foreach (ImageSimilarityReport r in reports)
{
sb.AppendFormat(CultureInfo.InvariantCulture, "Report ImageFrame {0}: ", r.Index)
.Append(r)
.Append(Environment.NewLine);
}

return sb.ToString();
}

private static string GetEnvironmentName()
{
if (TestEnvironment.IsMacOS)
{
return "MacOS";
}

if (TestEnvironment.IsLinux)
{
return "Linux";
}

if (TestEnvironment.IsWindows)
{
return "Windows";
}

return "Unknown";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.

using SixLabors.ImageSharp;

namespace SixLabors.Fonts.Tests.ImageComparison;

public class ImageDimensionsMismatchException : ImagesSimilarityException
{
public ImageDimensionsMismatchException(Size expectedSize, Size actualSize)
: base($"The image dimensions {actualSize} do not match the expected {expectedSize}!")
{
this.ExpectedSize = expectedSize;
this.ActualSize = actualSize;
}

public Size ExpectedSize { get; }

public Size ActualSize { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.

namespace SixLabors.Fonts.Tests.ImageComparison;

using System;

public class ImagesSimilarityException : Exception
{
public ImagesSimilarityException(string message)
: base(message)
{
}
}
Loading
Loading